blob: 4f48ad0a7bd5a813a16afed8de9a88913b78d0d8 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000015from oslo_log import log
Masayuki Igawabfa07602015-01-20 18:47:17 +090016
Yuiko Takada420f2eb2014-04-02 19:53:38 +090017from tempest.api.compute import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120018from tempest.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010019from tempest.lib.common.utils import test_utils
Yuiko Takada420f2eb2014-04-02 19:53:38 +090020from tempest import test
21
22LOG = log.getLogger(__name__)
23
24
25class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000026 """Tests Agents API"""
Yuiko Takada420f2eb2014-04-02 19:53:38 +090027
28 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053029 def setup_clients(cls):
30 super(AgentsAdminTestJSON, cls).setup_clients()
Yuiko Takada420f2eb2014-04-02 19:53:38 +090031 cls.client = cls.os_adm.agents_client
32
33 def setUp(self):
34 super(AgentsAdminTestJSON, self).setUp()
35 params = self._param_helper(
36 hypervisor='common', os='linux', architecture='x86_64',
37 version='7.0', url='xxx://xxxx/xxx/xxx',
38 md5hash='add6bb58e139be103324d04d82d8f545')
ghanshyam5805ccc2015-08-04 14:06:20 +090039 body = self.client.create_agent(**params)['agent']
Yuiko Takada420f2eb2014-04-02 19:53:38 +090040 self.agent_id = body['agent_id']
41
42 def tearDown(self):
43 try:
Jordan Pittier9e227c52016-02-09 14:35:18 +010044 test_utils.call_and_ignore_notfound_exc(
45 self.client.delete_agent, self.agent_id)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090046 except Exception:
47 LOG.exception('Exception raised deleting agent %s', self.agent_id)
48 super(AgentsAdminTestJSON, self).tearDown()
49
50 def _param_helper(self, **kwargs):
51 rand_key = 'architecture'
52 if rand_key in kwargs:
53 # NOTE: The rand_name is for avoiding agent conflicts.
54 # If you try to create an agent with the same hypervisor,
Felix Li6aebd7e2016-01-04 10:11:04 -050055 # os and architecture as an existing agent, Nova will return
Yuiko Takada420f2eb2014-04-02 19:53:38 +090056 # an HTTPConflict or HTTPServerError.
57 kwargs[rand_key] = data_utils.rand_name(kwargs[rand_key])
58 return kwargs
59
Chris Hoge7579c1a2015-02-26 14:12:15 -080060 @test.idempotent_id('1fc6bdc8-0b6d-4cc7-9f30-9b04fabe5b90')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090061 def test_create_agent(self):
62 # Create an agent.
63 params = self._param_helper(
64 hypervisor='kvm', os='win', architecture='x86',
65 version='7.0', url='xxx://xxxx/xxx/xxx',
66 md5hash='add6bb58e139be103324d04d82d8f545')
ghanshyam5805ccc2015-08-04 14:06:20 +090067 body = self.client.create_agent(**params)['agent']
Yuiko Takada420f2eb2014-04-02 19:53:38 +090068 self.addCleanup(self.client.delete_agent, body['agent_id'])
69 for expected_item, value in params.items():
70 self.assertEqual(value, body[expected_item])
71
Chris Hoge7579c1a2015-02-26 14:12:15 -080072 @test.idempotent_id('dc9ffd51-1c50-4f0e-a820-ae6d2a568a9e')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090073 def test_update_agent(self):
74 # Update an agent.
75 params = self._param_helper(
76 version='8.0', url='xxx://xxxx/xxx/xxx2',
77 md5hash='add6bb58e139be103324d04d82d8f547')
ghanshyam5805ccc2015-08-04 14:06:20 +090078 body = self.client.update_agent(self.agent_id, **params)['agent']
Yuiko Takada420f2eb2014-04-02 19:53:38 +090079 for expected_item, value in params.items():
80 self.assertEqual(value, body[expected_item])
81
Chris Hoge7579c1a2015-02-26 14:12:15 -080082 @test.idempotent_id('470e0b89-386f-407b-91fd-819737d0b335')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090083 def test_delete_agent(self):
84 # Delete an agent.
David Kranz0a735172015-01-16 10:51:18 -050085 self.client.delete_agent(self.agent_id)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090086
87 # Verify the list doesn't contain the deleted agent.
ghanshyam5805ccc2015-08-04 14:06:20 +090088 agents = self.client.list_agents()['agents']
Yuiko Takada420f2eb2014-04-02 19:53:38 +090089 self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents))
90
Chris Hoge7579c1a2015-02-26 14:12:15 -080091 @test.idempotent_id('6a326c69-654b-438a-80a3-34bcc454e138')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090092 def test_list_agents(self):
93 # List all agents.
ghanshyam5805ccc2015-08-04 14:06:20 +090094 agents = self.client.list_agents()['agents']
Yuiko Takada420f2eb2014-04-02 19:53:38 +090095 self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents)
96 self.assertIn(self.agent_id, map(lambda x: x['agent_id'], agents))
97
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('eabadde4-3cd7-4ec4-a4b5-5a936d2d4408')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090099 def test_list_agents_with_filter(self):
100 # List the agent builds by the filter.
101 params = self._param_helper(
102 hypervisor='xen', os='linux', architecture='x86',
103 version='7.0', url='xxx://xxxx/xxx/xxx1',
104 md5hash='add6bb58e139be103324d04d82d8f546')
ghanshyam5805ccc2015-08-04 14:06:20 +0900105 agent_xen = self.client.create_agent(**params)['agent']
Yuiko Takada420f2eb2014-04-02 19:53:38 +0900106 self.addCleanup(self.client.delete_agent, agent_xen['agent_id'])
107
108 agent_id_xen = agent_xen['agent_id']
ghanshyam5805ccc2015-08-04 14:06:20 +0900109 agents = (self.client.list_agents(hypervisor=agent_xen['hypervisor'])
110 ['agents'])
Yuiko Takada420f2eb2014-04-02 19:53:38 +0900111 self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents)
112 self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents))
113 self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents))