blob: 425ce13f260fea20aeb41aac8cf626d809b97743 [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
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010030 def resource_setup(cls):
31 super(AgentsAdminTestJSON, cls).resource_setup()
Yuiko Takada420f2eb2014-04-02 19:53:38 +090032 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')
David Kranz0a735172015-01-16 10:51:18 -050040 body = self.client.create_agent(**params)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090041 self.agent_id = body['agent_id']
42
43 def tearDown(self):
44 try:
45 self.client.delete_agent(self.agent_id)
46 except exceptions.NotFound:
47 pass
48 except Exception:
49 LOG.exception('Exception raised deleting agent %s', self.agent_id)
50 super(AgentsAdminTestJSON, self).tearDown()
51
52 def _param_helper(self, **kwargs):
53 rand_key = 'architecture'
54 if rand_key in kwargs:
55 # NOTE: The rand_name is for avoiding agent conflicts.
56 # If you try to create an agent with the same hypervisor,
57 # os and architecture as an exising agent, Nova will return
58 # an HTTPConflict or HTTPServerError.
59 kwargs[rand_key] = data_utils.rand_name(kwargs[rand_key])
60 return kwargs
61
62 @test.attr(type='gate')
63 def test_create_agent(self):
64 # Create an agent.
65 params = self._param_helper(
66 hypervisor='kvm', os='win', architecture='x86',
67 version='7.0', url='xxx://xxxx/xxx/xxx',
68 md5hash='add6bb58e139be103324d04d82d8f545')
David Kranz0a735172015-01-16 10:51:18 -050069 body = self.client.create_agent(**params)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090070 self.addCleanup(self.client.delete_agent, body['agent_id'])
71 for expected_item, value in params.items():
72 self.assertEqual(value, body[expected_item])
73
74 @test.attr(type='gate')
75 def test_update_agent(self):
76 # Update an agent.
77 params = self._param_helper(
78 version='8.0', url='xxx://xxxx/xxx/xxx2',
79 md5hash='add6bb58e139be103324d04d82d8f547')
David Kranz0a735172015-01-16 10:51:18 -050080 body = self.client.update_agent(self.agent_id, **params)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090081 for expected_item, value in params.items():
82 self.assertEqual(value, body[expected_item])
83
84 @test.attr(type='gate')
85 def test_delete_agent(self):
86 # Delete an agent.
David Kranz0a735172015-01-16 10:51:18 -050087 self.client.delete_agent(self.agent_id)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090088
89 # Verify the list doesn't contain the deleted agent.
David Kranz0a735172015-01-16 10:51:18 -050090 agents = self.client.list_agents()
Yuiko Takada420f2eb2014-04-02 19:53:38 +090091 self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents))
92
93 @test.attr(type='gate')
94 def test_list_agents(self):
95 # List all agents.
David Kranz0a735172015-01-16 10:51:18 -050096 agents = self.client.list_agents()
Yuiko Takada420f2eb2014-04-02 19:53:38 +090097 self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents)
98 self.assertIn(self.agent_id, map(lambda x: x['agent_id'], agents))
99
100 @test.attr(type='gate')
101 def test_list_agents_with_filter(self):
102 # List the agent builds by the filter.
103 params = self._param_helper(
104 hypervisor='xen', os='linux', architecture='x86',
105 version='7.0', url='xxx://xxxx/xxx/xxx1',
106 md5hash='add6bb58e139be103324d04d82d8f546')
David Kranz0a735172015-01-16 10:51:18 -0500107 agent_xen = self.client.create_agent(**params)
Yuiko Takada420f2eb2014-04-02 19:53:38 +0900108 self.addCleanup(self.client.delete_agent, agent_xen['agent_id'])
109
110 agent_id_xen = agent_xen['agent_id']
111 params_filter = {'hypervisor': agent_xen['hypervisor']}
David Kranz0a735172015-01-16 10:51:18 -0500112 agents = self.client.list_agents(params_filter)
Yuiko Takada420f2eb2014-04-02 19:53:38 +0900113 self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents)
114 self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents))
115 self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents))