summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaad Zaher <eng.szaher@gmail.com>2018-02-14 11:14:21 +0000
committerSaad Zaher <eng.szaher@gmail.com>2018-02-16 17:14:28 +0000
commitba9187eff25da03e9b21d2932b8f5f20521bfc84 (patch)
tree488f2c5381e855151ab4400502d6b322b802025f
parentd17bee69e787502cf6ff9528e52a54714342b7f1 (diff)
Use API V2 instead of V1
Notes
Notes (review): Code-Review+2: Saad Zaher <eng.szaher@gmail.com> Workflow+1: Saad Zaher <eng.szaher@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 16 Feb 2018 22:18:27 +0000 Reviewed-on: https://review.openstack.org/544245 Project: openstack/freezer-tempest-plugin Branch: refs/heads/master
-rw-r--r--freezer_tempest_plugin/services/freezer_api_client.py52
-rw-r--r--freezer_tempest_plugin/tests/freezer_api/api/test_api_backups.py3
-rw-r--r--freezer_tempest_plugin/tests/freezer_api/api/test_api_sessions.py1
3 files changed, 33 insertions, 23 deletions
diff --git a/freezer_tempest_plugin/services/freezer_api_client.py b/freezer_tempest_plugin/services/freezer_api_client.py
index eb535c4..f07e51e 100644
--- a/freezer_tempest_plugin/services/freezer_api_client.py
+++ b/freezer_tempest_plugin/services/freezer_api_client.py
@@ -14,11 +14,13 @@
14 14
15import urllib 15import urllib
16 16
17from oslo_log import log
17from oslo_serialization import jsonutils as json 18from oslo_serialization import jsonutils as json
18from tempest import config 19from tempest import config
19from tempest.lib.common import rest_client 20from tempest.lib.common import rest_client
20 21
21CONF = config.CONF 22CONF = config.CONF
23LOG = log.getLogger(__name__)
22 24
23 25
24class FreezerApiClient(rest_client.RestClient): 26class FreezerApiClient(rest_client.RestClient):
@@ -29,6 +31,9 @@ class FreezerApiClient(rest_client.RestClient):
29 CONF.backup.region or CONF.identity.region, 31 CONF.backup.region or CONF.identity.region,
30 endpoint_type=CONF.backup.endpoint_type 32 endpoint_type=CONF.backup.endpoint_type
31 ) 33 )
34 LOG.info(self)
35 if self.tenant_id:
36 LOG.info(self.tenant_id)
32 37
33 def get_version(self): 38 def get_version(self):
34 39
@@ -48,17 +53,17 @@ class FreezerApiClient(rest_client.RestClient):
48 def get_backups(self, backup_id=None, **params): 53 def get_backups(self, backup_id=None, **params):
49 54
50 if backup_id is None: 55 if backup_id is None:
51 uri = '/v1/backups' 56 uri = '/v2/{0}/backups'.format(self.tenant_id)
52 if params: 57 if params:
53 uri += '?%s' % urllib.urlencode(params) 58 uri += '?%s' % urllib.urlencode(params)
54 else: 59 else:
55 uri = '/v1/backups/' + backup_id 60 uri = '/v2/{0}/backups/{1}'.format(self.tenant_id, backup_id)
56 61
57 resp, response_body = self.get(uri) 62 resp, response_body = self.get(uri)
58 return resp, json.loads(response_body) 63 return resp, json.loads(response_body)
59 64
60 def post_backups(self, metadata, backup_id=None): 65 def post_backups(self, metadata, backup_id=None):
61 uri = '/v1/backups' 66 uri = '/v2/{0}/backups'.format(self.tenant_id)
62 if backup_id is not None: 67 if backup_id is not None:
63 uri += '/' + backup_id 68 uri += '/' + backup_id
64 69
@@ -69,18 +74,18 @@ class FreezerApiClient(rest_client.RestClient):
69 74
70 def delete_backups(self, backup_id): 75 def delete_backups(self, backup_id):
71 76
72 uri = '/v1/backups/' + backup_id 77 uri = '/v2/{0}/backups/{1}'.format(self.tenant_id, backup_id)
73 resp, response_body = self.delete(uri) 78 resp, response_body = self.delete(uri)
74 return resp, response_body 79 return resp, response_body
75 80
76 def get_clients(self, client_id=None, **params): 81 def get_clients(self, client_id=None, **params):
77 82
78 if client_id is None: 83 if client_id is None:
79 uri = '/v1/clients' 84 uri = '/v2/{0}/clients'.format(self.tenant_id)
80 if params: 85 if params:
81 uri += '?%s' % urllib.urlencode(params) 86 uri += '?%s' % urllib.urlencode(params)
82 else: 87 else:
83 uri = 'v1/clients/' + client_id 88 uri = 'v2/{0}/clients/{1}'.format(self.tenant_id, client_id)
84 89
85 resp, response_body = self.get(uri) 90 resp, response_body = self.get(uri)
86 return resp, response_body 91 return resp, response_body
@@ -88,23 +93,24 @@ class FreezerApiClient(rest_client.RestClient):
88 def post_clients(self, client): 93 def post_clients(self, client):
89 94
90 request_body = json.dumps(client) 95 request_body = json.dumps(client)
91 resp, response_body = self.post('/v1/clients', request_body) 96 resp, response_body = self.post('/v2/{0}/clients'.format(
97 self.tenant_id), request_body)
92 return resp, json.loads(response_body) 98 return resp, json.loads(response_body)
93 99
94 def delete_clients(self, client_id): 100 def delete_clients(self, client_id):
95 101
96 uri = '/v1/clients/' + client_id 102 uri = '/v2/{0}/clients/{1}'.format(self.tenant_id, client_id)
97 resp, response_body = self.delete(uri) 103 resp, response_body = self.delete(uri)
98 return resp, response_body 104 return resp, response_body
99 105
100 def get_jobs(self, job_id=None, **params): 106 def get_jobs(self, job_id=None, **params):
101 107
102 if job_id is None: 108 if job_id is None:
103 uri = '/v1/jobs' 109 uri = '/v2/{0}/jobs'.format(self.tenant_id)
104 if params: 110 if params:
105 uri += '?%s' % urllib.urlencode(params) 111 uri += '?%s' % urllib.urlencode(params)
106 else: 112 else:
107 uri = '/v1/jobs/' + job_id 113 uri = '/v2/{0}/jobs/{1}'.format(self.tenant_id, job_id)
108 114
109 resp, response_body = self.get(uri) 115 resp, response_body = self.get(uri)
110 return resp, response_body 116 return resp, response_body
@@ -112,23 +118,24 @@ class FreezerApiClient(rest_client.RestClient):
112 def post_jobs(self, job): 118 def post_jobs(self, job):
113 119
114 request_body = json.dumps(job) 120 request_body = json.dumps(job)
115 resp, response_body = self.post('/v1/jobs', request_body) 121 resp, response_body = self.post('/v2/{0}/jobs'.format(
122 self.tenant_id), request_body)
116 return resp, json.loads(response_body) 123 return resp, json.loads(response_body)
117 124
118 def delete_jobs(self, job_id): 125 def delete_jobs(self, job_id):
119 126
120 uri = '/v1/jobs/' + job_id 127 uri = '/v2/{0}/jobs/{1}'.format(self.tenant_id, job_id)
121 resp, response_body = self.delete(uri) 128 resp, response_body = self.delete(uri)
122 return resp, response_body 129 return resp, response_body
123 130
124 def get_actions(self, action_id=None, **params): 131 def get_actions(self, action_id=None, **params):
125 132
126 if action_id is None: 133 if action_id is None:
127 uri = '/v1/actions' 134 uri = '/v2/{0}/actions'.format(self.tenant_id)
128 if params: 135 if params:
129 uri += '?%s' % urllib.urlencode(params) 136 uri += '?%s' % urllib.urlencode(params)
130 else: 137 else:
131 uri = '/v1/actions/' + action_id 138 uri = '/v2/{0}/actions/{1}'.format(self.tenant_id, action_id)
132 139
133 resp, response_body = self.get(uri) 140 resp, response_body = self.get(uri)
134 return resp, response_body 141 return resp, response_body
@@ -138,9 +145,9 @@ class FreezerApiClient(rest_client.RestClient):
138 request_body = json.dumps(action) 145 request_body = json.dumps(action)
139 146
140 if action_id is None: 147 if action_id is None:
141 uri = '/v1/actions' 148 uri = '/v2/{0}/actions'.format(self.tenant_id)
142 else: 149 else:
143 uri = '/v1/actions/' + action_id 150 uri = '/v2/{0}/actions/{1}'.format(self.tenant_id, action_id)
144 151
145 resp, response_body = self.post(uri, request_body) 152 resp, response_body = self.post(uri, request_body)
146 return resp, json.loads(response_body) 153 return resp, json.loads(response_body)
@@ -149,24 +156,24 @@ class FreezerApiClient(rest_client.RestClient):
149 156
150 request_body = json.dumps(action) 157 request_body = json.dumps(action)
151 158
152 uri = '/v1/actions/' + action_id 159 uri = '/v2/{0}/actions/{1}'.format(self.tenant_id, action_id)
153 resp, response_body = self.patch(uri, request_body) 160 resp, response_body = self.patch(uri, request_body)
154 return resp, json.loads(response_body) 161 return resp, json.loads(response_body)
155 162
156 def delete_actions(self, id): 163 def delete_actions(self, id):
157 164
158 uri = '/v1/actions/' + id 165 uri = '/v2/{0}/actions/{1}'.format(self.tenant_id, id)
159 resp, response_body = self.delete(uri) 166 resp, response_body = self.delete(uri)
160 return resp, response_body 167 return resp, response_body
161 168
162 def get_sessions(self, session_id=None, **params): 169 def get_sessions(self, session_id=None, **params):
163 170
164 if session_id is None: 171 if session_id is None:
165 uri = '/v1/sessions' 172 uri = '/v2/{0}/sessions'.format(self.tenant_id)
166 if params: 173 if params:
167 uri += '?%s' % urllib.urlencode(params) 174 uri += '?%s' % urllib.urlencode(params)
168 else: 175 else:
169 uri = 'v1/sessions/' + session_id 176 uri = '/v2/{0}/sessions/'.format(self.tenant_id, session_id)
170 177
171 resp, response_body = self.get(uri) 178 resp, response_body = self.get(uri)
172 return resp, response_body 179 return resp, response_body
@@ -174,11 +181,12 @@ class FreezerApiClient(rest_client.RestClient):
174 def post_sessions(self, session): 181 def post_sessions(self, session):
175 182
176 request_body = json.dumps(session) 183 request_body = json.dumps(session)
177 resp, response_body = self.post('/v1/sessions', request_body) 184 resp, response_body = self.post('/v2/{0}/sessions'.format(
185 self.tenant_id), request_body)
178 return resp, json.loads(response_body) 186 return resp, json.loads(response_body)
179 187
180 def delete_sessions(self, session_id): 188 def delete_sessions(self, session_id):
181 189
182 uri = '/v1/sessions/' + session_id 190 uri = '/v2/{0}/sessions/{1}'.format(self.tenant_id, session_id)
183 resp, response_body = self.delete(uri) 191 resp, response_body = self.delete(uri)
184 return resp, response_body 192 return resp, response_body
diff --git a/freezer_tempest_plugin/tests/freezer_api/api/test_api_backups.py b/freezer_tempest_plugin/tests/freezer_api/api/test_api_backups.py
index f07f57b..5bd5948 100644
--- a/freezer_tempest_plugin/tests/freezer_api/api/test_api_backups.py
+++ b/freezer_tempest_plugin/tests/freezer_api/api/test_api_backups.py
@@ -163,7 +163,7 @@ class TestFreezerApiBackups(base.BaseFreezerApiTest):
163 """ 163 """
164 metadata = self._build_metadata("test_freezer_backups") 164 metadata = self._build_metadata("test_freezer_backups")
165 165
166 uri = '/v1/backups' 166 uri = '/v2/{0}/backups'.format(self.freezer_api_client.tenant_id)
167 request_body = json.dumps(metadata) 167 request_body = json.dumps(metadata)
168 168
169 # Passing in an empty dict for headers to avoid automatically 169 # Passing in an empty dict for headers to avoid automatically
@@ -231,6 +231,7 @@ class TestFreezerApiBackups(base.BaseFreezerApiTest):
231 return { 231 return {
232 'user_name': self.os_primary.credentials.username, 232 'user_name': self.os_primary.credentials.username,
233 'user_id': self.os_primary.credentials.user_id, 233 'user_id': self.os_primary.credentials.user_id,
234 'project_id': self.freezer_api_client.tenant_id,
234 'backup_metadata': metadata 235 'backup_metadata': metadata
235 } 236 }
236 237
diff --git a/freezer_tempest_plugin/tests/freezer_api/api/test_api_sessions.py b/freezer_tempest_plugin/tests/freezer_api/api/test_api_sessions.py
index c8e80e0..e298414 100644
--- a/freezer_tempest_plugin/tests/freezer_api/api/test_api_sessions.py
+++ b/freezer_tempest_plugin/tests/freezer_api/api/test_api_sessions.py
@@ -111,6 +111,7 @@ class TestFreezerApiSessions(base.BaseFreezerApiTest):
111 "time_ended": 1234, 111 "time_ended": 1234,
112 "status": "completed", 112 "status": "completed",
113 "result": "success", 113 "result": "success",
114 "project_id": self.freezer_api_client.tenant_id,
114 "user_id": "user-id-1" 115 "user_id": "user-id-1"
115 } 116 }
116 117