From c48bc45cc74e04952de18910e69b8aaec0ee330a Mon Sep 17 00:00:00 2001 From: Anja Strunk Date: Tue, 5 Nov 2024 12:55:03 +0100 Subject: [PATCH] Fix test cases Signed-off-by: Anja Strunk --- generator/common/gx_schema.py | 55 ++++++------------- .../openstack/openstack_discovery.py | 4 +- tests/test_cli.py | 5 +- tests/test_server_flavor_discovery.py | 2 +- tests/test_volume_types_discovery.py | 2 +- 5 files changed, 26 insertions(+), 42 deletions(-) diff --git a/generator/common/gx_schema.py b/generator/common/gx_schema.py index 6d2a4fd..6ae9365 100644 --- a/generator/common/gx_schema.py +++ b/generator/common/gx_schema.py @@ -1,5 +1,5 @@ # Auto generated from gaia-x.yaml by pythongen.py version: 0.0.1 -# Generation date: 2024-10-24T13:35:54 +# Generation date: 2024-10-30T13:54:11 # Schema: gaia-x # # id: https://w3id.org/gaia-x/development#gaia-x @@ -1318,7 +1318,7 @@ class GPU(Device): class_model_uri: ClassVar[URIRef] = GX.GPU gpuMemory: Optional[Union[dict, "MemorySize"]] = None - gpuInterconnection: Optional[Union[str, "GPUInterconnetionTypes"]] = None + gpuInterconnection: Optional[Union[str, "GPUInterconnetionTypes"]] = "none" gpuProcessingUnits: Optional[int] = None gpuPassthrough: Optional[Union[bool, Bool]] = False @@ -2665,26 +2665,6 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): super().__post_init__(**kwargs) -@dataclass(repr=False) -class LogicalConstraint(YAMLRoot): - """ - ODRL Core Vocabulary Terms related to Logical Constraints - """ - _inherited_slots: ClassVar[List[str]] = [] - - class_class_uri: ClassVar[URIRef] = ODRL["LogicalConstraint"] - class_class_curie: ClassVar[str] = "odrl:LogicalConstraint" - class_name: ClassVar[str] = "LogicalConstraint" - class_model_uri: ClassVar[URIRef] = GX.LogicalConstraint - - operand: Optional[str] = None - - def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): - if self.operand is not None and not isinstance(self.operand, str): - self.operand = str(self.operand) - - super().__post_init__(**kwargs) - class Participant(GaiaXEntity): """ An legal or natural person that is onboarded to Gaia-X and offers, consumes services or operates resources. @@ -4926,7 +4906,7 @@ class StorageServiceOffering(InfrastructureServiceOffering): providedBy: Union[str, LegalPersonRegistrationNumber] = None serviceOfferingTermsAndConditions: Union[Union[dict, TermsAndConditions], List[Union[dict, TermsAndConditions]]] = None dataAccountExport: Union[Union[dict, DataAccountExport], List[Union[dict, DataAccountExport]]] = None - storageConfiguration: Union[dict, StorageConfiguration] = None + storageConfiguration: Union[Union[dict, StorageConfiguration], List[Union[dict, StorageConfiguration]]] = None minimumSize: Optional[Union[dict, MemorySize]] = None maximumSize: Optional[Union[dict, MemorySize]] = None lifetimeManagement: Optional[int] = None @@ -4938,8 +4918,10 @@ class StorageServiceOffering(InfrastructureServiceOffering): def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if self._is_empty(self.storageConfiguration): self.MissingRequiredField("storageConfiguration") - if not isinstance(self.storageConfiguration, StorageConfiguration): - self.storageConfiguration = StorageConfiguration(**as_dict(self.storageConfiguration)) + if not isinstance(self.storageConfiguration, list): + self.storageConfiguration = [self.storageConfiguration] if self.storageConfiguration is not None else [] + self.storageConfiguration = [v if isinstance(v, StorageConfiguration) else StorageConfiguration(**as_dict(v)) + for v in self.storageConfiguration] if self.minimumSize is not None and not isinstance(self.minimumSize, MemorySize): self.minimumSize = MemorySize(**as_dict(self.minimumSize)) @@ -4980,15 +4962,16 @@ class FileStorageServiceOffering(StorageServiceOffering): providedBy: Union[str, LegalPersonRegistrationNumber] = None serviceOfferingTermsAndConditions: Union[Union[dict, TermsAndConditions], List[Union[dict, TermsAndConditions]]] = None dataAccountExport: Union[Union[dict, DataAccountExport], List[Union[dict, DataAccountExport]]] = None - storageConfiguration: Union[dict, FileStorageConfiguration] = None + storageConfiguration: Union[Union[dict, FileStorageConfiguration], List[Union[dict, FileStorageConfiguration]]] = None accessSemantics: Optional[Union[bool, Bool]] = None accessAttributes: Optional[Union[Union[str, "AccessAttribute"], List[Union[str, "AccessAttribute"]]]] = empty_list() def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if self._is_empty(self.storageConfiguration): self.MissingRequiredField("storageConfiguration") - if not isinstance(self.storageConfiguration, FileStorageConfiguration): - self.storageConfiguration = FileStorageConfiguration(**as_dict(self.storageConfiguration)) + if not isinstance(self.storageConfiguration, list): + self.storageConfiguration = [self.storageConfiguration] if self.storageConfiguration is not None else [] + self.storageConfiguration = [v if isinstance(v, FileStorageConfiguration) else FileStorageConfiguration(**as_dict(v)) for v in self.storageConfiguration] if self.accessSemantics is not None and not isinstance(self.accessSemantics, Bool): self.accessSemantics = Bool(self.accessSemantics) @@ -5015,13 +4998,14 @@ class BlockStorageServiceOffering(StorageServiceOffering): providedBy: Union[str, LegalPersonRegistrationNumber] = None serviceOfferingTermsAndConditions: Union[Union[dict, TermsAndConditions], List[Union[dict, TermsAndConditions]]] = None dataAccountExport: Union[Union[dict, DataAccountExport], List[Union[dict, DataAccountExport]]] = None - storageConfiguration: Union[dict, BlockStorageConfiguration] = None + storageConfiguration: Union[Union[dict, BlockStorageConfiguration], List[Union[dict, BlockStorageConfiguration]]] = None def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if self._is_empty(self.storageConfiguration): self.MissingRequiredField("storageConfiguration") - if not isinstance(self.storageConfiguration, BlockStorageConfiguration): - self.storageConfiguration = BlockStorageConfiguration(**as_dict(self.storageConfiguration)) + if not isinstance(self.storageConfiguration, list): + self.storageConfiguration = [self.storageConfiguration] if self.storageConfiguration is not None else [] + self.storageConfiguration = [v if isinstance(v, BlockStorageConfiguration) else BlockStorageConfiguration(**as_dict(v)) for v in self.storageConfiguration] super().__post_init__(**kwargs) @@ -5213,7 +5197,7 @@ class ServerFlavor(InstantiationRequirement): confidentialComputing: Optional[Union[dict, "ConfidentialComputing"]] = None hypervisor: Optional[Union[dict, Hypervisor]] = None hardwareAssistedVirtualization: Optional[Union[bool, Bool]] = False - hwRngTypeOfFlavor: Optional[Union[str, "RNGTypes"]] = None + hwRngTypeOfFlavor: Optional[Union[str, "RNGTypes"]] = "None" def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if self._is_empty(self.cpu): @@ -37017,9 +37001,6 @@ class slots: slots.rule__constraint = Slot(uri=ODRL.constraint, name="rule__constraint", curie=ODRL.curie('constraint'), model_uri=GX.rule__constraint, domain=None, range=Optional[Union[Union[dict, Constraint], List[Union[dict, Constraint]]]]) -slots.rule__logicalConstraint = Slot(uri=ODRL.logicalConstraint, name="rule__logicalConstraint", curie=ODRL.curie('logicalConstraint'), - model_uri=GX.rule__logicalConstraint, domain=None, range=Optional[Union[Union[dict, LogicalConstraint], List[Union[dict, LogicalConstraint]]]]) - slots.rule__duty = Slot(uri=ODRL.duty, name="rule__duty", curie=ODRL.curie('duty'), model_uri=GX.rule__duty, domain=None, range=Optional[Union[Union[dict, Duty], List[Union[dict, Duty]]]]) @@ -37336,7 +37317,7 @@ class slots: model_uri=GX.storageServiceOffering__multipleViews, domain=None, range=Optional[Union[bool, Bool]]) slots.fileStorageServiceOffering__storageConfiguration = Slot(uri=GX.storageConfiguration, name="fileStorageServiceOffering__storageConfiguration", curie=GX.curie('storageConfiguration'), - model_uri=GX.fileStorageServiceOffering__storageConfiguration, domain=None, range=Union[dict, FileStorageConfiguration]) + model_uri=GX.fileStorageServiceOffering__storageConfiguration, domain=None, range=Union[Union[dict, FileStorageConfiguration], List[Union[dict, FileStorageConfiguration]]]) slots.fileStorageServiceOffering__accessSemantics = Slot(uri=GX.accessSemantics, name="fileStorageServiceOffering__accessSemantics", curie=GX.curie('accessSemantics'), model_uri=GX.fileStorageServiceOffering__accessSemantics, domain=None, range=Optional[Union[bool, Bool]]) @@ -37345,7 +37326,7 @@ class slots: model_uri=GX.fileStorageServiceOffering__accessAttributes, domain=None, range=Optional[Union[Union[str, "AccessAttribute"], List[Union[str, "AccessAttribute"]]]]) slots.blockStorageServiceOffering__storageConfiguration = Slot(uri=GX.storageConfiguration, name="blockStorageServiceOffering__storageConfiguration", curie=GX.curie('storageConfiguration'), - model_uri=GX.blockStorageServiceOffering__storageConfiguration, domain=None, range=Union[dict, BlockStorageConfiguration]) + model_uri=GX.blockStorageServiceOffering__storageConfiguration, domain=None, range=Union[Union[dict, BlockStorageConfiguration], List[Union[dict, BlockStorageConfiguration]]]) slots.objectStorageServiceOffering__accessAttributes = Slot(uri=GX.accessAttributes, name="objectStorageServiceOffering__accessAttributes", curie=GX.curie('accessAttributes'), model_uri=GX.objectStorageServiceOffering__accessAttributes, domain=None, range=Optional[Union[Union[str, "AccessAttribute"], List[Union[str, "AccessAttribute"]]]]) diff --git a/generator/discovery/openstack/openstack_discovery.py b/generator/discovery/openstack/openstack_discovery.py index fc4b6f7..a6c4fa1 100644 --- a/generator/discovery/openstack/openstack_discovery.py +++ b/generator/discovery/openstack/openstack_discovery.py @@ -47,7 +47,7 @@ def discover(self) -> VirtualMachineServiceOffering: vm_offering = self._create_vm_offering(images,flavors, mand_props) storage_offering = self._create_storage_offering(vol_types, mand_props) - vm_offering.dependsOn(storage_offering) + vm_offering.dependsOn.append(storage_offering) return vm_offering @@ -117,6 +117,6 @@ def _create_vm_offering(self, images: List[GX_Image], flavors: List[GX_Flavor], def _create_storage_offering(self, vol_types: List[GX_Type], mand_prop: dict) -> BlockStorageServiceOffering: return BlockStorageServiceOffering( - storageConfiguration=[StorageConfiguration()], + storageConfiguration=vol_types, **mand_prop ) diff --git a/tests/test_cli.py b/tests/test_cli.py index 23a33ec..fc9e10b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -30,7 +30,9 @@ def test_generate_vsmo(self, cli_print_vs, os_connect, os_discover, load_jwk, gx providedBy="foo", serviceOfferingTermsAndConditions=[TermsAndConditions( url="https://example.com/tandc", - hash="123")], + hash="123"), TermsAndConditions( + url="https://example.com/tandc2", + hash="124")], dataAccountExport=DataAccountExport( requestType="API", accessType="digital", @@ -52,6 +54,7 @@ def test_generate_vsmo(self, cli_print_vs, os_connect, os_discover, load_jwk, gx conf = config.Config(yaml.safe_load(config_file)) vcs = cli.create_vmso_vcs(conf, "myCloud", csp_vcs) + os_connect.assert_called_once() os_discover.assert_called_once() gxdch_req_compl.assert_called_once() diff --git a/tests/test_server_flavor_discovery.py b/tests/test_server_flavor_discovery.py index 377814c..96c034d 100644 --- a/tests/test_server_flavor_discovery.py +++ b/tests/test_server_flavor_discovery.py @@ -20,7 +20,7 @@ class VMServerFlavorDiscoveryTestcase(OpenstackTestcase): def setUp(self): - self.conf = self.get_config() + self.conf = get_config() self.discovery = ServerFlavorDiscovery( conn=MockConnection(flavors=[OS_FLAVOR_1, OS_FLAVOR_2]), conf=self.conf) diff --git a/tests/test_volume_types_discovery.py b/tests/test_volume_types_discovery.py index 19856a8..8d5fa44 100644 --- a/tests/test_volume_types_discovery.py +++ b/tests/test_volume_types_discovery.py @@ -32,7 +32,7 @@ class VolumeTypeDiscoveryTestcase(OpenstackTestcase): def setUp(self): - self.conf = self.get_config() + self.conf = get_config() self.discovery = VolumeTypeDiscovery( conn=MockConnection(types=[OS_TYPE_1, OS_TYPE_2,