diff options
author | Xiaohua Zhang <xiaohua.zhang@windriver.com> | 2018-11-27 10:28:41 +0000 |
---|---|---|
committer | Xiaohua Zhang <xiaohua.zhang@windriver.com> | 2018-11-27 10:28:41 +0000 |
commit | 0d045c0bb7ee6e6162d2c1fc3e8031a3b067f49f (patch) | |
tree | f2e007e9d25320afaee402d0d25dae20710c5bb0 /windriver | |
parent | 87ba0b1dc07997db90d62df3c50cbb826fb8b828 (diff) |
Fix pep8 errors in multicloud plugin
Fix pep8 errors in registration moduel
Change-Id: I4b1d3ef1ed397c537b7904f229c0bbc07796a97e
Issue-ID: MULTICLOUD-420
Signed-off-by: Xiaohua Zhang <xiaohua.zhang@windriver.com>
Diffstat (limited to 'windriver')
6 files changed, 98 insertions, 109 deletions
diff --git a/windriver/titanium_cloud/registration/__init__.py b/windriver/titanium_cloud/registration/__init__.py index afa702d3..ae1ce9db 100644 --- a/windriver/titanium_cloud/registration/__init__.py +++ b/windriver/titanium_cloud/registration/__init__.py @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/windriver/titanium_cloud/registration/tests/__init__.py b/windriver/titanium_cloud/registration/tests/__init__.py index afa702d3..ae1ce9db 100644 --- a/windriver/titanium_cloud/registration/tests/__init__.py +++ b/windriver/titanium_cloud/registration/tests/__init__.py @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/windriver/titanium_cloud/registration/tests/test_registration.py b/windriver/titanium_cloud/registration/tests/test_registration.py index 38a6beed..749fba62 100644 --- a/windriver/titanium_cloud/registration/tests/test_registration.py +++ b/windriver/titanium_cloud/registration/tests/test_registration.py @@ -22,7 +22,7 @@ from newton_base.tests import test_base from newton_base.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"} @@ -117,9 +117,8 @@ TEST_REGISTER_ENDPOINT_REQUEST = { "defaultTenant": "project1" } - # HPA UT1: CPU-PINNING -MOCK_GET_HPA_FLAVOR_LIST1_RESPONSE= { +MOCK_GET_HPA_FLAVOR_LIST1_RESPONSE = { "flavors": [ { "id": "1", "name": "micro", "vcpus": 1, "ram": "1024", @@ -170,11 +169,11 @@ MOCK_GET_HPA_FLAVOR_onap_mini_EXTRA_SPECS4_RESPONSE = { "extra_specs": { "aggregate_instance_extra_specs:storage": "local_image", "capabilities:cpu_info:model": "Haswell", - "hw:numa_nodes": "2", - "hw:numa_cpus.0": "0,1", - "hw:numa_cpus.1": "2,3,4,5", - "hw:numa_mem.0": "2048", - "hw:numa_mem.1": "2048" + "hw:numa_nodes": "2", + "hw:numa_cpus.0": "0,1", + "hw:numa_cpus.1": "2,3,4,5", + "hw:numa_mem.0": "2048", + "hw:numa_mem.1": "2048" } } @@ -183,7 +182,7 @@ MOCK_GET_HPA_FLAVOR_onap_mini_EXTRA_SPECS5_RESPONSE = { "extra_specs": { "aggregate_instance_extra_specs:storage": "local_image", "capabilities:cpu_info:model": "Haswell", - "hw:capabilities:cpu_info:features": "avx,acpi" + "hw:capabilities:cpu_info:features": "avx,acpi" } } @@ -192,7 +191,7 @@ MOCK_GET_HPA_FLAVOR_onap_mini_EXTRA_SPECS6_RESPONSE = { "extra_specs": { "aggregate_instance_extra_specs:storage": "local_image", "capabilities:cpu_info:model": "Haswell", - "pci_passthrough:alias": "sriov-vf-intel-8086-15b3:4" + "pci_passthrough:alias": "sriov-vf-intel-8086-15b3:4" } } @@ -206,7 +205,6 @@ MOCK_GET_HPA_FLAVOR_onap_mini_EXTRA_SPECS7_RESPONSE = { class TestRegistration(test_base.TestRequest): - def setUp(self): super(TestRegistration, self).setUp() self.req_to_aai_backup = restcall.req_to_aai @@ -250,19 +248,18 @@ class TestRegistration(test_base.TestRequest): self.assertEquals(status.HTTP_202_ACCEPTED, response.status_code) -# @mock.patch.object(VimDriverUtils, 'delete_vim_info') -# def test_unregister_endpoint_successfully( -# self, mock_delete_vim_info): -# mock_delete_vim_info.return_value = 0 + # @mock.patch.object(VimDriverUtils, 'delete_vim_info') + # def test_unregister_endpoint_successfully( + # self, mock_delete_vim_info): + # mock_delete_vim_info.return_value = 0 -# response = self.client.delete(( -# "/api/multicloud-titanium_cloud/v0/windriver-hudson-dc_RegionOne/" -# "registry"), "{}", content_type="application/json", -# HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - -# self.assertEquals(status.HTTP_202_ACCEPTED, -# response.status_code) + # response = self.client.delete(( + # "/api/multicloud-titanium_cloud/v0/windriver-hudson-dc_RegionOne/" + # "registry"), "{}", 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( @@ -305,7 +302,7 @@ class TestRegistration(test_base.TestRequest): HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_202_ACCEPTED, - response.status_code) + response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') @@ -335,8 +332,7 @@ class TestRegistration(test_base.TestRequest): HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_202_ACCEPTED, - response.status_code) - + response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') @@ -366,7 +362,7 @@ class TestRegistration(test_base.TestRequest): HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_202_ACCEPTED, - response.status_code) + response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') @@ -396,7 +392,7 @@ class TestRegistration(test_base.TestRequest): HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_202_ACCEPTED, - response.status_code) + response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') @@ -426,7 +422,7 @@ class TestRegistration(test_base.TestRequest): HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_202_ACCEPTED, - response.status_code) + response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') @@ -456,7 +452,7 @@ class TestRegistration(test_base.TestRequest): HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_202_ACCEPTED, - response.status_code) + response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @mock.patch.object(VimDriverUtils, 'get_vim_info') @@ -486,5 +482,4 @@ class TestRegistration(test_base.TestRequest): HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) self.assertEquals(status.HTTP_202_ACCEPTED, - response.status_code) - + response.status_code) diff --git a/windriver/titanium_cloud/registration/tests/test_registration2.py b/windriver/titanium_cloud/registration/tests/test_registration2.py index a9c034a8..9f0cd4d2 100644 --- a/windriver/titanium_cloud/registration/tests/test_registration2.py +++ b/windriver/titanium_cloud/registration/tests/test_registration2.py @@ -15,19 +15,19 @@ import mock import unittest -import json +# import json from django.test import Client from rest_framework import status -from django.core.cache import cache -from common.msapi import extsys +# from django.core.cache import cache +# from common.msapi import extsys from common.utils import restcall -from newton_base.tests import mock_info -from newton_base.tests import test_base -from newton_base.util import VimDriverUtils +# from newton_base.tests import mock_info +# from newton_base.tests import test_base +# from newton_base.util import VimDriverUtils -from newton_base.registration import registration as newton_registration +# from newton_base.registration import registration as newton_registration from titanium_cloud.registration.views import registration from newton_base.tests import test_base @@ -55,8 +55,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, @@ -72,14 +72,15 @@ MOCK_GET_FLAVOR_RESPONSE_w_hpa_numa = { "id": "1", "name": "onap.big", "vcpus": 6, "ram": "8192", "disk": "10", "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}] + } ] } MOCK_GET_FLAVOR_EXTRASPECS_RESPONSE_w_hpa_numa = { "hw:numa_nodes": 2 } + class TestRegistration2(unittest.TestCase): def setUp(self): self.client = Client() @@ -88,13 +89,12 @@ class TestRegistration2(unittest.TestCase): def tearDown(self): pass - def test_discover_flavors(self): restcall.req_to_aai = mock.Mock() restcall.req_to_aai.return_value = (0, {}, status.HTTP_200_OK) - mock_session = test_base.get_mock_session( - ["get"], {"get": { - "content": MOCK_GET_FLAVOR_RESPONSE}}), + mock_session = test_base.get_mock_session( + ["get"], {"get": { + "content": MOCK_GET_FLAVOR_RESPONSE}}), resp = self.view._discover_flavors(vimid="windriver-hudson-dc_RegionOne", session=mock_session, viminfo=MOCK_VIM_INFO) @@ -105,8 +105,8 @@ class TestRegistration2(unittest.TestCase): restcall.req_to_aai = mock.Mock() restcall.req_to_aai.return_value = (0, {}, status.HTTP_200_OK) mock_session = test_base.get_mock_session( - ["get"], {"side_effect": [{ - "content": MOCK_GET_FLAVOR_RESPONSE_w_hpa_numa}, + ["get"], {"side_effect": [{ + "content": MOCK_GET_FLAVOR_RESPONSE_w_hpa_numa}, { "content": MOCK_GET_FLAVOR_EXTRASPECS_RESPONSE_w_hpa_numa} ]}), diff --git a/windriver/titanium_cloud/registration/views/__init__.py b/windriver/titanium_cloud/registration/views/__init__.py index afa702d3..ae1ce9db 100644 --- a/windriver/titanium_cloud/registration/views/__init__.py +++ b/windriver/titanium_cloud/registration/views/__init__.py @@ -11,4 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - diff --git a/windriver/titanium_cloud/registration/views/registration.py b/windriver/titanium_cloud/registration/views/registration.py index e2741638..5c29ccb0 100644 --- a/windriver/titanium_cloud/registration/views/registration.py +++ b/windriver/titanium_cloud/registration/views/registration.py @@ -20,7 +20,7 @@ import traceback from django.conf import settings from newton_base.registration import registration as newton_registration -from common.exceptions import VimDriverNewtonException +# from common.exceptions import VimDriverNewtonException from rest_framework import status from rest_framework.response import Response from common.msapi import extsys @@ -30,17 +30,17 @@ from common.utils import restcall logger = logging.getLogger(__name__) + # DEBUG=True -class Registry(newton_registration.Registry): +class Registry(newton_registration.Registry): def __init__(self): super(Registry, self).__init__() self.proxy_prefix = settings.MULTICLOUD_PREFIX self.aai_base_url = settings.AAI_BASE_URL # self._logger = logger - def _get_ovsdpdk_capabilities(self, extra_specs, viminfo): instruction_capability = {} feature_uuid = uuid.uuid4() @@ -51,15 +51,15 @@ class Registry(newton_registration.Registry): instruction_capability['hpa-version'] = 'v1' instruction_capability['hpa-feature-attributes'] = [] - instruction_capability['hpa-feature-attributes'].append({'hpa-attribute-key': 'dataProcessingAccelerationLibrary', - 'hpa-attribute-value': - '{{\"value\":\"{0}\"}}'.format("v17.02") - }) + instruction_capability['hpa-feature-attributes'].append( + {'hpa-attribute-key': 'dataProcessingAccelerationLibrary', + 'hpa-attribute-value': + '{{\"value\":\"{0}\"}}'.format("v17.02") + }) return instruction_capability class APIv1Registry(newton_registration.Registry): - def __init__(self): super(APIv1Registry, self).__init__() self.proxy_prefix = settings.MULTICLOUD_API_V1_PREFIX @@ -76,10 +76,11 @@ class APIv1Registry(newton_registration.Registry): instruction_capability['hpa-version'] = 'v1' instruction_capability['hpa-feature-attributes'] = [] - instruction_capability['hpa-feature-attributes'].append({'hpa-attribute-key': 'dataProcessingAccelerationLibrary', - 'hpa-attribute-value': - '{{\"value\":\"{0}\"}}'.format("v17.02") - }) + instruction_capability['hpa-feature-attributes'].append( + {'hpa-attribute-key': 'dataProcessingAccelerationLibrary', + 'hpa-attribute-value': + '{{\"value\":\"{0}\"}}'.format("v17.02") + }) return instruction_capability def _update_cloud_region(self, cloud_owner, cloud_region_id, openstack_region_id, viminfo, session=None): @@ -92,29 +93,30 @@ class APIv1Registry(newton_registration.Registry): "cloud_region_id": cloud_region_id }) - #Note1: The intent is to populate the openstack region id into property: cloud-region.esr-system-info.openstackRegionId - #Note2: As temp solution: the openstack region id was put into AAI cloud-region["cloud-epa-caps"] + # Note1: The intent is to populate the openstack region id into property: cloud-region.esr-system-info.openstackRegionId + # Note2: As temp solution: the openstack region id was put into AAI cloud-region["cloud-epa-caps"] resource_info = { "cloud-owner": cloud_owner, "cloud-region-id": cloud_region_id, "cloud-type": viminfo["type"], "cloud-region-version": viminfo["version"], - "identity-url": self.proxy_prefix + "/%s_%s/identity/v2.0" % (cloud_owner, cloud_region_id) \ - if self.proxy_prefix[-3:] == "/v0" else \ + "identity-url": + self.proxy_prefix + "/%s_%s/identity/v2.0" % (cloud_owner, cloud_region_id) + if self.proxy_prefix[-3:] == "/v0" else self.proxy_prefix + "/%s/%s/identity/v2.0" % (cloud_owner, cloud_region_id), "complex-name": viminfo["complex-name"], "cloud-extra-info": viminfo["cloud_extra_info"], - "cloud-epa-caps":openstack_region_id, - "esr-system-info-list":{ - "esr-system-info":[ + "cloud-epa-caps": openstack_region_id, + "esr-system-info-list": { + "esr-system-info": [ { "esr-system-info-id": str(uuid.uuid4()), "service-url": viminfo["url"], "user-name": viminfo["userName"], "password": viminfo["password"], - "system-type":"VIM", - "ssl-cacert":viminfo["cacert"], + "system-type": "VIM", + "ssl-cacert": viminfo["cacert"], "ssl-insecure": viminfo["insecure"], "cloud-domain": viminfo["domain"], "default-tenant": viminfo["tenant"] @@ -124,13 +126,13 @@ class APIv1Registry(newton_registration.Registry): } } - #get the resource first + # get the resource first resource_url = ("/cloud-infrastructure/cloud-regions/" - "cloud-region/%(cloud_owner)s/%(cloud_region_id)s" - % { - "cloud_owner": cloud_owner, - "cloud_region_id": cloud_region_id - }) + "cloud-region/%(cloud_owner)s/%(cloud_region_id)s" + % { + "cloud_owner": cloud_owner, + "cloud_region_id": cloud_region_id + }) # get cloud-region retcode, content, status_code = \ @@ -139,11 +141,11 @@ class APIv1Registry(newton_registration.Registry): # add resource-version if retcode == 0 and content: content = json.JSONDecoder().decode(content) - #resource_info["resource-version"] = content["resource-version"] + # resource_info["resource-version"] = content["resource-version"] content.update(resource_info) resource_info = content - #then update the resource + # then update the resource retcode, content, status_code = \ restcall.req_to_aai(resource_url, "PUT", content=resource_info) @@ -176,22 +178,22 @@ class APIv1Registry(newton_registration.Registry): try: regions = [] vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id) - isDistributedCloud = False; + isDistributedCloud = False openstackregions = self._get_list_resources( - "/regions", "identity", session, viminfo, vimid, - "regions") + "/regions", "identity", session, viminfo, vimid, + "regions") for region in openstackregions: - if (region['id'] == 'SystemController'): - isDistributedCloud = True; + if region['id'] == 'SystemController': + isDistributedCloud = True break else: continue for region in openstackregions: - if (region['id'] == 'SystemController'): + if region['id'] == 'SystemController': continue - elif (region['id'] == 'RegionOne' and isDistributedCloud == True): + elif region['id'] == 'RegionOne' and isDistributedCloud: continue else: regions.append(region['id']) @@ -202,7 +204,7 @@ class APIv1Registry(newton_registration.Registry): except HttpError as e: self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) return - except Exception as e: + except Exception: self._logger.error(traceback.format_exc()) return @@ -219,7 +221,7 @@ class APIv1Registry(newton_registration.Registry): cloud_extra_info = json.loads(cloud_extra_info_str) if cloud_extra_info_str else None except Exception as ex: logger.error("Can not convert cloud extra info %s %s" % ( - str(ex), cloud_extra_info_str)) + str(ex), cloud_extra_info_str)) pass region_specified = cloud_extra_info.get("openstack-region-id", None) if cloud_extra_info else None @@ -232,40 +234,38 @@ class APIv1Registry(newton_registration.Registry): # discover the regions region_ids = self._discover_regions(cloud_owner, cloud_region_id, sess, viminfo) - if (len(region_ids) == 0): + if len(region_ids) == 0: self._logger.error("_discover_regions, return regions:%s" % (region_ids)) return Response( - data={'error': "no region found for cloud region: %s,%s" % (cloud_owner, cloud_region_id)}, + data={'error': "no region found for cloud region: %s,%s" % (cloud_owner, cloud_region_id)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - # compare the regions with region_specified and then cloud_region_id - if (region_specified in region_ids): + if region_specified in region_ids: pass - elif (cloud_region_id in region_ids): + elif cloud_region_id in region_ids: region_specified = cloud_region_id pass else: # assume the first region be the primary region since we have no other way to determine it. - region_specified = region_ids.pop(0); + region_specified = region_ids.pop(0) # update cloud region and discover/register resource - if (multi_region_discovery): + if multi_region_discovery: # no input for specified cloud region, so discover all cloud region? for regionid in region_ids: # do not update the specified region here if region_specified == regionid: continue - #create cloud region with composed AAI cloud_region_id except for the one onboarded externally (e.g. ESR) + # create cloud region with composed AAI cloud_region_id except for the one onboarded externally (e.g. ESR) gen_cloud_region_id = cloud_region_id + "_" + regionid - self._logger.info("create a cloud region: %s,%s,%s" % (cloud_owner,gen_cloud_region_id,regionid)) + self._logger.info("create a cloud region: %s,%s,%s" % (cloud_owner, gen_cloud_region_id, regionid)) self._update_cloud_region(cloud_owner, gen_cloud_region_id, regionid, viminfo) new_vimid = extsys.encode_vim_id(cloud_owner, gen_cloud_region_id) super(APIv1Registry, self).post(request, new_vimid) - # update the specified region self._update_cloud_region(cloud_owner, cloud_region_id, region_specified, viminfo) return super(APIv1Registry, self).post(request, vimid) @@ -279,8 +279,6 @@ class APIv1Registry(newton_registration.Registry): data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - - def delete(self, request, cloud_owner="", cloud_region_id=""): self._logger.debug("unregister cloud region: %s, %s" % (cloud_owner, cloud_region_id)) @@ -288,9 +286,8 @@ class APIv1Registry(newton_registration.Registry): return super(APIv1Registry, self).delete(request, vimid) -### APIv0 handler upgrading: leverage APIv1 handler +# APIv0 handler upgrading: leverage APIv1 handler class APIv0Registry(APIv1Registry): - def __init__(self): super(APIv0Registry, self).__init__() self.proxy_prefix = settings.MULTICLOUD_PREFIX |