aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_so_db_adapter.py
blob: 50f26d61408364a9377e73234769942d7457ea7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#   Copyright 2022 Orange, Deutsche Telekom AG
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
from unittest import mock

from onapsdk.so.so_db_adapter import SoDbAdapter, IdentityService

ADD_CLOUD_SITE_RESPONSE = {
    '_links': {
        'cloudSite': {
            'href': 'http://so.api.simpledemo.onap.org:30277/cloudSite/mc_test_cloud_site_3'
        },
        'self': {
            'href': 'http://so.api.simpledemo.onap.org:30277/cloudSite/mc_test_cloud_site_3'
        }
    },
    'aic_version': '2.5',
    'clli': 'test_clli_0',
    'cloud_owner': None,
    'cloudify_id': None,
    'creation_timestamp': '2021-05-12T08:52:48.134+0000',
    'identityService': {
        'admin_tenant': 'service',
        'creation_timestamp': '2021-05-12T08:52:48.134+0000',
        'identityServerTypeAsString': 'KEYSTONE',
        'identity_authentication_type': 'USERNAME_PASSWORD',
        'identity_server_type': 'KEYSTONE',
        'identity_url': 'http://1.2.3.4:5000/v2.0',
        'last_updated_by': None,
        'member_role': 'admin',
        'mso_id': 'onapsdk_user',
        'mso_pass': 'mso_pass_onapsdk',
        'project_domain_name': 'NULL',
        'tenant_metadata': True,
        'update_timestamp': '2021-05-12T08:52:48.134+0000',
        'user_domain_name': 'NULL'
    },
    'identity_service_id': 'test_identity_0',
    'last_updated_by': None,
    'orchestrator': 'multicloud',
    'platform': None,
    'region_id': 'test_region_0',
    'support_fabric': True,
    'update_timestamp': '2021-05-12T08:52:48.134+0000',
    'uri': None
}

SERVICE_VNF_RESPONSE = {
    'serviceVnfs': [
        {
            'modelInfo': {
                'modelName': 'test_vnf_01',
                'modelUuid': 'd2779cc5-fb01-449f-a355-7e5d911dca93',
                'modelInvariantUuid': '027cb696-f68f-47db-9b0e-585ea3eaa512',
                'modelVersion': '1.0',
                'modelCustomizationUuid': 'b8740912-e0fc-426f-af97-7657caf57847',
                'modelInstanceName': 'test_vnf_01 0'
            },
            'toscaNodeType': 'org.openecomp.resource.vf.Mvnr5gCucpVfT003',
            'nfFunction': None,
            'nfType': None,
            'nfRole': None,
            'nfNamingCode': None,
            'multiStageDesign': 'false',
            'vnfcInstGroupOrder': None,
            'resourceInput': None,
            'vfModules': [{'modelInfo':
            {
                'modelName': 'test_vf_01',
                'modelUuid': '153464b8-4f47-4140-8b92-9614c4578d91',
                'modelInvariantUuid': '753deff5-99a2-4154-8c1d-3e956cb96f32',
                'modelVersion': '1',
                'modelCustomizationUuid': '7ca564f3-b908-499c-b086-ae77ad270d8c'
            },
            'isBase': False,
            'vfModuleLabel': 'vf_mod_label',
            'initialCount': 0,
            'hasVolumeGroup': False
            }
        ],
        'groups': []
    }
  ]
}


def test_identity_service():
    identity_service = IdentityService(identity_id="identity_123")
    assert identity_service.identity_id == "identity_123"
    assert identity_service.url == "http://1.2.3.4:5000/v2.0"
    assert identity_service.mso_id == "onapsdk_user"
    assert identity_service.mso_pass == "mso_pass_onapsdk"
    assert identity_service.project_domain_name == "NULL"
    assert identity_service.user_domain_name == "NULL"
    assert identity_service.admin_tenant == "service"
    assert identity_service.member_role == "admin"
    assert identity_service.identity_server_type == "KEYSTONE"
    assert identity_service.identity_authentication_type == "USERNAME_PASSWORD"
    assert identity_service.hibernate_lazy_initializer == {}
    assert identity_service.server_type_as_string == "KEYSTONE"
    assert identity_service.tenant_metadata is True

@mock.patch.object(SoDbAdapter, "send_message_json")
def test_add_cloud_site(mock_send_message_json):
    identity_service = IdentityService(identity_id="test_identity_0")
    mock_send_message_json.return_value = ADD_CLOUD_SITE_RESPONSE

    response = SoDbAdapter.add_cloud_site(cloud_region_id="test_region_0",
                                          complex_id="test_clli_0",
                                          identity_service=identity_service)
    assert response['region_id'] == "test_region_0"
    assert response['aic_version'] == "2.5"
    assert response['clli'] == "test_clli_0"
    assert response['orchestrator'] == "multicloud"
    assert response['identity_service_id'] == "test_identity_0"

@mock.patch.object(SoDbAdapter, "send_message_json")
def test_get_service_vnf_info(mock_send_message_json):
    mock_send_message_json.return_value = ADD_CLOUD_SITE_RESPONSE

    response = SoDbAdapter.get_service_vnf_info(identifier="test_id_0")
    assert response['region_id'] == "test_region_0"
    assert response['aic_version'] == "2.5"
    assert response['clli'] == "test_clli_0"
    assert response['orchestrator'] == "multicloud"
    assert response['identity_service_id'] == "test_identity_0"