summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSudhakarReddy <Sudhakar.Reddy@amdocs.com>2018-09-14 07:42:33 +0300
committerSudhakarReddy <Sudhakar.Reddy@amdocs.com>2018-09-14 12:40:54 +0300
commit05ac4a6e794062f9c4a5af6ac650e54b8d5ecf4b (patch)
tree3e8d89f2e59e049c81dd7b34fb644b03fa8a2df4
parent3f481265cf6cefced65cfb78699de920e0e81748 (diff)
Improve code coverage in sonar
Change-Id: Ia8b840ac5838a3a016d5e98bf9571923aab83188 Issue-ID: MULTICLOUD-354 Signed-off-by: SudhakarReddy <Sudhakar.Reddy@amdocs.com>
-rw-r--r--azure/multicloud_azure/pub/utils/restcall.py187
-rw-r--r--azure/multicloud_azure/pub/vim/vimsdk/azure_credentials.py11
-rw-r--r--azure/multicloud_azure/swagger/image_utils.py65
-rw-r--r--azure/multicloud_azure/swagger/utils.py1
-rw-r--r--azure/multicloud_azure/swagger/volume_utils.py72
-rw-r--r--azure/multicloud_azure/tests/aai_response.json54
-rw-r--r--azure/multicloud_azure/tests/test_pub_utils.py77
-rw-r--r--azure/multicloud_azure/tests/test_registry_view.py93
-rw-r--r--azure/multicloud_azure/tests/test_syscomm.py6
9 files changed, 238 insertions, 328 deletions
diff --git a/azure/multicloud_azure/pub/utils/restcall.py b/azure/multicloud_azure/pub/utils/restcall.py
index 984c425..ff5ca6a 100644
--- a/azure/multicloud_azure/pub/utils/restcall.py
+++ b/azure/multicloud_azure/pub/utils/restcall.py
@@ -224,30 +224,6 @@ class AAIClient(object):
logger.debug("basic_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
- # cpupining capabilities
- caps_dict = self._get_cpupinning_capabilities(flavor['extra_specs'])
- if len(caps_dict) > 0:
- logger.debug("cpupining_capabilities_info: %s" % caps_dict)
- hpa_caps.append(caps_dict)
-
- # cputopology capabilities
- caps_dict = self._get_cputopology_capabilities(flavor['extra_specs'])
- if len(caps_dict) > 0:
- logger.debug("cputopology_capabilities_info: %s" % caps_dict)
- hpa_caps.append(caps_dict)
-
- # hugepages capabilities
- caps_dict = self._get_hugepages_capabilities(flavor['extra_specs'])
- if len(caps_dict) > 0:
- logger.debug("hugepages_capabilities_info: %s" % caps_dict)
- hpa_caps.append(caps_dict)
-
- # numa capabilities
- caps_dict = self._get_numa_capabilities(flavor['extra_specs'])
- if len(caps_dict) > 0:
- logger.debug("numa_capabilities_info: %s" % caps_dict)
- hpa_caps.append(caps_dict)
-
# storage capabilities
caps_dict = self._get_storage_capabilities(flavor)
if len(caps_dict) > 0:
@@ -261,13 +237,6 @@ class AAIClient(object):
logger.debug("instruction_set_capabilities_info: %s" % caps_dict)
hpa_caps.append(caps_dict)
- # PCI passthrough capabilities
- caps_dict = self._get_pci_passthrough_capabilities(
- flavor['extra_specs'])
- if len(caps_dict) > 0:
- logger.debug("pci_passthrough_capabilities_info: %s" % caps_dict)
- hpa_caps.append(caps_dict)
-
# ovsdpdk capabilities
caps_dict = self._get_ovsdpdk_capabilities()
if len(caps_dict) > 0:
@@ -297,133 +266,6 @@ class AAIClient(object):
return basic_capability
- def _get_cpupinning_capabilities(self, extra_specs):
- cpupining_capability = {}
- feature_uuid = uuid.uuid4()
-
- if (extra_specs.get('hw:cpu_policy') or
- extra_specs.get('hw:cpu_thread_policy')):
- cpupining_capability['hpa-capability-id'] = str(feature_uuid)
- cpupining_capability['hpa-feature'] = 'cpuPinning'
- cpupining_capability['architecture'] = 'generic'
- cpupining_capability['hpa-version'] = 'v1'
-
- cpupining_capability['hpa-feature-attributes'] = []
- if extra_specs.get('hw:cpu_thread_policy'):
- cpupining_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'logicalCpuThreadPinningPolicy',
- 'hpa-attribute-value': json.dumps({'value': str(
- extra_specs['hw:cpu_thread_policy'])})})
- if extra_specs.get('hw:cpu_policy'):
- cpupining_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'logicalCpuPinningPolicy',
- 'hpa-attribute-value': json.dumps({'value': str(
- extra_specs['hw:cpu_policy'])})})
-
- return cpupining_capability
-
- def _get_cputopology_capabilities(self, extra_specs):
- cputopology_capability = {}
- feature_uuid = uuid.uuid4()
-
- if (extra_specs.get('hw:cpu_sockets') or
- extra_specs.get('hw:cpu_cores') or
- extra_specs.get('hw:cpu_threads')):
- cputopology_capability['hpa-capability-id'] = str(feature_uuid)
- cputopology_capability['hpa-feature'] = 'cpuTopology'
- cputopology_capability['architecture'] = 'generic'
- cputopology_capability['hpa-version'] = 'v1'
-
- cputopology_capability['hpa-feature-attributes'] = []
- if extra_specs.get('hw:cpu_sockets'):
- cputopology_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'numCpuSockets',
- 'hpa-attribute-value': json.dumps({'value': str(
- extra_specs['hw:cpu_sockets'])})})
- if extra_specs.get('hw:cpu_cores'):
- cputopology_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'numCpuCores',
- 'hpa-attribute-value': json.dumps({'value': str(
- extra_specs['hw:cpu_cores'])})})
- if extra_specs.get('hw:cpu_threads'):
- cputopology_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'numCpuThreads',
- 'hpa-attribute-value': json.dumps({'value': str(
- extra_specs['hw:cpu_threads'])})})
-
- return cputopology_capability
-
- def _get_hugepages_capabilities(self, extra_specs):
- hugepages_capability = {}
- feature_uuid = uuid.uuid4()
-
- if extra_specs.get('hw:mem_page_size'):
- hugepages_capability['hpa-capability-id'] = str(feature_uuid)
- hugepages_capability['hpa-feature'] = 'hugePages'
- hugepages_capability['architecture'] = 'generic'
- hugepages_capability['hpa-version'] = 'v1'
-
- hugepages_capability['hpa-feature-attributes'] = []
- if extra_specs['hw:mem_page_size'] == 'large':
- hugepages_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'memoryPageSize',
- 'hpa-attribute-value': json.dumps(
- {'value': '2', 'unit': 'MB'})})
- elif extra_specs['hw:mem_page_size'] == 'small':
- hugepages_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'memoryPageSize',
- 'hpa-attribute-value': json.dumps(
- {'value': '4', 'unit': 'KB'})})
- elif extra_specs['hw:mem_page_size'] == 'any':
- logger.info("Currently HPA feature memoryPageSize "
- "did not support 'any' page!!")
- else:
- hugepages_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'memoryPageSize',
- 'hpa-attribute-value': json.dumps({'value': str(
- extra_specs['hw:mem_page_size']), 'unit': 'KB'})
- })
-
- return hugepages_capability
-
- def _get_numa_capabilities(self, extra_specs):
- numa_capability = {}
- feature_uuid = uuid.uuid4()
-
- if extra_specs.get('hw:numa_nodes'):
- numa_capability['hpa-capability-id'] = str(feature_uuid)
- numa_capability['hpa-feature'] = 'numa'
- numa_capability['architecture'] = 'generic'
- numa_capability['hpa-version'] = 'v1'
-
- numa_capability['hpa-feature-attributes'] = []
- numa_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'numaNodes',
- 'hpa-attribute-value': json.dumps({'value': str(
- extra_specs['hw:numa_nodes'])})
- })
-
- for num in range(0, int(extra_specs['hw:numa_nodes'])):
- numa_cpu_node = "hw:numa_cpus.%s" % num
- numa_mem_node = "hw:numa_mem.%s" % num
- numacpu_key = "numaCpu-%s" % num
- numamem_key = "numaMem-%s" % num
-
- if (extra_specs.get(numa_cpu_node) and
- extra_specs.get(numa_mem_node)):
- numa_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': numacpu_key,
- 'hpa-attribute-value': json.dumps({'value': str(
- extra_specs[numa_cpu_node])})
- })
- numa_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': numamem_key,
- 'hpa-attribute-value': json.dumps({'value': str(
- extra_specs[numa_mem_node]), 'unit': 'MB'})
- })
-
- return numa_capability
-
def _get_storage_capabilities(self, flavor):
storage_capability = {}
feature_uuid = uuid.uuid4()
@@ -470,35 +312,6 @@ class AAIClient(object):
})
return instruction_capability
- def _get_pci_passthrough_capabilities(self, extra_specs):
- instruction_capability = {}
- feature_uuid = uuid.uuid4()
-
- if extra_specs.get('pci_passthrough:alias'):
- value1 = extra_specs['pci_passthrough:alias'].split(':')
- value2 = value1[0].split('-')
-
- instruction_capability['hpa-capability-id'] = str(feature_uuid)
- instruction_capability['hpa-feature'] = 'pciePassthrough'
- instruction_capability['architecture'] = str(value2[2])
- instruction_capability['hpa-version'] = 'v1'
-
- instruction_capability['hpa-feature-attributes'] = []
- instruction_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'pciCount',
- 'hpa-attribute-value': json.dumps({'value': value1[1]})
- })
- instruction_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'pciVendorId',
- 'hpa-attribute-value': json.dumps({'value': value2[3]})
- })
- instruction_capability['hpa-feature-attributes'].append({
- 'hpa-attribute-key': 'pciDeviceId',
- 'hpa-attribute-value': json.dumps({'value': value2[4]})
- })
-
- return instruction_capability
-
def _get_ovsdpdk_capabilities(self):
ovsdpdk_capability = {}
feature_uuid = uuid.uuid4()
diff --git a/azure/multicloud_azure/pub/vim/vimsdk/azure_credentials.py b/azure/multicloud_azure/pub/vim/vimsdk/azure_credentials.py
index e66ac7b..1989e2c 100644
--- a/azure/multicloud_azure/pub/vim/vimsdk/azure_credentials.py
+++ b/azure/multicloud_azure/pub/vim/vimsdk/azure_credentials.py
@@ -10,6 +10,7 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+from multicloud_azure.pub.exceptions import VimDriverAzureException
from azure.common.credentials import ServicePrincipalCredentials
@@ -22,7 +23,11 @@ class ClientObj(object):
CLIENT = params['username']
KEY = params['password']
- credentials = ServicePrincipalCredentials(client_id=CLIENT,
- secret=KEY, tenant=TENANT_ID)
+ try:
+ cred = ServicePrincipalCredentials(client_id=CLIENT,
+ secret=KEY, tenant=TENANT_ID)
+ except Exception as e:
+ raise VimDriverAzureException(status_code=e.args,
+ message=e.message)
- return credentials
+ return cred
diff --git a/azure/multicloud_azure/swagger/image_utils.py b/azure/multicloud_azure/swagger/image_utils.py
deleted file mode 100644
index a17565e..0000000
--- a/azure/multicloud_azure/swagger/image_utils.py
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright (c) 2018 Amdocs
-#
-# 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.
-
-
-def image_formatter(image):
-
- image = image.to_dict()
- properties = {}
- if image.get("vmware_adaptertype"):
- properties['vmware_adaptertype'] = image.get("vmware_adaptertype")
- if image.get("vmware_ostype"):
- properties['vmware_ostype'] = image.get("vmware_ostype")
-
- return {
- 'id': image.get("id"),
- 'name': image.get("name"),
- 'imageType': image.get("disk_format"),
- 'status': image.get("status"),
- 'size': image.get("size"),
- 'containerFormat': image.get("container_format"),
- 'visibility': image.get("visibility"),
- 'properties': properties
- }
-
-
-def vim_formatter(vim_info, tenantid):
-
- rsp = {}
- rsp['vimId'] = vim_info.get('vimId')
- rsp['vimName'] = vim_info.get('name')
- rsp['tenantId'] = tenantid
- return rsp
-
-
-def sdk_param_formatter(data):
-
- param = {}
- param['username'] = data.get('userName')
- param['password'] = data.get('password')
- param['auth_url'] = data.get('url')
- param['project_id'] = data.get('tenant')
- param['user_domain_name'] = 'default'
- param['project_domain_name'] = 'default'
- return param
-
-
-def req_body_formatter(body):
-
- param = {}
- param['name'] = body.get('name')
- param['disk_format'] = body.get('imageType')
- param['container_format'] = body.get('containerFormat')
- param['visibility'] = body.get('visibility')
- properties = body.get('properties', {})
- param.update(properties)
- return param
diff --git a/azure/multicloud_azure/swagger/utils.py b/azure/multicloud_azure/swagger/utils.py
index cb7e4f0..c244549 100644
--- a/azure/multicloud_azure/swagger/utils.py
+++ b/azure/multicloud_azure/swagger/utils.py
@@ -29,7 +29,6 @@ def get_swagger_json_data():
# f.close()
# json_data["paths"].update(json_data_temp["paths"])
# json_data["definitions"].update(json_data_temp["definitions"])
-
json_data["basePath"] = "/api/multicloud-azure/v0/"
json_data["info"]["title"] = "MultiVIM driver \
of Microsoft Azure Service NBI"
diff --git a/azure/multicloud_azure/swagger/volume_utils.py b/azure/multicloud_azure/swagger/volume_utils.py
deleted file mode 100644
index ae11285..0000000
--- a/azure/multicloud_azure/swagger/volume_utils.py
+++ /dev/null
@@ -1,72 +0,0 @@
-# Copyright (c) 2018 Amdocs
-#
-# 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.
-
-
-def volume_formatter(volume):
-
- attachments = []
- for attach in volume.attachments:
- vim_attach = {
- 'device': attach['device'],
- 'volumeId': attach['volume_id'],
- 'hostName': attach['host_name'],
- 'Id': attach['attachment_id'],
- 'serverId': attach['server_id']
- }
- attachments.append(vim_attach)
-
- return {
- 'id': volume.id,
- 'name': volume.name,
- 'createTime': volume.created_at,
- 'status': volume.status,
- 'type': volume.volume_type,
- 'size': volume.size,
- 'availabilityZone': volume.availability_zone,
- 'attachments': attachments
- }
-
-
-def vim_formatter(vim_info, tenantid):
-
- rsp = {}
- rsp['vimId'] = vim_info.get('vimId')
- rsp['vimName'] = vim_info.get('name')
- rsp['tenantId'] = tenantid
- return rsp
-
-
-def sdk_param_formatter(data):
-
- param = {}
- param['username'] = data.get('userName')
- param['password'] = data.get('password')
- param['auth_url'] = data.get('url')
- param['project_id'] = data.get('tenant')
- param['user_domain_name'] = 'default'
- param['project_domain_name'] = 'default'
- return param
-
-
-def req_body_formatter(body):
-
- param = {}
- param['name'] = body.get('name')
- param['size'] = body.get('volumeSize')
-
- if body.get('volumeType'):
- param['volume_type'] = body.get('volumeType')
- if body.get('availabilityZone'):
- param['availability_zone'] = body.get('availabilityZone')
- if body.get('imageId'):
- param['image_id'] = body.get('imageId')
- return param
diff --git a/azure/multicloud_azure/tests/aai_response.json b/azure/multicloud_azure/tests/aai_response.json
new file mode 100644
index 0000000..5361dc4
--- /dev/null
+++ b/azure/multicloud_azure/tests/aai_response.json
@@ -0,0 +1,54 @@
+{
+ "cloud-owner": "ATT",
+ "cloud-region-id": "eastus2",
+ "cloud-type": "azure",
+ "owner-defined-type": "owner-defined-type",
+ "cloud-region-version": "1.0",
+ "cloud-zone": "cloud zone",
+ "complex-name": "complex name",
+ "sriov-automation": false,
+ "cloud-extra-info": "{\"subscription_id\": \"test-sub-id\"}",
+ "resource-version": "1534835073750",
+ "tenants": {
+ "tenant": [
+ {
+ "tenant-id": "76486749673496734634634",
+ "tenant-name": "vfw-demo",
+ "resource-version": "1534835073868",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "service-subscription",
+ "related-link": "/aai/v11/business/customers/customer/amdocs/service-subscriptions/service-subscription/INFRA",
+ "relationship-data": [
+ {
+ "relationship-key": "customer.global-customer-id",
+ "relationship-value": "amdocs"
+ },
+ {
+ "relationship-key": "service-subscription.service-type",
+ "relationship-value": "INFRA"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "esr-system-info-list": {
+ "esr-system-info": [
+ {
+ "esr-system-info-id": "82badd77-82b3-4d37-ab2e-fb258ae55611",
+ "service-url": "http://10.247.134.140:5000/v3",
+ "user-name": "test-user-id",
+ "password": "test-client",
+ "system-type": "VIM",
+ "ssl-insecure": true,
+ "cloud-domain": "default",
+ "default-tenant": "test-tenant-id",
+ "resource-version": "1534835073979"
+ }
+ ]
+ }
+}
diff --git a/azure/multicloud_azure/tests/test_pub_utils.py b/azure/multicloud_azure/tests/test_pub_utils.py
new file mode 100644
index 0000000..1e08e9b
--- /dev/null
+++ b/azure/multicloud_azure/tests/test_pub_utils.py
@@ -0,0 +1,77 @@
+# Copyright (c) 2018 Amdocs
+#
+# 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.
+
+import unittest
+import os
+import mock
+import json
+
+from multicloud_azure.pub.utils.restcall import AAIClient
+from multicloud_azure.pub.msapi import extsys
+from multicloud_azure.pub.utils.timeutil import now_time
+from multicloud_azure.pub.utils.fileutil import make_dirs, delete_dirs
+from multicloud_azure.pub.utils.fileutil import download_file_from_http
+from multicloud_azure.pub.vim.vimsdk.azure_credentials import ClientObj
+from multicloud_azure.pub.exceptions import VimDriverAzureException
+
+TENANT_ID = '123'
+CLIENT = '456'
+KEY = '789'
+
+params = {
+ 'username': TENANT_ID,
+ 'password': KEY,
+ 'tenant_id': CLIENT
+ }
+
+
+class TestPub(unittest.TestCase):
+
+ def test_client_obj(self):
+ self.assertRaises(VimDriverAzureException,
+ ClientObj().get_client_obj, params)
+
+ def test_time(self):
+ fmt = "%Y-%m-%d %H:%M:%S"
+ self.assertIsNotNone(now_time(fmt))
+
+ def test_make_dirs(self):
+ path = "/tmp/azure/azure/bin"
+ self.assertEqual(os.makedirs(path, 0777), make_dirs(path))
+
+ def test_delete_dirs(self):
+ path = "/tmp/azure/azure/bin"
+ self.assertIsNone(delete_dirs(path))
+
+ def test_download_file(self):
+ url = "https://raw.githubusercontent.com/onapdemo/" \
+ "onap-scripts/master/entrypoint/azure-rancher-server.sh"
+ local_dir = "usr/local/bin"
+ file_name = "azure"
+ self.assertNotEquals(False, "usr/local/bin/azure",
+ download_file_from_http(url, local_dir,
+ file_name))
+
+ def test_split_vim_to_owner_region(self):
+ vim_id = 'ATT_eastus2'
+ self.assertEquals(('ATT', 'eastus2'),
+ extsys.split_vim_to_owner_region(vim_id))
+
+ @mock.patch.object(AAIClient, 'get_vim')
+ def test_get_vim_id(self, mock_vim_info):
+ vim_id = 'ATT_eastus2'
+ json_file = os.path.join(os.path.dirname(
+ __file__), 'aai_response.json')
+ f = open(json_file).read()
+ ret = json.loads(f)
+ mock_vim_info.return_value = ret
+ self.assertEqual(ret, extsys.get_vim_by_id(vim_id))
diff --git a/azure/multicloud_azure/tests/test_registry_view.py b/azure/multicloud_azure/tests/test_registry_view.py
new file mode 100644
index 0000000..53184a3
--- /dev/null
+++ b/azure/multicloud_azure/tests/test_registry_view.py
@@ -0,0 +1,93 @@
+# Copyright (c) 2018 Amdocs
+#
+# 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.
+
+import unittest
+import mock
+from rest_framework import status
+from multicloud_azure.swagger.views.registry.views import Registry
+from multicloud_azure.swagger.views.registry.views import UnRegistry
+
+
+from multicloud_azure.pub.msapi import extsys
+from multicloud_azure.pub.utils.restcall import AAIClient
+from multicloud_azure.pub.vim.vimapi.compute import OperateFlavors
+
+VIM_INFO = {'cloud_extra_info': 1, 'username': 'user1',
+ 'password': '1234', 'default_tenant': 't1',
+ 'cloud_region_id': 'r1'}
+
+
+class RegistryViewTest(unittest.TestCase):
+
+ def setUp(self):
+ self.reg = Registry()
+
+ def tearDown(self):
+ pass
+
+ @mock.patch.object(OperateFlavors.OperateFlavors, 'list_flavors')
+ @mock.patch.object(extsys, 'get_vim_by_id')
+ def test_reg_get_flavors_view_fail(self, mock_vim_info, mock_flavors):
+ mock_vim_info.return_value = VIM_INFO
+
+ class Flavor:
+ def __init__(self, id, name):
+ self.id = id
+ self.name = name
+
+ def to_dict(self):
+ return {"name": self.name, "id": self.id}
+
+ f1 = Flavor(1, "f1")
+ f2 = Flavor(2, "f2")
+ flavors = [f1.to_dict(), f2.to_dict()]
+ mock_flavors.return_value = flavors
+ auth = {
+ "subscription_id": "1",
+ "username": "user",
+ "password": "1234",
+ "tenant_id": "t1",
+ "region_id": "r1"}
+
+ self.assertEqual(
+ {'flavors': [{'id': 1, 'name': 'f1'},
+ {'id': 2, 'name': 'f2'}]},
+ self.reg._get_flavors(auth))
+
+ @mock.patch.object(OperateFlavors.OperateFlavors, 'list_flavors')
+ @mock.patch.object(extsys, 'get_vim_by_id')
+ def test_reg_get_flavors_view_fail2(self, mock_vim_info, mock_flavors):
+ mock_vim_info.return_value = VIM_INFO
+ mock_flavors.side_effect = Exception("something wrong")
+ self.assertRaises(Exception, self.reg._get_flavors)
+
+
+class UnRegistryViewTest(unittest.TestCase):
+
+ def setUp(self):
+ self.reg = UnRegistry()
+
+ def tearDown(self):
+ pass
+
+ @mock.patch.object(AAIClient, 'delete_vim')
+ @mock.patch.object(extsys, 'get_vim_by_id')
+ def test_reg_delete_view(self, mock_vim_info, mock_del_vim):
+ mock_vim_info.return_value = VIM_INFO
+
+ class Request:
+ def __init__(self, query_params):
+ self.query_params = query_params
+ req = Request({'k': 'v'})
+ self.assertEqual(
+ status.HTTP_204_NO_CONTENT,
+ self.reg.delete(req, "vimid").status_code)
diff --git a/azure/multicloud_azure/tests/test_syscomm.py b/azure/multicloud_azure/tests/test_syscomm.py
index 12507a4..5839aca 100644
--- a/azure/multicloud_azure/tests/test_syscomm.py
+++ b/azure/multicloud_azure/tests/test_syscomm.py
@@ -35,3 +35,9 @@ class SyscommTest(unittest.TestCase):
}
}
self.assertEquals(True, syscomm.verifyKeystoneV2(param))
+
+ def test_json_response(self):
+ data = "abcde"
+ res = data
+ content_type = "text/plain"
+ self.assertEquals((res, content_type), syscomm.jsonResponse(data))