summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--conductor/conductor/tests/unit/data/plugins/inventory_provider/_get_complex.json6
-rw-r--r--conductor/conductor/tests/unit/data/plugins/inventory_provider/_request_candidate_role.json20
-rw-r--r--conductor/conductor/tests/unit/data/plugins/inventory_provider/_request_network_role.json25
-rw-r--r--conductor/conductor/tests/unit/data/plugins/inventory_provider/cache_regions.json29
-rw-r--r--conductor/conductor/tests/unit/data/plugins/inventory_provider/generic_vnf_list.json90
-rw-r--r--conductor/conductor/tests/unit/data/plugins/inventory_provider/resolve_demand_service_response.json21
-rw-r--r--conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py104
7 files changed, 240 insertions, 55 deletions
diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/_get_complex.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/_get_complex.json
new file mode 100644
index 0000000..21a0b3c
--- /dev/null
+++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/_get_complex.json
@@ -0,0 +1,6 @@
+{
+ "country": "USA",
+ "region": "SE",
+ "latitude": "28.543251",
+ "longitude": "-81.377112"
+} \ No newline at end of file
diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/_request_candidate_role.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/_request_candidate_role.json
new file mode 100644
index 0000000..ee37e10
--- /dev/null
+++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/_request_candidate_role.json
@@ -0,0 +1,20 @@
+{
+ "generic-vnf": [{
+ "vnf-id": "vnf-id",
+ "vnf-name": "vnf-name",
+ "relationship-list": {
+ "relationship": [{
+ "related-to": "service-instance",
+ "related-link": "/aai/v10/service-instance-link",
+ "relationship-data": [{
+ "relationship-key": "customer.global-customer-id",
+ "relationship-value": "global-customer-id"
+ }
+ ]
+ }]
+ }
+ }],
+ "allotted-resource": [{
+ "role": "test-role"
+ }]
+} \ No newline at end of file
diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/_request_network_role.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/_request_network_role.json
new file mode 100644
index 0000000..aa63bae
--- /dev/null
+++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/_request_network_role.json
@@ -0,0 +1,25 @@
+{
+ "l3-network": [
+ {
+ "network-id": "network-id",
+ "network-name": "network-name",
+ "network-type": "network-type",
+ "network-role": "network-role",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "cloud-region",
+ "related-link": "cloud-region-link",
+ "relationship-data": [
+
+ {
+ "relationship-key": "cloud-region.cloud-region-id",
+ "relationship-value": "test-cloud-value"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ]
+} \ No newline at end of file
diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/cache_regions.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/cache_regions.json
new file mode 100644
index 0000000..8a6d00a
--- /dev/null
+++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/cache_regions.json
@@ -0,0 +1,29 @@
+{
+ "cloud-region": [
+ {
+ "cloud-owner": "att-aic",
+ "cloud-region-id": "mtunj1a",
+ "cloud-type": "openstack",
+ "owner-defined-type": "lcp",
+ "cloud-region-version": "aic3.0",
+ "identity-url": "https://identity-aic.mtunj1a.aic.cip.att.com:5000/v2.0",
+ "cloud-zone": "z1",
+ "complex-name": "c1",
+ "resource-version": "1486464068353",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "complex",
+ "related-link": "/aai/v10/cloud-infrastructure/complexes/complex/MDTWNJ21A6",
+ "relationship-data": [
+ {
+ "relationship-key": "complex.physical-location-id",
+ "relationship-value": "MDTWNJ21A6"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ]
+} \ No newline at end of file
diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/generic_vnf_list.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/generic_vnf_list.json
index 81a82ed..a95ad2d 100644
--- a/conductor/conductor/tests/unit/data/plugins/inventory_provider/generic_vnf_list.json
+++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/generic_vnf_list.json
@@ -1,49 +1,47 @@
-{
- "generic-vnf": [
+[
+ {
+ "vnf-id": "vnf-id",
+ "vnf-name": "vnf-name",
+ "vnf-type": "vpe",
+ "prov-status": "prov-status",
+ "equipment-role": "equipment-role",
+ "resource-version": "resource-version-id",
+ "relationship-list": {
+ "relationship": [
{
- "vnf-id": "vnf-id",
- "vnf-name": "vnf-name",
- "vnf-type": "vpe",
- "prov-status": "prov-status",
- "equipment-role": "equipment-role",
- "resource-version": "resource-version-id",
- "relationship-list": {
- "relationship": [
- {
- "related-to": "service-instance",
- "related-link": "service-instance-link",
- "relationship-data": [
- {
- "relationship-key": "customer.global-customer-id",
- "relationship-value": "customer-id"
- },
- {
- "relationship-key": "service-subscription.service-type",
- "relationship-value": "service-type"
- },
- {
- "relationship-key": "service-instance.service-instance-id",
- "relationship-value": "service-instance-id"
- }
- ]
- },
- {
- "related-to": "vserver",
- "related-link": "vserver-id",
- "relationship-data": [
- {
- "relationship-key": "cloud-region.cloud-owner",
- "relationship-value": "cloud-owner"
- },
- {
- "relationship-key": "cloud-region.cloud-region-id",
- "relationship-value": "cloud-region-id"
- }
- ]
- }
-
- ]
- }
+ "related-to": "service-instance",
+ "related-link": "/aai/v10/service-instance-link",
+ "relationship-data": [
+ {
+ "relationship-key": "customer.global-customer-id",
+ "relationship-value": "customer-123"
+ },
+ {
+ "relationship-key": "service-subscription.service-type",
+ "relationship-value": "service-type"
+ },
+ {
+ "relationship-key": "service-instance.service-instance-id",
+ "relationship-value": "service-instance-id"
+ }
+ ]
+ },
+ {
+ "related-to": "vserver",
+ "related-link": "/aai/v10/vserver-id",
+ "relationship-data": [
+ {
+ "relationship-key": "cloud-region.cloud-owner",
+ "relationship-value": "cloud-owner"
+ },
+ {
+ "relationship-key": "cloud-region.cloud-region-id",
+ "relationship-value": "cloud-region-id"
+ }
+ ]
}
+
]
-} \ No newline at end of file
+ }
+ }
+]
diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/resolve_demand_service_response.json b/conductor/conductor/tests/unit/data/plugins/inventory_provider/resolve_demand_service_response.json
new file mode 100644
index 0000000..c56c0a8
--- /dev/null
+++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/resolve_demand_service_response.json
@@ -0,0 +1,21 @@
+{
+ "cloud-region": [],
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "pserver",
+ "related-link": "/aai/v10/pserver"
+ },
+ {
+ "related-to": "complex",
+ "related-link": "/aai/v10/complex-id",
+ "relationship-data": [
+ {
+ "relationship-key": "complex.physical-location-id",
+ "relationship-value": "test-id"
+ }
+ ]
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py b/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py
index 4b9a24c..30a54a9 100644
--- a/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py
+++ b/conductor/conductor/tests/unit/data/plugins/inventory_provider/test_aai.py
@@ -88,7 +88,7 @@ class TestAAI(unittest.TestCase):
req_response.ok = True
req_response.json.return_value = req_json
- complex_json_file = './conductor/tests/unit/data/plugins/inventory_provider/_get_complex_host_name.json'
+ complex_json_file = './conductor/tests/unit/data/plugins/inventory_provider/_get_complex.json'
complex_json = json.loads(open(complex_json_file).read())
self.mock_get_request = mock.patch.object(AAI, '_request', return_value=req_response)
@@ -113,24 +113,32 @@ class TestAAI(unittest.TestCase):
regions_response_file = './conductor/tests/unit/data/plugins/inventory_provider/regions.json'
regions_response = json.loads(open(regions_response_file).read())
+ demand_service_response_file = './conductor/tests/unit/data/plugins/inventory_provider/resolve_demand_service_response.json'
+ demand_service_response = json.loads(open(demand_service_response_file).read())
+
+ complex_json_file = './conductor/tests/unit/data/plugins/inventory_provider/_get_complex.json'
+ complex_json = json.loads(open(complex_json_file).read())
+
req_response = mock.MagicMock()
req_response.status_code = 200
req_response.ok = True
- req_response.json.return_value = generic_vnf_list
+ req_response.json.return_value = demand_service_response
- self.mock_first_level_service_call = mock.patch.object(AAI, 'first_level_service_call', return_value=req_response)
+ self.mock_first_level_service_call = mock.patch.object(AAI, 'first_level_service_call', return_value=generic_vnf_list)
self.mock_first_level_service_call.start()
self.mock_get_regions = mock.patch.object(AAI, '_get_regions', return_value=regions_response)
self.mock_get_regions.start()
- self.maxDiff = None
- self.assertEqual({u'demand_name': [{'sriov_automation': 'false', 'longitude': u'30.12', 'inventory_type': 'cloud', 'inventory_provider': 'aai', 'cloud_owner': u'cloud-owner', 'cloud_region_version': u'1.0', 'service_resource_id': u'service-resource-id-123', 'city': u'Middletown', 'state': u'NJ', 'country': u'USA', 'existing_placement': 'false', 'location_type': 'att_aic', 'location_id': u'region-name', 'complex_name': u'complex-name', 'latitude': u'50.34', 'candidate_id': u'region-name', 'cost': 2.0, 'physical_location_id': u'complex-id', 'region': u'USA'}]} ,
- self.aai_ep.resolve_demands(demands_list))
-
+ self.mock_get_regions = mock.patch.object(AAI, '_request', return_value=req_response)
+ self.mock_get_regions.start()
- #check_network_roles
+ self.mock_get_complex = mock.patch.object(AAI, '_get_complex', return_value=complex_json)
+ self.mock_get_complex.start()
+ self.maxDiff = None
+ self.assertEqual({u'demand_name': [{'candidate_id': u'service-instance-id','city': None,'cloud_owner': u'cloud-owner','cloud_region_version': '','complex_name': None,'cost': 1.0,'country': u'USA','existing_placement': 'false','host_id': u'vnf-name','inventory_provider': 'aai','inventory_type': 'service','latitude': u'28.543251','location_id': u'cloud-region-id','location_type': 'att_aic','longitude': u'-81.377112','physical_location_id': 'test-id','region': u'SE','service_resource_id': '','sriov_automation': 'false','state': None},{'candidate_id': u'region-name','city': u'Middletown','cloud_owner': u'cloud-owner','cloud_region_version': u'1.0','complex_name': u'complex-name','cost': 2.0,'country': u'USA','existing_placement': 'false','inventory_provider': 'aai','inventory_type': 'cloud','latitude': u'50.34','location_id': u'region-name','location_type': 'att_aic','longitude': u'30.12','physical_location_id': u'complex-id','region': u'USA','service_resource_id': u'service-resource-id-123','sriov_automation': 'false','state': u'NJ'}]} ,
+ self.aai_ep.resolve_demands(demands_list))
def test_get_complex(self):
@@ -146,4 +154,82 @@ class TestAAI(unittest.TestCase):
self.mock_get_request.start()
self.assertEqual({u'city': u'Middletown', u'latitude': u'28.543251', u'longitude': u'-81.377112', u'country': u'USA', u'region': u'SE'} ,
- self.aai_ep._get_complex("/v10/complex/complex_id", "complex_id")) \ No newline at end of file
+ self.aai_ep._get_complex("/v10/complex/complex_id", "complex_id"))
+
+
+ def test_check_network_roles(self):
+
+ network_role_json_file = './conductor/tests/unit/data/plugins/inventory_provider/_request_network_role.json'
+ network_role_json = json.loads(open(network_role_json_file).read())
+
+ response = mock.MagicMock()
+ response.status_code = 200
+ response.ok = True
+ response.json.return_value = network_role_json
+
+ self.mock_get_request = mock.patch.object(AAI, '_request', return_value=response)
+ self.mock_get_request.start()
+ self.assertEqual(set(['test-cloud-value']) ,
+ self.aai_ep.check_network_roles("network_role_id"))
+
+
+ def test_check_candidate_role(self):
+
+ candidate_role_json_file = './conductor/tests/unit/data/plugins/inventory_provider/_request_candidate_role.json'
+ candidate_role_json = json.loads(open(candidate_role_json_file).read())
+
+ response = mock.MagicMock()
+ response.status_code = 200
+ response.ok = True
+ response.json.return_value = candidate_role_json
+
+ self.mock_get_request = mock.patch.object(AAI, '_request', return_value=response)
+ self.mock_get_request.start()
+
+ self.assertEqual("test-role",
+ self.aai_ep.check_candidate_role("candidate_host_id"))
+
+ def test_match_inventory_attributes(self):
+ template_attributes = dict()
+ template_attributes['attr-1'] = ['attr-1-value1', 'attr-1-value2']
+
+ inventory_attributes = dict()
+ inventory_attributes['attr-1'] = 'attr-1-value1'
+
+ self.assertEqual(True,
+ self.aai_ep.match_inventory_attributes(template_attributes, inventory_attributes, "candidate-id"))
+
+ template_attributes['attr-1'] = {
+ 'not': ['attr-1-value2']
+ }
+ self.assertEqual(True,
+ self.aai_ep.match_inventory_attributes(template_attributes, inventory_attributes,
+ "candidate-id"))
+
+ template_attributes['attr-1'] = {
+ 'not': ['attr-1-value1']
+ }
+ self.assertEqual(False,
+ self.aai_ep.match_inventory_attributes(template_attributes, inventory_attributes,
+ "candidate-id"))
+
+ def test_refresh_cache(self):
+ regions_response_file = './conductor/tests/unit/data/plugins/inventory_provider/cache_regions.json'
+ regions_response = json.loads(open(regions_response_file).read())
+
+ complex_json_file = './conductor/tests/unit/data/plugins/inventory_provider/_get_complex.json'
+ complex_json = json.loads(open(complex_json_file).read())
+
+ response = mock.MagicMock()
+ response.status_code = 200
+ response.ok = True
+ response.json.return_value = regions_response
+
+ self.mock_get_regions = mock.patch.object(AAI, '_request', return_value=response)
+ self.mock_get_regions.start()
+
+ self.mock_get_complex = mock.patch.object(AAI, '_get_complex', return_value=complex_json)
+ self.mock_get_complex.start()
+
+ self.assertEqual(None,
+ self.aai_ep._refresh_cache()) \ No newline at end of file