summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rw-r--r--share/common/msapi/helper.py6
-rw-r--r--share/common/utils/aai_cache.py4
-rw-r--r--share/common/utils/fileutil.py2
-rw-r--r--share/newton_base/registration/registration.py18
-rw-r--r--share/newton_base/resource/infra_workload_helper.py22
-rw-r--r--share/newton_base/tests/test_base.py16
-rw-r--r--share/starlingx_base/registration/registration.py8
-rw-r--r--share/starlingx_base/resource/infra_workload.py14
8 files changed, 51 insertions, 39 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