summaryrefslogtreecommitdiffstats
path: root/newton
diff options
context:
space:
mode:
Diffstat (limited to 'newton')
-rw-r--r--newton/newton/proxy/tests/test_service_proxy.py3
-rw-r--r--newton/newton/proxy/views/services.py59
-rw-r--r--newton/newton/registration/views/registration.py8
3 files changed, 37 insertions, 33 deletions
diff --git a/newton/newton/proxy/tests/test_service_proxy.py b/newton/newton/proxy/tests/test_service_proxy.py
index e9f2691d..2dd558d5 100644
--- a/newton/newton/proxy/tests/test_service_proxy.py
+++ b/newton/newton/proxy/tests/test_service_proxy.py
@@ -698,6 +698,7 @@ MOCK_PATCH_IMAGE_RESPONSE = {
class mock_get_servers_response_specs(object):
status_code = 200
+ content = ''
def json(self):
pass
@@ -735,6 +736,7 @@ class TestServiceProxy(unittest.TestCase):
mock_session = mock.Mock(name='mock_session', spec=mock_session_specs)
mock_get_servers_response_obj = mock.Mock(spec=mock_get_servers_response_specs)
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.get.return_value = mock_get_servers_response_obj
@@ -782,6 +784,7 @@ class TestServiceProxy(unittest.TestCase):
mock_session = mock.Mock(name='mock_session', spec=mock_session_specs)
mock_post_server_response_obj = mock.Mock(spec=mock_get_servers_response_specs)
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_session.post.return_value = mock_post_server_response_obj
diff --git a/newton/newton/proxy/views/services.py b/newton/newton/proxy/views/services.py
index 1a478f35..85de3aa6 100644
--- a/newton/newton/proxy/views/services.py
+++ b/newton/newton/proxy/views/services.py
@@ -72,7 +72,8 @@ class Services(APIView):
resp = sess.head(req_resource, endpoint_filter=service)
#update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
+ content = resp.json() if resp.content else None
+
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
#return resp
except VimDriverNewtonException as e:
@@ -142,13 +143,13 @@ class Services(APIView):
resp = sess.get(req_resource, endpoint_filter=service)
#update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
-
- #filter the resp content and replace all endpoint prefix
- tmp_content = json.dumps(content)
- tmp_pattern = re.compile(real_prefix)
- tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
- content = json.loads(tmp_content)
+ content = resp.json() if resp.content else None
+ if content:
+ #filter the resp content and replace all endpoint prefix
+ tmp_content = json.dumps(content)
+ tmp_pattern = re.compile(real_prefix)
+ tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
+ content = json.loads(tmp_content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
#return resp
@@ -220,13 +221,13 @@ class Services(APIView):
resp = sess.post(req_resource, data=json.JSONEncoder().encode(request.data),endpoint_filter=service)
# update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
-
- #filter the resp content and replace all endpoint prefix
- tmp_content = json.dumps(content)
- tmp_pattern = re.compile(real_prefix)
- tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
- content = json.loads(tmp_content)
+ content = resp.json() if resp.content else None
+ if content:
+ #filter the resp content and replace all endpoint prefix
+ tmp_content = json.dumps(content)
+ tmp_pattern = re.compile(real_prefix)
+ tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
+ content = json.loads(tmp_content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
@@ -298,13 +299,13 @@ class Services(APIView):
resp = sess.put(req_resource, data=json.JSONEncoder().encode(request.data),endpoint_filter=service)
# update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
-
- #filter the resp content and replace all endpoint prefix
- tmp_content = json.dumps(content)
- tmp_pattern = re.compile(real_prefix)
- tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
- content = json.loads(tmp_content)
+ content = resp.json() if resp.content else None
+ if content:
+ #filter the resp content and replace all endpoint prefix
+ tmp_content = json.dumps(content)
+ tmp_pattern = re.compile(real_prefix)
+ tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
+ content = json.loads(tmp_content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
@@ -377,13 +378,13 @@ class Services(APIView):
resp = sess.patch(req_resource, data=json.JSONEncoder().encode(request.data),endpoint_filter=service)
# update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
-
- #filter the resp content and replace all endpoint prefix
- tmp_content = json.dumps(content)
- tmp_pattern = re.compile(real_prefix)
- tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
- content = json.loads(tmp_content)
+ content = resp.json() if resp.content else None
+ if content:
+ #filter the resp content and replace all endpoint prefix
+ tmp_content = json.dumps(content)
+ tmp_pattern = re.compile(real_prefix)
+ tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
+ content = json.loads(tmp_content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
diff --git a/newton/newton/registration/views/registration.py b/newton/newton/registration/views/registration.py
index fa388b73..131a58e0 100644
--- a/newton/newton/registration/views/registration.py
+++ b/newton/newton/registration/views/registration.py
@@ -387,7 +387,7 @@ class Registry(APIView):
ret = self.update_az(cloud_owner, cloud_region_id, vg_info)
if ret != 0:
# failed to update image
- self._logger.debug("failed to populate az info into AAI: %s, volume-group-id: %s, ret:%s"
+ self._logger.debug("failed to populate volumegroup info into AAI: %s, volume-group-id: %s, ret:%s"
% (vimid, vg_info['volume-group-id'], ret))
continue
pass
@@ -454,7 +454,7 @@ class Registry(APIView):
ret = self.update_az(cloud_owner, cloud_region_id, snapshot_info)
if ret != 0:
# failed to update image
- self._logger.debug("failed to populate az info into AAI: %s, snapshot-id: %s, ret:%s"
+ self._logger.debug("failed to populate snapshot info into AAI: %s, snapshot-id: %s, ret:%s"
% (vimid, snapshot_info['snapshot-id'], ret))
continue
pass
@@ -554,7 +554,7 @@ class Registry(APIView):
req_to_aai("/cloud-infrastructure/pservers/pserver/%s/relationship-list/relationship"
% (pserverinfo['hostname']), "PUT", content=relationship_data)
- self._logger.debug("update_snapshot,vimid:%s_%s req_to_aai: %s, return %s, %s, %s"
+ self._logger.debug("update_pserver,vimid:%s_%s req_to_aai: %s, return %s, %s, %s"
% (cloud_owner, cloud_region_id, pserverinfo['hostname'], retcode, content,
status_code))
pass
@@ -578,7 +578,7 @@ class Registry(APIView):
for hypervisor in content.get('hypervisors'):
hypervisor_info = {
'hostname': hypervisor['hypervisor_hostname'],
- 'in-maint': hypervisor['name'],
+ 'in-maint': hypervisor['state'],
'pserver-id': hypervisor.get('id'),
'ptnii-equip-name': hypervisor.get('id'),