Ejemplo n.º 1
0
    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"])
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
def test_get_all_no_vl(mock_send):
    """Returns empty array if no vls."""
    mock_send.return_value = {}
    assert Vl.get_all() == []
    mock_send.assert_called_once_with(
        "GET", 'get Vls',
        'https://sdc.api.be.simpledemo.onap.org:30204/sdc/v1/catalog/resources?resourceType=VL'
    )
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
Ejemplo n.º 5
0
def test_get_all_vl(mock_send):
    mock_send.return_value = VLS
    vls = Vl.get_all()
    assert len(vls) == 2
    vl = vls[0]
    assert vl.name == "NeutronNet"
    assert vl.identifier == "e12cedf4-fd3f-4d76-ae2a-0368eaee40dc"
    assert vl.unique_uuid == "4084c513-5149-456d-9be0-efc503058799"
    assert vl.version == "1.0"
    assert vl.status == const.CERTIFIED
    vl = vls[1]
    assert vl.name == "Network"
    assert vl.identifier == "3b9f3a0d-f9d1-4d95-80ce-7f7812a2b7b5"
    assert vl.unique_uuid == "c4aa9ad7-1c68-4fde-884e-b9d693b5f725"
    assert vl.version == "1.0"
    assert vl.status == const.CERTIFIED
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
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")