Exemplo n.º 1
0
    def get_category_for_new_resource(self) -> ResourceCategory:
        """Get category for resource not created in SDC yet.

        If no category values are provided default category is going to be used.

        Returns:
            ResourceCategory: Category of the new resource

        """
        if not all([self._category_name, self._subcategory_name]):
            return ResourceCategory.get(name="Generic", subcategory="Abstract")
        return ResourceCategory.get(name=self._category_name,
                                    subcategory=self._subcategory_name)
def test_resource_category_create(mock_send_message_json):

    mock_send_message_json.return_value = CATEGORIES
    rc = ResourceCategory.create(name="Network Connectivity")
    assert rc.name == "Network Connectivity"
    assert rc.normalized_name == "network connectivity"
    assert rc.unique_id == "resourceNewCategory.network connectivity"
    assert not rc.icons
    assert not rc.version
    assert not rc.owner_id
    assert not rc.empty
    assert not rc.type
    ResourceCategory.create(name="New category")
Exemplo n.º 3
0
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"
Exemplo n.º 4
0
def test_resource_category_get(mock_send_message_json):

    mock_send_message_json.return_value = CATEGORIES
    rc = ResourceCategory.get(name="Network Connectivity")
    assert rc.name == "Network Connectivity"
    assert rc.normalized_name == "network connectivity"
    assert rc.unique_id == "resourceNewCategory.network connectivity"
    assert not rc.icons
    assert not rc.version
    assert not rc.owner_id
    assert not rc.empty
    assert not rc.type
    assert len(rc.subcategories) == 2

    with pytest.raises(ResourceNotFound):
        ResourceCategory.get(name="Network Connectivity", subcategory="Toto")
    rc = ResourceCategory.get(name="Network Connectivity",
                              subcategory="Connection Points")
    assert rc.name == "Network Connectivity"
    assert rc.normalized_name == "network connectivity"
    assert rc.unique_id == "resourceNewCategory.network connectivity"
    assert not rc.icons
    assert not rc.version
    assert not rc.owner_id
    assert not rc.empty
    assert not rc.type
    assert len(rc.subcategories) == 1

    mock_send_message_json.side_effect = APIError
    with pytest.raises(ResourceNotFound):
        ResourceCategory.get(name="Network Connectivity")

    mock_send_message_json.side_effect = KeyError
    with pytest.raises(ResourceNotFound):
        ResourceCategory.get(name="Network Connectivity")
def test_resource_category_exists(mock_send_message_json):

    rc = ResourceCategory(name="test_name")
    mock_send_message_json.return_value = {}
    assert not rc.exists()
    mock_send_message_json.return_value = CATEGORIES
    assert not rc.exists()
    rc = ResourceCategory(name="Network Connectivity")
    assert rc.exists()
Exemplo n.º 6
0
def test_create_issue_in_creation(mock_category, mock_send, mock_exists):
    # def test_create_issue_in_creation(mock_send, mock_exists):
    """Do nothing if not created but issue during creation."""
    pnf = Pnf()
    vsp = Vsp()
    vendor = Vendor()
    vsp._identifier = "1232"
    vsp.create_csar = MagicMock(return_value=True)
    vsp.vendor = vendor
    pnf.vsp = vsp
    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": "None",\n    "csarVersion": "1.0",\n    "vendorName": "Generic-Vendor",\n    \n    "deploymentArtifacts": {},\n    "description": "PNF",\n    "icon": "defaulticon",\n    "name": "ONAP-test-PNF",\n    "properties": [],\n    "groups": [],\n    "requirements": {},\n    "resourceType": "PNF",\n    "tags": ["ONAP-test-PNF"],\n    "toscaArtifacts": {},\n    "vendorRelease": "1.0"\n}'
    mock_exists.return_value = False
    mock_send.side_effect = RequestError
    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
    with pytest.raises(RequestError) as exc:
        pnf.create()
    mock_send.assert_called_once_with(
        "POST",
        "create Pnf",
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/resources',
        data=expected_data)
    assert not pnf.created()
Exemplo n.º 7
0
    def category(self) -> Union[ResourceCategory, ServiceCategory]:
        """Sdc resource category.

        Depends on the resource type returns ResourceCategory or ServiceCategory.

        Returns:
            Uniton[ResourceCategory, ServiceCategory]: resource category

        """
        if self.created():
            if not any([self._category_name, self._subcategory_name]):
                self.deep_load()
            if all([self._category_name, self._subcategory_name]):
                return ResourceCategory.get(name=self._category_name,
                                            subcategory=self._subcategory_name)
            return ServiceCategory.get(name=self._category_name)
        return self.get_category_for_new_resource()