blob: 3f05d3be600c0c02a83f8dc66e784f14240d1402 [file] [log] [blame]
Matthew Treinish9e26ca82016-02-23 11:43:20 -05001# 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
15from oslo_serialization import jsonutils as json
16from six.moves.urllib import parse as urllib
17
18from tempest.lib.api_schema.response.compute.v2_1 import agents as schema
19from tempest.lib.common import rest_client
Ghanshyamee9af302016-02-25 06:12:43 +090020from tempest.lib.services.compute import base_compute_client
Matthew Treinish9e26ca82016-02-23 11:43:20 -050021
22
Ghanshyamee9af302016-02-25 06:12:43 +090023class AgentsClient(base_compute_client.BaseComputeClient):
Matthew Treinish9e26ca82016-02-23 11:43:20 -050024 """Tests Agents API"""
25
26 def list_agents(self, **params):
Lv Fumei7e326332016-07-08 15:18:03 +080027 """List all agent builds.
28
29 Available params: see http://developer.openstack.org/
30 api-ref-compute-v2.1.html#listbuilds
31 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -050032 url = 'os-agents'
33 if params:
34 url += '?%s' % urllib.urlencode(params)
35 resp, body = self.get(url)
36 body = json.loads(body)
37 self.validate_response(schema.list_agents, resp, body)
38 return rest_client.ResponseBody(resp, body)
39
40 def create_agent(self, **kwargs):
41 """Create an agent build.
42
43 Available params: see http://developer.openstack.org/
44 api-ref-compute-v2.1.html#agentbuild
45 """
46 post_body = json.dumps({'agent': kwargs})
47 resp, body = self.post('os-agents', post_body)
48 body = json.loads(body)
49 self.validate_response(schema.create_agent, resp, body)
50 return rest_client.ResponseBody(resp, body)
51
52 def delete_agent(self, agent_id):
Lv Fumei7e326332016-07-08 15:18:03 +080053 """Delete an existing agent build.
54
55 Available params: see http://developer.openstack.org/
56 api-ref-compute-v2.1.html#deleteBuild
57 """
Matthew Treinish9e26ca82016-02-23 11:43:20 -050058 resp, body = self.delete("os-agents/%s" % agent_id)
59 self.validate_response(schema.delete_agent, resp, body)
60 return rest_client.ResponseBody(resp, body)
61
62 def update_agent(self, agent_id, **kwargs):
63 """Update an agent build.
64
65 Available params: see http://developer.openstack.org/
66 api-ref-compute-v2.1.html#updatebuild
67 """
68 put_body = json.dumps({'para': kwargs})
69 resp, body = self.put('os-agents/%s' % agent_id, put_body)
70 body = json.loads(body)
71 self.validate_response(schema.update_agent, resp, body)
72 return rest_client.ResponseBody(resp, body)