blob: 48086011431b47459ee028c393d6fcaa7edc20d8 [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
15from tempest.api.compute import base
16from tempest.common.utils import data_utils
17from tempest import exceptions
18from tempest.openstack.common import log
19from tempest import test
20
21LOG = log.getLogger(__name__)
22
23
24class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest):
25 """
26 Tests Agents API
27 """
28
29 @classmethod
30 def setUpClass(cls):
31 super(AgentsAdminTestJSON, cls).setUpClass()
32 cls.client = cls.os_adm.agents_client
33
34 def setUp(self):
35 super(AgentsAdminTestJSON, self).setUp()
36 params = self._param_helper(
37 hypervisor='common', os='linux', architecture='x86_64',
38 version='7.0', url='xxx://xxxx/xxx/xxx',
39 md5hash='add6bb58e139be103324d04d82d8f545')
40 resp, body = self.client.create_agent(**params)
41 self.assertEqual(200, resp.status)
42 self.agent_id = body['agent_id']
43
44 def tearDown(self):
45 try:
46 self.client.delete_agent(self.agent_id)
47 except exceptions.NotFound:
48 pass
49 except Exception:
50 LOG.exception('Exception raised deleting agent %s', self.agent_id)
51 super(AgentsAdminTestJSON, self).tearDown()
52
53 def _param_helper(self, **kwargs):
54 rand_key = 'architecture'
55 if rand_key in kwargs:
56 # NOTE: The rand_name is for avoiding agent conflicts.
57 # If you try to create an agent with the same hypervisor,
58 # os and architecture as an exising agent, Nova will return
59 # an HTTPConflict or HTTPServerError.
60 kwargs[rand_key] = data_utils.rand_name(kwargs[rand_key])
61 return kwargs
62
63 @test.attr(type='gate')
64 def test_create_agent(self):
65 # Create an agent.
66 params = self._param_helper(
67 hypervisor='kvm', os='win', architecture='x86',
68 version='7.0', url='xxx://xxxx/xxx/xxx',
69 md5hash='add6bb58e139be103324d04d82d8f545')
70 resp, body = self.client.create_agent(**params)
71 self.assertEqual(200, resp.status)
72 self.addCleanup(self.client.delete_agent, body['agent_id'])
73 for expected_item, value in params.items():
74 self.assertEqual(value, body[expected_item])
75
76 @test.attr(type='gate')
77 def test_update_agent(self):
78 # Update an agent.
79 params = self._param_helper(
80 version='8.0', url='xxx://xxxx/xxx/xxx2',
81 md5hash='add6bb58e139be103324d04d82d8f547')
82 resp, body = self.client.update_agent(self.agent_id, **params)
83 self.assertEqual(200, resp.status)
84 for expected_item, value in params.items():
85 self.assertEqual(value, body[expected_item])
86
87 @test.attr(type='gate')
88 def test_delete_agent(self):
89 # Delete an agent.
90 resp, _ = self.client.delete_agent(self.agent_id)
91 self.assertEqual(200, resp.status)
92
93 # Verify the list doesn't contain the deleted agent.
94 resp, agents = self.client.list_agents()
95 self.assertEqual(200, resp.status)
96 self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents))
97
98 @test.attr(type='gate')
99 def test_list_agents(self):
100 # List all agents.
101 resp, agents = self.client.list_agents()
102 self.assertEqual(200, resp.status)
103 self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents)
104 self.assertIn(self.agent_id, map(lambda x: x['agent_id'], agents))
105
106 @test.attr(type='gate')
107 def test_list_agents_with_filter(self):
108 # List the agent builds by the filter.
109 params = self._param_helper(
110 hypervisor='xen', os='linux', architecture='x86',
111 version='7.0', url='xxx://xxxx/xxx/xxx1',
112 md5hash='add6bb58e139be103324d04d82d8f546')
113 resp, agent_xen = self.client.create_agent(**params)
114 self.assertEqual(200, resp.status)
115 self.addCleanup(self.client.delete_agent, agent_xen['agent_id'])
116
117 agent_id_xen = agent_xen['agent_id']
118 params_filter = {'hypervisor': agent_xen['hypervisor']}
119 resp, agents = self.client.list_agents(params_filter)
120 self.assertEqual(200, resp.status)
121 self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents)
122 self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents))
123 self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents))