blob: c69e483b289a4550d337fa56f8a0ab85d89aca61 [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
Matthew Treinish89128142015-04-23 10:44:30 -040016
17from six.moves.urllib import parse as urllib
Yuiko Takada420f2eb2014-04-02 19:53:38 +090018
ghanshyamaa93b4b2015-03-20 11:03:44 +090019from tempest.api_schema.response.compute.v2_1 import agents as schema
David Kranz0a735172015-01-16 10:51:18 -050020from tempest.common import service_client
Yuiko Takada420f2eb2014-04-02 19:53:38 +090021
22
Ken'ichi Ohmichi4771cbc2015-01-19 23:45:23 +000023class AgentsClientJSON(service_client.ServiceClient):
Yuiko Takada420f2eb2014-04-02 19:53:38 +090024 """
25 Tests Agents API
26 """
27
Yuiko Takada420f2eb2014-04-02 19:53:38 +090028 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 Takadabde91262014-04-17 10:43:41 +000034 body = json.loads(body)
ghanshyamb8a61242015-03-20 11:25:22 +090035 self.validate_response(schema.list_agents, resp, body)
David Kranz0a735172015-01-16 10:51:18 -050036 return service_client.ResponseBodyList(resp, body['agents'])
Yuiko Takada420f2eb2014-04-02 19:53:38 +090037
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 Takada34e98ad2014-04-01 14:13:05 +000042 body = json.loads(body)
43 self.validate_response(schema.create_agent, resp, body)
David Kranz0a735172015-01-16 10:51:18 -050044 return service_client.ResponseBody(resp, body['agent'])
Yuiko Takada420f2eb2014-04-02 19:53:38 +090045
46 def delete_agent(self, agent_id):
47 """Delete an existing agent build."""
Yuiko Takadac32a98b2014-04-02 20:18:24 +090048 resp, body = self.delete("os-agents/%s" % str(agent_id))
49 self.validate_response(schema.delete_agent, resp, body)
David Kranz0a735172015-01-16 10:51:18 -050050 return service_client.ResponseBody(resp, body)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090051
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 Kranz0a735172015-01-16 10:51:18 -050056 return service_client.ResponseBody(resp, self._parse_resp(body))