Example #1
0
def test_blueprint_save():
    blueprint = Blueprint(b"test cba - it will never work")
    with TemporaryDirectory() as tmpdirname:
        path = os.path.join(tmpdirname, "test.zip")
        blueprint.save(path)
        with open(path, "rb") as f:
            assert f.read() == b"test cba - it will never work"
Example #2
0
def test_blueprint_get_mappings_from_mapping_file():
    b = Blueprint(b"test cba - it will never work")
    mappings = list(b.get_mappings_from_mapping_file(vLB_CBA_Python_base_template_mapping_bytes))
    assert len(mappings) == 5
    mapping = mappings[0]
    assert mapping.name == "service-instance-id"
    assert mapping.mapping_type == "string"
    assert mapping.dictionary_name == "service-instance-id"
    assert mapping.dictionary_sources == ["input"]
def test_blueprint_read_cba_metadata():
    b = Blueprint(b"test cba - it will never work")
    with raises(ValidationError) as exc:
        b.get_cba_metadata(b"Invalid")
        b.get_cba_metadata(b"123: 456")
    assert exc.type is ValidationError

    cba_metadata = b.get_cba_metadata(vLB_CBA_Python_meta_bytes)
    assert cba_metadata.tosca_meta_file_version == "1.0.0"
    assert cba_metadata.csar_version == 1.0
    assert cba_metadata.created_by == "PLATANIA, MARCO <*****@*****.**>"
    assert cba_metadata.entry_definitions == "Definitions/vLB_CDS.json"
    assert cba_metadata.template_name == "vDNS-CDS-test1"
    assert cba_metadata.template_version == 1.0
    assert cba_metadata.template_tags == "vDNS-CDS-test1"

    with open(Path(Path(__file__).resolve().parent, "data/vLB_CBA_Python.zip"),
              "rb") as cba_file:
        b = Blueprint(cba_file.read())
    assert b.metadata.tosca_meta_file_version == "1.0.0"
    assert b.metadata.csar_version == 1.0
    assert b.metadata.created_by == "PLATANIA, MARCO <*****@*****.**>"
    assert b.metadata.entry_definitions == "Definitions/vLB_CDS.json"
    assert b.metadata.template_name == "vDNS-CDS-test1"
    assert b.metadata.template_version == 1.0
    assert b.metadata.template_tags == "vDNS-CDS-test1"
def test_blueprint_get_resolved_template(cds_element_url_property_mock,
                                         mock_send_message_json):
    cds_element_url_property_mock.return_value = "http://127.0.0.1"

    with open(Path(Path(__file__).resolve().parent, "data/vLB_CBA_Python.zip"),
              "rb") as cba_file:
        b = Blueprint(cba_file.read())
    b.get_resolved_template("test_artifact")
    assert mock_send_message_json.called_once()
    assert mock_send_message_json.call_args[0][
        2] == 'http://127.0.0.1/api/v1/template?bpName=vDNS-CDS-test1&bpVersion=1.0&artifactName=test_artifact&format=application%2Fjson'
def test_blueprint_load_from_file_file_error():

    with TemporaryDirectory() as tmpdirname, \
        patch("__main__.open", new_callable=mock_open) as mo, \
        raises(FileError) as exc:

        path = os.path.join(tmpdirname, "nonexistent_file.zip")
        mo.side_effect = FileNotFoundError

        Blueprint.load_from_file(path)

    assert exc.type == FileError
def test_blueprint_store_resolved_template(cds_element_url_property_mock,
                                           mock_send_message):
    cds_element_url_property_mock.return_value = "http://127.0.0.1"

    with open(Path(Path(__file__).resolve().parent, "data/vLB_CBA_Python.zip"),
              "rb") as cba_file:
        b = Blueprint(cba_file.read())
    b.store_resolved_template("test_artifact",
                              resolution_key="resolution_key",
                              data={"a": "b"})
    assert mock_send_message.called_once()
    assert mock_send_message.call_args[0][
        2] == 'http://127.0.0.1/api/v1/template/vDNS-CDS-test1/1.0/test_artifact/resolution_key'
def test_blueprint_load_from_file():
    with TemporaryDirectory() as tmpdirname:
        path = os.path.join(tmpdirname, "test.zip")
        with open(path, "wb") as f:
            f.write(b"test cba - it will never work")
        blueprint = Blueprint.load_from_file(path)
        assert blueprint.cba_file_bytes == b"test cba - it will never work"
Example #8
0
def test_blueprint_get_workflows_from_entry_definitions_file():
    with open(Path(Path(__file__).resolve().parent, "data/vLB_CBA_Python.zip"), "rb") as cba_file:
        b = Blueprint(cba_file.read())
    assert len(b.workflows) == 3
    workflow = b.workflows[0]
    assert len(workflow.steps) == 1
    assert workflow.steps[0].name == "resource-assignment"
    assert workflow.steps[0].description == "Resource Assign Workflow"
    assert workflow.steps[0].target == "resource-assignment"
    assert len(workflow.inputs) == 2
    assert len(workflow.outputs) == 1
Example #9
0
def test_blueprint_enrichment(send_message_mock):
    blueprint = Blueprint(b"test cba - it will never work")
    blueprint.enrich()
    send_message_mock.assert_called_once()
    send_message_mock.reset_mock()
    send_message_mock.return_value = None
    with raises(AttributeError):
        blueprint.enrich()
def test_blueprint_enrichment(send_message_mock):
    blueprint = Blueprint(b"test cba - it will never work")
    blueprint.enrich()
    send_message_mock.assert_called_once()
    send_message_mock.reset_mock()
    send_message_mock.side_effect = RequestError
    with raises(RequestError):
        blueprint.enrich()
def test_blueprint_get_workflow_by_name():
    with open(Path(Path(__file__).resolve().parent, "data/vLB_CBA_Python.zip"),
              "rb") as cba_file:
        b = Blueprint(cba_file.read())
    workflow = b.get_workflow_by_name("resource-assignment")
    assert workflow.name == "resource-assignment"
    workflow = b.get_workflow_by_name("config-assign")
    assert workflow.name == "config-assign"
    workflow = b.get_workflow_by_name("config-deploy")
    assert workflow.name == "config-deploy"
    with raises(ParameterError):
        b.get_workflow_by_name("non-existing-workflow")
Example #12
0
def main():
    blueprint = None
    with zipfile.ZipFile(Config.VSPFILE, 'r') as package:
        with package.open("CBA.zip", 'r') as cba:
            blueprint = Blueprint(cba.read())

    healthcheck = Workflow('health-check', None, blueprint)
    serv_id, vnf_id = resolve_hc_inputs()
    cds_input = {
        "health-check-properties": {
            "service-instance-id": serv_id,
            "vnf-id": vnf_id
        }
    }
    logger.info("Requesting Healthcheck for CBA %s:%s with inputs:\n%s",
                blueprint.metadata.template_name,
                blueprint.metadata.template_version, cds_input)
    result = healthcheck.execute(cds_input)
    logger.info("Healthcheck process completed with result: %s", result)
    logger.info(
        "Please check cds-blueprints-processor logs to see exact status")
def test_cds_connection():

    TEST_DD_PATH = os.path.join(os.getcwd(), "integration_tests/test_files/test_dd.json")
    TEST_CBA_PATH = os.path.join(os.getcwd(), "integration_tests/test_files/test_vLB_CBA_Python.zip")


    # Endpoint availability
    response = requests.post("{}/api/v1/dictionary".format(settings.CDS_URL))
    assert response.status_code == 200

    response = requests.post("{}/api/v1/blueprint-model/enrich".format(settings.CDS_URL))
    assert response.status_code == 200

    response = requests.post("{}/api/v1/blueprint-model/publish".format(settings.CDS_URL))
    assert response.status_code == 200


    # Reads from the file system
    dd_set = DataDictionarySet.load_from_file(TEST_DD_PATH, True)
    blueprint = Blueprint.load_from_file(TEST_CBA_PATH)


    # Connection availability between CDS API and Blueprint/DataDictionarySet
    dd_set.upload()
    assert type(blueprint.cba_file_bytes) == bytes

    for dd in dd_set.dd_set:
        dd_obj = DataDictionary.get_by_name(dd.name)
        assert dd_obj == dd

    blueprint = blueprint.enrich()
    assert type(blueprint.cba_file_bytes) == bytes

    blueprint.publish()


    # Writes to the file system
    with TemporaryDirectory() as tmpdirname:
        path = os.path.join(tmpdirname, "test-CBA-enriched.zip")
        blueprint.save(path)
Example #14
0
def test_blueprint_deploy(send_message_mock):
    blueprint = Blueprint(b"test cba - it will never work")
    blueprint.deploy()
    send_message_mock.assert_called_once()
Example #15
0
def test_blueprint_generate_data_dictionary_set():
    with open(Path(Path(__file__).resolve().parent, "data/vLB_CBA_Python.zip"), "rb") as cba_file:
        b = Blueprint(cba_file.read())
    dd_set = b.get_data_dictionaries()
    print(dd_set)