blob: 1a1d832e2e8c72671aa3cd7d24d54db169cdc8f2 [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
Matthew Treinish21905512015-07-13 10:33:35 -040015from oslo_serialization import jsonutils as json
Matthew Treinish89128142015-04-23 10:44:30 -040016from six.moves.urllib import parse as urllib
Yuiko Takada420f2eb2014-04-02 19:53:38 +090017
ghanshyamaa93b4b2015-03-20 11:03:44 +090018from tempest.api_schema.response.compute.v2_1 import agents as schema
David Kranz0a735172015-01-16 10:51:18 -050019from tempest.common import service_client
Yuiko Takada420f2eb2014-04-02 19:53:38 +090020
21
Ken'ichi Ohmichia6287072015-07-02 02:43:15 +000022class AgentsClient(service_client.ServiceClient):
Yuiko Takada420f2eb2014-04-02 19:53:38 +090023 """
24 Tests Agents API
25 """
26
Ken'ichi Ohmichi118776d2015-07-01 08:15:00 +000027 def list_agents(self, **params):
Yuiko Takada420f2eb2014-04-02 19:53:38 +090028 """List all agent builds."""
29 url = 'os-agents'
30 if params:
31 url += '?%s' % urllib.urlencode(params)
32 resp, body = self.get(url)
Yuiko Takadabde91262014-04-17 10:43:41 +000033 body = json.loads(body)
ghanshyamb8a61242015-03-20 11:25:22 +090034 self.validate_response(schema.list_agents, resp, body)
David Kranz0a735172015-01-16 10:51:18 -050035 return service_client.ResponseBodyList(resp, body['agents'])
Yuiko Takada420f2eb2014-04-02 19:53:38 +090036
37 def create_agent(self, **kwargs):
38 """Create an agent build."""
39 post_body = json.dumps({'agent': kwargs})
40 resp, body = self.post('os-agents', post_body)
Yuiko Takada34e98ad2014-04-01 14:13:05 +000041 body = json.loads(body)
42 self.validate_response(schema.create_agent, resp, body)
David Kranz0a735172015-01-16 10:51:18 -050043 return service_client.ResponseBody(resp, body['agent'])
Yuiko Takada420f2eb2014-04-02 19:53:38 +090044
45 def delete_agent(self, agent_id):
46 """Delete an existing agent build."""
Ken'ichi Ohmichicd6e8992015-07-01 06:45:34 +000047 resp, body = self.delete("os-agents/%s" % agent_id)
Yuiko Takadac32a98b2014-04-02 20:18:24 +090048 self.validate_response(schema.delete_agent, resp, body)
David Kranz0a735172015-01-16 10:51:18 -050049 return service_client.ResponseBody(resp, body)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090050
51 def update_agent(self, agent_id, **kwargs):
52 """Update an agent build."""
53 put_body = json.dumps({'para': kwargs})
Ken'ichi Ohmichicd6e8992015-07-01 06:45:34 +000054 resp, body = self.put('os-agents/%s' % agent_id, put_body)
Ken'ichi Ohmichi14bf4242015-07-17 02:28:21 +000055 body = json.loads(body)
56 return service_client.ResponseBody(resp, body['agent'])