示例#1
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
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()))
示例#3
0
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
示例#4
0
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()
示例#5
0
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()
示例#6
0
def test_create_already_exists(mock_send, mock_exists):
    """Do nothing if already created in SDC."""
    vf = Vf()
    vsp = Vsp()
    vsp._identifier = "1232"
    vf.vsp = vsp
    mock_exists.return_value = True
    vf.create()
    mock_send.assert_not_called()
示例#7
0
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)
示例#8
0
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)
示例#9
0
def test_onboard_new_vf_no_vsp(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 = [None, const.APPROVED, const.APPROVED]
        vf = Vf()
        with pytest.raises(ValueError):
            vf.onboard()
            mock_create.assert_not_called()
            mock_submit.assert_not_called()
            mock_load.assert_not_called()
示例#10
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()
示例#11
0
def test_service_onboard_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', resources=[vf])
    svc.onboard()
    assert svc.distributed
示例#12
0
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"
示例#13
0
def test_get_all_no_vf(mock_send):
    """Returns empty array if no vfs."""
    mock_send.return_value = {}
    assert Vf.get_all() == []
    mock_send.assert_called_once_with(
        "GET", 'get Vfs',
        'https://sdc.api.be.simpledemo.onap.org:30204/sdc/v1/catalog/resources?resourceType=VF'
    )
示例#14
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"
示例#15
0
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
示例#16
0
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()
示例#17
0
def test_create_OK(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            "name": "Generic",\n            "normalizedName": "generic",\n            "uniqueId": "resourceNewCategory.generic",\n            "icons": null,\n            "subcategories":[\n                {\n                    "name": "Abstract",\n                    "normalizedName": "abstract",\n                    "uniqueId": "resourceNewCategory.generic.abstract",\n                    "icons":[\n                        "objectStorage",\n                        "compute"\n                    ],\n                    "groupings": null,\n                    "ownerId": null,\n                    "empty": false\n                }\n            ],\n            "ownerId": null,\n            "empty": false\n        }\n    ],\n    "componentInstances": [],\n    "componentInstancesAttributes": {},\n    "componentInstancesProperties": {},\n    "componentType": "RESOURCE",\n    "contactId": "cs0008",\n    "csarUUID": "1234",\n    "csarVersion": "1.0",\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'
    }
    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"
示例#18
0
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
示例#19
0
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)
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))
示例#21
0
 def get_vnf_model_info(cls, vf_name):
     """Retrieve the model info of the VFs."""
     vf_object = Vf(name=vf_name)
     template_service = jinja_env().get_template("vnf_model_info.json.j2")
     parsed = json.loads(
         template_service.render(
             vnf_model_invariant_uuid=vf_object.unique_uuid,
             vnf_model_customization_id="????",
             vnf_model_version_id=vf_object.identifier,
             vnf_model_name=vf_object.name,
             vnf_model_version=vf_object.version,
             vnf_model_instance_name=(vf_object.name + " 0"),
         ))
     # we need also a vnf instance Name
     # Usually it is found like that
     # name: toto
     # instance name: toto 0
     # it can be retrieved from the tosca
     return json.dumps(parsed, indent=4)
def test__deep_load_response_NOK_under_cert(mock_send, mock_created):
    mock_created.return_value = True
    vf = Vf()
    vf.identifier = "5678"
    vf._version = "4567"
    vf._status = const.UNDER_CERTIFICATION
    mock_send.return_value = {
        'resources': [{
            'uuid': '5689',
            'name': 'test',
            'uniqueId': '71011'
        }]
    }
    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_tester(vf.headers))
示例#23
0
def test_get_all_some_vfs(mock_send):
    """Returns a list of vf."""
    mock_send.return_value = [{
        'resourceType': 'VF',
        'name': 'one',
        'uuid': '1234',
        'invariantUUID': '5678',
        'version': '1.0',
        'lifecycleState': 'CERTIFIED'
    }, {
        'resourceType': 'VF',
        'name': 'two',
        'uuid': '1235',
        'invariantUUID': '5679',
        'version': '1.0',
        'lifecycleState': 'NOT_CERTIFIED_CHECKOUT'
    }]
    all_vfs = Vf.get_all()
    assert len(all_vfs) == 2
    vf_1 = all_vfs[0]
    assert vf_1.name == "one"
    assert vf_1.identifier == "1234"
    assert vf_1.unique_uuid == "5678"
    assert vf_1.version == "1.0"
    assert vf_1.status == const.CERTIFIED
    assert vf_1.created()
    vf_2 = all_vfs[1]
    assert vf_2.name == "two"
    assert vf_2.identifier == "1235"
    assert vf_2.unique_uuid == "5679"
    assert vf_2.status == const.DRAFT
    assert vf_2.version == "1.0"
    assert vf_2.created()
    mock_send.assert_called_once_with(
        "GET", 'get Vfs',
        'https://sdc.api.be.simpledemo.onap.org:30204/sdc/v1/catalog/resources?resourceType=VF'
    )
示例#24
0
def test_create_issue_in_creation(mock_send, mock_exists):
    """Do nothing if not created but issue during creation."""
    vf = Vf()
    vsp = Vsp()
    vendor = Vendor()
    vsp._identifier = "1232"
    vsp.create_csar = MagicMock(return_value=True)
    vsp.vendor = vendor
    vf.vsp = vsp
    expected_data = '{\n    "artifacts": {},\n    "attributes": [],\n    "capabilities": {},\n    "categories":[\n        {\n            "name": "Generic",\n            "normalizedName": "generic",\n            "uniqueId": "resourceNewCategory.generic",\n            "icons": null,\n            "subcategories":[\n                {\n                    "name": "Abstract",\n                    "normalizedName": "abstract",\n                    "uniqueId": "resourceNewCategory.generic.abstract",\n                    "icons":[\n                        "objectStorage",\n                        "compute"\n                    ],\n                    "groupings": null,\n                    "ownerId": null,\n                    "empty": false\n                }\n            ],\n            "ownerId": null,\n            "empty": false\n        }\n    ],\n    "componentInstances": [],\n    "componentInstancesAttributes": {},\n    "componentInstancesProperties": {},\n    "componentType": "RESOURCE",\n    "contactId": "cs0008",\n    "csarUUID": "None",\n    "csarVersion": "1.0",\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 = {}
    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 not vf.created()
def test__unique_uuid_setter():
    vf = Vf()
    vf.identifier = "1234"
    vf.unique_uuid = "4567"
    assert vf._unique_uuid == "4567"
def test__unique_uuid_load(mock_load):
    vf = Vf()
    vf.identifier = "1234"
    assert vf.unique_uuid == None
    mock_load.assert_called_once()
def test__unique_uuid_no_load(mock_load):
    vf = Vf()
    vf.identifier = "1234"
    vf._unique_uuid = "4567"
    assert vf.unique_uuid == "4567"
    mock_load.assert_not_called()
def test__get_items_version_details_no_version(mock_send, mock_load):
    vf = Vf()
    vf.identifier = "1234"
    assert vf._get_item_version_details() == {}
    mock_send.assert_not_called()
def test__get_items_version_details_not_created(mock_send, mock_created):
    vf = Vf()
    mock_created.return_value = False
    assert vf._get_item_version_details() == {}
    mock_send.assert_not_called()
def test__status_setter():
    vf = Vf()
    vf.identifier = "1234"
    vf.status = "4567"
    assert vf._status == "4567"