summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMyung Bae <myungbae@us.ibm.com>2023-10-04 17:19:38 +0300
committerMyung Bae <myungbae@us.ibm.com>2023-10-11 00:17:47 +0300
commit480662d437e238048a56efea591dbfbae9d5d065 (patch)
treeea01027b80f48670ef1406f9f3f011ced0dd9d59 /scripts
parent6fd295531d34a3f1df887200ad904321b6020ddd (diff)
downloadbmcweb-480662d437e238048a56efea591dbfbae9d5d065.tar.xz
Fix update_schemas.py to add Oem JsonSchemas
GET on redfish/v1/JsonSchema does not show OEM schemas but shows only DMTF redfish schemas. It is because Oem schemas are not included into `schemas.hpp`. In addition, the explicit OEM JsonSchema gives the content of the file rather than the valid Json output. Tested: - Query JsonSchemas ``` curl -k -H "X-Auth-Token: $token" -X GET "https://$bmc/redfish/v1/JsonSchemas" curl -k -H "X-Auth-Token: $token" -X GET "https://$bmc/redfish/v1/JsonSchemas/<OemSchema>" e.g. curl -k -H "X-Auth-Token: $token" -X GET "https://$bmc/redfish/v1/JsonSchemas/OemManager" ``` - Redfish Service Validator passed Change-Id: I0fc9c3d4a48fb9c6ddec9591af12fd2c849331e3 Signed-off-by: Myung Bae <myungbae@us.ibm.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/update_schemas.py141
1 files changed, 61 insertions, 80 deletions
diff --git a/scripts/update_schemas.py b/scripts/update_schemas.py
index 92d446fbbc..cbdcf0a590 100755
--- a/scripts/update_schemas.py
+++ b/scripts/update_schemas.py
@@ -140,6 +140,14 @@ include_list = [
"redfish-schema-v1",
]
+# OEM schemas
+oem_schema_names = [
+ "OemManager",
+ "OemComputerSystem",
+ "OemVirtualMedia",
+ "OpenBMCAccountService",
+]
+
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
proxies = {"https": os.environ.get("https_proxy", None)}
@@ -259,6 +267,15 @@ json_schema_files = OrderedDict(
)
csdl_filenames.sort(key=SchemaVersion)
+
+# Create oem filenames - from oem json names
+oem_csdl_filenames = []
+for filename in oem_schema_names:
+ oem_csdl_filenames.append(filename + "_v1.xml")
+
+# Append Oem csdl files
+csdl_filenames += oem_csdl_filenames
+
with open(metadata_index_path, "w") as metadata_index:
metadata_index.write('<?xml version="1.0" encoding="UTF-8"?>\n')
metadata_index.write(
@@ -269,43 +286,47 @@ with open(metadata_index_path, "w") as metadata_index:
for filename in csdl_filenames:
# filename looks like Zone_v1.xml
- with open(os.path.join(schema_path, filename), "wb") as schema_out:
- content = zip_ref.read(os.path.join("csdl", filename))
- content = content.replace(b"\r\n", b"\n")
-
- schema_out.write(content)
-
- filenamesplit = filename.split("_")
- if filenamesplit[0] not in include_list:
- continue
- metadata_index.write(
- ' <edmx:Reference Uri="/redfish/v1/schema/'
- + filename
- + '">\n'
- )
-
- xml_root = ET.fromstring(content)
- edmx = "{http://docs.oasis-open.org/odata/ns/edmx}"
- edm = "{http://docs.oasis-open.org/odata/ns/edm}"
- for edmx_child in xml_root:
- if edmx_child.tag == edmx + "DataServices":
- for data_child in edmx_child:
- if data_child.tag == edm + "Schema":
- namespace = data_child.attrib["Namespace"]
- if namespace.startswith("RedfishExtensions"):
- metadata_index.write(
- ' <edmx:Include Namespace="'
- + namespace
- + '" Alias="Redfish"/>\n'
- )
-
- else:
- metadata_index.write(
- ' <edmx:Include Namespace="'
- + namespace
- + '"/>\n'
- )
- metadata_index.write(" </edmx:Reference>\n")
+ if filename in oem_csdl_filenames:
+ with open(
+ os.path.join(schema_path, filename), "rb"
+ ) as oem_csdl_in:
+ content = oem_csdl_in.read()
+ content = content.replace(b"\r\n", b"\n")
+ else:
+ with open(os.path.join(schema_path, filename), "wb") as schema_out:
+ content = zip_ref.read(os.path.join("csdl", filename))
+ content = content.replace(b"\r\n", b"\n")
+ schema_out.write(content)
+ filenamesplit = filename.split("_")
+ if filenamesplit[0] not in include_list:
+ continue
+
+ metadata_index.write(
+ ' <edmx:Reference Uri="/redfish/v1/schema/' + filename + '">\n'
+ )
+
+ xml_root = ET.fromstring(content)
+ edmx = "{http://docs.oasis-open.org/odata/ns/edmx}"
+ edm = "{http://docs.oasis-open.org/odata/ns/edm}"
+ for edmx_child in xml_root:
+ if edmx_child.tag == edmx + "DataServices":
+ for data_child in edmx_child:
+ if data_child.tag == edm + "Schema":
+ namespace = data_child.attrib["Namespace"]
+ if namespace.startswith("RedfishExtensions"):
+ metadata_index.write(
+ ' <edmx:Include Namespace="'
+ + namespace
+ + '" Alias="Redfish"/>\n'
+ )
+
+ else:
+ metadata_index.write(
+ ' <edmx:Include Namespace="'
+ + namespace
+ + '"/>\n'
+ )
+ metadata_index.write(" </edmx:Reference>\n")
metadata_index.write(
" <edmx:DataServices>\n"
@@ -317,49 +338,6 @@ with open(metadata_index_path, "w") as metadata_index:
" </Schema>\n"
" </edmx:DataServices>\n"
)
- # TODO:Issue#32 There's a bug in the script that currently deletes this
- # schema (because it's an OEM schema). Because it's the only six, and we
- # don't update schemas very often, we just manually fix it. Need a
- # permanent fix to the script.
- metadata_index.write(
- ' <edmx:Reference Uri="/redfish/v1/schema/OemManager_v1.xml">\n'
- )
- metadata_index.write(' <edmx:Include Namespace="OemManager"/>\n')
- metadata_index.write(" </edmx:Reference>\n")
-
- metadata_index.write(
- ' <edmx:Reference Uri="'
- '/redfish/v1/schema/OemComputerSystem_v1.xml">\n'
- )
- metadata_index.write(
- ' <edmx:Include Namespace="OemComputerSystem"/>\n'
- )
- metadata_index.write(" </edmx:Reference>\n")
-
- metadata_index.write(
- ' <edmx:Reference Uri="'
- '/redfish/v1/schema/OemVirtualMedia_v1.xml">\n'
- )
- metadata_index.write(
- ' <edmx:Include Namespace="OemVirtualMedia"/>\n'
- )
- metadata_index.write(
- ' <edmx:Include Namespace="OemVirtualMedia.v1_0_0"/>\n'
- )
- metadata_index.write(" </edmx:Reference>\n")
-
- metadata_index.write(
- ' <edmx:Reference Uri="'
- '/redfish/v1/schema/OpenBMCAccountService_v1.xml">\n'
- )
- metadata_index.write(
- ' <edmx:Include Namespace="OpenBMCAccountService"/>\n'
- )
- metadata_index.write(
- ' <edmx:Include Namespace="OpenBMCAccountService.v1_0_0"/>\n'
- )
- metadata_index.write(" </edmx:Reference>\n")
-
metadata_index.write("</edmx:Edmx>\n")
@@ -385,6 +363,9 @@ with open(os.path.join(cpp_path, "schemas.hpp"), "w") as hpp_file:
for schema_file in json_schema_files:
hpp_file.write(' "{}",\n'.format(schema_file))
+ for schema_file in oem_schema_names:
+ hpp_file.write(' "{}",\n'.format(schema_file))
+
hpp_file.write(" };\n}\n")
zip_ref.close()