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 | |
| 15 | import json |
| 16 | import urllib |
| 17 | |
Marc Koderer | 6fbd74f | 2014-08-04 09:38:19 +0200 | [diff] [blame] | 18 | from tempest.api_schema.response.compute import agents as common_schema |
ghanshyam | aa93b4b | 2015-03-20 11:03:44 +0900 | [diff] [blame^] | 19 | from tempest.api_schema.response.compute.v2_1 import agents as schema |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 20 | from tempest.common import service_client |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 21 | |
| 22 | |
Ken'ichi Ohmichi | 4771cbc | 2015-01-19 23:45:23 +0000 | [diff] [blame] | 23 | class AgentsClientJSON(service_client.ServiceClient): |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 24 | """ |
| 25 | Tests Agents API |
| 26 | """ |
| 27 | |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 28 | def list_agents(self, params=None): |
| 29 | """List all agent builds.""" |
| 30 | url = 'os-agents' |
| 31 | if params: |
| 32 | url += '?%s' % urllib.urlencode(params) |
| 33 | resp, body = self.get(url) |
Yuiko Takada | bde9126 | 2014-04-17 10:43:41 +0000 | [diff] [blame] | 34 | body = json.loads(body) |
| 35 | self.validate_response(common_schema.list_agents, resp, body) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 36 | return service_client.ResponseBodyList(resp, body['agents']) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 37 | |
| 38 | def create_agent(self, **kwargs): |
| 39 | """Create an agent build.""" |
| 40 | post_body = json.dumps({'agent': kwargs}) |
| 41 | resp, body = self.post('os-agents', post_body) |
Yuiko Takada | 34e98ad | 2014-04-01 14:13:05 +0000 | [diff] [blame] | 42 | body = json.loads(body) |
| 43 | self.validate_response(schema.create_agent, resp, body) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 44 | return service_client.ResponseBody(resp, body['agent']) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 45 | |
| 46 | def delete_agent(self, agent_id): |
| 47 | """Delete an existing agent build.""" |
Yuiko Takada | c32a98b | 2014-04-02 20:18:24 +0900 | [diff] [blame] | 48 | resp, body = self.delete("os-agents/%s" % str(agent_id)) |
| 49 | self.validate_response(schema.delete_agent, resp, body) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 50 | return service_client.ResponseBody(resp, body) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 51 | |
| 52 | def update_agent(self, agent_id, **kwargs): |
| 53 | """Update an agent build.""" |
| 54 | put_body = json.dumps({'para': kwargs}) |
| 55 | resp, body = self.put('os-agents/%s' % str(agent_id), put_body) |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 56 | return service_client.ResponseBody(resp, self._parse_resp(body)) |