* [edk2-redfish-client][PATCH 3/6] Tool/Redfish-Profile-Simulator: Update patch method of computer system
@ 2023-05-08 14:51 Nickle Wang
2023-05-09 6:06 ` Chang, Abner
0 siblings, 1 reply; 2+ messages in thread
From: Nickle Wang @ 2023-05-08 14:51 UTC (permalink / raw)
To: devel; +Cc: Abner Chang, Igor Kulchytskyy
Remove attribute check during patch of computer system and return
content-type with JSON format in HTTP header.
Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
.../v1sim/resource.py | 4 ++-
.../v1sim/systems.py | 28 +++++++------------
2 files changed, 13 insertions(+), 19 deletions(-)
diff --git a/Tools/Redfish-Profile-Simulator/v1sim/resource.py b/Tools/Redfish-Profile-Simulator/v1sim/resource.py
index ca7541f1..e722d16a 100644
--- a/Tools/Redfish-Profile-Simulator/v1sim/resource.py
+++ b/Tools/Redfish-Profile-Simulator/v1sim/resource.py
@@ -2,6 +2,7 @@
# Copyright Notice:
#
# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
# Copyright Notice:
@@ -47,6 +48,7 @@ class RfResource:
try:
# SHA1 should generate well-behaved etags
response = flask.make_response(self.response)
+ response.mimetype = 'application/json'
etag = hashlib.sha1(self.response.encode('utf-8')).hexdigest()
response.set_etag(etag)
return response
@@ -69,7 +71,7 @@ class RfResource:
else:
raise Exception("attribute %s not found" % key)
- resp = flask.Response(json.dumps(self.res_data,indent=4))
+ resp = flask.Response(json.dumps(self.res_data,indent=4), mimetype="application/json")
return 0, 200, None, resp
def post_resource(self, post_data):
diff --git a/Tools/Redfish-Profile-Simulator/v1sim/systems.py b/Tools/Redfish-Profile-Simulator/v1sim/systems.py
index de4b839a..6305a51e 100644
--- a/Tools/Redfish-Profile-Simulator/v1sim/systems.py
+++ b/Tools/Redfish-Profile-Simulator/v1sim/systems.py
@@ -2,7 +2,7 @@
# Copyright Notice:
#
# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
-# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
+# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
# Copyright Notice:
@@ -63,15 +63,7 @@ class RfSystemObj(RfResource):
self.components[item] = RfBootOptionCollection(base_path, os.path.join(rel_path, item), parent=self)
def patch_resource(self, patch_data):
- # first verify client didn't send us a property we cant patch
- for key in patch_data.keys():
- if key != "AssetTag" and key != "IndicatorLED" and key != "Boot" and key != "BiosVersion":
- return 4, 400, "Invalid Patch Property Sent", ""
- elif key == "Boot":
- for prop2 in patch_data["Boot"].keys():
- if prop2 != "BootSourceOverrideEnabled" and prop2 != "BootSourceOverrideTarget" and prop2 != "BootNext" and prop2 != "BootOrder":
- return 4, 400, "Invalid Patch Property Sent", ""
- # now patch the valid properties sent
+ # patch the valid properties sent
if "AssetTag" in patch_data:
print("assetTag:{}".format(patch_data["AssetTag"]))
self.res_data['AssetTag'] = patch_data['AssetTag']
@@ -100,7 +92,7 @@ class RfSystemObj(RfResource):
if "BootOrder" in boot_data:
self.res_data['Boot']['BootOrder'] = boot_data['BootOrder']
- resp = flask.Response(json.dumps(self.res_data,indent=4))
+ resp = flask.Response(json.dumps(self.res_data,indent=4), mimetype="application/json")
return 0, 200, None, resp
def reset_resource(self, reset_data):
@@ -150,7 +142,7 @@ class RfMemoryCollection(RfCollection):
post_data["@odata.etag"] = etag_str
self.elements[str(newMemoryIdx)] = post_data
- resp = flask.Response(json.dumps(post_data,indent=4))
+ resp = flask.Response(json.dumps(post_data,indent=4), mimetype="application/json")
resp.headers["Location"] = newMemoryUrl
resp.headers["ETag"] = etag_str
@@ -163,7 +155,7 @@ class RfMemoryCollection(RfCollection):
patch_data["@odata.etag"] = etag_str
self.elements[str(Idx)] = {**self.elements[str(Idx)], **patch_data}
- resp = flask.Response(json.dumps(self.elements[str(Idx)],indent=4))
+ resp = flask.Response(json.dumps(self.elements[str(Idx)],indent=4), mimetype="application/json")
return 0, 200, None, resp
def get_memory(self, Idx):
@@ -172,7 +164,7 @@ class RfMemoryCollection(RfCollection):
def delete_memory(self, Idx):
print("in delete_memory")
- resp = flask.Response(json.dumps(self.elements[Idx],indent=4))
+ resp = flask.Response(json.dumps(self.elements[Idx],indent=4), mimetype="application/json")
self.elements.pop(Idx)
self.res_data["Members@odata.count"] = self.res_data["Members@odata.count"] - 1
@@ -228,7 +220,7 @@ class RfBiosSettings(RfResource):
return 4, 400, "Invalid Patch Property Sent", ""
else:
self.res_data["Attributes"][key] = patch_data["Attributes"][key]
- resp = flask.Response(json.dumps(self.res_data,indent=4))
+ resp = flask.Response(json.dumps(self.res_data,indent=4), mimetype="application/json")
return 0, 200, None, resp
@@ -297,13 +289,13 @@ class RfBootOptionCollection(RfCollection):
post_data["@odata.id"] = newBootOptUrl
self.bootOptions[str(newBootOptIdx)] = post_data
- resp = flask.Response(json.dumps(post_data,indent=4))
+ resp = flask.Response(json.dumps(post_data,indent=4), mimetype="application/json")
resp.headers["Location"] = newBootOptUrl
return 0, 200, None, resp
def patch_bootOpt(self, Idx, patch_data):
self.bootOptions[str(Idx)] = {**self.bootOptions[str(Idx)], **patch_data}
- resp = flask.Response(json.dumps(self.bootOptions[str(Idx)],indent=4))
+ resp = flask.Response(json.dumps(self.bootOptions[str(Idx)],indent=4), mimetype="application/json")
return 0, 200, None, resp
def get_bootOpt(self, Idx):
@@ -312,7 +304,7 @@ class RfBootOptionCollection(RfCollection):
def delete_bootOpt(self, Idx):
print("in delete_bootOpt")
- resp = flask.Response(json.dumps(self.bootOptions[Idx],indent=4))
+ resp = flask.Response(json.dumps(self.bootOptions[Idx],indent=4), mimetype="application/json")
self.bootOptions.pop(Idx)
self.res_data["Members@odata.count"] = self.res_data["Members@odata.count"] - 1
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [edk2-redfish-client][PATCH 3/6] Tool/Redfish-Profile-Simulator: Update patch method of computer system
2023-05-08 14:51 [edk2-redfish-client][PATCH 3/6] Tool/Redfish-Profile-Simulator: Update patch method of computer system Nickle Wang
@ 2023-05-09 6:06 ` Chang, Abner
0 siblings, 0 replies; 2+ messages in thread
From: Chang, Abner @ 2023-05-09 6:06 UTC (permalink / raw)
To: Nickle Wang, devel@edk2.groups.io; +Cc: Igor Kulchytskyy
[AMD Official Use Only - General]
Reviewed-by: Abner Chang <abner.chang@amd.com>
> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Monday, May 8, 2023 10:52 PM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>
> Subject: [edk2-redfish-client][PATCH 3/6] Tool/Redfish-Profile-Simulator:
> Update patch method of computer system
>
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
>
>
> Remove attribute check during patch of computer system and return
> content-type with JSON format in HTTP header.
>
> Signed-off-by: Nickle Wang <nicklew@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> ---
> .../v1sim/resource.py | 4 ++-
> .../v1sim/systems.py | 28 +++++++------------
> 2 files changed, 13 insertions(+), 19 deletions(-)
>
> diff --git a/Tools/Redfish-Profile-Simulator/v1sim/resource.py
> b/Tools/Redfish-Profile-Simulator/v1sim/resource.py
> index ca7541f1..e722d16a 100644
> --- a/Tools/Redfish-Profile-Simulator/v1sim/resource.py
> +++ b/Tools/Redfish-Profile-Simulator/v1sim/resource.py
> @@ -2,6 +2,7 @@
> # Copyright Notice:
> #
> # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
> +# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
> # SPDX-License-Identifier: BSD-2-Clause-Patent # # Copyright Notice:
> @@ -47,6 +48,7 @@ class RfResource:
> try:
> # SHA1 should generate well-behaved etags
> response = flask.make_response(self.response)
> + response.mimetype = 'application/json'
> etag = hashlib.sha1(self.response.encode('utf-8')).hexdigest()
> response.set_etag(etag)
> return response
> @@ -69,7 +71,7 @@ class RfResource:
> else:
> raise Exception("attribute %s not found" % key)
>
> - resp = flask.Response(json.dumps(self.res_data,indent=4))
> + resp = flask.Response(json.dumps(self.res_data,indent=4),
> + mimetype="application/json")
> return 0, 200, None, resp
>
> def post_resource(self, post_data):
> diff --git a/Tools/Redfish-Profile-Simulator/v1sim/systems.py
> b/Tools/Redfish-Profile-Simulator/v1sim/systems.py
> index de4b839a..6305a51e 100644
> --- a/Tools/Redfish-Profile-Simulator/v1sim/systems.py
> +++ b/Tools/Redfish-Profile-Simulator/v1sim/systems.py
> @@ -2,7 +2,7 @@
> # Copyright Notice:
> #
> # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> -# (C)
> Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
> +# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
> # SPDX-License-Identifier: BSD-2-Clause-Patent # # Copyright Notice:
> @@ -63,15 +63,7 @@ class RfSystemObj(RfResource):
> self.components[item] = RfBootOptionCollection(base_path,
> os.path.join(rel_path, item), parent=self)
>
> def patch_resource(self, patch_data):
> - # first verify client didn't send us a property we cant patch
> - for key in patch_data.keys():
> - if key != "AssetTag" and key != "IndicatorLED" and key != "Boot" and
> key != "BiosVersion":
> - return 4, 400, "Invalid Patch Property Sent", ""
> - elif key == "Boot":
> - for prop2 in patch_data["Boot"].keys():
> - if prop2 != "BootSourceOverrideEnabled" and prop2 !=
> "BootSourceOverrideTarget" and prop2 != "BootNext" and prop2 !=
> "BootOrder":
> - return 4, 400, "Invalid Patch Property Sent", ""
> - # now patch the valid properties sent
> + # patch the valid properties sent
> if "AssetTag" in patch_data:
> print("assetTag:{}".format(patch_data["AssetTag"]))
> self.res_data['AssetTag'] = patch_data['AssetTag'] @@ -100,7 +92,7
> @@ class RfSystemObj(RfResource):
> if "BootOrder" in boot_data:
> self.res_data['Boot']['BootOrder'] = boot_data['BootOrder']
>
> - resp = flask.Response(json.dumps(self.res_data,indent=4))
> + resp = flask.Response(json.dumps(self.res_data,indent=4),
> + mimetype="application/json")
> return 0, 200, None, resp
>
> def reset_resource(self, reset_data):
> @@ -150,7 +142,7 @@ class RfMemoryCollection(RfCollection):
> post_data["@odata.etag"] = etag_str
> self.elements[str(newMemoryIdx)] = post_data
>
> - resp = flask.Response(json.dumps(post_data,indent=4))
> + resp = flask.Response(json.dumps(post_data,indent=4),
> + mimetype="application/json")
> resp.headers["Location"] = newMemoryUrl
> resp.headers["ETag"] = etag_str
>
> @@ -163,7 +155,7 @@ class RfMemoryCollection(RfCollection):
> patch_data["@odata.etag"] = etag_str
>
> self.elements[str(Idx)] = {**self.elements[str(Idx)], **patch_data}
> - resp = flask.Response(json.dumps(self.elements[str(Idx)],indent=4))
> + resp =
> + flask.Response(json.dumps(self.elements[str(Idx)],indent=4),
> + mimetype="application/json")
> return 0, 200, None, resp
>
> def get_memory(self, Idx):
> @@ -172,7 +164,7 @@ class RfMemoryCollection(RfCollection):
> def delete_memory(self, Idx):
> print("in delete_memory")
>
> - resp = flask.Response(json.dumps(self.elements[Idx],indent=4))
> + resp = flask.Response(json.dumps(self.elements[Idx],indent=4),
> + mimetype="application/json")
>
> self.elements.pop(Idx)
> self.res_data["Members@odata.count"] =
> self.res_data["Members@odata.count"] - 1 @@ -228,7 +220,7 @@ class
> RfBiosSettings(RfResource):
> return 4, 400, "Invalid Patch Property Sent", ""
> else:
> self.res_data["Attributes"][key] = patch_data["Attributes"][key]
> - resp = flask.Response(json.dumps(self.res_data,indent=4))
> + resp = flask.Response(json.dumps(self.res_data,indent=4),
> + mimetype="application/json")
> return 0, 200, None, resp
>
>
> @@ -297,13 +289,13 @@ class RfBootOptionCollection(RfCollection):
> post_data["@odata.id"] = newBootOptUrl
> self.bootOptions[str(newBootOptIdx)] = post_data
>
> - resp = flask.Response(json.dumps(post_data,indent=4))
> + resp = flask.Response(json.dumps(post_data,indent=4),
> + mimetype="application/json")
> resp.headers["Location"] = newBootOptUrl
> return 0, 200, None, resp
>
> def patch_bootOpt(self, Idx, patch_data):
> self.bootOptions[str(Idx)] = {**self.bootOptions[str(Idx)], **patch_data}
> - resp = flask.Response(json.dumps(self.bootOptions[str(Idx)],indent=4))
> + resp =
> + flask.Response(json.dumps(self.bootOptions[str(Idx)],indent=4),
> + mimetype="application/json")
> return 0, 200, None, resp
>
> def get_bootOpt(self, Idx):
> @@ -312,7 +304,7 @@ class RfBootOptionCollection(RfCollection):
> def delete_bootOpt(self, Idx):
> print("in delete_bootOpt")
>
> - resp = flask.Response(json.dumps(self.bootOptions[Idx],indent=4))
> + resp =
> + flask.Response(json.dumps(self.bootOptions[Idx],indent=4),
> + mimetype="application/json")
>
> self.bootOptions.pop(Idx)
> self.res_data["Members@odata.count"] =
> self.res_data["Members@odata.count"] - 1
> --
> 2.17.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-09 6:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-08 14:51 [edk2-redfish-client][PATCH 3/6] Tool/Redfish-Profile-Simulator: Update patch method of computer system Nickle Wang
2023-05-09 6:06 ` Chang, Abner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox