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