def execute(self): """Onboard service. Use settings values: - VL_NAME, - VF_NAME, - PNF_NAME, - SERVICE_NAME, - SERVICE_INSTANTIATION_TYPE. """ super().execute() service: Service = Service( name=settings.SERVICE_NAME, instantiation_type=settings.SERVICE_INSTANTIATION_TYPE) if not service.created(): service.create() if settings.VL_NAME != "": vl: Vl = Vl(name=settings.VL_NAME) service.add_resource(vl) if settings.VF_NAME != "": vf: Vf = Vf(name=settings.VF_NAME) service.add_resource(vf) if settings.PNF_NAME != "": pnf: Pnf = Pnf(name=settings.PNF_NAME) service.add_resource(pnf) # If the service is already distributed, do not try to checkin/onboard (replay of tests) # checkin is done if needed # If service is replayed, no need to try to re-onboard the model if not service.distributed: time.sleep(10) service.checkin() service.onboard()
def assign_properties(self, service: Service) -> None: """Assign components properties. For each component set properties and it's value if are declared in YAML template. Args: service (Service): Service object """ if "networks" in self.yaml_template[self.service_name]: for net in self.yaml_template[self.service_name]["networks"]: if "properties" in net: vl: Vl = Vl(name=net['vl_name']) vl_component: Component = service.get_component(vl) self.assign_properties_to_component( vl_component, net["properties"]) if "vnfs" in self.yaml_template[self.service_name]: for vnf in self.yaml_template[self.service_name]["vnfs"]: if "properties" in vnf: vf: Vf = Vf(name=vnf["vnf_name"]) vf_component: Component = service.get_component(vf) self.assign_properties_to_component( vf_component, vnf["properties"]) if "pnfs" in self.yaml_template[self.service_name]: for pnf in self.yaml_template[self.service_name]["pnfs"]: if "properties" in pnf: pnf_obj: Pnf = Pnf(name=pnf["pnf_name"]) pnf_component: Component = service.get_component(pnf_obj) self.assign_properties_to_component( pnf_component, pnf["properties"])
def declare_resources(self, service: Service) -> None: """Declare resources. Resources defined in YAML template are declared. Args: service (Service): Service object """ if "networks" in self.yaml_template[self.service_name]: for net in self.yaml_template[self.service_name]["networks"]: vl: Vl = Vl(name=net['vl_name']) service.add_resource(vl) if "vnfs" in self.yaml_template[self.service_name]: for vnf in self.yaml_template[self.service_name]["vnfs"]: vf: Vf = Vf(name=vnf["vnf_name"]) service.add_resource(vf) if "pnfs" in self.yaml_template[self.service_name]: for pnf in self.yaml_template[self.service_name]["pnfs"]: pnf_obj: Pnf = Pnf(name=pnf["pnf_name"]) service.add_resource(pnf_obj)
def test_vl_properties(mock_exists, mock_send_json): mock_exists.return_value = True vl = Vl(name="test") vl.unique_identifier = "toto" mock_send_json.return_value = {} assert len(list(vl.properties)) == 0 mock_send_json.return_value = VL_PROPERTIES properties_list = list(vl.properties) assert len(properties_list) == 1 prop = properties_list[0] assert prop.sdc_resource == vl assert prop.unique_id == "d37cd65e-9842-4490-9343-a1a874e6b52a.network_role" assert prop.name == "network_role" assert prop.property_type == "string" assert prop.parent_unique_id == "1af9771b-0f79-4e98-8747-30fd06da85cb" assert prop.value is None assert prop.description == "Unique label that defines the role that this network performs. example: vce oam network, vnat sr-iov1 network\n" assert prop.get_input_values is None assert prop.input is None
def test_create_vl_not_exists(mock_send): mock_send.return_value = VLS with pytest.raises(ValueError): Vl("not_exists")
def test_create_vl_not_exists(mock_send): mock_send.return_value = VLS with pytest.raises(ResourceNotFound): Vl("not_exists")