def test_equality_really_equals():
    """Check two Vendors are equals if name is the same."""
    vendor_1 = Vendor(name="equal")
    vendor_1.identifier = "1234"
    vendor_2 = Vendor(name="equal")
    vendor_2.identifier = "1235"
    assert vendor_1 == vendor_2
def test_exists_not_exists(mock_get_all):
    """Return False if vendor doesn't exist in SDC."""
    vendor_1 = Vendor(name="one")
    vendor_1.identifier = "1234"
    mock_get_all.return_value = [vendor_1]
    vendor = Vendor(name="two")
    assert not vendor.exists()
def test_equality_not_equals():
    """Check two Vendors are not equals if name is not the same."""
    vendor_1 = Vendor(name="equal")
    vendor_1.identifier = "1234"
    vendor_2 = Vendor(name="not_equal")
    vendor_2.identifier = "1234"
    assert vendor_1 != vendor_2
def test_exists_exists(mock_get_all):
    """Return True if vendor exists in SDC."""
    vendor_1 = Vendor(name="one")
    vendor_1.identifier = "1234"
    vendor_1.version = "1.1"
    mock_get_all.return_value = [vendor_1]
    vendor = Vendor(name="one")
    assert vendor.exists()
Ejemplo n.º 5
0
    def execute(self):
        """Onboard Vsps from YAML template.

        Use settings values:
         - VENDOR_NAME.
        """
        super().execute()
        vendor: Vendor = Vendor(name=settings.VENDOR_NAME)
        if "vnfs" in self.yaml_template:
            for vnf in self.yaml_template["vnfs"]:
                with open(sys.path[-1] + "/" + vnf["heat_files_to_upload"],
                          "rb") as package:
                    vsp: Vsp = Vsp(name=f"{vnf['vnf_name']}_VSP",
                                   vendor=vendor,
                                   package=package)
                    vsp.onboard()
        elif "pnfs" in self.yaml_template:
            for pnf in self.yaml_template["pnfs"]:
                if "heat_files_to_upload" in pnf:
                    with open(sys.path[-1] + "/" + pnf["heat_files_to_upload"],
                              "rb") as package:
                        vsp: Vsp = Vsp(name=f"{pnf['pnf_name']}_VSP",
                                       vendor=vendor,
                                       package=package)
                        vsp.onboard()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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_vendor_onboard_unknown():
    """Integration tests for Vendor."""
    response = requests.post("{}/reset".format(SDC.base_front_url))
    response.raise_for_status()
    vendor = Vendor(name="test")
    vendor.onboard()
    assert vendor.status == const.CERTIFIED
def test_submit_already_certified(mock_send, mock_load, mock_exists):
    """Do nothing if already certified."""
    mock_exists.return_value = True
    vendor = Vendor()
    vendor._status = const.CERTIFIED
    vendor.submit()
    mock_send.assert_not_called()
Ejemplo n.º 10
0
def test_vendor_created_but_already_vendor(mock_created, mock_details):
    mock_created.return_value = True
    vsp = Vsp()
    vendor = Vendor()
    vsp.vendor = vendor
    assert vsp.vendor == vendor
    mock_details.assert_not_called()
Ejemplo n.º 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
Ejemplo n.º 12
0
 def vendor(self) -> Vendor:
     """Return and lazy load the vendor."""
     if self.created() and not self._vendor:
         details = self._get_vsp_details()
         if details:
             self._vendor = Vendor(name=details['vendorName'])
     return self._vendor
Ejemplo n.º 13
0
def test_status_no_load_created(mock_load, mock_created):
    mock_created.return_value = True
    vendor = Vendor()
    vendor.identifier = "12345"
    vendor._status = "Draft"
    assert vendor.status == "Draft"
    mock_load.assert_not_called()
Ejemplo n.º 14
0
def test_create_OK(mock_send, mock_exists):
    """Create and update object."""
    vsp = Vsp()
    vendor = Vendor()
    vendor._identifier = "1232"
    vsp.vendor = vendor
    expected_data = '{\n  "name": "ONAP-test-VSP",\n  "description": "vendor software product",\n  "icon": "icon",\n  "category": "resourceNewCategory.generic",\n  "subCategory": "resourceNewCategory.generic.abstract",\n  "vendorName": "Generic-Vendor",\n  "vendorId": "1232",\n  "licensingData": {},\n  "onboardingMethod": "NetworkPackage"\n}'
    mock_exists.return_value = False
    mock_send.return_value = {
        'itemId': "1234",
        'version': {
            'id': "5678",
            'status': 'state_created'
        }
    }
    vsp.create()
    mock_send.assert_called_once_with(
        "POST",
        "create Vsp",
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products',
        data=expected_data)
    assert vsp.created() == True
    assert vsp._status == const.DRAFT
    assert vsp.identifier == "1234"
    assert vsp.version == "5678"
Ejemplo n.º 15
0
def test_onboard_whole_vendor(mock_create, mock_submit):
    getter_mock = mock.Mock(wraps=Vendor.status.fget)
    mock_status = Vendor.status.getter(getter_mock)
    with mock.patch.object(Vendor, 'status', mock_status):
        getter_mock.side_effect = [None, const.DRAFT, const.DRAFT, None]
        vendor = Vendor()
        vendor.onboard()
        mock_submit.assert_called_once()
        mock_create.assert_called_once()
Ejemplo n.º 16
0
def test_create_already_exists(mock_send, mock_exists):
    """Do nothing if already created in SDC."""
    vsp = Vsp()
    vendor = Vendor()
    vendor._identifier = "1232"
    vsp.vendor = vendor
    mock_exists.return_value = True
    vsp.create()
    mock_send.assert_not_called()
Ejemplo n.º 17
0
def test_init_with_name():
    """Check init with no names."""
    vendor = Vendor(name="YOLO")
    assert vendor._identifier == None
    assert vendor._version == None
    assert vendor.name == "YOLO"
    assert vendor.headers["USER_ID"] == "cs0008"
    assert isinstance(vendor._base_url(), str)
    assert "sdc1/feProxy/onboarding-api/v1.0" in vendor._base_url()
def test__get_items_version_details(mock_send):
    vendor = Vendor()
    vendor.identifier = "1234"
    vendor._version = "4567"
    mock_send.return_value = {'return': 'value'}
    assert vendor._get_item_version_details() == {'return': 'value'}
    mock_send.assert_called_once_with(
        'GET', 'get item version',
        "{}/items/1234/versions/4567".format(vendor._base_url()))
Ejemplo n.º 19
0
    def execute(self):
        """Onboard vendor.

        Use settings values:
         - VENDOR_NAME.

        """
        super().execute()
        vendor: Vendor = Vendor(name=settings.VENDOR_NAME)
        vendor.onboard()
Ejemplo n.º 20
0
def test_vsp_onboard_unknown():
    """Integration tests for Vsp."""
    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()
    assert vsp.status == const.CERTIFIED
    assert vsp.csar_uuid is not None
Ejemplo n.º 21
0
def test_create_issue_in_creation(mock_send, mock_exists):
    """Do nothing if not created but issue during creation."""
    vendor = Vendor()
    expected_data = '{\n  "iconRef": "icon",\n  "vendorName": "Generic-Vendor",\n  "description": "vendor"\n}'
    mock_exists.return_value = False
    mock_send.return_value = {}
    vendor.create()
    mock_send.assert_called_once_with("POST",
                                      "create Vendor",
                                      mock.ANY,
                                      data=expected_data)
    assert vendor.created() == False
Ejemplo n.º 22
0
def test_init_no_name(mock_exists):
    """Check init with no names."""
    mock_exists.return_value = False
    vendor = Vendor()
    assert isinstance(vendor, SdcElement)
    assert vendor._identifier == None
    assert vendor._version == None
    assert vendor.name == "Generic-Vendor"
    assert vendor.created() == False
    assert vendor.headers["USER_ID"] == "cs0008"
    assert isinstance(vendor._base_url(), str)
    assert "sdc1/feProxy/onboarding-api/v1.0" in vendor._base_url()
Ejemplo n.º 23
0
def test_load_not_created(mock_send, mock_get_all):
    mock_send.return_value = {
        'results': [{
            'status': 'state_one',
            'id': "5678"
        }]
    }
    vendor = Vendor(name="one")
    vendor.load()
    mock_get_all.return_value = []
    mock_send.assert_not_called()
    assert vendor._status == None
    assert vendor.version == None
    assert vendor._identifier == None
Ejemplo n.º 24
0
    def execute(self):
        """Onboard Vsp.

        Use settings values:
         - VSP_NAME,
         - VSP_FILE_PATH,
         - VENDOR_NAME.

        """
        super().execute()
        vendor: Vendor = Vendor(name=settings.VENDOR_NAME)
        vsp: Vsp = Vsp(name=settings.VSP_NAME,
                       vendor=vendor,
                       package=open(settings.VSP_FILE_PATH, "rb"))
        vsp.onboard()
Ejemplo n.º 25
0
def test_create_issue_in_creation(mock_send, mock_exists):
    """Do nothing if not created but issue during creation."""
    vsp = Vsp()
    vendor = Vendor()
    vendor._identifier = "1232"
    vsp.vendor = vendor
    expected_data = '{\n  "name": "ONAP-test-VSP",\n  "description": "vendor software product",\n  "icon": "icon",\n  "category": "resourceNewCategory.generic",\n  "subCategory": "resourceNewCategory.generic.abstract",\n  "vendorName": "Generic-Vendor",\n  "vendorId": "1232",\n  "licensingData": {},\n  "onboardingMethod": "NetworkPackage"\n}'
    mock_exists.return_value = False
    mock_send.return_value = {}
    vsp.create()
    mock_send.assert_called_once_with(
        "POST",
        "create Vsp",
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products',
        data=expected_data)
    assert vsp.created() == False
Ejemplo n.º 26
0
def test_submit_certified_OK(mock_send, mock_load, mock_exists):
    """Set status to CERTIFIED if submission OK."""
    mock_exists.return_value = True
    vendor = Vendor()
    vendor._status = "Draft"
    vendor._version = "1234"
    vendor.identifier = "12345"
    mock_send.return_value = mock.Mock()
    expected_data = '{\n\n  "action": "Submit"\n}'
    vendor.submit()
    mock_send.assert_called_once_with(
        "PUT",
        "Submit Vendor",
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-license-models/12345/versions/1234/actions',
        data=expected_data)
    assert vendor.status == const.CERTIFIED
Ejemplo n.º 27
0
    def import_from_sdc(cls, values: Dict[str, Any]) -> 'Vsp':
        """
        Import Vsp from SDC.

        Args:
            values (Dict[str, Any]): dict to parse returned from SDC.

        Returns:
            a Vsp instance with right values

        """
        cls._logger.debug("importing VSP %s from SDC", values['name'])
        vsp = Vsp(values['name'])
        vsp.identifier = values['id']
        vsp.vendor = Vendor(name=values['vendorName'])
        return vsp
Ejemplo n.º 28
0
def test_load_created(mock_send, mock_get_all):
    mock_send.return_value = {
        'results': [{
            'status': 'state_one',
            'id': "5678"
        }]
    }
    vendor = Vendor(name="one")
    vendor.identifier = "1234"
    vendor.load()
    mock_get_all.assert_not_called()
    mock_send.assert_called_once_with(
        'GET', 'get item',
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/items/1234/versions'
    )
    assert vendor.status == "state_one"
    assert vendor.version == "5678"
Ejemplo n.º 29
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
Ejemplo n.º 30
0
def test_submit_certified_NOK(mock_send, mock_load, mock_exists):
    """Don't update status if submission NOK."""
    mock_exists.return_value = True
    vendor = Vendor()
    vendor._identifier = "12345"
    mock_send.side_effect = RequestError
    expected_data = '{\n\n  "action": "Submit"\n}'
    vendor._status = "Draft"
    vendor._version = "1234"
    with pytest.raises(RequestError) as err:
        vendor.submit()
    assert err.type == RequestError
    mock_send.assert_called_once_with(
        "PUT",
        "Submit Vendor",
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-license-models/12345/versions/1234/actions',
        data=expected_data)
    assert vendor._status != const.CERTIFIED