Ejemplo n.º 1
0
def test_vnf_two_vf_modules():
    """Test parsing TOSCA file with two VNF which has associated one VFmodule"""
    service = Service(name="test")
    with open(
            Path(
                Path(__file__).resolve().parent,
                "data/service-VfwcdsService-template.yml"), "r") as template:
        service._tosca_template = yaml.safe_load(template.read())
        assert len(service.vnfs) == 1
        vnf = service.vnfs[0]
        assert len(vnf.vf_modules) == 4
Ejemplo n.º 2
0
def test_pnf_modules_one():
    """Test parsing TOSCA file with one PNF which has associated one PNFmodule"""
    service = Service(name="test")
    with open(
            Path(
                Path(__file__).resolve().parent,
                "data/service-TestPnfVsp-template.yml"), "r") as pnf:
        service._tosca_template = yaml.safe_load(pnf.read())
        assert len(service.pnfs) == 1
        pnf = service.pnfs[0]
        assert pnf.name == "test_pnf_vsp 0"
        assert pnf.node_template_type == "org.openecomp.resource.pnf.TestPnfVsp"
Ejemplo n.º 3
0
def test_service_networks():
    service = Service(name="test")
    with open(
            Path(
                Path(__file__).resolve().parent,
                "data/service-TestServiceFyx-template.yml"),
            "r") as service_file:
        service._tosca_template = yaml.safe_load(service_file.read())
    assert len(service.networks) == 1

    network = service.networks[0]
    assert network.name == "NeutronNet 0"
    assert network.node_template_type == "org.openecomp.resource.vl.nodes.heat.network.neutron.Net"
Ejemplo n.º 4
0
def test_vnf_vf_modules_one():
    """Test parsing TOSCA file with one VNF which has associated one VFmodule"""
    service = Service(name="test")
    with open(
            Path(
                Path(__file__).resolve().parent,
                "data/service-Ubuntu16-template.yml"), "r") as ubuntu:
        service._tosca_template = yaml.safe_load(ubuntu.read())
        assert len(service.vnfs) == 1
        vnf = service.vnfs[0]
        assert vnf.name == "ubuntu16_VF 0"
        assert vnf.node_template_type == "org.openecomp.resource.vf.Ubuntu16Vf"
        assert vnf.vf_modules
        assert vnf.vf_modules[
            0].name == "ubuntu16_vf0..Ubuntu16Vf..base_ubuntu16..module-0"
Ejemplo n.º 5
0
def test_vnf_vf_modules_two():
    """Test parsing TOSCA file with two VNF which has associated one VFmodule"""
    service = Service(name="test")
    with open(
            Path(
                Path(__file__).resolve().parent,
                "data/service-Foo-template.yml"), "r") as ubuntu:
        service._tosca_template = yaml.safe_load(ubuntu.read())
        assert len(service.vnfs) == 2
        vnf = service.vnfs[0]
        assert vnf.name == "vFWCL_vPKG-vf 0"
        assert vnf.node_template_type == "org.openecomp.resource.vf.VfwclVpkgVf"
        assert vnf.vf_modules
        assert vnf.vf_modules[
            0].name == "vfwcl_vpkgvf0..VfwclVpkgVf..base_vpkg..module-0"

        vnf = service.vnfs[1]
        assert vnf.name == "vFWCL_vFWSNK-vf 0"
        assert vnf.node_template_type == "org.openecomp.resource.vf.VfwclVfwsnkVf"
        assert vnf.vf_modules
        assert vnf.vf_modules[
            0].name == "vfwcl_vfwsnkvf0..VfwclVfwsnkVf..base_vfw..module-0"
Ejemplo n.º 6
0
def test_tosca_template_present(mock_unzip):
    service = Service(name="test")
    service._tosca_template = "test"
    assert service.tosca_template == "test"
    mock_unzip.assert_not_called()
Ejemplo n.º 7
0
def test_instantiate_macro_multiple_vnf(mock_service_components,
                                        mock_service_vnfs):
    requests.get(f"{ServiceInstantiation.base_url}/reset")
    requests.get(f"{Customer.base_url}/reset")
    requests.post(f"{ServiceInstantiation.base_url}/set_aai_mock",
                  json={"AAI_MOCK": settings.AAI_URL})

    customer = Customer.create(global_customer_id="test_global_customer_id",
                               subscriber_name="test_subscriber_name",
                               subscriber_type="test_subscriber_type")
    service = Service("test_service")
    service._tosca_template = "n/a"

    mock_service_vnfs.return_value = [
        Vnf(name="test_vnf",
            node_template_type="vf",
            model_name="test_vnf_model",
            model_version_id=str(uuid4()),
            model_invariant_id=str(uuid4()),
            model_version="1.0",
            model_customization_id=str(uuid4()),
            model_instance_name=str(uuid4()),
            component=MagicMock(),
            vf_modules=[
                VfModule(name="TestVnfModel..base..module-0",
                         group_type="vf-module",
                         model_name="TestVnfModel..base..module-0",
                         model_version_id=str(uuid4()),
                         model_invariant_uuid=str(uuid4()),
                         model_version="1",
                         model_customization_id=str(uuid4()),
                         properties=None)
            ])
    ]
    service.unique_uuid = str(uuid4())
    service.identifier = str(uuid4())
    service.name = str(uuid4())
    customer.subscribe_service("service_type")
    service_subscription = customer.get_service_subscription_by_service_type(
        "service_type")
    cloud_region = CloudRegion.create("test_owner",
                                      "test_cloud_region",
                                      orchestration_disabled=True,
                                      in_maint=False)
    cloud_region.add_tenant(tenant_id="test_tenant_name",
                            tenant_name="test_tenant_name",
                            tenant_context="test_tenant_context")
    tenant = cloud_region.get_tenant(tenant_id="test_tenant_name")
    service_subscription.link_to_cloud_region_and_tenant(
        cloud_region=cloud_region, tenant=tenant)
    owning_entity = "test_owning_entity"
    project = "test_project"
    line_of_business = "test_line_of_business"
    platform = "test_platform"

    so_service = SoService.load({
        "subscription_service_type":
        "service_type",
        "vnfs": [{
            "model_name":
            "test_vnf_model",
            "instance_name":
            "vnf0",
            "parameters": {
                "param1": "value1"
            },
            "vf_modules": [{
                "instance_name": "vnf0_vfm0",
                "model_name": "base",
                "parameters": {
                    "vfm_param1": "vfm_value1"
                }
            }]
        }, {
            "model_name":
            "test_vnf_model",
            "instance_name":
            "vnf1",
            "parameters": {
                "param2": "value2"
            },
            "vf_modules": [{
                "instance_name": "vnf1_vfm0",
                "model_name": "base",
                "parameters": {
                    "vfm_param2": "vfm_value2"
                }
            }]
        }]
    })

    # Service instantiation
    service._distributed = True
    assert len(list(service_subscription.service_instances)) == 0
    service_instantiation_request = ServiceInstantiation.instantiate_macro(
        sdc_service=service,
        customer=customer,
        owning_entity=owning_entity,
        project=project,
        line_of_business=line_of_business,
        platform=platform,
        cloud_region=cloud_region,
        tenant=tenant,
        so_service=so_service)
    assert service_instantiation_request.status == ServiceInstantiation.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert service_instantiation_request.status == ServiceInstantiation.StatusEnum.COMPLETED
    assert len(list(service_subscription.service_instances)) == 1
    service_instance = next(service_subscription.service_instances)

    # Cleanup
    with patch.object(ServiceInstance, "sdc_service",
                      return_value=service) as service_mock:
        service_deletion_request = service_instance.delete()
    assert service_deletion_request.status == ServiceDeletionRequest.StatusEnum.IN_PROGRESS
    time.sleep(
        2)  # After 1 second mocked server changed request status to complete
    assert service_deletion_request.status == ServiceDeletionRequest.StatusEnum.COMPLETED
    assert len(list(service_subscription.service_instances)) == 0