def test_service_properties(): """Integration test to check properties assignment for Service.""" response = requests.post("{}/reset".format(SDC.base_front_url)) response.raise_for_status() vendor = Vendor(name="test") vendor.onboard() vsp = Vsp(name="test", package=open( "{}/ubuntu16.zip".format( os.path.dirname(os.path.abspath(__file__))), 'rb')) vsp.vendor = vendor vsp.onboard() vf = Vf(name='test', vsp=vsp) vf.onboard() properties = [ Property(name="test1", property_type="string", value="123"), Property(name="test2", property_type="integer") ] svc = Service(name='test', resources=[vf], properties=properties, inputs=[properties[1]]) svc.onboard() service_properties = list(svc.properties) service_inputs = list(svc.inputs) assert len(service_properties) == 2 assert len(service_inputs) == 1
def test_sdc_resource_is_own_property(mock_send_json): sdc_resource = SdcResource(name="test") sdc_resource.unique_identifier = "toto" mock_send_json.return_value = PROPERTIES prop1 = Property(name="llllll", property_type="integer") prop2 = Property(name="test2", property_type="string") assert sdc_resource.is_own_property(prop1) assert not sdc_resource.is_own_property(prop2)
def test_add_properties(mock_send_message_json): vf = Vf(name="test") vf._identifier = "toto" vf._unique_identifier = "toto" vf._status = const.CERTIFIED with pytest.raises(StatusError): vf.add_property(Property(name="test", property_type="string")) vf._status = const.DRAFT vf.add_property(Property(name="test", property_type="string")) mock_send_message_json.assert_called_once()
def test_add_properties(mock_send_message_json): service = Service(name="test") service._identifier = "toto" service._unique_identifier = "toto" service._status = const.CERTIFIED with pytest.raises(AttributeError): service.add_property(Property(name="test", property_type="string")) service._status = const.DRAFT service.add_property(Property(name="test", property_type="string")) mock_send_message_json.assert_called_once()
def test_declare_resources_and_properties(mock_declare_input, mock_add_property, mock_add_resource): service = Service( name="test", resources=[SdcResource()], properties=[Property(name="test", property_type="string")], inputs=[Property(name="test", property_type="string")]) service.declare_resources_and_properties() mock_add_resource.assert_called_once() mock_add_property.assert_called_once() mock_declare_input.assert_called_once()
def create_node_template(self, node_template_type: Type[NodeTemplate], component: "Component") -> NodeTemplate: """Create a node template type object. The base of the all node template types objects (Vnf, Pnf, Network) is the same. The difference is only for the Vnf which can have vf modules associated with. Vf modules could have "vf_module_label" property with"base_template_dummy_ignore" value. These vf modules should be ignored/ Args: node_template_type (Type[NodeTemplate]): Node template class type component (Component): Component on which base node template object should be created Returns: NodeTemplate: Node template object created from component """ node_template: NodeTemplate = node_template_type( name=component.name, node_template_type=component.tosca_component_name, model_name=component.component_name, model_version_id=component.sdc_resource.identifier, model_invariant_id=component.sdc_resource.unique_uuid, model_version=component.sdc_resource.version, model_customization_id=component.customization_uuid, model_instance_name=self.name, component=component) if node_template_type is Vnf: if component.group_instances: for vf_module in component.group_instances: if not any([property_def["name"] == "vf_module_label"] and \ property_def["value"] == "base_template_dummy_ignore" for \ property_def in vf_module["properties"]): node_template.vf_modules.append(VfModule( name=vf_module["name"], group_type=vf_module["type"], model_name=vf_module["groupName"], model_version_id=vf_module["groupUUID"], model_invariant_uuid=vf_module["invariantUUID"], model_version=vf_module["version"], model_customization_id=vf_module["customizationUUID"], properties=( Property( name=property_def["name"], property_type=property_def["type"], description=property_def["description"], value=property_def["value"] ) for property_def in vf_module["properties"] \ if property_def["value"] and not ( property_def["name"] == "vf_module_label" and \ property_def["value"] == "base_template_dummy_ignore" ) ) )) return node_template
def test_sdc_resource_set_property_value(mock_send_message_json, mock_sdc_resource_properties): sdc_resource = SdcResource(name="test") sdc_resource.unique_identifier = "toto" mock_sdc_resource_properties.return_value = [ Property(name="test", property_type="string", sdc_resource=sdc_resource) ] with pytest.raises(ValueError): sdc_resource.set_property_value(Property(name="test2", property_type="integer", sdc_resource=sdc_resource), value="lalala") prop = sdc_resource.get_property(property_name="test") assert prop.name == "test" assert prop.property_type == "string" assert not prop.value prop.value = "test" mock_send_message_json.assert_called_once() assert prop.value == "test"
def test_vf_properties(): """Integration test to check properties assignment for Vf.""" response = requests.post("{}/reset".format(Vendor.base_front_url)) response.raise_for_status() vendor = Vendor(name="test") vendor.onboard() vsp = Vsp(name="test", package=open( "{}/ubuntu16.zip".format( os.path.dirname(os.path.abspath(__file__))), 'rb')) vsp.vendor = vendor vsp.onboard() prop = Property(name="test1", property_type="string", value="123") vf = Vf(name="test", vsp=vsp, properties=[prop, Property(name="test2", property_type="integer")], inputs=[prop]) vf.onboard() vf_properties = list(vf.properties) vf_inputs = list(vf.inputs) assert len(vf_properties) == 2 assert len(vf_inputs) == 1
def test_vf_declare_input(mock_send_message, mock_sdc_resource_declare_input): vf = Vf() prop = Property(name="test_prop", property_type="string") nested_input = NestedInput(MagicMock(), MagicMock()) vf.declare_input(prop) mock_sdc_resource_declare_input.assert_called_once() mock_send_message.assert_not_called() mock_sdc_resource_declare_input.reset_mock() vf.declare_input(nested_input) mock_sdc_resource_declare_input.assert_called_once() mock_send_message.assert_not_called() mock_sdc_resource_declare_input.reset_mock() vf.declare_input( ComponentProperty("test_unique_id", "test_property_type", "test_name", MagicMock())) mock_send_message.assert_called() mock_sdc_resource_declare_input.assert_not_called()
def test_declare_input(mock_nested, mock_own, mock_is_own): sdc_resource = SdcResource() prop = Property(name="test", property_type="test") mock_is_own.return_value = False with pytest.raises(ValueError): sdc_resource.declare_input(prop) mock_is_own.return_value = True sdc_resource.declare_input(prop) mock_own.assert_called_once() mock_nested.assert_not_called() mock_nested.reset_mock() mock_own.reset_mock() sdc_resource.declare_input( NestedInput(sdc_resource=mock.MagicMock(), input_obj=mock.MagicMock())) mock_own.assert_not_called() mock_nested.assert_called_once()
def properties(self) -> Iterator[Property]: """SDC resource properties. Iterate resource properties. Yields: Property: Resource property """ for property_data in self.send_message_json(\ "GET", f"Get {self.name} resource properties", self.properties_url).get("properties", []): yield Property( sdc_resource=self, unique_id=property_data["uniqueId"], name=property_data["name"], property_type=property_data["type"], parent_unique_id=property_data["parentUniqueId"], value=property_data.get("value"), description=property_data.get("description"), get_input_values=property_data.get("getInputValues"), )
logger.info("******** Onboard Vendor *******") vendor = Vendor(name=Config.VENDOR) vendor.onboard() logger.info("******** Onboard VSP *******") mypath = os.path.dirname(os.path.realpath(__file__)) myvspfile = os.path.join(mypath, Config.VSPFILE) vsp = Vsp(name=Config.VSPNAME, vendor=vendor, package=open(myvspfile, 'rb')) vsp.onboard() logger.info("******** Onboard VF *******") vf = Vf(name=Config.VFNAME, properties=[ Property(name="sdnc_model_name", property_type="string", value=SDNC_MODEL_NAME), Property(name="sdnc_model_version", property_type="string", value=SDNC_MODEL_VERSION), Property(name="sdnc_artifact_name", property_type="string", value=Config.SDNC_ARTIFACT_NAME) ]) vf.vsp = vsp vf.onboard() logger.info("******** Onboard Service *******") svc = Service(name=Config.SERVICENAME, resources=[vf], instantiation_type=ServiceInstantiationType.MACRO)