Example #1
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 #2
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 #3
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 #4
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
Example #5
0
def test_onboard_new_vsp_create_csar(mock_create, mock_upload_package,
                                     mock_validate, mock_commit, mock_submit,
                                     mock_create_csar):
    getter_mock = mock.Mock(wraps=Vsp.status.fget)
    mock_status = Vsp.status.getter(getter_mock)
    with mock.patch.object(Vsp, 'status', mock_status):
        getter_mock.side_effect = [const.CERTIFIED, const.APPROVED, None]
        vsp = Vsp()
        vsp.onboard()
        mock_create.assert_not_called()
        mock_upload_package.assert_not_called()
        mock_validate.assert_not_called()
        mock_commit.assert_not_called()
        mock_submit.assert_not_called()
        mock_create_csar.assert_called_once()
Example #6
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
def test_onboard_vsp_upload_no_files(mock_create, mock_upload_package,
                                     mock_validate, mock_commit, mock_submit,
                                     mock_create_csar):
    getter_mock = mock.Mock(wraps=Vsp.status.fget)
    mock_status = Vsp.status.getter(getter_mock)
    with mock.patch.object(Vsp, 'status', mock_status):
        getter_mock.side_effect = [
            const.DRAFT, const.DRAFT, const.APPROVED, const.APPROVED,
            const.APPROVED, const.APPROVED, const.APPROVED, None
        ]
        vsp = Vsp()
        with pytest.raises(ValueError):
            vsp.onboard()
            mock_create.assert_not_called()
            mock_upload_package.assert_not_called()
            mock_validate.assert_not_called()
            mock_commit.assert_not_called()
            mock_submit.assert_not_called()
            mock_create_csar.assert_not_called()
Example #8
0
def test_onboard_whole_vsp(mock_load, mock_created, mock_create,
                           mock_upload_package, mock_validate, mock_commit,
                           mock_submit, mock_create_csar):
    getter_mock = mock.Mock(wraps=Vsp.status.fget)
    mock_status = Vsp.status.getter(getter_mock)
    with mock.patch.object(Vsp, 'status', mock_status):
        getter_mock.side_effect = [
            None, const.DRAFT, const.UPLOADED, const.VALIDATED, const.COMMITED,
            const.CERTIFIED, None
        ]
        vendor = Vendor()
        vsp = Vsp(vendor=vendor, package="yes")
        vsp.onboard()
        mock_create.assert_called_once()
        mock_upload_package.assert_called_once()
        mock_validate.assert_called_once()
        mock_commit.assert_called_once()
        mock_submit.assert_called_once()
        mock_create_csar.assert_called_once()
def test_onboard_new_vsp(mock_created, mock_create, mock_upload_package,
                         mock_validate, mock_commit, mock_submit,
                         mock_create_csar):
    mock_created.return_value = False
    getter_mock = mock.Mock(wraps=Vsp.status.fget)
    mock_status = Vsp.status.getter(getter_mock)
    with mock.patch.object(Vsp, 'status', mock_status):
        getter_mock.side_effect = [
            None, const.APPROVED, const.APPROVED, const.APPROVED,
            const.APPROVED, const.APPROVED, None
        ]
        vendor = Vendor()
        vsp = Vsp(vendor=vendor)
        vsp.onboard()
        mock_create.assert_called_once()
        mock_upload_package.assert_not_called()
        mock_validate.assert_not_called()
        mock_commit.assert_not_called()
        mock_submit.assert_not_called()
        mock_create_csar.assert_not_called()
Example #10
0
def test_vf_properties():
    """Integration test to check properties assignment 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()
    prop = Property(name="test1", property_type="string", value="123")
    vf = Vf(name="test",
            vsp=vsp,
            properties=[prop,
                        Property(name="test2", property_type="integer")],
            inputs=[prop])
    vf.onboard()
    vf_properties = list(vf.properties)
    vf_inputs = list(vf.inputs)
    assert len(vf_properties) == 2
    assert len(vf_inputs) == 1
Example #11
0
def test_vf_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.create()
    assert vf.identifier is not None
    assert vf.status == const.DRAFT
    assert vf.version == "0.1"
    vf.submit()
    assert vsp.status == const.CERTIFIED
    assert vf.version == "1.0"
    vf.load()
    assert vsp.status == const.CERTIFIED
    assert vf.version == "1.0"
Example #12
0
            SDNC_MODEL_NAME = tosca_meta.get("Template-Name")
            SDNC_MODEL_VERSION = tosca_meta.get("Template-Version")

logger.info("*******************************")
logger.info("******** SERVICE DESIGN *******")
logger.info("*******************************")

logger.info("******** Onboard Vendor *******")
vendor = Vendor(name=Config.VENDOR)
vendor.onboard()

logger.info("******** Onboard VSP *******")
mypath = os.path.dirname(os.path.realpath(__file__))
myvspfile = os.path.join(mypath, Config.VSPFILE)
vsp = Vsp(name=Config.VSPNAME, vendor=vendor, package=open(myvspfile, 'rb'))
vsp.onboard()

logger.info("******** Onboard VF *******")
vf = Vf(name=Config.VFNAME)
vf.vsp = vsp
vf.create()
vf.onboard()

logger.info("******** Onboard Service *******")
svc = Service(name=Config.SERVICENAME,
              instantiation_type=ServiceInstantiationType.MACRO)
svc.create()

if svc.status == const.DRAFT:
    svc.add_resource(vf)