diff options
31 files changed, 173 insertions, 134 deletions
diff --git a/share/common/msapi/helper.py b/share/common/msapi/helper.py index d45a7293..fa754aa6 100644 --- a/share/common/msapi/helper.py +++ b/share/common/msapi/helper.py @@ -349,7 +349,7 @@ class MultiCloudThreadHelper(object): try: item["status"] = worker(*payload) or 0 except Exception as e: - item["status"] = e.message + item["status"] = str(e) cache_item_for_query = { "id": item["id"], "status": item["status"] @@ -364,14 +364,14 @@ class MultiCloudThreadHelper(object): cache.set(self.owner.cache_expired_prefix + cache_item_for_query["id"], cache_item_for_query, 3600*24) cache.delete(self.owner.cache_prefix + cache_item_for_query["id"]) except Exception as e: - logger.error(e.message) + logger.error(str(e)) else: item["timestamp"] = now #update cache try: cache.set(self.owner.cache_prefix + cache_item_for_query["id"], cache_item_for_query, 3600*24) except Exception as e: - logger.error(e.message) + logger.error(str(e)) pass # end of loop # while True: diff --git a/share/common/utils/aai_cache.py b/share/common/utils/aai_cache.py index 41506aca..62545df6 100644 --- a/share/common/utils/aai_cache.py +++ b/share/common/utils/aai_cache.py @@ -33,7 +33,7 @@ def get_cache_by_url(resource_url): else: return None except Exception as e: - logger.error("get_cache_by_url exception: %s" % e.message) + logger.error("get_cache_by_url exception: %s" % str(e)) return None @@ -45,7 +45,7 @@ def set_cache_by_url(resource_url, resource_in_json): # logger.debug("Cache the resource: "+ resource_url) cache.set("AAI_" + resource_url, json.dumps(resource_in_json), 3600 * 24) except Exception as e: - logger.error("get_cache_by_url exception: %s" % e.message) + logger.error("get_cache_by_url exception: %s" % str(e)) pass def filter_cache_by_url(resource_url): diff --git a/share/common/utils/fileutil.py b/share/common/utils/fileutil.py index 5a1624b0..accd3bc3 100644 --- a/share/common/utils/fileutil.py +++ b/share/common/utils/fileutil.py @@ -28,7 +28,7 @@ def delete_dirs(path): shutil.rmtree(path) except Exception as e: logger.error(traceback.format_exc()) - logger.error("Failed to delete %s:%s", path, e.message) + logger.error("Failed to delete %s:%s", path, str(e)) def download_file_from_http(url, local_dir, file_name): diff --git a/share/newton_base/registration/registration.py b/share/newton_base/registration/registration.py index 5656c6b6..dc595387 100644 --- a/share/newton_base/registration/registration.py +++ b/share/newton_base/registration/registration.py @@ -495,7 +495,7 @@ class RegistryHelper(MultiCloudAAIHelper): self._logger.error(traceback.format_exc()) return ( 11, - ex.message + str(ex) ) else: self._logger.error( @@ -508,7 +508,7 @@ class RegistryHelper(MultiCloudAAIHelper): self._logger.error(traceback.format_exc()) return ( 11, - e.message + str(e) ) def _discover_flavors(self, vimid="", session=None, viminfo=None): @@ -568,7 +568,7 @@ class RegistryHelper(MultiCloudAAIHelper): except Exception as e: self._logger.error(traceback.format_exc()) return ( - 11, e.message + 11, str(e) ) def _get_hpa_capabilities(self, flavor, extra_specs, viminfo): @@ -661,7 +661,7 @@ class RegistryHelper(MultiCloudAAIHelper): except Exception as e: self._logger.error(traceback.format_exc()) return ( - 11, e.message + 11, str(e) ) return basic_capability @@ -1071,7 +1071,7 @@ class RegistryHelper(MultiCloudAAIHelper): except Exception as e: self._logger.error(traceback.format_exc()) return ( - 11, e.message + 11, str(e) ) def _discover_availability_zones(self, vimid="", session=None, @@ -1160,7 +1160,7 @@ class RegistryHelper(MultiCloudAAIHelper): except Exception as e: self._logger.error(traceback.format_exc()) return ( - 11, e.message + 11, str(e) ) # def _discover_volumegroups(self, vimid="", session=None, viminfo=None): @@ -1229,7 +1229,7 @@ class RegistryHelper(MultiCloudAAIHelper): except Exception as e: self._logger.error(traceback.format_exc()) return ( - 11, e.message + 11, str(e) ) # def _discover_servergroups(self, vimid="", session=None, viminfo=None): @@ -1456,7 +1456,7 @@ class RegistryHelper(MultiCloudAAIHelper): except Exception as e: self._logger.error(traceback.format_exc()) return ( - 11, e.message + 11, str(e) ) def _update_proxy_identity_endpoint(self, vimid): @@ -1531,6 +1531,6 @@ class RegistryHelper(MultiCloudAAIHelper): except Exception as e: self._logger.error(traceback.format_exc()) return ( - 11, e.message + 11, str(e) ) diff --git a/share/newton_base/resource/infra_workload_helper.py b/share/newton_base/resource/infra_workload_helper.py index f274148b..e6e78130 100644 --- a/share/newton_base/resource/infra_workload_helper.py +++ b/share/newton_base/resource/infra_workload_helper.py @@ -228,8 +228,8 @@ class InfraWorkloadHelper(object): self._logger.debug("AAI update %s response: %s" % (aai_resource['uri'], content)) except Exception as e: - self._logger.error(e.message) - return status.HTTP_500_INTERNAL_SERVER_ERROR, "UPDATE_FAILED", e.message + self._logger.error(str(e)) + return status.HTTP_500_INTERNAL_SERVER_ERROR, "UPDATE_FAILED", str(e) # aai_resource_transactions = {"put": [aai_resource]} # transactions.append(aai_resource_transactions) @@ -284,8 +284,8 @@ class InfraWorkloadHelper(object): self._logger.debug("AAI update %s response: %s" % (aai_resource['uri'], content)) except Exception as e: - self._logger.error(e.message) - return status.HTTP_500_INTERNAL_SERVER_ERROR, "UPDATE_FAILED", e.message + self._logger.error(str(e)) + return status.HTTP_500_INTERNAL_SERVER_ERROR, "UPDATE_FAILED", str(e) # aai_resource_transactions = {"put": [aai_resource]} # transactions.append(aai_resource_transactions) @@ -373,7 +373,7 @@ class InfraWorkloadHelper(object): restcall.req_to_aai(vport_delete_url, "DELETE") except Exception as e: - # return 12, "DELETE_FAILED", e.message + # return 12, "DELETE_FAILED", str(e) pass try: @@ -389,8 +389,8 @@ class InfraWorkloadHelper(object): return 0, "DELETE_COMPLETE", "succeed" except Exception as e: - self._logger.error(e.message) - return status.HTTP_500_INTERNAL_SERVER_ERROR, "DELETE_FAILED", e.message + self._logger.error(str(e)) + return status.HTTP_500_INTERNAL_SERVER_ERROR, "DELETE_FAILED", str(e) pass def workload_status(self, vimid, stack_id=None, stack_name=None, otherinfo=None, project_idorname=None): @@ -444,8 +444,8 @@ class InfraWorkloadHelper(object): return retcode, workload_status, content except Exception as e: - self._logger.error(e.message) - return status.HTTP_500_INTERNAL_SERVER_ERROR, "GET_FAILED", e.message + self._logger.error(str(e)) + return status.HTTP_500_INTERNAL_SERVER_ERROR, "GET_FAILED", str(e) def workload_detail(self, vimid, stack_id, nexturi=None, otherinfo=None, project_idorname=None): @@ -497,5 +497,5 @@ class InfraWorkloadHelper(object): return 0, workload_status, content except Exception as e: - self._logger.error(e.message) - return status.HTTP_500_INTERNAL_SERVER_ERROR, "GET_FAILED", e.message + self._logger.error(str(e)) + return status.HTTP_500_INTERNAL_SERVER_ERROR, "GET_FAILED", str(e) diff --git a/share/newton_base/tests/test_base.py b/share/newton_base/tests/test_base.py index 15160d06..b9923d1c 100644 --- a/share/newton_base/tests/test_base.py +++ b/share/newton_base/tests/test_base.py @@ -12,11 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys import json -import mock +# import mock from rest_framework import status import unittest +if sys.version_info < (3, 0): + import mock +else: + from unittest import mock + from abc import ABCMeta from django.conf import settings from django.test import Client @@ -35,9 +41,15 @@ class MockResponse(object): pass +def get_mock_response(return_value=None): + mock_response = mock.Mock(spec=MockResponse) + mock_response.status_code = status.HTTP_200_OK + mock_response.json.return_value = return_value + return mock_response + def get_mock_session(http_actions, response_dict={}): mock_session = mock.Mock( - name='mock_session',spec=http_actions) + name='mock_session', spec=http_actions) for action in http_actions: side_effect = response_dict.get("side_effect") if side_effect and isinstance(side_effect, list): diff --git a/share/starlingx_base/registration/registration.py b/share/starlingx_base/registration/registration.py index b6ed9250..85d3faa0 100644 --- a/share/starlingx_base/registration/registration.py +++ b/share/starlingx_base/registration/registration.py @@ -229,26 +229,26 @@ class RegistryHelper(newton_registration.RegistryHelper): self._update_cloud_region( cloud_owner, gen_cloud_region_id, regionid, viminfo) except Exception as e: - self._logger.debug("update cloud region fails %s" % e.message) + self._logger.debug("update cloud region fails %s" % str(e)) try: new_vimid = extsys.encode_vim_id( cloud_owner, gen_cloud_region_id) super(RegistryHelper, self).registryV0(new_vimid, project_idorname) except Exception as e: - self._logger.debug("registryV0 fails %s" % e.message) + self._logger.debug("registryV0 fails %s" % str(e)) # update the specified region try: self._update_cloud_region(cloud_owner, cloud_region_id, region_specified, viminfo) except Exception as e: - self._logger.debug("update cloud region fails %s" % e.message) + self._logger.debug("update cloud region fails %s" % str(e)) try: super(RegistryHelper, self).registryV0(vimid, project_idorname) except Exception as e: - self._logger.debug("registryV0 fails %s" % e.message) + self._logger.debug("registryV0 fails %s" % str(e)) return 0 diff --git a/share/starlingx_base/resource/infra_workload.py b/share/starlingx_base/resource/infra_workload.py index 9524d673..5020af94 100644 --- a/share/starlingx_base/resource/infra_workload.py +++ b/share/starlingx_base/resource/infra_workload.py @@ -139,12 +139,12 @@ class InfraWorkload(newton_infra_workload.InfraWorkload): status_code = status.HTTP_202_ACCEPTED\ if progress_code == 0 else progress_code except Exception as e: - self._logger.warn("Exception: %s" % e.message) + self._logger.warn("Exception: %s" % str(e)) resp_template["workload_status_reason"] = progress return Response(data=resp_template, status=status_code) except Exception as e: - errmsg = e.message + errmsg = str(e) self._logger.error(errmsg) resp_template["workload_status_reason"] = errmsg return Response(data=resp_template, @@ -252,8 +252,8 @@ class InfraWorkload(newton_infra_workload.InfraWorkload): return Response(data=resp_template, status=status_code) except Exception as e: - self._logger.error(e.message) - resp_template["workload_status_reason"] = e.message + self._logger.error(str(e)) + resp_template["workload_status_reason"] = str(e) return Response(data=resp_template, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -339,8 +339,8 @@ class InfraWorkload(newton_infra_workload.InfraWorkload): resp_template["workload_status_reason"] = progress return Response(data=resp_template, status=status_code) except Exception as e: - self._logger.error(e.message) - resp_template["workload_status_reason"] = e.message + self._logger.error(str(e)) + resp_template["workload_status_reason"] = str(e) return Response(data=resp_template, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -486,7 +486,7 @@ class InfraWorkloadHelper(infra_workload_helper.InfraWorkloadHelper): self._logger.info("artifacts not available for vfmodule %s" % vf_module_model_customization_id) pass except Exception as e: - self._logger.error("template_update fails: %s" % e.message) + self._logger.error("template_update fails: %s" % str(e)) # try 2: reuse the input: template_data return template_data diff --git a/windriver/docker/Dockerfile b/windriver/docker/Dockerfile index ca300fdc..8310238c 100644 --- a/windriver/docker/Dockerfile +++ b/windriver/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM python:2-alpine +FROM python:3-alpine ARG HTTP_PROXY=${HTTP_PROXY} ARG HTTPS_PROXY=${HTTPS_PROXY} @@ -18,15 +18,15 @@ EXPOSE 9005 RUN addgroup -S onap && adduser -S -G onap onap # COPY ./ /opt/windriver/ - +COPY ./multicloud-openstack-windriver-*.zip /opt/multicloud-openstack-windriver.zip RUN apk update && \ apk add uwsgi memcached wget unzip gcc make libc-dev libffi-dev openssl-dev && \ cd /opt/ && \ - wget -O multicloud-openstack-windriver.zip "https://nexus.onap.org/service/local/artifact/maven/redirect?r=staging&g=org.onap.multicloud.openstack&a=multicloud-openstack-windriver&e=zip&v=1.4.0" && \ unzip -q -o -B multicloud-openstack-windriver.zip && \ chmod +x /opt/windriver/*.sh && \ rm -f multicloud-openstack-windriver.zip && \ - pip install -r /opt/windriver/requirements.txt && \ + pip3 install -r /opt/windriver/requirements.txt && \ + pip3 install -r /opt/windriver/uwsgi-requirements.txt && \ apk del wget unzip gcc make libc-dev libffi-dev openssl-dev && \ mkdir -p /var/log/onap/multicloud/openstack/windriver && \ chown onap:onap /var/log/onap -R && \ diff --git a/windriver/initialize.sh b/windriver/initialize.sh index 99a8cdd0..be8e56ec 100644 --- a/windriver/initialize.sh +++ b/windriver/initialize.sh @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -pip install -r requirements.txt +pip3 install -r requirements.txt diff --git a/windriver/mvn-phase-script.sh b/windriver/mvn-phase-script.sh index ad1d6329..6cc1b2bb 100755 --- a/windriver/mvn-phase-script.sh +++ b/windriver/mvn-phase-script.sh @@ -53,7 +53,7 @@ run_tox_test() DIR=$(echo "$TOXINI" | rev | cut -f2- -d'/' | rev) cd "${CURDIR}/${DIR}" rm -rf ./venv-tox ./.tox - virtualenv ./venv-tox + virtualenv ./venv-tox --python=python3 source ./venv-tox/bin/activate pip install --upgrade pip pip install --upgrade tox argparse diff --git a/windriver/pom.xml b/windriver/pom.xml index 7299038d..09c8ac7c 100644 --- a/windriver/pom.xml +++ b/windriver/pom.xml @@ -125,17 +125,28 @@ <executions> <execution> <id>copy-resources</id> - <phase>validate</phase> + <phase>install</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> + <overwrite>true</overwrite> + <nonFilteredFileExtensions> + <nonFilteredFileExtension>zip</nonFilteredFileExtension> + </nonFilteredFileExtensions> <outputDirectory>${project.basedir}/docker_target</outputDirectory> <resources> <resource> <directory>${project.basedir}/docker</directory> <filtering>true</filtering> </resource> + <resource> + <directory>${project.basedir}/target</directory> + <filtering>true</filtering> + <includes> + <include>*.zip</include> + </includes> + </resource> </resources> </configuration> </execution> diff --git a/windriver/requirements.txt b/windriver/requirements.txt index fefde87b..bad5c0d4 100644 --- a/windriver/requirements.txt +++ b/windriver/requirements.txt @@ -1,18 +1,18 @@ # rest framework -Django==1.9.6 -djangorestframework==3.3.3 +Django==2.2.3 +djangorestframework==3.9.4 # for call rest api -httplib2==0.9.2 +httplib2==0.13.0 # for call openstack auth and transport api keystoneauth1==2.18.0 -#python-memcached +# python-memcached python-memcached -#uwsgi for parallel processing -uwsgi +# uwsgi for parallel processing +# uwsgi # for unit test # coverage==4.2 @@ -20,7 +20,7 @@ uwsgi # unittest_xml_reporting==1.12.0 # for onap logging -onappylog>=1.0.8 +onappylog>=1.0.9 # for background tasks # celery >= 4.0 diff --git a/windriver/test-requirements.txt b/windriver/test-requirements.txt index cc3059e2..d91d31db 100644 --- a/windriver/test-requirements.txt +++ b/windriver/test-requirements.txt @@ -1,6 +1,6 @@ # for unit test coverage==4.2 -mock==2.0.0 +mock==3.0.5 unittest_xml_reporting==1.12.0 pylint # GPLv2 diff --git a/windriver/titanium_cloud/extensions/tests/test_extensions.py b/windriver/titanium_cloud/extensions/tests/test_extensions.py index 26687b33..978e2023 100644 --- a/windriver/titanium_cloud/extensions/tests/test_extensions.py +++ b/windriver/titanium_cloud/extensions/tests/test_extensions.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2018 Wind River Systems, Inc. +# Copyright (c) 2017-2019 Wind River Systems, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import unittest from django.test import Client from rest_framework import status -import unittest class TestExtensions(unittest.TestCase): @@ -30,12 +30,12 @@ class TestExtensions(unittest.TestCase): "/api/multicloud-titaniumcloud/v0/" + vimid + "/extensions/") json_content = response.json() - self.assertEquals(status.HTTP_200_OK, response.status_code) - self.assertEquals(4, len(json_content.keys())) + self.assertEqual(status.HTTP_200_OK, response.status_code) + self.assertEqual(4, len(list(json_content.keys()))) - self.assertEquals(cloud_owner, json_content["cloud-owner"]) - self.assertEquals(cloud_region_id, json_content["cloud-region-id"]) - self.assertEquals(vimid, json_content["vimid"]) + self.assertEqual(cloud_owner, json_content["cloud-owner"]) + self.assertEqual(cloud_region_id, json_content["cloud-region-id"]) + self.assertEqual(vimid, json_content["vimid"]) - self.assertEquals("Multiple network support", json_content["extensions"][0]["description"]) - self.assertEquals("", json_content["extensions"][0]["spec"]) + self.assertEqual("Multiple network support", json_content["extensions"][0]["description"]) + self.assertEqual("", json_content["extensions"][0]["spec"]) diff --git a/windriver/titanium_cloud/extensions/urls.py b/windriver/titanium_cloud/extensions/urls.py index 3bcf9a4c..842d8542 100644 --- a/windriver/titanium_cloud/extensions/urls.py +++ b/windriver/titanium_cloud/extensions/urls.py @@ -17,8 +17,8 @@ from rest_framework.urlpatterns import format_suffix_patterns from titanium_cloud.extensions.views import extensions -urlpatterns = [ +URLPATTERNS = [ url(r'^sions/?$', extensions.Extensions.as_view()), ] -urlpatterns = format_suffix_patterns(urlpatterns) +urlpatterns = format_suffix_patterns(URLPATTERNS) diff --git a/windriver/titanium_cloud/extensions/urlsV1.py b/windriver/titanium_cloud/extensions/urlsV1.py index f6398ef6..06a9e861 100644 --- a/windriver/titanium_cloud/extensions/urlsV1.py +++ b/windriver/titanium_cloud/extensions/urlsV1.py @@ -17,8 +17,8 @@ from rest_framework.urlpatterns import format_suffix_patterns from titanium_cloud.extensions.views import extensions -urlpatterns = [ +URLPATTERNS = [ url(r'^sions/?$', extensions.APIv1Extensions.as_view()), ] -urlpatterns = format_suffix_patterns(urlpatterns) +urlpatterns = format_suffix_patterns(URLPATTERNS) diff --git a/windriver/titanium_cloud/extensions/views/extensions.py b/windriver/titanium_cloud/extensions/views/extensions.py index 7dd78272..1bfe7417 100644 --- a/windriver/titanium_cloud/extensions/views/extensions.py +++ b/windriver/titanium_cloud/extensions/views/extensions.py @@ -25,7 +25,7 @@ from common.exceptions import VimDriverNewtonException from common.msapi import extsys from newton_base.extensions import extensions as newton_extensions -logger = logging.getLogger(__name__) +LOGGER = logging.getLogger(__name__) # DEBUG=True @@ -34,12 +34,12 @@ class Extensions(newton_extensions.Extensions): def __init__(self): super(Extensions, self).__init__() - # self._logger = logger + # self._logger = LOGGER self.proxy_prefix = settings.MULTICLOUD_PREFIX def get(self, request, vimid=""): - logger.debug("Extensions--get::data> %s" % request.data) - logger.debug("Extensions--get::vimid> %s" + LOGGER.debug("Extensions--get::data> %s" % request.data) + LOGGER.debug("Extensions--get::vimid> %s" % vimid) try: cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) @@ -65,10 +65,10 @@ class Extensions(newton_extensions.Extensions): except VimDriverNewtonException as e: return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: - logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) + LOGGER.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) return Response(data=e.response.json(), status=e.http_status) except Exception as e: - logger.error(traceback.format_exc()) + LOGGER.error(traceback.format_exc()) return Response(data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -77,11 +77,11 @@ class APIv1Extensions(Extensions): def __init__(self): super(APIv1Extensions, self).__init__() - # self._logger = logger + # self._logger = LOGGER self.proxy_prefix = settings.MULTICLOUD_API_V1_PREFIX def get(self, request, cloud_owner="", cloud_region_id=""): - self._logger.info( + LOGGER.info( "cloud_owner,cloud_region_id: %s,%s" % (cloud_owner, cloud_region_id)) diff --git a/windriver/titanium_cloud/proxy/tests/test_service_proxy.py b/windriver/titanium_cloud/proxy/tests/test_service_proxy.py index 15d46ae1..c206ba75 100644 --- a/windriver/titanium_cloud/proxy/tests/test_service_proxy.py +++ b/windriver/titanium_cloud/proxy/tests/test_service_proxy.py @@ -718,12 +718,12 @@ class TestServiceProxy(unittest.TestCase): response = self.client.head( "/api/multicloud-titaniumcloud/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) + self.assertEqual(status.HTTP_200_OK, response.status_code) def test_unauthorized_access(self): response = self.client.get( "/api/multicloud-titaniumcloud/v0/windriver-hudson-dc_RegionOne/compute/v2.1/fcca3cc49d5e42caae15459e27103efc/servers") - self.assertEquals(status.HTTP_403_FORBIDDEN, response.status_code) + self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) @mock.patch.object(VimDriverUtils, 'get_vim_info') def test_expired_auth_token(self, mock_get_vim_info): @@ -732,7 +732,7 @@ class TestServiceProxy(unittest.TestCase): response = self.client.get( "/api/multicloud-titaniumcloud/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) + self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) @mock.patch.object(VimDriverUtils, 'get_token_cache') @mock.patch.object(VimDriverUtils, 'get_vim_info') @@ -744,14 +744,14 @@ class TestServiceProxy(unittest.TestCase): url_part3 = "/v2.1/fcca3cc49d5e42caae15459e27103efc/servers" url = (url_part1 + servicetype + url_part3) response = self.client.get(url, {}, HTTP_X_AUTH_TOKEN=MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) + self.assertEqual(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) + self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) metadata_catalog = copy.deepcopy(MOCK_INTERNAL_METADATA_CATALOG) metadata_catalog[servicetype]['prefix'] = None @@ -759,7 +759,7 @@ class TestServiceProxy(unittest.TestCase): 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) + self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) @mock.patch.object(VimDriverUtils, 'get_vim_info') @mock.patch.object(VimDriverUtils, 'get_session') @@ -818,29 +818,29 @@ class TestServiceProxy(unittest.TestCase): "/api/multicloud-titaniumcloud/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) + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) context = response.json() - self.assertEquals(MOCK_TOKEN_ID, response['X-Subject-Token']) + self.assertEqual(MOCK_TOKEN_ID, response['X-Subject-Token']) self.assertIsNotNone(context['server']) # Retrieve resource response = self.client.get( "/api/multicloud-titaniumcloud/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) + self.assertEqual(status.HTTP_200_OK, response.status_code) context = response.json() - self.assertEquals(MOCK_TOKEN_ID, response['X-Subject-Token']) + self.assertEqual(MOCK_TOKEN_ID, response['X-Subject-Token']) self.assertIsNotNone(context['servers']) # Update resource response = self.client.get( "/api/multicloud-titaniumcloud/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) + self.assertEqual(status.HTTP_200_OK, response.status_code) context = response.json() - self.assertEquals(MOCK_TOKEN_ID, response['X-Subject-Token']) + self.assertEqual(MOCK_TOKEN_ID, response['X-Subject-Token']) self.assertIsNotNone(context['servers']) # simulate client to make the request @@ -848,5 +848,5 @@ class TestServiceProxy(unittest.TestCase): "/api/multicloud-titaniumcloud/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']) + self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) + self.assertEqual(MOCK_TOKEN_ID, response['X-Subject-Token']) diff --git a/windriver/titanium_cloud/proxy/urls.py b/windriver/titanium_cloud/proxy/urls.py index 22f714d1..7b33801d 100644 --- a/windriver/titanium_cloud/proxy/urls.py +++ b/windriver/titanium_cloud/proxy/urls.py @@ -19,7 +19,7 @@ from titanium_cloud.proxy.views import identityV3 from titanium_cloud.proxy.views import services from newton_base.proxy import dnsaasdelegate -urlpatterns = [ +URLPATTERNS = [ # url(r'^identity/v2)$', # identityV2.Tokens.as_view()), url(r'^identity/v3/auth/tokens/?$', @@ -38,4 +38,4 @@ urlpatterns = [ services.Services.as_view()), ] -urlpatterns = format_suffix_patterns(urlpatterns) +urlpatterns = format_suffix_patterns(URLPATTERNS) diff --git a/windriver/titanium_cloud/proxy/urlsV1.py b/windriver/titanium_cloud/proxy/urlsV1.py index 757ddf7e..88a8638a 100644 --- a/windriver/titanium_cloud/proxy/urlsV1.py +++ b/windriver/titanium_cloud/proxy/urlsV1.py @@ -19,7 +19,7 @@ from titanium_cloud.proxy.views import identityV3 from titanium_cloud.proxy.views import services from newton_base.proxy import dnsaasdelegate -urlpatterns = [ +URLPATTERNS = [ url(r'^identity/v3/auth/tokens/?$', identityV3.APIv1Tokens.as_view()), url(r'^identity/v3/?$', @@ -36,4 +36,4 @@ urlpatterns = [ services.APIv1Services.as_view()), ] -urlpatterns = format_suffix_patterns(urlpatterns) +urlpatterns = format_suffix_patterns(URLPATTERNS) diff --git a/windriver/titanium_cloud/registration/tests/test_registration.py b/windriver/titanium_cloud/registration/tests/test_registration.py index 49df5b23..48d638d7 100644 --- a/windriver/titanium_cloud/registration/tests/test_registration.py +++ b/windriver/titanium_cloud/registration/tests/test_registration.py @@ -245,7 +245,7 @@ class TestRegistration(test_base.TestRequest): "registry"), TEST_REGISTER_ENDPOINT_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_202_ACCEPTED, + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) # @mock.patch.object(VimDriverUtils, 'delete_vim_info') @@ -258,7 +258,7 @@ class TestRegistration(test_base.TestRequest): # "registry"), "{}", content_type="application/json", # HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - # self.assertEquals(status.HTTP_202_ACCEPTED, + # self.assertEqual(status.HTTP_202_ACCEPTED, # response.status_code) @mock.patch.object(VimDriverUtils, 'delete_vim_info') @@ -271,7 +271,7 @@ class TestRegistration(test_base.TestRequest): "registry"), "{}", content_type="application/json", HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_204_NO_CONTENT, + self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @@ -301,7 +301,7 @@ class TestRegistration(test_base.TestRequest): "registry"), TEST_REGISTER_ENDPOINT_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_202_ACCEPTED, + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @@ -331,7 +331,7 @@ class TestRegistration(test_base.TestRequest): "registry"), TEST_REGISTER_ENDPOINT_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_202_ACCEPTED, + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @@ -361,7 +361,7 @@ class TestRegistration(test_base.TestRequest): "registry"), TEST_REGISTER_ENDPOINT_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_202_ACCEPTED, + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @@ -391,7 +391,7 @@ class TestRegistration(test_base.TestRequest): "registry"), TEST_REGISTER_ENDPOINT_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_202_ACCEPTED, + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @@ -421,7 +421,7 @@ class TestRegistration(test_base.TestRequest): "registry"), TEST_REGISTER_ENDPOINT_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_202_ACCEPTED, + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @@ -451,7 +451,7 @@ class TestRegistration(test_base.TestRequest): "registry"), TEST_REGISTER_ENDPOINT_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_202_ACCEPTED, + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) @mock.patch.object(VimDriverUtils, 'get_session') @@ -481,5 +481,5 @@ class TestRegistration(test_base.TestRequest): "registry"), TEST_REGISTER_ENDPOINT_REQUEST, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_202_ACCEPTED, + self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code) diff --git a/windriver/titanium_cloud/registration/tests/test_registration2.py b/windriver/titanium_cloud/registration/tests/test_registration2.py index e00c6adc..1072b373 100644 --- a/windriver/titanium_cloud/registration/tests/test_registration2.py +++ b/windriver/titanium_cloud/registration/tests/test_registration2.py @@ -12,9 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock - +# import mock import unittest +from unittest import mock + # import json from django.test import Client from rest_framework import status @@ -72,6 +73,7 @@ MOCK_GET_FLAVOR_EXTRASPECS_RESPONSE_w_hpa_numa = { } + class TestRegistration2(unittest.TestCase): def setUp(self): self.client = Client() @@ -84,25 +86,30 @@ 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"], {"get": { - "content": MOCK_GET_FLAVOR_RESPONSE}}), - - retcode, content = self.view.register_helper._discover_flavors(vimid="windriver-hudson-dc_RegionOne", + ["get"], { + "side_effect": [ + test_base.get_mock_response(MOCK_GET_FLAVOR_RESPONSE) + ] + }) + retcode, content = self.view.register_helper._discover_flavors( + vimid="windriver-hudson-dc_RegionOne", session=mock_session, viminfo=MOCK_VIM_INFO) - self.assertEquals(retcode, 11) + self.assertEqual(retcode, 0) def test_discover_flavors_w_hpa_numa(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"], {"side_effect": [{ - "content": MOCK_GET_FLAVOR_RESPONSE_w_hpa_numa}, - { - "content": MOCK_GET_FLAVOR_EXTRASPECS_RESPONSE_w_hpa_numa} - ]}), + ["get"], { + "side_effect": [ + test_base.get_mock_response(MOCK_GET_FLAVOR_RESPONSE_w_hpa_numa), + test_base.get_mock_response(MOCK_GET_FLAVOR_EXTRASPECS_RESPONSE_w_hpa_numa), + ] + }) - retcode, content = self.view.register_helper._discover_flavors(vimid="windriver-hudson-dc_RegionOne", + retcode, content = self.view.register_helper._discover_flavors( + vimid="windriver-hudson-dc_RegionOne", session=mock_session, viminfo=MOCK_VIM_INFO) - self.assertEquals(retcode, 11) + self.assertEqual(retcode, 0) diff --git a/windriver/titanium_cloud/requests/urls.py b/windriver/titanium_cloud/requests/urls.py index bfba9c73..73a91f20 100644 --- a/windriver/titanium_cloud/requests/urls.py +++ b/windriver/titanium_cloud/requests/urls.py @@ -25,7 +25,7 @@ from newton_base.openoapi import limits from newton_base.openoapi import hosts from newton_base.openoapi import flavor -urlpatterns = [ +URLPATTERNS = [ url(r'^networks(/(?P<networkid>[0-9a-zA-Z_-]+))?', network.Networks.as_view()), url(r'^subnets(/(?P<subnetid>[0-9a-zA-Z_-]+))?', @@ -50,4 +50,4 @@ urlpatterns = [ url(r'^hosts(/(?P<hostname>[0-9a-zA-Z_-]+))?', hosts.Hosts.as_view()), ] -urlpatterns = format_suffix_patterns(urlpatterns) +urlpatterns = format_suffix_patterns(URLPATTERNS) diff --git a/windriver/titanium_cloud/requests/urlsV1.py b/windriver/titanium_cloud/requests/urlsV1.py index eaca68c6..2bd18287 100644 --- a/windriver/titanium_cloud/requests/urlsV1.py +++ b/windriver/titanium_cloud/requests/urlsV1.py @@ -25,7 +25,7 @@ from newton_base.openoapi import limits from newton_base.openoapi import hosts from newton_base.openoapi import flavor -urlpatterns = [ +URLPATTERNS = [ url(r'^networks(/(?P<networkid>[0-9a-zA-Z_-]+))?', network.APIv1Networks.as_view()), url(r'^subnets(/(?P<subnetid>[0-9a-zA-Z_-]+))?', @@ -50,4 +50,4 @@ urlpatterns = [ url(r'^hosts(/(?P<hostname>[0-9a-zA-Z_-]+))?', hosts.APIv1Hosts.as_view()), ] -urlpatterns = format_suffix_patterns(urlpatterns) +urlpatterns = format_suffix_patterns(URLPATTERNS) diff --git a/windriver/titanium_cloud/resource/tests/test_capacity.py b/windriver/titanium_cloud/resource/tests/test_capacity.py index 82c453a2..72fff786 100644 --- a/windriver/titanium_cloud/resource/tests/test_capacity.py +++ b/windriver/titanium_cloud/resource/tests/test_capacity.py @@ -143,7 +143,7 @@ class TestCapacity(test_base.TestRequest): TEST_REQ_SUCCESS_SOURCE, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual({'AZs': [],"result": True}, response.data) @mock.patch.object(VimDriverUtils, 'get_session') @@ -164,7 +164,7 @@ class TestCapacity(test_base.TestRequest): TEST_REQ_FAILED_SOURCE, HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual({'AZs': [],"result": False}, response.data) @mock.patch.object(VimDriverUtils, 'get_session') @@ -186,7 +186,7 @@ class TestCapacity(test_base.TestRequest): content_type='application/json', HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual({'AZs': [],"result": False}, response.data) @mock.patch.object(VimDriverUtils, 'get_session') @@ -208,7 +208,7 @@ class TestCapacity(test_base.TestRequest): content_type='application/json', HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual({'AZs': [],"result": False}, response.data) @mock.patch.object(VimDriverUtils, 'get_session') @@ -230,7 +230,7 @@ class TestCapacity(test_base.TestRequest): content_type='application/json', HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual({'AZs': [],"result": False}, response.data) @mock.patch.object(VimDriverUtils, 'get_session') @@ -252,7 +252,7 @@ class TestCapacity(test_base.TestRequest): content_type='application/json', HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual({'AZs': [], "result": False}, response.data) @mock.patch.object(VimDriverUtils, 'get_session') @@ -274,5 +274,5 @@ class TestCapacity(test_base.TestRequest): content_type='application/json', HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID) - self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual({'AZs': [], "result": False}, response.data) diff --git a/windriver/titanium_cloud/samples/urls.py b/windriver/titanium_cloud/samples/urls.py index e5f0e65c..71a53593 100644 --- a/windriver/titanium_cloud/samples/urls.py +++ b/windriver/titanium_cloud/samples/urls.py @@ -13,7 +13,10 @@ # limitations under the License. from django.conf.urls import url +from rest_framework.urlpatterns import format_suffix_patterns from titanium_cloud.samples import views -urlpatterns = [ +URLPATTERNS = [ url(r'^samples/?$', views.SampleList.as_view()), ] + +urlpatterns = format_suffix_patterns(URLPATTERNS)
\ No newline at end of file diff --git a/windriver/titanium_cloud/swagger/urls.py b/windriver/titanium_cloud/swagger/urls.py index a690d9cf..cdd9e8ed 100644 --- a/windriver/titanium_cloud/swagger/urls.py +++ b/windriver/titanium_cloud/swagger/urls.py @@ -20,7 +20,7 @@ from titanium_cloud.swagger.views import APIv1SwaggerJsonViewDepreciated from titanium_cloud.swagger.views import SwaggerJsonView from titanium_cloud.swagger.views import APIv1SwaggerJsonView -urlpatterns = [ +URLPATTERNS = [ # API v0, depreciated url(r'^api/multicloud-titanium_cloud/v0/swagger.json$', SwaggerJsonViewDepreciated.as_view()), @@ -35,4 +35,4 @@ urlpatterns = [ ] -urlpatterns = format_suffix_patterns(urlpatterns) +urlpatterns = format_suffix_patterns(URLPATTERNS) diff --git a/windriver/titanium_cloud/wsgi.py b/windriver/titanium_cloud/wsgi.py index 14676067..975baed0 100644 --- a/windriver/titanium_cloud/wsgi.py +++ b/windriver/titanium_cloud/wsgi.py @@ -19,4 +19,4 @@ from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "titanium_cloud.settings") -application = get_wsgi_application() +APPLICATION = get_wsgi_application() diff --git a/windriver/tox.ini b/windriver/tox.ini index 680db516..defe6218 100644 --- a/windriver/tox.ini +++ b/windriver/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,cov,pylint +envlist = py36,cov,pylint skipsdist = true [tox:jenkins] @@ -11,6 +11,10 @@ exclude = ./venv-tox,./.tox max-complexity = 27 [testenv] +basepython = + py36: python3 + cov: python3 + pylint: python3 setenv = PYTHONPATH = {toxinidir}/../share deps = @@ -22,7 +26,7 @@ commands = [testenv:pep8] deps=flake8 -commands=flake8 +commands=python3 -m flake8 [testenv:cov] commands = coverage xml --omit="./venv-tox/*,./.tox/*,*tests*,*__init__.py,*newton_base*,*common*,*starlingx_base* *site-packages*" diff --git a/windriver/uwsgi-requirements.txt b/windriver/uwsgi-requirements.txt new file mode 100644 index 00000000..5b24077b --- /dev/null +++ b/windriver/uwsgi-requirements.txt @@ -0,0 +1,2 @@ +# uwsgi for parallel processing +uwsgi
\ No newline at end of file |