Exemplo n.º 1
0
def test_onboard_service_several_resources(mock_create, mock_add_resource,
                                           mock_checkin, mock_submit,
                                           mock_start_certification,
                                           mock_certify, mock_approve,
                                           mock_distribute):
    getter_mock = mock.Mock(wraps=Service.status.fget)
    mock_status = Service.status.getter(getter_mock)
    with mock.patch.object(Service, 'status', mock_status):
        getter_mock.side_effect = [
            const.DRAFT, const.DRAFT, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, None
        ]
        resource1 = SdcResource()
        resource2 = SdcResource()
        service = Service(resources=[resource1, resource2])
        service._time_wait = 0
        service.onboard()
        mock_create.assert_not_called()
        calls = [mock.call(resource1), mock.call(resource2)]
        mock_add_resource.assert_has_calls(calls, any_order=True)
        assert mock_add_resource.call_count == 2
        mock_checkin.assert_called_once()
        mock_submit.assert_not_called()
        mock_start_certification.assert_not_called()
        mock_certify.assert_not_called()
        mock_approve.assert_not_called()
        mock_distribute.assert_not_called()
Exemplo n.º 2
0
def test_equality_not_equals_not_same_object():
    """Check a vf and something different are not equals."""
    svc_1 = Service(name="equal")
    svc_1.identifier = "1234"
    svc_2 = SdcResource()
    svc_2.name = "equal"
    assert svc_1 != svc_2
Exemplo n.º 3
0
def test_equality_not_equals_not_same_object():
    """Check a vf and something different are not equals."""
    vf_1 = Vf(name="equal")
    vf_1.identifier = "1234"
    vf_2 = SdcResource()
    vf_2.name = "equal"
    assert vf_1 != vf_2
Exemplo n.º 4
0
def test_equality_not_equals_not_same_object():
    """Check a pnf and something different are not equals."""
    pnf_1 = Pnf(name="equal")
    pnf_1.identifier = "1234"
    pnf_2 = SdcResource()
    pnf_2.name = "equal"
    assert pnf_1 != pnf_2
Exemplo n.º 5
0
def test__action_url_action_type():
    sdcResource = SdcResource()
    url = sdcResource._action_url("base",
                                  "subpath",
                                  "version_path",
                                  action_type="distribution")
    assert url == "base/resources/version_path/distribution/subpath"
def test_sdc_resource_is_own_property(mock_send_json):
    sdc_resource = SdcResource(name="test")
    sdc_resource.unique_identifier = "toto"
    mock_send_json.return_value = PROPERTIES
    prop1 = Property(name="llllll", property_type="integer")
    prop2 = Property(name="test2", property_type="string")
    assert sdc_resource.is_own_property(prop1)
    assert not sdc_resource.is_own_property(prop2)
Exemplo n.º 7
0
def test_declare_nested_input(mock_resource_inputs, mock_get_component,
                              mock_send_json):
    sdc_resource = SdcResource()
    sdc_resource.unique_identifier = "toto"
    mock_resource_inputs.return_value = "test"
    sdc_resource.declare_input(
        NestedInput(sdc_resource=mock.MagicMock(), input_obj=mock.MagicMock()))
    mock_get_component.assert_called_once()
    mock_send_json.assert_called_once()
def test_sdc_resource_input_default_value(mock_send_message_json, mock_inputs):
    sdc_resource = SdcResource(name="test")
    sdc_resource.unique_identifier = "toto"

    mock_inputs.return_value = [
        Input(unique_id="123",
              input_type="integer",
              name="test",
              sdc_resource=sdc_resource)
    ]
    assert sdc_resource.get_input("test")
    input_obj = sdc_resource.get_input("test")
    assert not input_obj.default_value
    input_obj.default_value = "123"
    mock_send_message_json.assert_called_once()
    assert input_obj.default_value == "123"
Exemplo n.º 9
0
def test_add_resource_not_draft(mock_send, mock_exists):
    mock_exists.return_value = False
    vf = Vf()
    resource = SdcResource()
    with pytest.raises(StatusError):
        vf.add_resource(resource)
    mock_send.assert_not_called()
Exemplo n.º 10
0
def test_component_properties():
    sdc_resource = mock.MagicMock()
    parent_sdc_resource = SdcResource()

    component = Component(created_from_csar=False,
                          actual_component_uid="123",
                          unique_id="123",
                          normalized_name="123",
                          name="123",
                          origin_type="123",
                          customization_uuid="123",
                          tosca_component_name="123",
                          component_name="123",
                          component_uid="123",
                          component_version="123",
                          sdc_resource=sdc_resource,
                          parent_sdc_resource=mock.MagicMock())
    sdc_resource.send_message_json.return_value = {}
    assert not len(list(component.properties))

    sdc_resource.send_message_json.return_value = COMPONENT_PROPERTIES
    properties = list(component.properties)
    assert len(properties) == 2
    prop1, prop2 = properties

    assert prop1.unique_id == "3d9a184f-4268-4a0e-9ddd-252e49670013.vf_module_id"
    assert prop1.property_type == "string"
    assert prop1.name == "vf_module_id"
    assert prop1.value is None

    assert prop2.unique_id == "74f79006-ae56-4d58-947e-6a5089000774.skip_post_instantiation_configuration"
    assert prop2.property_type == "boolean"
    assert prop2.name == "skip_post_instantiation_configuration"
    assert prop2.value == "true"
Exemplo n.º 11
0
def test_update_informations_from_sdc_creation_no_distribitution_state(
        mock_parse):
    mock_parse.return_value = "12"
    sdcResource = SdcResource()
    details = {
        'invariantUUID': '1234',
        'lifecycleState': 'state',
        'version': 'v12',
        'uniqueId': '5678'
    }

    sdcResource.update_informations_from_sdc_creation(details)
    assert sdcResource.unique_uuid == "1234"
    assert sdcResource.status == "12"
    assert sdcResource.version == "v12"
    assert sdcResource.unique_identifier == "5678"
    mock_parse.assert_called_once_with("state", None, mock.ANY)
Exemplo n.º 12
0
def test_declare_resources_and_properties(mock_declare_input,
                                          mock_add_property,
                                          mock_add_resource):

    service = Service(
        name="test",
        resources=[SdcResource()],
        properties=[Property(name="test", property_type="string")],
        inputs=[Property(name="test", property_type="string")])
    service.declare_resources_and_properties()
    mock_add_resource.assert_called_once()
    mock_add_property.assert_called_once()
    mock_declare_input.assert_called_once()
Exemplo n.º 13
0
def test_declare_input(mock_nested, mock_own, mock_is_own):
    sdc_resource = SdcResource()
    prop = Property(name="test", property_type="test")
    mock_is_own.return_value = False
    with pytest.raises(ValueError):
        sdc_resource.declare_input(prop)
    mock_is_own.return_value = True
    sdc_resource.declare_input(prop)
    mock_own.assert_called_once()
    mock_nested.assert_not_called()

    mock_nested.reset_mock()
    mock_own.reset_mock()
    sdc_resource.declare_input(
        NestedInput(sdc_resource=mock.MagicMock(), input_obj=mock.MagicMock()))
    mock_own.assert_not_called()
    mock_nested.assert_called_once()
Exemplo n.º 14
0
def test_get_component(mock_components):
    sdc_resource = SdcResource()

    mock_components.return_value = [
        Component(created_from_csar=False,
                  actual_component_uid="123",
                  unique_id="123",
                  normalized_name="123",
                  name="123",
                  origin_type="123",
                  customization_uuid="123",
                  tosca_component_name="123",
                  component_name="123",
                  component_uid="123",
                  component_version="123",
                  sdc_resource=SdcResource(name="test"),
                  parent_sdc_resource=sdc_resource)
    ]
    assert sdc_resource.get_component(SdcResource(name="test"))
    with pytest.raises(AttributeError):
        sdc_resource.get_component(SdcResource(name="test2"))
Exemplo n.º 15
0
def test_onboard_whole_service(mock_create, mock_add_resource, mock_checkin,
                               mock_certify, mock_distribute):
    getter_mock = mock.Mock(wraps=Service.status.fget)
    mock_status = Service.status.getter(getter_mock)
    with mock.patch.object(Service, 'status', mock_status):
        getter_mock.side_effect = [
            None, const.DRAFT, const.DRAFT, const.CHECKED_IN, const.CHECKED_IN,
            const.CHECKED_IN, const.CERTIFIED, const.CERTIFIED,
            const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, None
        ]
        resource = SdcResource()
        service = Service(resources=[resource])
        service._time_wait = 0
        service.onboard()
        mock_create.assert_called_once()
        mock_add_resource.assert_called_once_with(resource)
        mock_checkin.assert_called_once()
        mock_certify.assert_called_once()
        mock_distribute.assert_called_once()
Exemplo n.º 16
0
def test_get_input(mock_inputs):
    sdc_resource = SdcResource()

    mock_inputs.return_value = [
        Input(unique_id="123",
              input_type="integer",
              name="test",
              sdc_resource=sdc_resource),
        Input(unique_id="321",
              input_type="string",
              name="test2",
              sdc_resource=sdc_resource)
    ]
    assert sdc_resource.get_input("test")
    assert sdc_resource.get_input("test2")
    with pytest.raises(AttributeError):
        sdc_resource.get_input("test3")
Exemplo n.º 17
0
def test_onboard_service_resources(mock_create, mock_add_resource,
                                   mock_checkin, mock_submit,
                                   mock_start_certification, mock_certify,
                                   mock_approve, mock_distribute):
    getter_mock = mock.Mock(wraps=Service.status.fget)
    mock_status = Service.status.getter(getter_mock)
    with mock.patch.object(Service, 'status', mock_status):
        getter_mock.side_effect = [
            const.DRAFT, const.DRAFT, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, None
        ]
        resource = SdcResource()
        service = Service(resources=[resource])
        service._time_wait = 0
        service.onboard()
        mock_create.assert_not_called()
        mock_add_resource.assert_called_once_with(resource)
        mock_checkin.assert_called_once()
        mock_submit.assert_not_called()
        mock_start_certification.assert_not_called()
        mock_certify.assert_not_called()
        mock_approve.assert_not_called()
        mock_distribute.assert_not_called()
Exemplo n.º 18
0
def test_add_resource_bad_result(mock_send, mock_load):
    vf = Vf()
    vf.unique_identifier = "45"
    vf.identifier = "93"
    vf.status = const.DRAFT
    mock_send.return_value = {}
    resource = SdcResource()
    resource.unique_identifier = "12"
    resource.created = MagicMock(return_value=True)
    resource.version = "40"
    resource.name = "test"
    assert vf.add_resource(resource) is None
    mock_send.assert_called_once_with(
        'POST',
        'Add SDCRESOURCE to VF',
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/resources/45/resourceInstance',
        data=
        '{\n  "name": "test",\n  "componentVersion": "40",\n  "posY": 100,\n  "posX": 200,\n  "uniqueId": "12",\n  "originType": "SDCRESOURCE",\n  "componentUid": "12",\n  "icon": "defaulticon"\n}'
    )
Exemplo n.º 19
0
def test_add_resource_OK(mock_send, mock_load):
    svc = Service()
    svc.unique_identifier = "45"
    svc.identifier = "93"
    svc.status = const.DRAFT
    mock_send.return_value = {'yes': 'indeed'}
    resource = SdcResource()
    resource.unique_identifier = "12"
    resource.created = MagicMock(return_value=True)
    resource.version = "40"
    resource.name = "test"
    result = svc.add_resource(resource)
    assert result['yes'] == "indeed"
    mock_send.assert_called_once_with(
        'POST',
        'Add SdcResource to service',
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/services/45/resourceInstance',
        data=
        '{\n  "name": "test",\n  "componentVersion": "40",\n  "posY": 100,\n  "posX": 200,\n  "uniqueId": "12",\n  "originType": "SDCRESOURCE",\n  "componentUid": "12",\n  "icon": "defaulticon"\n}'
    )
def test_sdc_resource_set_property_value(mock_send_message_json,
                                         mock_sdc_resource_properties):
    sdc_resource = SdcResource(name="test")
    sdc_resource.unique_identifier = "toto"

    mock_sdc_resource_properties.return_value = [
        Property(name="test",
                 property_type="string",
                 sdc_resource=sdc_resource)
    ]
    with pytest.raises(ValueError):
        sdc_resource.set_property_value(Property(name="test2",
                                                 property_type="integer",
                                                 sdc_resource=sdc_resource),
                                        value="lalala")
    prop = sdc_resource.get_property(property_name="test")
    assert prop.name == "test"
    assert prop.property_type == "string"
    assert not prop.value

    prop.value = "test"
    mock_send_message_json.assert_called_once()
    assert prop.value == "test"
Exemplo n.º 21
0
def test__parse_sdc_status_distributed():
    assert SdcResource._parse_sdc_status(
        "CERTIFIED", const.SDC_DISTRIBUTED,
        logging.getLogger()) == const.DISTRIBUTED
Exemplo n.º 22
0
def test__parse_sdc_status_submitted():
    assert SdcResource._parse_sdc_status(
        const.READY_FOR_CERTIFICATION, None,
        logging.getLogger()) == const.SUBMITTED
Exemplo n.º 23
0
def test__parse_sdc_status_under_certification():
    assert SdcResource._parse_sdc_status(
        const.CERTIFICATION_IN_PROGRESS, None,
        logging.getLogger()) == const.UNDER_CERTIFICATION
Exemplo n.º 24
0
def test__parse_sdc_status_unknown():
    assert SdcResource._parse_sdc_status("UNKNOWN", None,
                                         logging.getLogger()) == 'UNKNOWN'
Exemplo n.º 25
0
def test__parse_sdc_status_empty():
    assert SdcResource._parse_sdc_status("", None, logging.getLogger()) is None
Exemplo n.º 26
0
def test__really_submit():
    sdcResource = SdcResource()
    with pytest.raises(NotImplementedError):
        sdcResource._really_submit()
Exemplo n.º 27
0
def test__action_url_no_action_type():
    sdcResource = SdcResource()
    url = sdcResource._action_url("base", "subpath", "version_path")
    assert url == "base/resources/version_path/lifecycleState/subpath"
Exemplo n.º 28
0
def test_init():
    """Test the initialization."""
    element = SdcResource()
    assert isinstance(element, OnapService)
Exemplo n.º 29
0
def test__parse_sdc_status_draft():
    assert SdcResource._parse_sdc_status(
        const.NOT_CERTIFIED_CHECKIN, None,
        logging.getLogger()) == const.CHECKED_IN
Exemplo n.º 30
0
def test_add_resource_not_draft(mock_send, mock_exists):
    mock_exists.return_value = False
    svc = Service()
    resource = SdcResource()
    svc.add_resource(resource)
    mock_send.assert_not_called()