Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 1 | # Copyright 2014 NEC Corporation. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Matthew Treinish | 2190551 | 2015-07-13 10:33:35 -0400 | [diff] [blame] | 15 | from oslo_serialization import jsonutils as json |
Matthew Treinish | 8912814 | 2015-04-23 10:44:30 -0400 | [diff] [blame] | 16 | from six.moves.urllib import parse as urllib |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 17 | |
ghanshyam | aa93b4b | 2015-03-20 11:03:44 +0900 | [diff] [blame] | 18 | from tempest.api_schema.response.compute.v2_1 import agents as schema |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 19 | from tempest.common import service_client |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 20 | |
| 21 | |
Ken'ichi Ohmichi | a628707 | 2015-07-02 02:43:15 +0000 | [diff] [blame] | 22 | class AgentsClient(service_client.ServiceClient): |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 23 | """ |
| 24 | Tests Agents API |
| 25 | """ |
| 26 | |
Ken'ichi Ohmichi | 118776d | 2015-07-01 08:15:00 +0000 | [diff] [blame] | 27 | def list_agents(self, **params): |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 28 | """List all agent builds.""" |
| 29 | url = 'os-agents' |
| 30 | if params: |
| 31 | url += '?%s' % urllib.urlencode(params) |
| 32 | resp, body = self.get(url) |
Yuiko Takada | bde9126 | 2014-04-17 10:43:41 +0000 | [diff] [blame] | 33 | body = json.loads(body) |
ghanshyam | b8a6124 | 2015-03-20 11:25:22 +0900 | [diff] [blame] | 34 | self.validate_response(schema.list_agents, resp, body) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 35 | return service_client.ResponseBodyList(resp, body['agents']) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 36 | |
| 37 | def create_agent(self, **kwargs): |
| 38 | """Create an agent build.""" |
| 39 | post_body = json.dumps({'agent': kwargs}) |
| 40 | resp, body = self.post('os-agents', post_body) |
Yuiko Takada | 34e98ad | 2014-04-01 14:13:05 +0000 | [diff] [blame] | 41 | body = json.loads(body) |
| 42 | self.validate_response(schema.create_agent, resp, body) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 43 | return service_client.ResponseBody(resp, body['agent']) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 44 | |
| 45 | def delete_agent(self, agent_id): |
| 46 | """Delete an existing agent build.""" |
Ken'ichi Ohmichi | cd6e899 | 2015-07-01 06:45:34 +0000 | [diff] [blame] | 47 | resp, body = self.delete("os-agents/%s" % agent_id) |
Yuiko Takada | c32a98b | 2014-04-02 20:18:24 +0900 | [diff] [blame] | 48 | self.validate_response(schema.delete_agent, resp, body) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 49 | return service_client.ResponseBody(resp, body) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 50 | |
| 51 | def update_agent(self, agent_id, **kwargs): |
| 52 | """Update an agent build.""" |
| 53 | put_body = json.dumps({'para': kwargs}) |
Ken'ichi Ohmichi | cd6e899 | 2015-07-01 06:45:34 +0000 | [diff] [blame] | 54 | resp, body = self.put('os-agents/%s' % agent_id, put_body) |
Ken'ichi Ohmichi | 14bf424 | 2015-07-17 02:28:21 +0000 | [diff] [blame] | 55 | body = json.loads(body) |
| 56 | return service_client.ResponseBody(resp, body['agent']) |