diff options
Diffstat (limited to 'newton')
-rw-r--r-- | newton/newton/extensions/tests/test_epacaps.py | 37 | ||||
-rw-r--r-- | newton/newton/extensions/tests/test_extensions.py | 26 | ||||
-rw-r--r-- | newton/newton/proxy/tests/test_identity_proxy.py | 938 | ||||
-rw-r--r-- | newton/newton/proxy/tests/test_service_proxy.py | 964 | ||||
-rw-r--r-- | newton/newton/registration/tests/test_registration.py | 42 | ||||
-rw-r--r-- | newton/newton/requests/tests/mock_info.py | 48 | ||||
-rw-r--r-- | newton/newton/requests/tests/test_base.py | 108 | ||||
-rw-r--r-- | newton/newton/requests/tests/test_flavor.py | 54 | ||||
-rw-r--r-- | newton/newton/requests/tests/test_image.py | 23 | ||||
-rw-r--r-- | newton/newton/requests/tests/test_limits.py | 37 | ||||
-rw-r--r-- | newton/newton/requests/tests/test_server.py | 67 | ||||
-rw-r--r-- | newton/newton/requests/tests/test_subnet.py | 8 | ||||
-rw-r--r-- | newton/newton/requests/tests/test_tenant.py | 13 | ||||
-rw-r--r-- | newton/newton/requests/tests/test_volume.py | 9 | ||||
-rw-r--r-- | newton/newton/requests/tests/test_vport.py | 4 | ||||
-rw-r--r-- | newton/newton/settings.py | 4 | ||||
-rw-r--r-- | newton/newton/swagger/tests.py | 10 |
17 files changed, 1002 insertions, 1390 deletions
diff --git a/newton/newton/extensions/tests/test_epacaps.py b/newton/newton/extensions/tests/test_epacaps.py index 65125a43..35604165 100644 --- a/newton/newton/extensions/tests/test_epacaps.py +++ b/newton/newton/extensions/tests/test_epacaps.py @@ -19,29 +19,10 @@ from django.test import Client from rest_framework import status import unittest +from newton.requests.tests import test_base +from newton.requests.tests import mock_info from newton.requests.views.util import VimDriverUtils -MOCK_VIM_INFO = { - "createTime": "2017-04-01 02:22:27", - "domain": "Default", - "name": "TiS_R4", - "password": "admin", - "tenant": "admin", - "type": "openstack", - "url": "http://128.224.180.14:5000/v3", - "userName": "admin", - "vendor": "WindRiver", - "version": "newton", - "vimId": "windriver-hudson-dc_RegionOne", - 'cloud_owner':'windriver-hudson-dc', - 'cloud_region_id':'RegionOne', - 'cloud_extra_info':'', - 'cloud_epa_caps':'{"huge_page":"true","cpu_pinning":"true",\ - "cpu_thread_policy":"true","numa_aware":"true","sriov":"true",\ - "dpdk_vswitch":"true","rdt":"false","numa_locality_pci":"true"}', - 'insecure':'True', -} - class TestEpaCaps(unittest.TestCase): def setUp(self): @@ -49,19 +30,23 @@ class TestEpaCaps(unittest.TestCase): @mock.patch.object(VimDriverUtils, 'get_vim_info') def test_get_epa_caps_info(self, mock_get_vim_info): - mock_get_vim_info.return_value = MOCK_VIM_INFO + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO cloud_owner = "windriver-hudson-dc" cloud_region_id = "RegionOne" vimid = cloud_owner + "_" + cloud_region_id response = self.client.get( - "/api/multicloud-newton/v0/" + vimid + "/extensions/epa-caps") + "/api/%s/v0/%s/extensions/epa-caps" % ( + test_base.MULTIVIM_VERSION, + vimid)) json_content = response.json() self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertEquals(4, len(json_content.keys())) self.assertEquals(cloud_owner, json_content["cloud-owner"]) - self.assertEquals(cloud_region_id, json_content["cloud-region-id"]) + self.assertEquals(cloud_region_id, + json_content["cloud-region-id"]) self.assertEquals(vimid, json_content["vimid"]) - self.assertEquals(json.loads(MOCK_VIM_INFO['cloud_epa_caps']), - json_content["cloud-epa-caps"])
\ No newline at end of file + self.assertEquals( + json.loads(mock_info.MOCK_VIM_INFO['cloud_epa_caps']), + json_content["cloud-epa-caps"]) diff --git a/newton/newton/extensions/tests/test_extensions.py b/newton/newton/extensions/tests/test_extensions.py index 89ef0d11..7b92b61e 100644 --- a/newton/newton/extensions/tests/test_extensions.py +++ b/newton/newton/extensions/tests/test_extensions.py @@ -16,6 +16,8 @@ from django.test import Client from rest_framework import status import unittest +from newton.requests.tests import test_base + class TestExtensions(unittest.TestCase): def setUp(self): @@ -27,19 +29,27 @@ class TestExtensions(unittest.TestCase): vimid = cloud_owner + "_" + cloud_region_id response = self.client.get( - "/api/multicloud-newton/v0/" + vimid + "/extensions/") + "/api/%s/v0/%s/extensions/" % ( + test_base.MULTIVIM_VERSION, vimid)) json_content = response.json() self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertEquals(4, len(json_content.keys())) self.assertEquals(cloud_owner, json_content["cloud-owner"]) - self.assertEquals(cloud_region_id, json_content["cloud-region-id"]) + self.assertEquals(cloud_region_id, + json_content["cloud-region-id"]) self.assertEquals(vimid, json_content["vimid"]) - self.assertEquals("epa-caps", json_content["extensions"][0]["alias"]) - self.assertEquals("Multiple network support", json_content["extensions"][0]["description"]) - self.assertEquals("EPACapsQuery", json_content["extensions"][0]["name"]) - self.assertEquals("http://127.0.0.1:80/api/multicloud-newton/v0/%s/extensions/epa-caps" % vimid, - json_content["extensions"][0]["url"]) - self.assertEquals("", json_content["extensions"][0]["spec"])
\ No newline at end of file + self.assertEquals("epa-caps", + json_content["extensions"][0]["alias"]) + self.assertEquals("Multiple network support", + json_content["extensions"][0][ + "description"]) + self.assertEquals("EPACapsQuery", + json_content["extensions"][0]["name"]) + self.assertEquals( + "http://127.0.0.1:80/api/%s/v0/%s/extensions/epa-caps" % ( + test_base.MULTIVIM_VERSION, vimid), + json_content["extensions"][0]["url"]) + self.assertEquals("", json_content["extensions"][0]["spec"]) diff --git a/newton/newton/proxy/tests/test_identity_proxy.py b/newton/newton/proxy/tests/test_identity_proxy.py index 6fb85b2c..4cc61676 100644 --- a/newton/newton/proxy/tests/test_identity_proxy.py +++ b/newton/newton/proxy/tests/test_identity_proxy.py @@ -13,484 +13,459 @@ # limitations under the License. import json -import mock -import unittest - from django.test import Client +import mock from rest_framework import status +import unittest -from keystoneauth1 import session -from keystoneauth1.exceptions import HttpError - +from newton.requests.tests import test_base from newton.requests.views.util import VimDriverUtils -from newton.proxy.views.identityV3 import Tokens +from newton.requests.tests import mock_info -mock_viminfo = { - "createTime": "2017-04-01 02:22:27", - "domain": "Default", - "name": "TiS_R4", - "password": "admin", - "tenant": "admin", - "type": "openstack", - "url": "http://128.224.180.14:5000/v3", - "userName": "admin", - "vendor": "WindRiver", - "version": "newton", - "vimId": "windriver-hudson-dc_RegionOne", - 'cloud_owner':'windriver-hudson-dc', - 'cloud_region_id':'RegionOne', - 'cloud_extra_info':'', - 'cloud_epa_caps':'{"huge_page":"true","cpu_pinning":"true",\ - "cpu_thread_policy":"true","numa_aware":"true","sriov":"true",\ - "dpdk_vswitch":"true","rdt":"false","numa_locality_pci":"true"}', - 'insecure':'True', -} - -mock_token_id="1a62b3971d774404a504c5d9a3e506e3" mock_catalog_response = { - "catalog" : [ - { - "id" : "99aefcc82a9246f98f8c281e61ffc754", - "endpoints" : [ - { - "region" : "RegionOne", - "url" : "http://128.224.180.14:9696", - "id" : "39583c1508ad4b71b380570a745ee10a", - "interface" : "public", - "region_id" : "RegionOne" - }, - { - "url" : "http://192.168.204.2:9696", - "region" : "RegionOne", - "id" : "37e8d07ba24e4b8f93490c9daaba06e2", - "interface" : "internal", - "region_id" : "RegionOne" - }, - { - "interface" : "admin", - "id" : "7eee4ca98d444b1abb00a50d4b89373f", - "region_id" : "RegionOne", - "region" : "RegionOne", - "url" : "http://192.168.204.2:9696" - } - ], - "name" : "neutron", - "type" : "network" - }, - { - "endpoints" : [ - { - "interface" : "public", - "id" : "10496738fa374295a4a88a63b81a1589", - "region_id" : "RegionOne", - "url" : "http://128.224.180.14:8777", - "region" : "RegionOne" - }, - { - "id" : "02dcb8c0bd464c4489fa0a0c9f28571f", - "region_id" : "RegionOne", - "interface" : "internal", - "url" : "http://192.168.204.2:8777", - "region" : "RegionOne" - }, - { - "region_id" : "RegionOne", - "id" : "8a73b0d3743b4e78b87614690f6e97fe", - "interface" : "admin", - "url" : "http://192.168.204.2:8777", - "region" : "RegionOne" - } - ], - "id" : "d131054da83f4c93833799747a0f4709", - "name" : "ceilometer", - "type" : "metering" - }, - { - "type" : "volumev2", - "name" : "cinderv2", - "endpoints" : [ - { - "id" : "35a67ad36f0447d19c9662babf7cf609", - "interface" : "public", - "region_id" : "RegionOne", - "url" : "http://128.224.180.14:8776/v2/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8776/v2/fcca3cc49d5e42caae15459e27103efc", - "id" : "c6ea42052268420fa2c8d351ee68c922", - "interface" : "internal", - "region_id" : "RegionOne" - }, - { - "region_id" : "RegionOne", - "id" : "91cb24853dc3450d847b0c286a2e44ea", - "interface" : "admin", - "region" : "RegionOne", - "url" : "http://192.168.204.2:8776/v2/fcca3cc49d5e42caae15459e27103efc" - } - ], - "id" : "40440057102440739c30be10a66bc5d1" - }, - { - "name" : "heat", - "type" : "orchestration", - "id" : "35300cce88db4bd4bb5a72ffe3b88b00", - "endpoints" : [ - { - "id" : "58999d7b4a94439089ecfb2aca2d7f6c", - "region_id" : "RegionOne", - "interface" : "public", - "region" : "RegionOne", - "url" : "http://128.224.180.14:8004/v1/fcca3cc49d5e42caae15459e27103efc" - }, - { - "url" : "http://192.168.204.2:8004/v1/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne", - "interface" : "internal", - "id" : "1e0ee1a2aef84802b921d422372a567e", - "region_id" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8004/v1/fcca3cc49d5e42caae15459e27103efc", - "id" : "17661bf4859741b8a43a461dedad1871", - "region_id" : "RegionOne", - "interface" : "admin" - } - ] - }, - { - "id" : "08dc6912aea64c01925012c8a6df250a", - "endpoints" : [ - { - "id" : "02792c4eed77486083f9b2e52d7b94b0", - "region_id" : "RegionOne", - "interface" : "public", - "region" : "RegionOne", - "url" : "http://128.224.180.14:5000/v3" - }, - { - "id" : "b6d5cad394b94309ae40d8de88059c5f", - "region_id" : "RegionOne", - "interface" : "internal", - "url" : "http://192.168.204.2:5000/v3", - "region" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:35357/v3", - "region_id" : "RegionOne", - "id" : "1f18e2b7c6a34493b86853b65917888e", - "interface" : "admin" - } - ], - "type" : "identity", - "name" : "keystone" - }, - { - "name" : "vim", - "type" : "nfv", - "endpoints" : [ - { - "url" : "http://128.224.180.14:4545", - "region" : "RegionOne", - "id" : "b33e317345e4480ab0786e4960995ec9", - "interface" : "public", - "region_id" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:4545", - "interface" : "internal", - "id" : "03c85828d5bf432ab04831aa65ac9c52", - "region_id" : "RegionOne" - }, - { - "id" : "067983abb061476cb53a9e23a740d98f", - "region_id" : "RegionOne", - "interface" : "admin", - "url" : "http://192.168.204.2:4545", - "region" : "RegionOne" - } - ], - "id" : "01636c856fc84988b38b9117eb4a8021" - }, - { - "name" : "aodh", - "type" : "alarming", - "id" : "eb269151d0e44744a5b5449657bdc61c", - "endpoints" : [ - { - "id" : "5bfc6c056e0244c493642eb82f6aaa11", - "region_id" : "RegionOne", - "interface" : "public", - "url" : "http://128.224.180.14:8042", - "region" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8042", - "region_id" : "RegionOne", - "id" : "ad69c7f76dce4089a195b9221ddbfb44", - "interface" : "internal" - }, - { - "interface" : "admin", - "id" : "3e8fcdfa7bcb40b0ae33c282adfcc9ff", - "region_id" : "RegionOne", - "region" : "RegionOne", - "url" : "http://192.168.204.2:8042" - } - ] - }, - { - "name" : "sysinv", - "type" : "platform", - "endpoints" : [ - { - "region" : "RegionOne", - "url" : "http://128.224.180.14:6385/v1", - "interface" : "public", - "id" : "ba4ba8104590421b84672306c7e0e1f1", - "region_id" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:6385/v1", - "interface" : "internal", - "id" : "a1cba34b163f496ab1acd6e9b51e39a2", - "region_id" : "RegionOne" - }, - { - "url" : "http://192.168.204.2:6385/v1", - "region" : "RegionOne", - "id" : "7c171210a2c841a6a52a5713e316d6fc", - "interface" : "admin", - "region_id" : "RegionOne" - } - ], - "id" : "256bbad671f946fea543e6bd71f98875" - }, - { - "id" : "e84665dcce814c05b4c5084964547534", - "endpoints" : [ - { - "url" : "http://128.224.180.14:8000/v1/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne", - "region_id" : "RegionOne", - "id" : "b2ed1a23dc6944bea129c20861e0286a", - "interface" : "public" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8000/v1/fcca3cc49d5e42caae15459e27103efc", - "interface" : "internal", - "id" : "c4df7c6bc15646848eff35caf6ffea8e", - "region_id" : "RegionOne" - }, - { - "region_id" : "RegionOne", - "id" : "61b3dabb761443a89ab549f437c05ab0", - "interface" : "admin", - "region" : "RegionOne", - "url" : "http://192.168.204.2:8000/v1/fcca3cc49d5e42caae15459e27103efc" - } - ], - "name" : "heat-cfn", - "type" : "cloudformation" - }, - { - "id" : "823024424a014981a3721229491c0b1a", - "endpoints" : [ - { - "region" : "RegionOne", - "url" : "http://128.224.180.14:8776/v1/fcca3cc49d5e42caae15459e27103efc", - "region_id" : "RegionOne", - "id" : "4a52e4e54ff440789f9a797919c4a0f2", - "interface" : "public" - }, - { - "url" : "http://192.168.204.2:8776/v1/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne", - "id" : "d4f9a84476524a39844f0fce63f1022e", - "region_id" : "RegionOne", - "interface" : "internal" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8776/v1/fcca3cc49d5e42caae15459e27103efc", - "interface" : "admin", - "id" : "81bf3810a8cc4697b68c6e93b5b8fe1f", - "region_id" : "RegionOne" - } - ], - "type" : "volume", - "name" : "cinder" - }, - { - "name" : "glance", - "type" : "image", - "endpoints" : [ - { - "id" : "bd930aba961946cfb1401bada56d55e3", - "region_id" : "RegionOne", - "interface" : "public", - "region" : "RegionOne", - "url" : "http://128.224.180.14:9292" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:9292", - "id" : "c11da585f0b141b99d1e18bb9a607beb", - "region_id" : "RegionOne", - "interface" : "internal" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:9292", - "id" : "31b26c625a6a4fc7910dc5935155996e", - "interface" : "admin", - "region_id" : "RegionOne" - } - ], - "id" : "3b78cf039bc54d1bbb99ab3a4be15ef1" - }, - { - "id" : "b8701374bf254de1beee8a2c9ecc6b33", - "endpoints" : [ - { - "region_id" : "RegionOne", - "id" : "f7407f330c8b4577b1d377d3fab9c2f8", - "interface" : "public", - "region" : "RegionOne", - "url" : "http://128.224.180.14:15491" - }, - { - "url" : "http://192.168.204.2:5491", - "region" : "RegionOne", - "interface" : "internal", - "id" : "0b37ce31a32f4b6fa5e1aa0d6c20680f", - "region_id" : "RegionOne" - }, - { - "region_id" : "RegionOne", - "id" : "7b87ea72adf245e1991e9e0df29b7ea9", - "interface" : "admin", - "region" : "RegionOne", - "url" : "http://192.168.204.2:5491" - } - ], - "type" : "patching", - "name" : "patching" - }, - { - "id" : "0ec0923a58f04ffeb6fced3bbc5c0947", - "endpoints" : [ - { - "url" : "http://128.224.180.14:8774/v2.1/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne", - "id" : "13168b12da17451fb39630de67db168f", - "region_id" : "RegionOne", - "interface" : "public" - }, - { - "id" : "22dd6a44209f42d986b82e3aa6535f82", - "interface" : "internal", - "region_id" : "RegionOne", - "region" : "RegionOne", - "url" : "http://192.168.204.2:8774/v2.1/fcca3cc49d5e42caae15459e27103efc" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8774/v2.1/fcca3cc49d5e42caae15459e27103efc", - "id" : "552a991ae501492f841c1b6e2ff38fc5", - "region_id" : "RegionOne", - "interface" : "admin" - } - ], - "type" : "compute", - "name" : "nova" - }, - { - "id" : "50b219650f1049b097b3f14e8c70cdf8", - "endpoints" : [ - { - "interface" : "public", - "id" : "5a4276cd6e4d43e883cf8640d4e13f7d", - "region_id" : "RegionOne", - "region" : "RegionOne", - "url" : "http://128.224.180.14:8776/v3/fcca3cc49d5e42caae15459e27103efc" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8776/v3/fcca3cc49d5e42caae15459e27103efc", - "region_id" : "RegionOne", - "id" : "c796df3ca5a84fc18db5b43a55283953", - "interface" : "internal" - }, - { - "region_id" : "RegionOne", - "id" : "cf55c2b34d0049ba835a2e48b9ad0e2e", - "interface" : "admin", - "url" : "http://192.168.204.2:8776/v3/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne" - } - ], - "type" : "volumev3", - "name" : "cinderv3" - } - ], + "catalog": [ + { + "id": "99aefcc82a9246f98f8c281e61ffc754", + "endpoints": [ + { + "region": "RegionOne", + "url": "http://128.224.180.14:9696", + "id": "39583c1508ad4b71b380570a745ee10a", + "interface": "public", + "region_id": "RegionOne" + }, + { + "url": "http://192.168.204.2:9696", + "region": "RegionOne", + "id": "37e8d07ba24e4b8f93490c9daaba06e2", + "interface": "internal", + "region_id": "RegionOne" + }, + { + "interface": "admin", + "id": "7eee4ca98d444b1abb00a50d4b89373f", + "region_id": "RegionOne", + "region": "RegionOne", + "url": "http://192.168.204.2:9696" + } + ], + "name": "neutron", + "type": "network" + }, + { + "endpoints": [ + { + "interface": "public", + "id": "10496738fa374295a4a88a63b81a1589", + "region_id": "RegionOne", + "url": "http://128.224.180.14:8777", + "region": "RegionOne" + }, + { + "id": "02dcb8c0bd464c4489fa0a0c9f28571f", + "region_id": "RegionOne", + "interface": "internal", + "url": "http://192.168.204.2:8777", + "region": "RegionOne" + }, + { + "region_id": "RegionOne", + "id": "8a73b0d3743b4e78b87614690f6e97fe", + "interface": "admin", + "url": "http://192.168.204.2:8777", + "region": "RegionOne" + } + ], + "id": "d131054da83f4c93833799747a0f4709", + "name": "ceilometer", + "type": "metering" + }, + { + "type": "volumev2", + "name": "cinderv2", + "endpoints": [ + { + "id": "35a67ad36f0447d19c9662babf7cf609", + "interface": "public", + "region_id": "RegionOne", + "url": "http://128.224.180.14:8776/v2/fcca3cc49d5e42caae15459e27103efc", + "region": "RegionOne" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:8776/v2/fcca3cc49d5e42caae15459e27103efc", + "id": "c6ea42052268420fa2c8d351ee68c922", + "interface": "internal", + "region_id": "RegionOne" + }, + { + "region_id": "RegionOne", + "id": "91cb24853dc3450d847b0c286a2e44ea", + "interface": "admin", + "region": "RegionOne", + "url": "http://192.168.204.2:8776/v2/fcca3cc49d5e42caae15459e27103efc" + } + ], + "id": "40440057102440739c30be10a66bc5d1" + }, + { + "name": "heat", + "type": "orchestration", + "id": "35300cce88db4bd4bb5a72ffe3b88b00", + "endpoints": [ + { + "id": "58999d7b4a94439089ecfb2aca2d7f6c", + "region_id": "RegionOne", + "interface": "public", + "region": "RegionOne", + "url": "http://128.224.180.14:8004/v1/fcca3cc49d5e42caae15459e27103efc" + }, + { + "url": "http://192.168.204.2:8004/v1/fcca3cc49d5e42caae15459e27103efc", + "region": "RegionOne", + "interface": "internal", + "id": "1e0ee1a2aef84802b921d422372a567e", + "region_id": "RegionOne" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:8004/v1/fcca3cc49d5e42caae15459e27103efc", + "id": "17661bf4859741b8a43a461dedad1871", + "region_id": "RegionOne", + "interface": "admin" + } + ] + }, + { + "id": "08dc6912aea64c01925012c8a6df250a", + "endpoints": [ + { + "id": "02792c4eed77486083f9b2e52d7b94b0", + "region_id": "RegionOne", + "interface": "public", + "region": "RegionOne", + "url": "http://128.224.180.14:5000/v3" + }, + { + "id": "b6d5cad394b94309ae40d8de88059c5f", + "region_id": "RegionOne", + "interface": "internal", + "url": "http://192.168.204.2:5000/v3", + "region": "RegionOne" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:35357/v3", + "region_id": "RegionOne", + "id": "1f18e2b7c6a34493b86853b65917888e", + "interface": "admin" + } + ], + "type": "identity", + "name": "keystone" + }, + { + "name": "vim", + "type": "nfv", + "endpoints": [ + { + "url": "http://128.224.180.14:4545", + "region": "RegionOne", + "id": "b33e317345e4480ab0786e4960995ec9", + "interface": "public", + "region_id": "RegionOne" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:4545", + "interface": "internal", + "id": "03c85828d5bf432ab04831aa65ac9c52", + "region_id": "RegionOne" + }, + { + "id": "067983abb061476cb53a9e23a740d98f", + "region_id": "RegionOne", + "interface": "admin", + "url": "http://192.168.204.2:4545", + "region": "RegionOne" + } + ], + "id": "01636c856fc84988b38b9117eb4a8021" + }, + { + "name": "aodh", + "type": "alarming", + "id": "eb269151d0e44744a5b5449657bdc61c", + "endpoints": [ + { + "id": "5bfc6c056e0244c493642eb82f6aaa11", + "region_id": "RegionOne", + "interface": "public", + "url": "http://128.224.180.14:8042", + "region": "RegionOne" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:8042", + "region_id": "RegionOne", + "id": "ad69c7f76dce4089a195b9221ddbfb44", + "interface": "internal" + }, + { + "interface": "admin", + "id": "3e8fcdfa7bcb40b0ae33c282adfcc9ff", + "region_id": "RegionOne", + "region": "RegionOne", + "url": "http://192.168.204.2:8042" + } + ] + }, + { + "name": "sysinv", + "type": "platform", + "endpoints": [ + { + "region": "RegionOne", + "url": "http://128.224.180.14:6385/v1", + "interface": "public", + "id": "ba4ba8104590421b84672306c7e0e1f1", + "region_id": "RegionOne" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:6385/v1", + "interface": "internal", + "id": "a1cba34b163f496ab1acd6e9b51e39a2", + "region_id": "RegionOne" + }, + { + "url": "http://192.168.204.2:6385/v1", + "region": "RegionOne", + "id": "7c171210a2c841a6a52a5713e316d6fc", + "interface": "admin", + "region_id": "RegionOne" + } + ], + "id": "256bbad671f946fea543e6bd71f98875" + }, + { + "id": "e84665dcce814c05b4c5084964547534", + "endpoints": [ + { + "url": "http://128.224.180.14:8000/v1/fcca3cc49d5e42caae15459e27103efc", + "region": "RegionOne", + "region_id": "RegionOne", + "id": "b2ed1a23dc6944bea129c20861e0286a", + "interface": "public" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:8000/v1/fcca3cc49d5e42caae15459e27103efc", + "interface": "internal", + "id": "c4df7c6bc15646848eff35caf6ffea8e", + "region_id": "RegionOne" + }, + { + "region_id": "RegionOne", + "id": "61b3dabb761443a89ab549f437c05ab0", + "interface": "admin", + "region": "RegionOne", + "url": "http://192.168.204.2:8000/v1/fcca3cc49d5e42caae15459e27103efc" + } + ], + "name": "heat-cfn", + "type": "cloudformation" + }, + { + "id": "823024424a014981a3721229491c0b1a", + "endpoints": [ + { + "region": "RegionOne", + "url": "http://128.224.180.14:8776/v1/fcca3cc49d5e42caae15459e27103efc", + "region_id": "RegionOne", + "id": "4a52e4e54ff440789f9a797919c4a0f2", + "interface": "public" + }, + { + "url": "http://192.168.204.2:8776/v1/fcca3cc49d5e42caae15459e27103efc", + "region": "RegionOne", + "id": "d4f9a84476524a39844f0fce63f1022e", + "region_id": "RegionOne", + "interface": "internal" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:8776/v1/fcca3cc49d5e42caae15459e27103efc", + "interface": "admin", + "id": "81bf3810a8cc4697b68c6e93b5b8fe1f", + "region_id": "RegionOne" + } + ], + "type": "volume", + "name": "cinder" + }, + { + "name": "glance", + "type": "image", + "endpoints": [ + { + "id": "bd930aba961946cfb1401bada56d55e3", + "region_id": "RegionOne", + "interface": "public", + "region": "RegionOne", + "url": "http://128.224.180.14:9292" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:9292", + "id": "c11da585f0b141b99d1e18bb9a607beb", + "region_id": "RegionOne", + "interface": "internal" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:9292", + "id": "31b26c625a6a4fc7910dc5935155996e", + "interface": "admin", + "region_id": "RegionOne" + } + ], + "id": "3b78cf039bc54d1bbb99ab3a4be15ef1" + }, + { + "id": "b8701374bf254de1beee8a2c9ecc6b33", + "endpoints": [ + { + "region_id": "RegionOne", + "id": "f7407f330c8b4577b1d377d3fab9c2f8", + "interface": "public", + "region": "RegionOne", + "url": "http://128.224.180.14:15491" + }, + { + "url": "http://192.168.204.2:5491", + "region": "RegionOne", + "interface": "internal", + "id": "0b37ce31a32f4b6fa5e1aa0d6c20680f", + "region_id": "RegionOne" + }, + { + "region_id": "RegionOne", + "id": "7b87ea72adf245e1991e9e0df29b7ea9", + "interface": "admin", + "region": "RegionOne", + "url": "http://192.168.204.2:5491" + } + ], + "type": "patching", + "name": "patching" + }, + { + "id": "0ec0923a58f04ffeb6fced3bbc5c0947", + "endpoints": [ + { + "url": "http://128.224.180.14:8774/v2.1/fcca3cc49d5e42caae15459e27103efc", + "region": "RegionOne", + "id": "13168b12da17451fb39630de67db168f", + "region_id": "RegionOne", + "interface": "public" + }, + { + "id": "22dd6a44209f42d986b82e3aa6535f82", + "interface": "internal", + "region_id": "RegionOne", + "region": "RegionOne", + "url": "http://192.168.204.2:8774/v2.1/fcca3cc49d5e42caae15459e27103efc" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:8774/v2.1/fcca3cc49d5e42caae15459e27103efc", + "id": "552a991ae501492f841c1b6e2ff38fc5", + "region_id": "RegionOne", + "interface": "admin" + } + ], + "type": "compute", + "name": "nova" + }, + { + "id": "50b219650f1049b097b3f14e8c70cdf8", + "endpoints": [ + { + "interface": "public", + "id": "5a4276cd6e4d43e883cf8640d4e13f7d", + "region_id": "RegionOne", + "region": "RegionOne", + "url": "http://128.224.180.14:8776/v3/fcca3cc49d5e42caae15459e27103efc" + }, + { + "region": "RegionOne", + "url": "http://192.168.204.2:8776/v3/fcca3cc49d5e42caae15459e27103efc", + "region_id": "RegionOne", + "id": "c796df3ca5a84fc18db5b43a55283953", + "interface": "internal" + }, + { + "region_id": "RegionOne", + "id": "cf55c2b34d0049ba835a2e48b9ad0e2e", + "interface": "admin", + "url": "http://192.168.204.2:8776/v3/fcca3cc49d5e42caae15459e27103efc", + "region": "RegionOne" + } + ], + "type": "volumev3", + "name": "cinderv3" + } + ], } mock_auth_state = { - "body" : { - "token" : { - "is_domain" : "false", - "expires_at" : "2017-08-27T14:19:15.000000Z", - "issued_at" : "2017-08-27T13:19:15.000000Z", - "roles" : [ - { - "id" : "9fe2ff9ee4384b1894a90878d3e92bab", - "name" : "_member_" + "body": { + "token": { + "is_domain": "false", + "expires_at": "2017-08-27T14:19:15.000000Z", + "issued_at": "2017-08-27T13:19:15.000000Z", + "roles": [ + { + "id": "9fe2ff9ee4384b1894a90878d3e92bab", + "name": "_member_" + }, + { + "id": "b86a7e02935844b899d3d326f83c1b1f", + "name": "admin" + }, + { + "name": "heat_stack_owner", + "id": "7de502236e954c8282de32e773fc052e" + } + ], + "methods": [ + "password" + ], + "catalog": mock_catalog_response['catalog'], + "project": { + "name": "admin", + "id": "fcca3cc49d5e42caae15459e27103efc", + "domain": { + "id": "default", + "name": "Default" + } }, - { - "id" : "b86a7e02935844b899d3d326f83c1b1f", - "name" : "admin" + "user": { + "name": "admin", + "id": "9efb043c7629497a8028d7325ca1afb0", + "domain": { + "id": "default", + "name": "Default" + } }, - { - "name" : "heat_stack_owner", - "id" : "7de502236e954c8282de32e773fc052e" - } - ], - "methods" : [ - "password" - ], - "catalog" : mock_catalog_response['catalog'], - "project" : { - "name" : "admin", - "id" : "fcca3cc49d5e42caae15459e27103efc", - "domain" : { - "id" : "default", - "name" : "Default" - } - }, - "user" : { - "name" : "admin", - "id" : "9efb043c7629497a8028d7325ca1afb0", - "domain" : { - "id" : "default", - "name" : "Default" - } - }, - "audit_ids" : [ - "_ZWT10DtSZKRXIvIcxun7w" - ] - } - }, - "auth_token" : mock_token_id + "audit_ids": [ + "_ZWT10DtSZKRXIvIcxun7w" + ] + } + }, + "auth_token": mock_info.MOCK_TOKEN_ID } @@ -502,7 +477,8 @@ class TestIdentityService(unittest.TestCase): @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_auth_state') @mock.patch.object(VimDriverUtils, 'update_token_cache') - def test_token(self, mock_update_token_cache, mock_get_auth_state, mock_get_session, mock_get_vim_info): + def test_token(self, mock_update_token_cache, mock_get_auth_state, + mock_get_session, mock_get_vim_info): ''' test API: get token :param mock_update_token_cache: @@ -512,22 +488,28 @@ class TestIdentityService(unittest.TestCase): :return: ''' - #mock VimDriverUtils APIs + # mock VimDriverUtils APIs mock_session_specs = ["get"] - mock_session_get_response = {'status':200} - mock_session = mock.Mock(name='mock_session', spec=mock_session_specs) + mock_session_get_response = {'status': 200} + mock_session = mock.Mock(name='mock_session', + spec=mock_session_specs) mock_session.get.return_value = mock_session_get_response - mock_get_vim_info.return_value = mock_viminfo + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO mock_get_session.return_value = mock_session mock_get_auth_state.return_value = json.dumps(mock_auth_state) - mock_update_token_cache.return_value = mock_token_id + mock_update_token_cache.return_value = mock_info.MOCK_TOKEN_ID - #simulate client to make the request - data ={} - response = self.client.post("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/identity/v3/auth/tokens", data=data, format='json') - self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code) + # simulate client to make the request + data = {} + response = self.client.post( + "/api/%s/v0/windriver-hudson-dc_RegionOne/identity/v3/" + "auth/tokens" % test_base.MULTIVIM_VERSION, + data=data, format='json') + self.failUnlessEqual(status.HTTP_201_CREATED, + response.status_code) context = response.json() - self.assertTrue(response['X-Subject-Token'] == mock_token_id) - self.assertTrue(context['token']['catalog'] != None) + self.assertEqual(mock_info.MOCK_TOKEN_ID, + response['X-Subject-Token']) + self.assertIsNotNone(context['token']['catalog']) diff --git a/newton/newton/proxy/tests/test_service_proxy.py b/newton/newton/proxy/tests/test_service_proxy.py index adac3002..1687733a 100644 --- a/newton/newton/proxy/tests/test_service_proxy.py +++ b/newton/newton/proxy/tests/test_service_proxy.py @@ -20,600 +20,76 @@ import mock from rest_framework import status import unittest - +from newton.requests.tests import mock_info +from newton.requests.tests import test_base from newton.requests.views.util import VimDriverUtils -MOCK_VIM_INFO = { - "createTime": "2017-04-01 02:22:27", - "domain": "Default", - "name": "TiS_R4", - "password": "admin", - "tenant": "admin", - "type": "openstack", - "url": "http://128.224.180.14:5000/v3", - "userName": "admin", - "vendor": "WindRiver", - "version": "newton", - "vimId": "windriver-hudson-dc_RegionOne", - 'cloud_owner':'windriver-hudson-dc', - 'cloud_region_id':'RegionOne', - 'cloud_extra_info':'', - 'cloud_epa_caps':'{"huge_page":"true","cpu_pinning":"true",\ - "cpu_thread_policy":"true","numa_aware":"true","sriov":"true",\ - "dpdk_vswitch":"true","rdt":"false","numa_locality_pci":"true"}', - 'insecure':'True', -} - -MOCK_TOKEN_ID="1a62b3971d774404a504c5d9a3e506e3" - -MOCK_CATALOG_RESPONSE = { - "catalog" : [ - { - "id" : "99aefcc82a9246f98f8c281e61ffc754", - "endpoints" : [ - { - "region" : "RegionOne", - "url" : "http://128.224.180.14:9696", - "id" : "39583c1508ad4b71b380570a745ee10a", - "interface" : "public", - "region_id" : "RegionOne" - }, - { - "url" : "http://192.168.204.2:9696", - "region" : "RegionOne", - "id" : "37e8d07ba24e4b8f93490c9daaba06e2", - "interface" : "internal", - "region_id" : "RegionOne" - }, - { - "interface" : "admin", - "id" : "7eee4ca98d444b1abb00a50d4b89373f", - "region_id" : "RegionOne", - "region" : "RegionOne", - "url" : "http://192.168.204.2:9696" - } - ], - "name" : "neutron", - "type" : "network" - }, - { - "endpoints" : [ - { - "interface" : "public", - "id" : "10496738fa374295a4a88a63b81a1589", - "region_id" : "RegionOne", - "url" : "http://128.224.180.14:8777", - "region" : "RegionOne" - }, - { - "id" : "02dcb8c0bd464c4489fa0a0c9f28571f", - "region_id" : "RegionOne", - "interface" : "internal", - "url" : "http://192.168.204.2:8777", - "region" : "RegionOne" - }, - { - "region_id" : "RegionOne", - "id" : "8a73b0d3743b4e78b87614690f6e97fe", - "interface" : "admin", - "url" : "http://192.168.204.2:8777", - "region" : "RegionOne" - } - ], - "id" : "d131054da83f4c93833799747a0f4709", - "name" : "ceilometer", - "type" : "metering" - }, - { - "type" : "volumev2", - "name" : "cinderv2", - "endpoints" : [ - { - "id" : "35a67ad36f0447d19c9662babf7cf609", - "interface" : "public", - "region_id" : "RegionOne", - "url" : "http://128.224.180.14:8776/v2/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8776/v2/fcca3cc49d5e42caae15459e27103efc", - "id" : "c6ea42052268420fa2c8d351ee68c922", - "interface" : "internal", - "region_id" : "RegionOne" - }, - { - "region_id" : "RegionOne", - "id" : "91cb24853dc3450d847b0c286a2e44ea", - "interface" : "admin", - "region" : "RegionOne", - "url" : "http://192.168.204.2:8776/v2/fcca3cc49d5e42caae15459e27103efc" - } - ], - "id" : "40440057102440739c30be10a66bc5d1" - }, - { - "name" : "heat", - "type" : "orchestration", - "id" : "35300cce88db4bd4bb5a72ffe3b88b00", - "endpoints" : [ - { - "id" : "58999d7b4a94439089ecfb2aca2d7f6c", - "region_id" : "RegionOne", - "interface" : "public", - "region" : "RegionOne", - "url" : "http://128.224.180.14:8004/v1/fcca3cc49d5e42caae15459e27103efc" - }, - { - "url" : "http://192.168.204.2:8004/v1/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne", - "interface" : "internal", - "id" : "1e0ee1a2aef84802b921d422372a567e", - "region_id" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8004/v1/fcca3cc49d5e42caae15459e27103efc", - "id" : "17661bf4859741b8a43a461dedad1871", - "region_id" : "RegionOne", - "interface" : "admin" - } - ] - }, - { - "id" : "08dc6912aea64c01925012c8a6df250a", - "endpoints" : [ - { - "id" : "02792c4eed77486083f9b2e52d7b94b0", - "region_id" : "RegionOne", - "interface" : "public", - "region" : "RegionOne", - "url" : "http://128.224.180.14:5000/v3" - }, - { - "id" : "b6d5cad394b94309ae40d8de88059c5f", - "region_id" : "RegionOne", - "interface" : "internal", - "url" : "http://192.168.204.2:5000/v3", - "region" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:35357/v3", - "region_id" : "RegionOne", - "id" : "1f18e2b7c6a34493b86853b65917888e", - "interface" : "admin" - } - ], - "type" : "identity", - "name" : "keystone" - }, - { - "name" : "vim", - "type" : "nfv", - "endpoints" : [ - { - "url" : "http://128.224.180.14:4545", - "region" : "RegionOne", - "id" : "b33e317345e4480ab0786e4960995ec9", - "interface" : "public", - "region_id" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:4545", - "interface" : "internal", - "id" : "03c85828d5bf432ab04831aa65ac9c52", - "region_id" : "RegionOne" - }, - { - "id" : "067983abb061476cb53a9e23a740d98f", - "region_id" : "RegionOne", - "interface" : "admin", - "url" : "http://192.168.204.2:4545", - "region" : "RegionOne" - } - ], - "id" : "01636c856fc84988b38b9117eb4a8021" - }, - { - "name" : "aodh", - "type" : "alarming", - "id" : "eb269151d0e44744a5b5449657bdc61c", - "endpoints" : [ - { - "id" : "5bfc6c056e0244c493642eb82f6aaa11", - "region_id" : "RegionOne", - "interface" : "public", - "url" : "http://128.224.180.14:8042", - "region" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8042", - "region_id" : "RegionOne", - "id" : "ad69c7f76dce4089a195b9221ddbfb44", - "interface" : "internal" - }, - { - "interface" : "admin", - "id" : "3e8fcdfa7bcb40b0ae33c282adfcc9ff", - "region_id" : "RegionOne", - "region" : "RegionOne", - "url" : "http://192.168.204.2:8042" - } - ] - }, - { - "name" : "sysinv", - "type" : "platform", - "endpoints" : [ - { - "region" : "RegionOne", - "url" : "http://128.224.180.14:6385/v1", - "interface" : "public", - "id" : "ba4ba8104590421b84672306c7e0e1f1", - "region_id" : "RegionOne" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:6385/v1", - "interface" : "internal", - "id" : "a1cba34b163f496ab1acd6e9b51e39a2", - "region_id" : "RegionOne" - }, - { - "url" : "http://192.168.204.2:6385/v1", - "region" : "RegionOne", - "id" : "7c171210a2c841a6a52a5713e316d6fc", - "interface" : "admin", - "region_id" : "RegionOne" - } - ], - "id" : "256bbad671f946fea543e6bd71f98875" - }, - { - "id" : "e84665dcce814c05b4c5084964547534", - "endpoints" : [ - { - "url" : "http://128.224.180.14:8000/v1/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne", - "region_id" : "RegionOne", - "id" : "b2ed1a23dc6944bea129c20861e0286a", - "interface" : "public" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8000/v1/fcca3cc49d5e42caae15459e27103efc", - "interface" : "internal", - "id" : "c4df7c6bc15646848eff35caf6ffea8e", - "region_id" : "RegionOne" - }, - { - "region_id" : "RegionOne", - "id" : "61b3dabb761443a89ab549f437c05ab0", - "interface" : "admin", - "region" : "RegionOne", - "url" : "http://192.168.204.2:8000/v1/fcca3cc49d5e42caae15459e27103efc" - } - ], - "name" : "heat-cfn", - "type" : "cloudformation" - }, - { - "id" : "823024424a014981a3721229491c0b1a", - "endpoints" : [ - { - "region" : "RegionOne", - "url" : "http://128.224.180.14:8776/v1/fcca3cc49d5e42caae15459e27103efc", - "region_id" : "RegionOne", - "id" : "4a52e4e54ff440789f9a797919c4a0f2", - "interface" : "public" - }, - { - "url" : "http://192.168.204.2:8776/v1/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne", - "id" : "d4f9a84476524a39844f0fce63f1022e", - "region_id" : "RegionOne", - "interface" : "internal" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8776/v1/fcca3cc49d5e42caae15459e27103efc", - "interface" : "admin", - "id" : "81bf3810a8cc4697b68c6e93b5b8fe1f", - "region_id" : "RegionOne" - } - ], - "type" : "volume", - "name" : "cinder" - }, - { - "name" : "glance", - "type" : "image", - "endpoints" : [ - { - "id" : "bd930aba961946cfb1401bada56d55e3", - "region_id" : "RegionOne", - "interface" : "public", - "region" : "RegionOne", - "url" : "http://128.224.180.14:9292" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:9292", - "id" : "c11da585f0b141b99d1e18bb9a607beb", - "region_id" : "RegionOne", - "interface" : "internal" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:9292", - "id" : "31b26c625a6a4fc7910dc5935155996e", - "interface" : "admin", - "region_id" : "RegionOne" - } - ], - "id" : "3b78cf039bc54d1bbb99ab3a4be15ef1" - }, - { - "id" : "b8701374bf254de1beee8a2c9ecc6b33", - "endpoints" : [ - { - "region_id" : "RegionOne", - "id" : "f7407f330c8b4577b1d377d3fab9c2f8", - "interface" : "public", - "region" : "RegionOne", - "url" : "http://128.224.180.14:15491" - }, - { - "url" : "http://192.168.204.2:5491", - "region" : "RegionOne", - "interface" : "internal", - "id" : "0b37ce31a32f4b6fa5e1aa0d6c20680f", - "region_id" : "RegionOne" - }, - { - "region_id" : "RegionOne", - "id" : "7b87ea72adf245e1991e9e0df29b7ea9", - "interface" : "admin", - "region" : "RegionOne", - "url" : "http://192.168.204.2:5491" - } - ], - "type" : "patching", - "name" : "patching" - }, - { - "id" : "0ec0923a58f04ffeb6fced3bbc5c0947", - "endpoints" : [ - { - "url" : "http://128.224.180.14:8774/v2.1/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne", - "id" : "13168b12da17451fb39630de67db168f", - "region_id" : "RegionOne", - "interface" : "public" - }, - { - "id" : "22dd6a44209f42d986b82e3aa6535f82", - "interface" : "internal", - "region_id" : "RegionOne", - "region" : "RegionOne", - "url" : "http://192.168.204.2:8774/v2.1/fcca3cc49d5e42caae15459e27103efc" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8774/v2.1/fcca3cc49d5e42caae15459e27103efc", - "id" : "552a991ae501492f841c1b6e2ff38fc5", - "region_id" : "RegionOne", - "interface" : "admin" - } - ], - "type" : "compute", - "name" : "nova" - }, - { - "id" : "50b219650f1049b097b3f14e8c70cdf8", - "endpoints" : [ - { - "interface" : "public", - "id" : "5a4276cd6e4d43e883cf8640d4e13f7d", - "region_id" : "RegionOne", - "region" : "RegionOne", - "url" : "http://128.224.180.14:8776/v3/fcca3cc49d5e42caae15459e27103efc" - }, - { - "region" : "RegionOne", - "url" : "http://192.168.204.2:8776/v3/fcca3cc49d5e42caae15459e27103efc", - "region_id" : "RegionOne", - "id" : "c796df3ca5a84fc18db5b43a55283953", - "interface" : "internal" - }, - { - "region_id" : "RegionOne", - "id" : "cf55c2b34d0049ba835a2e48b9ad0e2e", - "interface" : "admin", - "url" : "http://192.168.204.2:8776/v3/fcca3cc49d5e42caae15459e27103efc", - "region" : "RegionOne" - } - ], - "type" : "volumev3", - "name" : "cinderv3" - } - ] -} - -MOCK_AUTH_STATE = { - "body" : { - "token" : { - "is_domain" : "false", - "expires_at" : "2017-08-27T14:19:15.000000Z", - "issued_at" : "2017-08-27T13:19:15.000000Z", - "roles" : [ - { - "id" : "9fe2ff9ee4384b1894a90878d3e92bab", - "name" : "_member_" - }, - { - "id" : "b86a7e02935844b899d3d326f83c1b1f", - "name" : "admin" - }, - { - "name" : "heat_stack_owner", - "id" : "7de502236e954c8282de32e773fc052e" - } - ], - "methods" : [ - "password" - ], - "catalog" : MOCK_CATALOG_RESPONSE['catalog'], - "project" : { - "name" : "admin", - "id" : "fcca3cc49d5e42caae15459e27103efc", - "domain" : { - "id" : "default", - "name" : "Default" - } - }, - "user" : { - "name" : "admin", - "id" : "9efb043c7629497a8028d7325ca1afb0", - "domain" : { - "id" : "default", - "name" : "Default" - } - }, - "audit_ids" : [ - "_ZWT10DtSZKRXIvIcxun7w" - ] - } - }, - "auth_token" : MOCK_TOKEN_ID -} - -MOCK_INTERNAL_METADATA_CATALOG = { - "identity" : { - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/identity", - "prefix" : "http://128.224.180.14:5000", - "suffix" : "v3" - }, - "patching" : { - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/patching", - "suffix" : "", - "prefix" : "http://128.224.180.14:15491" - }, - "orchestration" : { - "suffix" : "v1/fcca3cc49d5e42caae15459e27103efc", - "prefix" : "http://128.224.180.14:8004", - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/orchestration" - }, - "volume" : { - "prefix" : "http://128.224.180.14:8776", - "suffix" : "v1/fcca3cc49d5e42caae15459e27103efc", - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/volume" - }, - "metering" : { - "suffix" : "", - "prefix" : "http://128.224.180.14:8777", - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/metering" - }, - "volumev3" : { - "prefix" : "http://128.224.180.14:8776", - "suffix" : "v3/fcca3cc49d5e42caae15459e27103efc", - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/volumev3" - }, - "compute" : { - "suffix" : "v2.1/fcca3cc49d5e42caae15459e27103efc", - "prefix" : "http://128.224.180.14:8774", - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/compute" - }, - "platform" : { - "prefix" : "http://128.224.180.14:6385", - "suffix" : "v1", - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/platform" - }, - "nfv" : { - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/nfv", - "prefix" : "http://128.224.180.14:4545", - "suffix" : "" - }, - "volumev2" : { - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/volumev2", - "suffix" : "v2/fcca3cc49d5e42caae15459e27103efc", - "prefix" : "http://128.224.180.14:8776" - }, - "image" : { - "suffix" : "", - "prefix" : "http://128.224.180.14:9292", - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/image" - }, - "network" : { - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/network", - "prefix" : "http://128.224.180.14:9696", - "suffix" : "" - }, - "alarming" : { - "suffix" : "", - "prefix" : "http://128.224.180.14:8042", - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/alarming" - }, - "cloudformation" : { - "proxy_prefix" : "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/cloudformation", - "prefix" : "http://128.224.180.14:8000", - "suffix" : "v1/fcca3cc49d5e42caae15459e27103efc" - } -} - - MOCK_GET_SERVERS_RESPONSE = { - "servers" : [ - { - "links" : [ - { - "href" : "http://128.224.180.14:8774/v2.1/fcca3cc49d5e42caae15459e27103efc/servers/b2581b5c-7c56-4564-819d-fe7a2ce9c261", - "rel" : "self" - }, - { - "href" : "http://128.224.180.14:8774/fcca3cc49d5e42caae15459e27103efc/servers/b2581b5c-7c56-4564-819d-fe7a2ce9c261", - "rel" : "bookmark" - } - ], - "id" : "b2581b5c-7c56-4564-819d-fe7a2ce9c261", - "name" : "t1" - }, - { - "id" : "ff7b51ca-a272-45f4-b54c-e40b8099e67d", - "name" : "t2", - "links" : [ - { - "rel" : "self", - "href" : "http://128.224.180.14:8774/v2.1/fcca3cc49d5e42caae15459e27103efc/servers/ff7b51ca-a272-45f4-b54c-e40b8099e67d" - }, - { - "rel" : "bookmark", - "href" : "http://128.224.180.14:8774/fcca3cc49d5e42caae15459e27103efc/servers/ff7b51ca-a272-45f4-b54c-e40b8099e67d" - } - ] - } - ] + "servers": [ + { + "links": [ + { + "href": "http://128.224.180.14:8774/v2.1/" + "fcca3cc49d5e42caae15459e27103efc/servers" + "/b2581b5c-7c56-4564-819d-fe7a2ce9c261", + "rel": "self" + }, + { + "href": "http://128.224.180.14:8774/" + "fcca3cc49d5e42caae15459e27103efc/servers" + "/b2581b5c-7c56-4564-819d-fe7a2ce9c261", + "rel": "bookmark" + } + ], + "id": "b2581b5c-7c56-4564-819d-fe7a2ce9c261", + "name": "t1" + }, + { + "id": "ff7b51ca-a272-45f4-b54c-e40b8099e67d", + "name": "t2", + "links": [ + { + "rel": "self", + "href": "http://128.224.180.14:8774/v2.1/" + "fcca3cc49d5e42caae15459e27103efc/servers" + "/ff7b51ca-a272-45f4-b54c-e40b8099e67d" + }, + { + "rel": "bookmark", + "href": "http://128.224.180.14:8774/" + "fcca3cc49d5e42caae15459e27103efc/servers" + "/ff7b51ca-a272-45f4-b54c-e40b8099e67d" + } + ] + } + ] } MOCK_POST_SERVER_REQUEST = { - "server" : { + "server": { "accessIPv4": "1.2.3.4", "accessIPv6": "80fe::", - "name" : "new-server-test", - "imageRef" : "70a599e0-31e7-49b7-b260-868f441e862b", - "flavorRef" : "1", + "name": "new-server-test", + "imageRef": "70a599e0-31e7-49b7-b260-868f441e862b", + "flavorRef": "1", "availability_zone": "nova", "OS-DCF:diskConfig": "AUTO", - "metadata" : { - "My Server Name" : "Apache1" + "metadata": { + "My Server Name": "Apache1" }, "personality": [ { "path": "/etc/banner.txt", - "contents": "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 b25zLiINCg0KLVJpY2hhcmQgQmFjaA==" + "contents": + "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp " + "dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k " + "IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs " + "c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g " + "QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo " + "ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv " + "dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy " + "c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6 " + "b25zLiINCg0KLVJpY2hhcmQgQmFjaA==" } ], "security_groups": [ @@ -621,7 +97,8 @@ MOCK_POST_SERVER_REQUEST = { "name": "default" } ], - "user_data" : "IyEvYmluL2Jhc2gKL2Jpbi9zdQplY2hvICJJIGFtIGluIHlvdSEiCg==" + "user_data": + "IyEvYmluL2Jhc2gKL2Jpbi9zdQplY2hvICJJIGFtIGluIHlvdSEiCg==" }, "OS-SCH-HNT:scheduler_hints": { "same_host": "48e6a9f6-30af-47e0-bc04-acaed113bb4e" @@ -635,11 +112,15 @@ MOCK_POST_SERVER_RESPONSE = { "id": "f5dc173b-6804-445a-a6d8-c705dad5b5eb", "links": [ { - "href": "http://openstack.example.com/v2/6f70656e737461636b20342065766572/servers/f5dc173b-6804-445a-a6d8-c705dad5b5eb", + "href": "http://openstack.example.com/v2/" + "6f70656e737461636b20342065766572/servers/" + "f5dc173b-6804-445a-a6d8-c705dad5b5eb", "rel": "self" }, { - "href": "http://openstack.example.com/6f70656e737461636b20342065766572/servers/f5dc173b-6804-445a-a6d8-c705dad5b5eb", + "href": "http://openstack.example.com/" + "6f70656e737461636b20342065766572/servers/" + "f5dc173b-6804-445a-a6d8-c705dad5b5eb", "rel": "bookmark" } ], @@ -651,7 +132,6 @@ MOCK_POST_SERVER_RESPONSE = { } } - MOCK_PATCH_IMAGE_REQUEST = [ { "op": "replace", @@ -695,11 +175,11 @@ MOCK_PATCH_IMAGE_RESPONSE = { class MockResponse(object): - status_code = 200 - content = '' + status_code = 200 + content = '' - def json(self): - pass + def json(self): + pass class TestServiceProxy(unittest.TestCase): @@ -709,147 +189,197 @@ class TestServiceProxy(unittest.TestCase): @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_token_cache') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_get_token(self, mock_get_vim_info, mock_get_token_cache, mock_get_session): - mock_session_specs = ["head"] - mock_session = mock.Mock(name='mock_session', spec=mock_session_specs) - mock_get_servers_response_obj = mock.Mock(spec=MockResponse) - mock_get_servers_response_obj.status_code=200 - mock_get_servers_response_obj.content = MOCK_GET_SERVERS_RESPONSE - mock_get_servers_response_obj.json.return_value=MOCK_GET_SERVERS_RESPONSE - mock_session.head.return_value = mock_get_servers_response_obj - - mock_get_vim_info.return_value = MOCK_VIM_INFO - mock_get_session.return_value = mock_session - mock_get_token_cache.return_value = (json.dumps(MOCK_AUTH_STATE),json.dumps(MOCK_INTERNAL_METADATA_CATALOG)) - response = self.client.head( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/compute/v2.1/fcca3cc49d5e42caae15459e27103efc/servers", - {}, HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) + def test_get_token(self, mock_get_vim_info, mock_get_token_cache, + mock_get_session): + mock_session_specs = ["head"] + mock_session = mock.Mock(name='mock_session', + spec=mock_session_specs) + mock_get_servers_response_obj = mock.Mock(spec=MockResponse) + mock_get_servers_response_obj.status_code = 200 + mock_get_servers_response_obj.content = MOCK_GET_SERVERS_RESPONSE + mock_get_servers_response_obj.json.return_value = MOCK_GET_SERVERS_RESPONSE + mock_session.head.return_value = mock_get_servers_response_obj + + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_session.return_value = mock_session + mock_get_token_cache.return_value = ( + json.dumps(mock_info.MOCK_AUTH_STATE), + json.dumps(mock_info.MOCK_INTERNAL_METADATA_CATALOG)) + response = self.client.head( + "/api/%s/v0/windriver-hudson-dc_RegionOne/compute/v2.1" + "/fcca3cc49d5e42caae15459e27103efc/" + "servers" % test_base.MULTIVIM_VERSION, + {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + self.assertEquals(status.HTTP_200_OK, response.status_code) def test_unauthorized_access(self): - response = self.client.get( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/compute/v2.1/fcca3cc49d5e42caae15459e27103efc/servers") - self.assertEquals(status.HTTP_403_FORBIDDEN, response.status_code) + response = self.client.get( + "/api/%s/v0/windriver-hudson-dc_RegionOne/compute/v2.1/" + "fcca3cc49d5e42caae15459e27103efc/" + "servers" % test_base.MULTIVIM_VERSION) + self.assertEquals(status.HTTP_403_FORBIDDEN, + response.status_code) @mock.patch.object(VimDriverUtils, 'get_vim_info') def test_expired_auth_token(self, mock_get_vim_info): - mock_get_vim_info.return_value = MOCK_VIM_INFO + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO - response = self.client.get( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/compute/v2.1/fcca3cc49d5e42caae15459e27103efc/servers", - {}, HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_403_FORBIDDEN, response.status_code) + response = self.client.get( + "/api/%s/v0/windriver-hudson-dc_RegionOne/compute/v2.1/" + "fcca3cc49d5e42caae15459e27103efc/" + "servers" % test_base.MULTIVIM_VERSION, + {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + self.assertEquals(status.HTTP_403_FORBIDDEN, + response.status_code) @mock.patch.object(VimDriverUtils, 'get_token_cache') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_request_without_servicetype(self, mock_get_vim_info, mock_get_token_cache): - mock_get_vim_info.return_value = MOCK_VIM_INFO - mock_get_token_cache.return_value = (json.dumps(MOCK_AUTH_STATE), {}) - servicetype = "compute" - url = ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" + servicetype + - "/v2.1/fcca3cc49d5e42caae15459e27103efc/servers") - response = self.client.get(url, {}, HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) - - metadata_catalog = copy.deepcopy(MOCK_INTERNAL_METADATA_CATALOG) - metadata_catalog[servicetype] = None - mock_get_token_cache.return_value = (json.dumps(MOCK_AUTH_STATE), json.dumps(metadata_catalog)) - - response = self.client.get(url, {}, HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) - - metadata_catalog = copy.deepcopy(MOCK_INTERNAL_METADATA_CATALOG) - metadata_catalog[servicetype]['prefix'] = None - metadata_catalog[servicetype]['proxy_prefix'] = None - mock_get_token_cache.return_value = (json.dumps(MOCK_AUTH_STATE), json.dumps(metadata_catalog)) - - response = self.client.get(url, {}, HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) + def test_request_without_servicetype(self, mock_get_vim_info, + mock_get_token_cache): + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_token_cache.return_value = ( + json.dumps(mock_info.MOCK_AUTH_STATE), {}) + servicetype = "compute" + url = ( + "/api/%s/v0/windriver-hudson-dc_RegionOne/%s/v2.1/" + "fcca3cc49d5e42caae15459e27103efc/" + "servers" % (test_base.MULTIVIM_VERSION, servicetype)) + response = self.client.get( + url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, + response.status_code) + + metadata_catalog = copy.deepcopy( + mock_info.MOCK_INTERNAL_METADATA_CATALOG) + metadata_catalog[servicetype] = None + mock_get_token_cache.return_value = ( + json.dumps(mock_info.MOCK_AUTH_STATE), + json.dumps(metadata_catalog)) + + response = self.client.get( + url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, + response.status_code) + + metadata_catalog = copy.deepcopy( + mock_info.MOCK_INTERNAL_METADATA_CATALOG) + metadata_catalog[servicetype]['prefix'] = None + metadata_catalog[servicetype]['proxy_prefix'] = None + mock_get_token_cache.return_value = ( + json.dumps(mock_info.MOCK_AUTH_STATE), + json.dumps(metadata_catalog)) + + response = self.client.get( + url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, + response.status_code) @mock.patch.object(VimDriverUtils, 'get_vim_info') @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_auth_state') @mock.patch.object(VimDriverUtils, 'update_token_cache') @mock.patch.object(VimDriverUtils, 'get_token_cache') - def test_crud_resources(self, mock_get_token_cache, mock_update_token_cache, mock_get_auth_state, mock_get_session, mock_get_vim_info): - ''' - Test service proxy API: GET - - :param mock_get_token_cache: - :param mock_update_token_cache: - :param mock_get_auth_state: - :param mock_get_session: - :param mock_get_vim_info: - :return: - ''' - - #mock VimDriverUtils APIs - mock_session_specs = ["get", "post", "put", "patch", "delete"] - - mock_get_servers_response_obj = mock.Mock(spec=MockResponse) - mock_get_servers_response_obj.status_code=200 - mock_get_servers_response_obj.content = MOCK_GET_SERVERS_RESPONSE - mock_get_servers_response_obj.json.return_value=MOCK_GET_SERVERS_RESPONSE - - mock_post_server_response_obj = mock.Mock(spec=MockResponse) - mock_post_server_response_obj.status_code=202 - mock_post_server_response_obj.content = MOCK_POST_SERVER_RESPONSE - mock_post_server_response_obj.json.return_value=MOCK_POST_SERVER_RESPONSE - - mock_patch_server_response_obj = mock.Mock(spec=MockResponse) - mock_patch_server_response_obj.status_code=202 - mock_patch_server_response_obj.content = MOCK_PATCH_IMAGE_REQUEST - mock_patch_server_response_obj.json.return_value=MOCK_PATCH_IMAGE_REQUEST - - mock_delete_server_response_obj = mock.Mock(spec=MockResponse) - mock_delete_server_response_obj.status_code=204 - - mock_session = mock.Mock(name='mock_session', spec=mock_session_specs) - mock_session.get.return_value = mock_get_servers_response_obj - mock_session.post.return_value = mock_post_server_response_obj - mock_session.patch.return_value = mock_patch_server_response_obj - mock_session.delete.return_value = mock_delete_server_response_obj - - mock_get_vim_info.return_value = MOCK_VIM_INFO - mock_get_session.return_value = mock_session - mock_get_auth_state.return_value = json.dumps(MOCK_AUTH_STATE) - mock_update_token_cache.return_value = MOCK_TOKEN_ID - mock_get_token_cache.return_value = (json.dumps(MOCK_AUTH_STATE),json.dumps(MOCK_INTERNAL_METADATA_CATALOG)) - - # Create resource - response = self.client.post( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/compute/v2.1/fcca3cc49d5e42caae15459e27103efc/servers", - MOCK_POST_SERVER_REQUEST, HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - - self.assertEquals(status.HTTP_202_ACCEPTED, response.status_code) - context = response.json() - self.assertEquals(MOCK_TOKEN_ID, response['X-Subject-Token']) - self.assertIsNotNone(context['server']) - - # Retrieve resource - response = self.client.get( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/compute/v2.1/fcca3cc49d5e42caae15459e27103efc/servers", - {}, HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) - context = response.json() - - self.assertEquals(MOCK_TOKEN_ID, response['X-Subject-Token']) - self.assertIsNotNone(context['servers']) - - # Update resource - response = self.client.get( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/compute/v2.1/fcca3cc49d5e42caae15459e27103efc/servers", - {}, HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) - context = response.json() - - self.assertEquals(MOCK_TOKEN_ID, response['X-Subject-Token']) - self.assertIsNotNone(context['servers']) - - #simulate client to make the request - response = self.client.delete( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/compute/v2.1/fcca3cc49d5e42caae15459e27103efc/servers/324dfb7d-f4a9-419a-9a19-237df04b443b", - HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - - self.assertEquals(status.HTTP_204_NO_CONTENT, response.status_code) - self.assertEquals(MOCK_TOKEN_ID, response['X-Subject-Token']) + def test_crud_resources(self, mock_get_token_cache, + mock_update_token_cache, + mock_get_auth_state, mock_get_session, + mock_get_vim_info): + ''' + Test service proxy API: GET + + :param mock_get_token_cache: + :param mock_update_token_cache: + :param mock_get_auth_state: + :param mock_get_session: + :param mock_get_vim_info: + :return: + ''' + + # mock VimDriverUtils APIs + mock_session_specs = ["get", "post", "put", "patch", "delete"] + + mock_get_servers_response_obj = mock.Mock(spec=MockResponse) + mock_get_servers_response_obj.status_code = 200 + mock_get_servers_response_obj.content = MOCK_GET_SERVERS_RESPONSE + mock_get_servers_response_obj.json.return_value = MOCK_GET_SERVERS_RESPONSE + + mock_post_server_response_obj = mock.Mock(spec=MockResponse) + mock_post_server_response_obj.status_code = 202 + mock_post_server_response_obj.content = MOCK_POST_SERVER_RESPONSE + mock_post_server_response_obj.json.return_value = MOCK_POST_SERVER_RESPONSE + + mock_patch_server_response_obj = mock.Mock(spec=MockResponse) + mock_patch_server_response_obj.status_code = 202 + mock_patch_server_response_obj.content = MOCK_PATCH_IMAGE_REQUEST + mock_patch_server_response_obj.json.return_value = MOCK_PATCH_IMAGE_REQUEST + + mock_delete_server_response_obj = mock.Mock(spec=MockResponse) + mock_delete_server_response_obj.status_code = 204 + + mock_session = mock.Mock(name='mock_session', + spec=mock_session_specs) + mock_session.get.return_value = mock_get_servers_response_obj + mock_session.post.return_value = mock_post_server_response_obj + mock_session.patch.return_value = mock_patch_server_response_obj + mock_session.delete.return_value = mock_delete_server_response_obj + + mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO + mock_get_session.return_value = mock_session + mock_get_auth_state.return_value = json.dumps( + mock_info.MOCK_AUTH_STATE) + mock_update_token_cache.return_value = mock_info.MOCK_TOKEN_ID + mock_get_token_cache.return_value = ( + json.dumps(mock_info.MOCK_AUTH_STATE), + json.dumps(mock_info.MOCK_INTERNAL_METADATA_CATALOG)) + + # Create resource + response = self.client.post( + "/api/%s/v0/windriver-hudson-dc_RegionOne/compute/v2.1/" + "fcca3cc49d5e42caae15459e27103efc/" + "servers" % test_base.MULTIVIM_VERSION, + MOCK_POST_SERVER_REQUEST, + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + + self.assertEquals(status.HTTP_202_ACCEPTED, + response.status_code) + context = response.json() + self.assertEquals(mock_info.MOCK_TOKEN_ID, + response['X-Subject-Token']) + self.assertIsNotNone(context['server']) + + # Retrieve resource + response = self.client.get( + "/api/%s/v0/windriver-hudson-dc_RegionOne/compute/v2.1/" + "fcca3cc49d5e42caae15459e27103efc/" + "servers" % test_base.MULTIVIM_VERSION, + {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + self.assertEquals(status.HTTP_200_OK, response.status_code) + context = response.json() + + self.assertEquals(mock_info.MOCK_TOKEN_ID, + response['X-Subject-Token']) + self.assertIsNotNone(context['servers']) + + # Update resource + response = self.client.get( + "/api/%s/v0/windriver-hudson-dc_RegionOne/compute/v2.1/" + "fcca3cc49d5e42caae15459e27103efc/" + "servers" % test_base.MULTIVIM_VERSION, + {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + self.assertEquals(status.HTTP_200_OK, response.status_code) + context = response.json() + + self.assertEquals(mock_info.MOCK_TOKEN_ID, + response['X-Subject-Token']) + self.assertIsNotNone(context['servers']) + + # simulate client to make the request + response = self.client.delete( + "/api/%s/v0/windriver-hudson-dc_RegionOne/compute/v2.1/" + "fcca3cc49d5e42caae15459e27103efc/servers/" + "324dfb7d-f4a9-419a-9a19-237df04b443b" % test_base.MULTIVIM_VERSION, + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + + self.assertEquals(status.HTTP_204_NO_CONTENT, + response.status_code) + self.assertEquals(mock_info.MOCK_TOKEN_ID, + response['X-Subject-Token']) diff --git a/newton/newton/registration/tests/test_registration.py b/newton/newton/registration/tests/test_registration.py index 40c729d7..36b45f9f 100644 --- a/newton/newton/registration/tests/test_registration.py +++ b/newton/newton/registration/tests/test_registration.py @@ -22,7 +22,7 @@ from newton.requests.tests import test_base from newton.requests.views.util import VimDriverUtils MOCK_GET_TENANT_RESPONSE = { - "projects":[ + "projects": [ {"id": "1", "name": "project"}, {"id": "2", "name": "project2"}, ] @@ -34,8 +34,8 @@ MOCK_GET_FLAVOR_RESPONSE = { "id": "1", "name": "micro", "vcpus": 1, "ram": "1MB", "disk": "1G", "OS-FLV-EXT-DATA:ephemeral": False, "swap": True, "os-flavor-access:is_public": True, - "OS-FLV-DISABLED:disabled": True, "link": [{"href":1}] - }, + "OS-FLV-DISABLED:disabled": True, "link": [{"href": 1}] + }, { "id": "2", "name": "mini", "vcpus": 2, "ram": "2MB", "disk": "2G", "OS-FLV-EXT-DATA:ephemeral": True, @@ -69,7 +69,7 @@ MOCK_GET_AZ_RESPONSE = { { "zoneName": "production", "zoneState": {"available": True}, - "hosts": { "hypervisor": "kvm" } + "hosts": {"hypervisor": "kvm"} }, { "zoneName": "testing", @@ -88,9 +88,9 @@ MOCK_GET_SNAPSHOT_RESPONSE = { { "id": 1, "name": "test", "metadata": { - "architecture": "x86", "os-distro": "clearlinux", - "os-version": "276", "vendor": "intel", "version": 3, - "selflink": "test", "prev-snapshot-id": "test-id" + "architecture": "x86", "os-distro": "clearlinux", + "os-version": "276", "vendor": "intel", "version": 3, + "selflink": "test", "prev-snapshot-id": "test-id" } }, {"id": 2, "name": "test2"} @@ -103,7 +103,9 @@ MOCK_GET_HYPERVISOR_RESPONSE = { "hypervisor_hostname": "testing", "state": "ACTIVE", "id": 1, "local_gb": 256, "memory_mb": 1024, "hypervisor_links": "link", "host_ip": "127.0.0.1", - "cpu_info": u'{"topology": {"cores": 8, "threads": 16, "sockets": 4}}' + "cpu_info": + u'{"topology": {"cores": 8, "threads": 16,' + u'"sockets": 4}}' }, { "hypervisor_hostname": "testing2", "state": "XXX", @@ -117,8 +119,8 @@ TEST_REGISTER_ENDPOINT_REQUEST = { "defaultTenant": "project1" } -class TestFlavors(test_base.TestRequest): +class TestFlavors(test_base.TestRequest): def setUp(self): super(TestFlavors, self).setUp() self.req_to_aai_backup = restcall.req_to_aai @@ -149,14 +151,17 @@ class TestFlavors(test_base.TestRequest): self._get_mock_response(), self._get_mock_response(MOCK_GET_AZ_RESPONSE), self._get_mock_response(MOCK_HYPERVISOR_RESPONSE), - self._get_mock_response(MOCK_GET_SNAPSHOT_RESPONSE), - self._get_mock_response(MOCK_GET_HYPERVISOR_RESPONSE) + self._get_mock_response( + MOCK_GET_SNAPSHOT_RESPONSE), + self._get_mock_response( + MOCK_GET_HYPERVISOR_RESPONSE) ] }) response = self.client.post(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "registry"), TEST_REGISTER_ENDPOINT_REQUEST, + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "registry" % test_base.MULTIVIM_VERSION), + TEST_REGISTER_ENDPOINT_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_202_ACCEPTED, @@ -168,22 +173,23 @@ class TestFlavors(test_base.TestRequest): mock_delete_vim_info.return_value = 0 response = self.client.delete(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "registry"), "{}", content_type="application/json", + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "registry" % test_base.MULTIVIM_VERSION), + "{}", content_type="application/json", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_202_ACCEPTED, response.status_code) - @mock.patch.object(VimDriverUtils, 'delete_vim_info') def test_fail_unregister_endpoint( self, mock_delete_vim_info): mock_delete_vim_info.return_value = 1 response = self.client.delete(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "registry"), "{}", content_type="application/json", + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "registry" % test_base.MULTIVIM_VERSION), + "{}", content_type="application/json", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, diff --git a/newton/newton/requests/tests/mock_info.py b/newton/newton/requests/tests/mock_info.py index 9bcad7e0..0c7556ee 100644 --- a/newton/newton/requests/tests/mock_info.py +++ b/newton/newton/requests/tests/mock_info.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from django.conf import settings + MOCK_VIM_INFO = { "createTime": "2017-04-01 02:22:27", "domain": "Default", @@ -27,9 +29,17 @@ MOCK_VIM_INFO = { 'cloud_owner': 'windriver-hudson-dc', 'cloud_region_id': 'RegionOne', 'cloud_extra_info': '', - 'cloud_epa_caps': '{"huge_page":"true","cpu_pinning":"true",\ - "cpu_thread_policy":"true","numa_aware":"true","sriov":"true",\ - "dpdk_vswitch":"true","rdt":"false","numa_locality_pci":"true"}', + 'cloud_epa_caps': + '{' + '"huge_page":"true",' + '"cpu_pinning":"true",' + '"cpu_thread_policy":"true",' + '"numa_aware":"true",' + '"sriov":"true",' + '"dpdk_vswitch":"true",' + '"rdt":"false",' + '"numa_locality_pci":"true"' + '}', 'insecure': 'True', } @@ -480,74 +490,78 @@ MOCK_AUTH_STATE = { "auth_token": MOCK_TOKEN_ID } +BASE_URL = ("http://172.16.77.20:9003/api/%s/v0/" + "windriver-hudson-dc_RegionOne/" + % settings.MULTIVIM_VERSION) + MOCK_INTERNAL_METADATA_CATALOG = { "identity": { - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/identity", + "proxy_prefix": BASE_URL + "identity", "prefix": "http://128.224.180.14:5000", "suffix": "v3" }, "patching": { - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/patching", + "proxy_prefix": BASE_URL + "patching", "suffix": "", "prefix": "http://128.224.180.14:15491" }, "orchestration": { "suffix": "v1/fcca3cc49d5e42caae15459e27103efc", "prefix": "http://128.224.180.14:8004", - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/orchestration" + "proxy_prefix": BASE_URL + "orchestration" }, "volume": { "prefix": "http://128.224.180.14:8776", "suffix": "v1/fcca3cc49d5e42caae15459e27103efc", - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/volume" + "proxy_prefix": BASE_URL + "volume" }, "metering": { "suffix": "", "prefix": "http://128.224.180.14:8777", - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/metering" + "proxy_prefix": BASE_URL + "metering" }, "volumev3": { "prefix": "http://128.224.180.14:8776", "suffix": "v3/fcca3cc49d5e42caae15459e27103efc", - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/volumev3" + "proxy_prefix": BASE_URL + "volumev3" }, "compute": { "suffix": "v2.1/fcca3cc49d5e42caae15459e27103efc", "prefix": "http://128.224.180.14:8774", - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/compute" + "proxy_prefix": BASE_URL + "compute" }, "platform": { "prefix": "http://128.224.180.14:6385", "suffix": "v1", - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/platform" + "proxy_prefix": BASE_URL + "platform" }, "nfv": { - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/nfv", + "proxy_prefix": BASE_URL + "nfv", "prefix": "http://128.224.180.14:4545", "suffix": "" }, "volumev2": { - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/volumev2", + "proxy_prefix": BASE_URL + "volumev2", "suffix": "v2/fcca3cc49d5e42caae15459e27103efc", "prefix": "http://128.224.180.14:8776" }, "image": { "suffix": "", "prefix": "http://128.224.180.14:9292", - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/image" + "proxy_prefix": BASE_URL + "image" }, "network": { - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/network", + "proxy_prefix": BASE_URL + "network", "prefix": "http://128.224.180.14:9696", "suffix": "" }, "alarming": { "suffix": "", "prefix": "http://128.224.180.14:8042", - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/alarming" + "proxy_prefix": BASE_URL + "alarming" }, "cloudformation": { - "proxy_prefix": "http://172.16.77.20:9003/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/cloudformation", + "proxy_prefix": BASE_URL + "cloudformation", "prefix": "http://128.224.180.14:8000", "suffix": "v1/fcca3cc49d5e42caae15459e27103efc" } diff --git a/newton/newton/requests/tests/test_base.py b/newton/newton/requests/tests/test_base.py index d2065b06..4db0cf64 100644 --- a/newton/newton/requests/tests/test_base.py +++ b/newton/newton/requests/tests/test_base.py @@ -17,11 +17,14 @@ from rest_framework import status import unittest from abc import ABCMeta +from django.conf import settings from django.test import Client from newton.requests.tests import mock_info from newton.requests.views.util import VimDriverUtils +MULTIVIM_VERSION = settings.MULTIVIM_VERSION + class MockResponse(object): status_code = status.HTTP_200_OK @@ -66,10 +69,10 @@ class AbstractTestResource(object): self.client = Client() - self.openstack_version = "newton" self.region = "windriver-hudson-dc_RegionOne" - self.url = "/api/multicloud-{}/v0/{}/fcca3cc49d5e42caae15459e27103efc/".format( - self.openstack_version, self.region) + self.url = ("/api/%s/v0/%s/" + "fcca3cc49d5e42caae15459e27103efc/" % ( + MULTIVIM_VERSION, self.region)) self.MOCK_GET_RESOURCES_RESPONSE = {} self.MOCK_GET_RESOURCE_RESPONSE = {} @@ -87,51 +90,68 @@ class AbstractTestResource(object): @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_get_resources_list(self, mock_get_vim_info, mock_get_session): + def test_get_resources_list( + self, mock_get_vim_info, mock_get_session): mock_get_session.side_effect = [ get_mock_session( - ["get"], {"get": {"content": self.MOCK_GET_RESOURCES_RESPONSE}}), + ["get"], {"get": { + "content": self.MOCK_GET_RESOURCES_RESPONSE}}), ] mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO - response = self.client.get(self.url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + response = self.client.get( + self.url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertIsNotNone(context[self.assert_keys]) self.assertEqual( - self.MOCK_GET_RESOURCES_RESPONSE[self.assert_keys], context[self.assert_keys]) + self.MOCK_GET_RESOURCES_RESPONSE[self.assert_keys], + context[self.assert_keys]) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_get_resource_info(self, mock_get_vim_info, mock_get_session): + def test_get_resource_info( + self, mock_get_vim_info, mock_get_session): mock_get_session.side_effect = [ get_mock_session( - ["get"], {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE}}), + ["get"], {"get": { + "content": self.MOCK_GET_RESOURCE_RESPONSE}}), ] mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO - response = self.client.get(self.url + "/uuid_1", {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + response = self.client.get( + self.url + "/uuid_1", {}, + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertEquals( - self.MOCK_GET_RESOURCE_RESPONSE[self.assert_key], context[self.assert_key]) + self.MOCK_GET_RESOURCE_RESPONSE[self.assert_key], + context[self.assert_key]) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_get_resource_not_found(self, mock_get_vim_info, mock_get_session): + def test_get_resource_not_found( + self, mock_get_vim_info, mock_get_session): mock_get_session.side_effect = [ get_mock_session( - ["get"], {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND, - "status_code": 404}}), + ["get"], { + "get": { + "content": self.MOCK_GET_RESOURCE_RESPONSE_NOT_FOUND, + "status_code": 404 + } + } + ), ] mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO - response = self.client.get(self.url + "/uuid_3", {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + response = self.client.get( + self.url + "/uuid_3", {}, + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(self.HTTP_not_found, response.status_code) @@ -140,35 +160,45 @@ class AbstractTestResource(object): def test_post_resource(self, mock_get_vim_info, mock_get_session): mock_get_session.side_effect = [ get_mock_session( - ["get"], {"get": {"content": self.MOCK_GET_RESOURCES_RESPONSE}}), + ["get"], {"get": { + "content": self.MOCK_GET_RESOURCES_RESPONSE}}), get_mock_session( - ["post"], {"post": {"content": self.MOCK_POST_RESOURCE_RESPONSE, - "status_code": 202}}), + ["post"], {"post": { + "content": self.MOCK_POST_RESOURCE_RESPONSE, + "status_code": 202}}), ] mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO - response = self.client.post(self.url, self.MOCK_POST_RESOURCE_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + response = self.client.post( + self.url, self.MOCK_POST_RESOURCE_REQUEST, + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() - self.assertEquals(status.HTTP_202_ACCEPTED, response.status_code) + self.assertEquals(status.HTTP_202_ACCEPTED, + response.status_code) self.assertIsNotNone(context['id']) self.assertEqual(1, context['returnCode']) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_post_resource_existing(self, mock_get_vim_info, mock_get_session): + def test_post_resource_existing( + self, mock_get_vim_info, mock_get_session): mock_get_session.side_effect = [ get_mock_session( - ["get"], {"get": {"content": self.MOCK_GET_RESOURCES_RESPONSE}}), + ["get"], {"get": { + "content": self.MOCK_GET_RESOURCES_RESPONSE}}), get_mock_session( - ["post"], {"post": {"content": self.MOCK_POST_RESOURCE_RESPONSE, - "status_code": 201}}), + ["post"], {"post": { + "content": self.MOCK_POST_RESOURCE_RESPONSE, + "status_code": 201}}), ] mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO - response = self.client.post(self.url, self.MOCK_POST_RESOURCE_REQUEST_EXISTING, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + response = self.client.post( + self.url, self.MOCK_POST_RESOURCE_REQUEST_EXISTING, + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() self.assertEquals(status.HTTP_200_OK, response.status_code) @@ -177,26 +207,33 @@ class AbstractTestResource(object): @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_post_resource_empty(self, mock_get_vim_info, mock_get_session): + def test_post_resource_empty( + self, mock_get_vim_info, mock_get_session): mock_get_session.side_effect = [ get_mock_session( - ["get"], {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE}}), + ["get"], {"get": { + "content": self.MOCK_GET_RESOURCE_RESPONSE}}), get_mock_session( - ["post"], {"post": {"content": self.MOCK_POST_RESOURCE_RESPONSE, - "status_code": 202}}), + ["post"], {"post": { + "content": self.MOCK_POST_RESOURCE_RESPONSE, + "status_code": 202}}), ] mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO - response = self.client.post(self.url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + response = self.client.post( + self.url, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() self.assertIn('error', context) - self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) + self.assertEquals( + status.HTTP_500_INTERNAL_SERVER_ERROR, + response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_delete_resource(self, mock_get_vim_info, mock_get_session): + def test_delete_resource( + self, mock_get_vim_info, mock_get_session): mock_get_session.side_effect = [ get_mock_session( @@ -206,7 +243,10 @@ class AbstractTestResource(object): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO - response = self.client.delete(self.url + "/uuid_1", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + response = self.client.delete( + self.url + "/uuid_1", + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) + self.assertEqual(status.HTTP_204_NO_CONTENT, + response.status_code) self.assertIsNone(response.data) diff --git a/newton/newton/requests/tests/test_flavor.py b/newton/newton/requests/tests/test_flavor.py index 26e3f381..765121ff 100644 --- a/newton/newton/requests/tests/test_flavor.py +++ b/newton/newton/requests/tests/test_flavor.py @@ -82,7 +82,8 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): mock_get_flavor_extra_specs): mock_get_session.side_effect = [ test_base.get_mock_session( - ["get"], {"get": {"content": self.MOCK_GET_RESOURCES_RESPONSE}}), + ["get"], {"get": { + "content": self.MOCK_GET_RESOURCES_RESPONSE}}), ] mock_extra_specs = mock.Mock(spec=test_base.MockResponse) @@ -92,8 +93,9 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO response = self.client.get( - ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne" - "/fcca3cc49d5e42caae15459e27103efc/flavors"), + ("/api/%s/v0/windriver-hudson-dc_RegionOne" + "/fcca3cc49d5e42caae15459e27103efc/" + "flavors" % test_base.MULTIVIM_VERSION), {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() @@ -110,7 +112,8 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): mock_get_session.side_effect = [ test_base.get_mock_session( ["get"], - {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE}}), + {"get": { + "content": self.MOCK_GET_RESOURCE_RESPONSE}}), ] mock_extra_specs = mock.Mock(spec=test_base.MockResponse) @@ -120,13 +123,15 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO response = self.client.get( - ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne" - "/fcca3cc49d5e42caae15459e27103efc/flavors/uuid_1"), + ("/api/%s/v0/windriver-hudson-dc_RegionOne" + "/fcca3cc49d5e42caae15459e27103efc/flavors/" + "uuid_1" % test_base.MULTIVIM_VERSION), {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() self.assertEquals(status.HTTP_200_OK, response.status_code) - self.assertEqual(self.MOCK_GET_RESOURCE_RESPONSE["id"], context["id"]) + self.assertEqual(self.MOCK_GET_RESOURCE_RESPONSE["id"], + context["id"]) @mock.patch.object(Flavors, '_get_flavor_extra_specs') @mock.patch.object(VimDriverUtils, 'get_session') @@ -147,8 +152,9 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO response = self.client.get( - ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne" - "/fcca3cc49d5e42caae15459e27103efc/flavors/uuid_1"), + ("/api/%s/v0/windriver-hudson-dc_RegionOne" + "/fcca3cc49d5e42caae15459e27103efc/flavors/" + "uuid_1" % test_base.MULTIVIM_VERSION), {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) # TODO(sshank): 404 status is not possible. @@ -158,11 +164,13 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_create_flavor(self, mock_get_vim_info, mock_get_session): + def test_create_flavor( + self, mock_get_vim_info, mock_get_session): mock_get_session.side_effect = [ test_base.get_mock_session( ["get", "post"], { - "get": {"content": self.MOCK_GET_RESOURCES_RESPONSE}, + "get": { + "content": self.MOCK_GET_RESOURCES_RESPONSE}, "post": { "content": self.MOCK_POST_RESOURCE_RESPONSE, "status_code": status.HTTP_202_ACCEPTED, @@ -173,8 +181,9 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO response = self.client.post( - ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne" - "/fcca3cc49d5e42caae15459e27103efc/flavors"), + ("/api/%s/v0/windriver-hudson-dc_RegionOne" + "/fcca3cc49d5e42caae15459e27103efc/" + "flavors" % test_base.MULTIVIM_VERSION), self.MOCK_POST_RESOURCE_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() @@ -193,7 +202,8 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): mock_get_session.side_effect = [ test_base.get_mock_session( ["get", "post"], { - "get": {"content": self.MOCK_GET_RESOURCES_RESPONSE}, + "get": { + "content": self.MOCK_GET_RESOURCES_RESPONSE}, "post": { "content": self.MOCK_POST_RESOURCE_RESPONSE, "status_code": status.HTTP_202_ACCEPTED, @@ -207,8 +217,9 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO response = self.client.post( - ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "fcca3cc49d5e42caae15459e27103efc/flavors"), + ("/api/%s/v0/windriver-hudson-dc_RegionOne/" + "fcca3cc49d5e42caae15459e27103efc/" + "flavors" % test_base.MULTIVIM_VERSION), self.MOCK_POST_RESOURCE_REQUEST_EXISTING, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) @@ -219,20 +230,23 @@ class TestFlavorsNewton(unittest.TestCase, AbstractTestResource): @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_delete_flavor(self, mock_get_vim_info, mock_get_session): + def test_delete_flavor( + self, mock_get_vim_info, mock_get_session): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO mock_get_session.side_effect = [ test_base.get_mock_session( ["get", "delete"], { "get": { "content": self.MOCK_GET_EXTRA_SPECS }, - "delete": {"status_code": status.HTTP_204_NO_CONTENT } + "delete": { + "status_code": status.HTTP_204_NO_CONTENT } }), ] response = self.client.delete( - ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "fcca3cc49d5e42caae15459e27103efc/flavors/uuid_1"), + ("/api/%s/v0/windriver-hudson-dc_RegionOne/" + "fcca3cc49d5e42caae15459e27103efc/flavors/" + "uuid_1" % test_base.MULTIVIM_VERSION), HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEqual(status.HTTP_204_NO_CONTENT, diff --git a/newton/newton/requests/tests/test_image.py b/newton/newton/requests/tests/test_image.py index a290302e..40326c2d 100644 --- a/newton/newton/requests/tests/test_image.py +++ b/newton/newton/requests/tests/test_image.py @@ -26,7 +26,6 @@ from newton.requests.views.util import VimDriverUtils class TestImageNewton(unittest.TestCase, AbstractTestResource): - def setUp(self): AbstractTestResource.__init__(self) @@ -74,14 +73,16 @@ class TestImageNewton(unittest.TestCase, AbstractTestResource): @mock.patch.object(urllib, 'request') @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_post_image(self, mock_get_vim_info, mock_get_session, mock_request, mock_run): - + def test_post_image(self, mock_get_vim_info, mock_get_session, + mock_request, mock_run): mock_get_session.side_effect = [ test_base.get_mock_session( - ["get"], {"get": {"content": self.MOCK_GET_RESOURCES_RESPONSE}}), + ["get"], {"get": { + "content": self.MOCK_GET_RESOURCES_RESPONSE}}), test_base.get_mock_session( - ["post"], {"post": {"content": self.MOCK_POST_RESOURCE_RESPONSE, - "status_code": 201}}), + ["post"], + {"post": {"content": self.MOCK_POST_RESOURCE_RESPONSE, + "status_code": 201}}), ] mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO @@ -89,11 +90,15 @@ class TestImageNewton(unittest.TestCase, AbstractTestResource): mock_request.urlopen.return_value = "image" response = self.client.post( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/images", - self.MOCK_POST_RESOURCE_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "fcca3cc49d5e42caae15459e27103efc/" + "images" % test_base.MULTIVIM_VERSION, + self.MOCK_POST_RESOURCE_REQUEST, + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() - self.assertEquals(status.HTTP_201_CREATED, response.status_code) + self.assertEquals(status.HTTP_201_CREATED, + response.status_code) self.assertIsNotNone(context['id']) self.assertEqual(1, context['returnCode']) diff --git a/newton/newton/requests/tests/test_limits.py b/newton/newton/requests/tests/test_limits.py index d37e7e6d..6438e975 100644 --- a/newton/newton/requests/tests/test_limits.py +++ b/newton/newton/requests/tests/test_limits.py @@ -53,51 +53,62 @@ class TestLimitNewton(unittest.TestCase, AbstractTestResource): @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_get_limits_list(self, mock_get_vim_info, mock_get_session): - + def test_get_limits_list( + self, mock_get_vim_info, mock_get_session): mock_get_session.return_value = test_base.get_mock_session( ["get"], { "side_effect": [ - self._get_mock_response(self.MOCK_GET_LIMITS_RESPONSE), - self._get_mock_response(self.MOCK_GET_QUOTAS_RESPONSE), - self._get_mock_response(self.MOCK_GET_LIMITS_RESPONSE) + self._get_mock_response( + self.MOCK_GET_LIMITS_RESPONSE), + self._get_mock_response( + self.MOCK_GET_QUOTAS_RESPONSE), + self._get_mock_response( + self.MOCK_GET_LIMITS_RESPONSE) ] }) mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO response = self.client.get( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/limits", + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "fcca3cc49d5e42caae15459e27103efc/" + "limits" % test_base.MULTIVIM_VERSION, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertIsNotNone(context) self.assertIn( - self.MOCK_GET_LIMITS_RESPONSE["limits"]["absolute"]['id'], context['id']) + self.MOCK_GET_LIMITS_RESPONSE["limits"]["absolute"]['id'], + context['id']) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') - def test_get_limits_list_failure(self, mock_get_vim_info, mock_get_session): - + def test_get_limits_list_failure( + self, mock_get_vim_info, mock_get_session): mock_get_session.return_value = test_base.get_mock_session( ["get"], { "side_effect": [ - self._get_mock_response(self.MOCK_GET_LIMITS_RESPONSE), + self._get_mock_response( + self.MOCK_GET_LIMITS_RESPONSE), self._get_mock_response({}), - self._get_mock_response(self.MOCK_GET_LIMITS_RESPONSE) + self._get_mock_response( + self.MOCK_GET_LIMITS_RESPONSE) ] }) mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO response = self.client.get( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/limits", + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "fcca3cc49d5e42caae15459e27103efc/" + "limits" % test_base.MULTIVIM_VERSION, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() self.assertIn('error', context) - self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) + self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, + response.status_code) def test_get_resources_list(self): pass diff --git a/newton/newton/requests/tests/test_server.py b/newton/newton/requests/tests/test_server.py index b5e6e3fe..15a77948 100644 --- a/newton/newton/requests/tests/test_server.py +++ b/newton/newton/requests/tests/test_server.py @@ -26,7 +26,7 @@ MOCK_GET_SERVERS_RESPONSE = { { "name": "compute_1", "id": "1" - }, + }, { "name": "compute_2", "id": "2" @@ -39,17 +39,17 @@ MOCK_GET_SERVER_RESPONSE = { { "name": "compute_1", "id": "1" - } + } } MOCK_GET_PORTS_RESPONSE = { "interfaceAttachments": [ { "port_id": "1", - }, + }, { "port_id": "2", - }, + }, ] } @@ -86,7 +86,6 @@ MOCK_POST_SERVER_CREATED_THREAD_RESPONSE = { class TestNetwork(test_base.TestRequest): - @mock.patch.object(VimDriverUtils, 'get_vim_info') def test_get_servers_failure(self, mock_get_vim_info): mock_get_vim_info.raiseError.side_effect = mock.Mock( @@ -94,8 +93,8 @@ class TestNetwork(test_base.TestRequest): tenant_id = "fcca3cc49d5e42caae15459e27103efc" response = self.client.get(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "" + tenant_id + "/servers"), + "/api/%s/v0/windriver-hudson-dc_RegionOne/%s/" + "servers" % (test_base.MULTIVIM_VERSION, tenant_id)), {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, @@ -110,10 +109,10 @@ class TestNetwork(test_base.TestRequest): mock_get_session.side_effect = [ test_base.get_mock_session( ["get"], - {"get": { "content": MOCK_GET_SERVERS_RESPONSE }}), + {"get": {"content": MOCK_GET_SERVERS_RESPONSE}}), test_base.get_mock_session( ["get"], - {"get": { "content":MOCK_GET_PORTS_RESPONSE}}), + {"get": {"content": MOCK_GET_PORTS_RESPONSE}}), test_base.get_mock_session( ["get"], {"get": {"content": None}}), @@ -121,8 +120,8 @@ class TestNetwork(test_base.TestRequest): tenant_id = "fcca3cc49d5e42caae15459e27103efc" response = self.client.get(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "" + tenant_id + "/servers"), + "/api/%s/v0/windriver-hudson-dc_RegionOne/%s/" + "servers" % (test_base.MULTIVIM_VERSION, tenant_id)), {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_200_OK, response.status_code) @@ -142,16 +141,19 @@ class TestNetwork(test_base.TestRequest): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO mock_get_session.side_effect = [ test_base.get_mock_session( - ["get"], {"get": {"content": MOCK_GET_SERVER_RESPONSE.copy()}}), + ["get"], {"get": { + "content": MOCK_GET_SERVER_RESPONSE.copy()}}), test_base.get_mock_session( - ["get"], {"get": {"content": MOCK_GET_PORTS_RESPONSE.copy()}}), + ["get"], {"get": { + "content": MOCK_GET_PORTS_RESPONSE.copy()}}), ] tenant_id = "fcca3cc49d5e42caae15459e27103efc" server_id = "f5dc173b-6804-445a-a6d8-c705dad5b5eb" response = self.client.get(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "" + tenant_id + "/servers/" + server_id), + "/api/%s/v0/windriver-hudson-dc_RegionOne/%s/" + "servers/%s" % (test_base.MULTIVIM_VERSION, + tenant_id, server_id)), {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_200_OK, response.status_code) @@ -170,9 +172,9 @@ class TestNetwork(test_base.TestRequest): mock_get_session.side_effect = [ test_base.get_mock_session( ["get"], - {"get": {"content":MOCK_GET_SERVERS_RESPONSE}}), + {"get": {"content": MOCK_GET_SERVERS_RESPONSE}}), test_base.get_mock_session( - ["get"], {"get": {"content":None}}), + ["get"], {"get": {"content": None}}), test_base.get_mock_session( ["get"], {"get": {"content": None}}), ] @@ -181,21 +183,22 @@ class TestNetwork(test_base.TestRequest): server_id = "f5dc173b-6804-445a-a6d8-c705dad5b5eb" response = self.client.post(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "" + tenant_id + "/servers/" + server_id), + "/api/%s/v0/windriver-hudson-dc_RegionOne/%s/" + "servers/%s" % (test_base.MULTIVIM_VERSION, tenant_id, + server_id)), data=json.dumps(TEST_CREATE_SERVER), content_type="application/json", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() - self.assertEquals(status.HTTP_200_OK,response.status_code) + self.assertEquals(status.HTTP_200_OK, response.status_code) self.assertIsNone(context["volumeArray"]) self.assertIsNone(context["flavorId"]) self.assertIsNone(context["availabilityZone"]) self.assertEquals(TEST_CREATE_SERVER["name"], context["name"]) self.assertEquals( MOCK_GET_SERVERS_RESPONSE["servers"][0]["id"], - context["id"]) + context["id"]) self.assertIsNone(context["nicArray"]) self.assertIsNotNone(context["boot"]) self.assertEquals(0, context["returnCode"]) @@ -207,16 +210,18 @@ class TestNetwork(test_base.TestRequest): mock_get_session.side_effect = [ test_base.get_mock_session( - ["get"], {"get": {"content": {"servers":[]}}}), + ["get"], {"get": {"content": {"servers": []}}}), test_base.get_mock_session( - ["post"], {"post": {"content": MOCK_POST_SERVER_RESPONSE.copy()}}), + ["post"], {"post": { + "content": MOCK_POST_SERVER_RESPONSE.copy()}}), ] tenant_id = "fcca3cc49d5e42caae15459e27103efc" server_id = "f5dc173b-6804-445a-a6d8-c705dad5b5eb" response = self.client.post(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "" + tenant_id + "/servers/" + server_id), + "/api/%s/v0/windriver-hudson-dc_RegionOne/%s/" + "servers/%s" % (test_base.MULTIVIM_VERSION, tenant_id, + server_id)), data=json.dumps(TEST_CREATE_SERVER), content_type="application/json", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) @@ -249,14 +254,15 @@ class TestNetwork(test_base.TestRequest): @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') def test_delete_existing_server(self, mock_get_vim_info, - mock_get_session): + mock_get_session): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO mock_get_session.side_effect = [ test_base.get_mock_session( ["delete"], {"delete": {"content": None}}), test_base.get_mock_session( ["get"], - {"get": {"content": MOCK_GET_SERVER_RESPONSE.copy()}}), + {"get": { + "content": MOCK_GET_SERVER_RESPONSE.copy()}}), test_base.get_mock_session( ["get"], {"get": {"content": None}}), ] @@ -265,10 +271,11 @@ class TestNetwork(test_base.TestRequest): server_id = "f5dc173b-6804-445a-a6d8-c705dad5b5eb" response = self.client.delete(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "" + tenant_id + "/servers/" + server_id), + "/api/%s/v0/windriver-hudson-dc_RegionOne/%s/" + "servers/%s" % (test_base.MULTIVIM_VERSION, tenant_id, + server_id)), data=json.dumps(TEST_CREATE_SERVER), content_type="application/json", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code)
\ No newline at end of file + self.assertEquals(status.HTTP_200_OK, response.status_code) diff --git a/newton/newton/requests/tests/test_subnet.py b/newton/newton/requests/tests/test_subnet.py index 653df33d..9cc1ea3c 100644 --- a/newton/newton/requests/tests/test_subnet.py +++ b/newton/newton/requests/tests/test_subnet.py @@ -80,13 +80,15 @@ class TestSubnetNewton(unittest.TestCase, AbstractTestResource): mock_get_vim_info.return_value = mock_info.MOCK_VIM_INFO response = self.client.get( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/subnets" - "/uuid_1", + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "fcca3cc49d5e42caae15459e27103efc/subnets/" + "uuid_1" % test_base.MULTIVIM_VERSION, {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() self.assertEquals(status.HTTP_200_OK, response.status_code) - self.assertEqual(self.MOCK_GET_RESOURCE_RESPONSE["id"], context["id"]) + self.assertEqual(self.MOCK_GET_RESOURCE_RESPONSE["id"], + context["id"]) # Overridden method from test base to not make it run for current test case. def test_get_resource_info(self): diff --git a/newton/newton/requests/tests/test_tenant.py b/newton/newton/requests/tests/test_tenant.py index 67c02b51..87db8abd 100644 --- a/newton/newton/requests/tests/test_tenant.py +++ b/newton/newton/requests/tests/test_tenant.py @@ -20,7 +20,7 @@ from newton.requests.tests import test_base from newton.requests.views.util import VimDriverUtils MOCK_GET_PROJECTS_RESPONSE = { - "tenants":[ + "tenants": [ {"id": "1", "name": "project"}, {"id": "2", "name": "project2"}, ] @@ -28,7 +28,6 @@ MOCK_GET_PROJECTS_RESPONSE = { class TestNetwork(test_base.TestRequest): - @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') def test_retrieve_projects( @@ -37,12 +36,12 @@ class TestNetwork(test_base.TestRequest): mock_get_session.side_effect = [ test_base.get_mock_session( ["get"], - {"get": { "content": MOCK_GET_PROJECTS_RESPONSE }}), + {"get": {"content": MOCK_GET_PROJECTS_RESPONSE}}), ] response = self.client.get(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "tenants"), {}, + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "tenants" % test_base.MULTIVIM_VERSION), {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_200_OK, response.status_code) @@ -71,8 +70,8 @@ class TestNetwork(test_base.TestRequest): ] response = self.client.get(( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "tenants?name=project"), {}, + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "tenants?name=project" % test_base.MULTIVIM_VERSION), {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_200_OK, response.status_code) diff --git a/newton/newton/requests/tests/test_volume.py b/newton/newton/requests/tests/test_volume.py index fb58d240..ff3e2cf9 100644 --- a/newton/newton/requests/tests/test_volume.py +++ b/newton/newton/requests/tests/test_volume.py @@ -78,12 +78,15 @@ class TestVolumesNewton(unittest.TestCase, AbstractTestResource): {"get": {"content": self.MOCK_GET_RESOURCE_RESPONSE}}) response = self.client.get( - "/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/fcca3cc49d5e42caae15459e27103efc/" - "volumes/uuid_1", {}, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) + "/api/%s/v0/windriver-hudson-dc_RegionOne/" + "fcca3cc49d5e42caae15459e27103efc/volumes/" + "uuid_1" % test_base.MULTIVIM_VERSION, {}, + HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) context = response.json() self.assertEquals(status.HTTP_200_OK, response.status_code) - self.assertEquals(self.MOCK_GET_RESOURCE_RESPONSE['id'], context['id']) + self.assertEquals(self.MOCK_GET_RESOURCE_RESPONSE['id'], + context['id']) # Overridden method from test base to not make it run for current test case. def test_get_resource_info(self): diff --git a/newton/newton/requests/tests/test_vport.py b/newton/newton/requests/tests/test_vport.py index c272f5db..3fc4bfca 100644 --- a/newton/newton/requests/tests/test_vport.py +++ b/newton/newton/requests/tests/test_vport.py @@ -53,8 +53,8 @@ MOCK_POST_VPORT_RESPONSE = { class Testvports(test_base.TestRequest): - url = ("/api/multicloud-newton/v0/windriver-hudson-dc_RegionOne/" - "fcca3cc49d5e42caae15459e27103efc/") + url = ("/api/%s/v0/windriver-hudson-dc_RegionOne/" + "fcca3cc49d5e42caae15459e27103efc/" % test_base.MULTIVIM_VERSION) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') def test_get_vports(self, mock_get_vim_info, mock_get_session): diff --git a/newton/newton/settings.py b/newton/newton/settings.py index d460758c..713470a6 100644 --- a/newton/newton/settings.py +++ b/newton/newton/settings.py @@ -116,6 +116,10 @@ CACHES = { } } +OPENSTACK_VERSION = "newton" +MULTIVIM_VERSION = "multicloud-" + OPENSTACK_VERSION + + if 'test' in sys.argv: from newton.pub.config import config diff --git a/newton/newton/swagger/tests.py b/newton/newton/swagger/tests.py index 78546039..53b247ba 100644 --- a/newton/newton/swagger/tests.py +++ b/newton/newton/swagger/tests.py @@ -10,17 +10,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. import unittest -import json from django.test import Client from rest_framework import status +from newton.requests.tests import test_base + class SampleViewTest(unittest.TestCase): def setUp(self): self.client = Client() def test_sample(self): - response = self.client.get("/api/multicloud-newton/v0/swagger.json") - self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) -# resp_data = json.loads(response.content) -# self.assertEqual({"status": "active"}, resp_data) + response = self.client.get( + "/api/%s/v0/swagger.json" % test_base.MULTIVIM_VERSION) + self.assertEqual(status.HTTP_200_OK, response.status_code) |