def test_vf_category(mock_resource_category, mock_created):
    mock_created.return_value = False
    vf = Vf(name="test")
    _ = vf.category
    mock_resource_category.assert_called_once_with(name="Generic",
                                                   subcategory="Abstract")
    mock_resource_category.reset_mock()

    vf = Vf(name="test",
            category="Allotted Resource",
            subcategory="Allotted Resource")
    _ = vf.category
    mock_resource_category.assert_called_once_with(
        name="Allotted Resource", subcategory="Allotted Resource")
    mock_resource_category.reset_mock()

    vf = Vf(name="test", category="test", subcategory="test")
    _ = vf.category
    mock_resource_category.assert_called_once_with(name="test",
                                                   subcategory="test")
    mock_resource_category.reset_mock()

    mock_created.return_value = True
    _ = vf.category
    mock_resource_category.assert_called_once_with(name="test",
                                                   subcategory="test")
def test_equality_really_equals():
    """Check two vfs are equals if name is the same."""
    vf_1 = Vf(name="equal")
    vf_1.identifier = "1234"
    vf_2 = Vf(name="equal")
    vf_2.identifier = "1235"
    assert vf_1 == vf_2
def test_equality_not_equals():
    """Check two vfs are not equals if name is not the same."""
    vf_1 = Vf(name="equal")
    vf_1.identifier = "1234"
    vf_2 = Vf(name="not_equal")
    vf_2.identifier = "1234"
    assert vf_1 != vf_2
def test_exists_not_exists(mock_get_all):
    """Return False if vf doesn't exist in SDC."""
    vf_1 = Vf(name="one")
    vf_1.identifier = "1234"
    mock_get_all.return_value = [vf_1]
    vf = Vf(name="two")
    assert not vf.exists()
def test_submit_not_Commited(mock_send, mock_load, mock_exists, status):
    """Do nothing if not created."""
    mock_exists.return_value = False
    vf = Vf()
    vf._status = status
    vf.submit()
    mock_send.assert_not_called()
def test_add_resource_not_draft(mock_send, mock_exists):
    mock_exists.return_value = False
    vf = Vf()
    resource = SdcResource()
    with pytest.raises(StatusError):
        vf.add_resource(resource)
    mock_send.assert_not_called()
    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"])
Example #9
0
def test_service_upload_tca_artifact():
    """Integration tests 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()
    svc = Service(name='test')
    svc.create()
    svc.add_resource(vf)
    assert svc.status == const.DRAFT
    payload_file = open(
        "{}/tca_clampnode.yaml".format(
            os.path.dirname(os.path.abspath(__file__))), 'rb')
    data = payload_file.read()
    svc.add_artifact_to_vf(vnf_name="test",
                           artifact_type="DCAE_INVENTORY_BLUEPRINT",
                           artifact_name="tca_clampnode.yaml",
                           artifact=data)
    payload_file.close()
Example #10
0
def test_service_unknown():
    """Integration tests 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()
    svc = Service(name='test')
    assert svc.identifier is None
    assert svc.status is None
    svc.create()
    assert svc.identifier is not None
    assert svc.status == const.DRAFT
    svc.add_resource(vf)
    svc.checkin()
    assert svc.status == const.CHECKED_IN
    svc.certify()
    assert svc.status == const.CERTIFIED
    svc.distribute()
    assert svc.status == const.DISTRIBUTED
    assert svc.distributed
Example #11
0
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
Example #12
0
def test__get_item_details_created(mock_send):
    vf = Vf()
    vf.identifier = "1234"
    mock_send.return_value = {'return': 'value'}
    assert vf._get_item_details() == {'return': 'value'}
    mock_send.assert_called_once_with(
        'GET', 'get item', "{}/items/1234/versions".format(vf._base_url()))
def test_version_no_load_created(mock_load):
    """Test versions when created."""
    vf = Vf()
    vf.identifier = "1234"
    vf._version = "64"
    assert vf.version == "64"
    mock_load.assert_not_called()
def test_exists_exists(mock_get_all):
    """Return True if vf exists in SDC."""
    vf_1 = Vf(name="one")
    vf_1.identifier = "1234"
    vf_1.unique_uuid = "5689"
    vf_1.unique_identifier = "71011"
    vf_1.status = const.DRAFT
    vf_1.version = "1.1"
    mock_get_all.return_value = [vf_1]
    vf = Vf(name="one")
    assert vf.exists()
    assert vf.identifier == "1234"
    assert vf.unique_uuid == "5689"
    assert vf.unique_identifier == "71011"
    assert vf.status == const.DRAFT
    assert vf.version == "1.1"
Example #15
0
def test__deep_load_response_OK_under_cert(mock_send, mock_created):
    mock_created.return_value = True
    vf = Vf()
    vf.identifier = "5689"
    vf._version = "4567"
    vf._status = const.UNDER_CERTIFICATION
    mock_send.return_value = {
        'resources': [{
            'uuid':
            '5689',
            'name':
            'test',
            'uniqueId':
            '71011',
            'categories': [{
                'name': 'test',
                'subcategories': [{
                    'name': 'test_subcategory'
                }]
            }]
        }]
    }
    vf.deep_load()
    assert vf.unique_identifier == "71011"
    assert vf._category_name == "test"
    assert vf._subcategory_name == "test_subcategory"
    mock_send.assert_called_once_with(
        'GET',
        'Deep Load Vf',
        "{}/sdc1/feProxy/rest/v1/screen?excludeTypes=VFCMT&excludeTypes=Configuration"
        .format(vf.base_front_url),
        headers=headers_sdc_tester(vf.headers))
def test_equality_not_equals_not_same_object():
    """Check a vf and something different are not equals."""
    vf_1 = Vf(name="equal")
    vf_1.identifier = "1234"
    vf_2 = SdcResource()
    vf_2.name = "equal"
    assert vf_1 != vf_2
def test_create_no_vsp(mock_send, mock_exists):
    """Do nothing if no vsp."""
    vf = Vf()
    mock_exists.return_value = False
    with pytest.raises(ParameterError) as err:
        vf.create()
    assert err.type == ParameterError
    assert str(err.value) == "At least vsp or vendor needs to be given"
def test_vf_properties(mock_send_json):
    vf = Vf(name="test")
    vf.unique_identifier = "toto"

    mock_send_json.return_value = {}
    assert len(list(vf.properties)) == 0

    mock_send_json.return_value = PROPERTIES
    properties_list = list(vf.properties)
    assert len(properties_list) == 4
    prop1, prop2, prop3, prop4 = properties_list

    mock_send_json.return_value = INPUTS

    assert prop1.sdc_resource == vf
    assert prop1.unique_id == "4a84415b-4580-4a78-aa33-501f0cd3d079.llllll"
    assert prop1.name == "llllll"
    assert prop1.property_type == "integer"
    assert prop1.parent_unique_id == "4a84415b-4580-4a78-aa33-501f0cd3d079"
    assert prop1.value == '{"get_input":["lililili","INDEX","llllll"]}'
    assert prop1.description is None
    assert prop1.get_input_values
    prop1_input = prop1.input
    assert prop1_input.unique_id == "4a84415b-4580-4a78-aa33-501f0cd3d079.lililili"
    assert prop1_input.input_type == "list"
    assert prop1_input.name == "lililili"
    assert prop1_input.default_value is None

    assert prop2.sdc_resource == vf
    assert prop2.unique_id == "4a84415b-4580-4a78-aa33-501f0cd3d079.test"
    assert prop2.name == "test"
    assert prop2.property_type == "string"
    assert prop2.parent_unique_id == "4a84415b-4580-4a78-aa33-501f0cd3d079"
    assert prop2.value is None
    assert prop2.description is None
    assert prop2.get_input_values == []
    assert prop2.input is None

    assert prop3.sdc_resource == vf
    assert prop3.unique_id == "4a84415b-4580-4a78-aa33-501f0cd3d079.yyy"
    assert prop3.name == "yyy"
    assert prop3.property_type == "string"
    assert prop3.parent_unique_id == "4a84415b-4580-4a78-aa33-501f0cd3d079"
    assert prop3.value == "lalala"
    assert prop3.description is None
    assert prop3.get_input_values is None
    assert prop3.input is None

    assert prop4.sdc_resource == vf
    assert prop4.unique_id == "4a84415b-4580-4a78-aa33-501f0cd3d079.test2"
    assert prop4.name == "test2"
    assert prop4.property_type == "boolean"
    assert prop4.parent_unique_id == "4a84415b-4580-4a78-aa33-501f0cd3d079"
    assert prop4.value == '{"get_input":"test2"}'
    assert prop4.description == "test2"
    assert prop4.get_input_values
    with pytest.raises(AttributeError):
        prop4.input
def test_create_already_exists(mock_category, mock_send, mock_exists):
    """Do nothing if already created in SDC."""
    vf = Vf(vendor=MagicMock())
    vsp = Vsp()
    vsp._identifier = "1232"
    vf.vsp = vsp
    mock_exists.return_value = True
    vf.create()
    mock_send.assert_not_called()
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_init_no_name():
    """Check init with no names."""
    vf = Vf()
    assert isinstance(vf, SdcResource)
    assert vf._identifier is None
    assert vf._version is None
    assert vf.name == "ONAP-test-VF"
    assert vf.headers["USER_ID"] == "cs0008"
    assert vf.vsp is None
    assert isinstance(vf._base_url(), str)
def test_init_with_name(mock_exists):
    """Check init with no names."""
    mock_exists.return_value = False
    vf = Vf(name="YOLO")
    assert vf._identifier == None
    assert vf._version == None
    assert vf.name == "YOLO"
    assert vf.created() == False
    assert vf.headers["USER_ID"] == "cs0008"
    assert vf.vsp == None
    assert isinstance(vf._base_url(), str)
Example #23
0
    def execute(self):
        """Onboard Vf.

        Use settings values:
         - VSP_NAME,
         - VF_NAME.

        """
        super().execute()
        vsp: Vsp = Vsp(name=settings.VSP_NAME)
        vf: Vf = Vf(name=settings.VF_NAME, vsp=vsp)
        if not vf.created():
            vf.onboard()
def test_create_OK(mock_category, mock_send, mock_exists):
    """Create and update object."""
    vf = Vf()
    vsp = Vsp()
    vendor = Vendor()
    vsp._identifier = "1232"
    vf.vsp = vsp
    vsp.vendor = vendor
    vsp._csar_uuid = "1234"
    expected_data = '{\n    "artifacts": {},\n    "attributes": [],\n    "capabilities": {},\n      "categories": [\n    {\n      "normalizedName": "generic",\n      "name": "Generic",\n      "uniqueId": "resourceNewCategory.generic",\n      "subcategories": [{"empty": false, "groupings": null, "icons": ["objectStorage", "compute"], "name": "Abstract", "normalizedName": "abstract", "ownerId": null, "type": null, "uniqueId": "resourceNewCategory.generic.abstract", "version": null}],\n      "version": null,\n      "ownerId": null,\n      "empty": false,\n      "type": null,\n      "icons": null\n    }\n  ],\n    "componentInstances": [],\n    "componentInstancesAttributes": {},\n    "componentInstancesProperties": {},\n    "componentType": "RESOURCE",\n    "contactId": "cs0008",\n    \n        "csarUUID": "1234",\n        "csarVersion": "1.0",\n    \n    "deploymentArtifacts": {},\n    "description": "VF",\n    "icon": "defaulticon",\n    "name": "ONAP-test-VF",\n    "properties": [],\n    "groups": [],\n    "requirements": {},\n    "resourceType": "VF",\n    "tags": ["ONAP-test-VF"],\n    "toscaArtifacts": {},\n    "vendorName": "Generic-Vendor",\n    "vendorRelease": "1.0"\n}'
    mock_exists.return_value = False
    mock_send.return_value = {
        'resourceType': 'VF',
        'name': 'one',
        'uuid': '1234',
        'invariantUUID': '5678',
        'version': '1.0',
        'uniqueId': '91011',
        'lifecycleState': 'NOT_CERTIFIED_CHECKOUT'
    }
    rc = ResourceCategory(name="Generic")
    rc.normalized_name = "generic"
    rc.unique_id = "resourceNewCategory.generic"
    rc.subcategories = [{
        "empty": False,
        "groupings": None,
        "icons": ["objectStorage", "compute"],
        "name": "Abstract",
        "normalizedName": "abstract",
        "ownerId": None,
        "type": None,
        "uniqueId": "resourceNewCategory.generic.abstract",
        "version": None
    }]
    rc.version = None
    rc.owner_id = None
    rc.empty = False
    rc.type = None
    rc.icons = None
    mock_category.return_value = rc
    vf.create()
    mock_send.assert_called_once_with(
        "POST",
        "create Vf",
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/resources',
        data=expected_data)
    assert vf.created()
    assert vf._status == const.DRAFT
    assert vf.identifier == "1234"
    assert vf.unique_uuid == "5678"
    assert vf.version == "1.0"
Example #25
0
def test_onboard_vf_load(mock_create, mock_submit, mock_load):
    getter_mock = mock.Mock(wraps=Vf.status.fget)
    mock_status = Vf.status.getter(getter_mock)
    with mock.patch.object(Vf, 'status', mock_status):
        getter_mock.side_effect = [
            const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.APPROVED,
            const.APPROVED, const.APPROVED
        ]
        vf = Vf()
        vf._time_wait = 0
        vf.onboard()
        mock_create.assert_not_called()
        mock_submit.assert_not_called()
        mock_load.assert_called_once()
def test_submit_OK(mock_send, mock_load, mock_exists):
    """Don't update status if submission NOK."""
    mock_exists.return_value = True
    vf = Vf()
    vf._status = const.COMMITED
    expected_data = '{\n  "userRemarks": "certify"\n}'
    vf._version = "1234"
    vf._unique_identifier = "12345"
    vf.submit()
    mock_send.assert_called_once_with(
        "POST",
        "Certify Vf",
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/resources/12345/lifecycleState/Certify',
        data=expected_data)
Example #27
0
def test__deep_load_no_response(mock_send, mock_created):
    mock_created.return_value = True
    vf = Vf()
    vf.identifier = "1234"
    vf._version = "4567"
    vf._status = const.CHECKED_IN
    mock_send.return_value = {}
    vf.deep_load()
    assert vf._unique_identifier is None
    mock_send.assert_called_once_with(
        'GET',
        'Deep Load Vf',
        "{}/sdc1/feProxy/rest/v1/screen?excludeTypes=VFCMT&excludeTypes=Configuration"
        .format(vf.base_front_url),
        headers=headers_sdc_creator(vf.headers))
def test_vf_vendor_property(mock_resource_inputs_url, mock_send_message_json,
                            mock_created):
    mock_created.return_value = False
    vf = Vf()
    assert vf.vendor is None

    vsp_mock = MagicMock()
    vsp_mock.vendor = MagicMock()
    vf.vsp = vsp_mock
    assert vf.vendor == vsp_mock.vendor

    vf._vendor = None
    mock_created.return_value = True
    mock_send_message_json.return_value = {"vendorName": "123"}
    assert vf.vendor.name == "123"
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()
Example #30
0
def test_vf_onboard_unknown():
    """Integration tests 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()
    vf = Vf(name='test')
    vf.vsp = vsp
    vf.onboard()
    assert vsp.status == const.CERTIFIED
    assert vf.version == "1.0"