blob: 98d889659a9c0806f3d0312b2f5a2e8278945f35 [file] [log] [blame]
Yuiko Takada420f2eb2014-04-02 19:53:38 +09001# 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
15import json
16import urllib
17
Yuiko Takadabde91262014-04-17 10:43:41 +000018from tempest.api_schema.compute import agents as common_schema
Yuiko Takadac32a98b2014-04-02 20:18:24 +090019from tempest.api_schema.compute.v2 import agents as schema
Yuiko Takada420f2eb2014-04-02 19:53:38 +090020from tempest.common import rest_client
21from tempest import config
22
23CONF = config.CONF
24
25
26class 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 Takadabde91262014-04-17 10:43:41 +000041 body = json.loads(body)
42 self.validate_response(common_schema.list_agents, resp, body)
43 return resp, body['agents']
Yuiko Takada420f2eb2014-04-02 19:53:38 +090044
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 Takadac32a98b2014-04-02 20:18:24 +090053 resp, body = self.delete("os-agents/%s" % str(agent_id))
54 self.validate_response(schema.delete_agent, resp, body)
55 return resp, body
Yuiko Takada420f2eb2014-04-02 19:53:38 +090056
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)