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 | |
Yuiko Takada | bde9126 | 2014-04-17 10:43:41 +0000 | [diff] [blame] | 18 | from tempest.api_schema.compute import agents as common_schema |
Yuiko Takada | c32a98b | 2014-04-02 20:18:24 +0900 | [diff] [blame] | 19 | from tempest.api_schema.compute.v2 import agents as schema |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 20 | from tempest.common import rest_client |
| 21 | from tempest import config |
| 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | |
| 26 | class AgentsClientJSON(rest_client.RestClient): |
| 27 | """ |
| 28 | Tests Agents API |
| 29 | """ |
| 30 | |
| 31 | def __init__(self, auth_provider): |
| 32 | super(AgentsClientJSON, self).__init__(auth_provider) |
| 33 | self.service = CONF.compute.catalog_type |
| 34 | |
| 35 | def list_agents(self, params=None): |
| 36 | """List all agent builds.""" |
| 37 | url = 'os-agents' |
| 38 | if params: |
| 39 | url += '?%s' % urllib.urlencode(params) |
| 40 | resp, body = self.get(url) |
Yuiko Takada | bde9126 | 2014-04-17 10:43:41 +0000 | [diff] [blame] | 41 | body = json.loads(body) |
| 42 | self.validate_response(common_schema.list_agents, resp, body) |
| 43 | return resp, body['agents'] |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 44 | |
| 45 | def create_agent(self, **kwargs): |
| 46 | """Create an agent build.""" |
| 47 | post_body = json.dumps({'agent': kwargs}) |
| 48 | resp, body = self.post('os-agents', post_body) |
| 49 | return resp, self._parse_resp(body) |
| 50 | |
| 51 | def delete_agent(self, agent_id): |
| 52 | """Delete an existing agent build.""" |
Yuiko Takada | c32a98b | 2014-04-02 20:18:24 +0900 | [diff] [blame] | 53 | resp, body = self.delete("os-agents/%s" % str(agent_id)) |
| 54 | self.validate_response(schema.delete_agent, resp, body) |
| 55 | return resp, body |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 56 | |
| 57 | def update_agent(self, agent_id, **kwargs): |
| 58 | """Update an agent build.""" |
| 59 | put_body = json.dumps({'para': kwargs}) |
| 60 | resp, body = self.put('os-agents/%s' % str(agent_id), put_body) |
| 61 | return resp, self._parse_resp(body) |