blob: 40cb5237bfe3a4965e42b88b5e98243b1aaae273 [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
Yuiko Takada420f2eb2014-04-02 19:53:38 +090019from tempest import test
20
21LOG = log.getLogger(__name__)
22
23
24class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest):
Ken'ichi Ohmichi88363cb2015-11-19 08:00:54 +000025 """Tests Agents API"""
Yuiko Takada420f2eb2014-04-02 19:53:38 +090026
27 @classmethod
Rohan Kanade60b73092015-02-04 17:58:19 +053028 def setup_clients(cls):
29 super(AgentsAdminTestJSON, cls).setup_clients()
Yuiko Takada420f2eb2014-04-02 19:53:38 +090030 cls.client = cls.os_adm.agents_client
31
Benny Kopilovc1daa122016-09-26 14:19:50 +030032 @classmethod
33 def resource_setup(cls):
34 super(AgentsAdminTestJSON, cls).resource_setup()
35 cls.params_agent = cls._param_helper(
Yuiko Takada420f2eb2014-04-02 19:53:38 +090036 hypervisor='common', os='linux', architecture='x86_64',
37 version='7.0', url='xxx://xxxx/xxx/xxx',
38 md5hash='add6bb58e139be103324d04d82d8f545')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090039
Benny Kopilovc1daa122016-09-26 14:19:50 +030040 @staticmethod
41 def _param_helper(**kwargs):
Yuiko Takada420f2eb2014-04-02 19:53:38 +090042 rand_key = 'architecture'
43 if rand_key in kwargs:
44 # NOTE: The rand_name is for avoiding agent conflicts.
45 # If you try to create an agent with the same hypervisor,
Felix Li6aebd7e2016-01-04 10:11:04 -050046 # os and architecture as an existing agent, Nova will return
Yuiko Takada420f2eb2014-04-02 19:53:38 +090047 # an HTTPConflict or HTTPServerError.
48 kwargs[rand_key] = data_utils.rand_name(kwargs[rand_key])
49 return kwargs
50
Chris Hoge7579c1a2015-02-26 14:12:15 -080051 @test.idempotent_id('1fc6bdc8-0b6d-4cc7-9f30-9b04fabe5b90')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090052 def test_create_agent(self):
53 # Create an agent.
54 params = self._param_helper(
55 hypervisor='kvm', os='win', architecture='x86',
56 version='7.0', url='xxx://xxxx/xxx/xxx',
57 md5hash='add6bb58e139be103324d04d82d8f545')
ghanshyam5805ccc2015-08-04 14:06:20 +090058 body = self.client.create_agent(**params)['agent']
Yuiko Takada420f2eb2014-04-02 19:53:38 +090059 self.addCleanup(self.client.delete_agent, body['agent_id'])
60 for expected_item, value in params.items():
61 self.assertEqual(value, body[expected_item])
62
Chris Hoge7579c1a2015-02-26 14:12:15 -080063 @test.idempotent_id('dc9ffd51-1c50-4f0e-a820-ae6d2a568a9e')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090064 def test_update_agent(self):
Benny Kopilovc1daa122016-09-26 14:19:50 +030065 # Create and update an agent.
66 body = self.client.create_agent(**self.params_agent)['agent']
67 self.addCleanup(self.client.delete_agent, body['agent_id'])
68 agent_id = body['agent_id']
Yuiko Takada420f2eb2014-04-02 19:53:38 +090069 params = self._param_helper(
70 version='8.0', url='xxx://xxxx/xxx/xxx2',
71 md5hash='add6bb58e139be103324d04d82d8f547')
Benny Kopilovc1daa122016-09-26 14:19:50 +030072 body = self.client.update_agent(agent_id, **params)['agent']
Yuiko Takada420f2eb2014-04-02 19:53:38 +090073 for expected_item, value in params.items():
74 self.assertEqual(value, body[expected_item])
75
Chris Hoge7579c1a2015-02-26 14:12:15 -080076 @test.idempotent_id('470e0b89-386f-407b-91fd-819737d0b335')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090077 def test_delete_agent(self):
Benny Kopilovc1daa122016-09-26 14:19:50 +030078 # Create an agent and delete it.
79 body = self.client.create_agent(**self.params_agent)['agent']
80 self.client.delete_agent(body['agent_id'])
Yuiko Takada420f2eb2014-04-02 19:53:38 +090081
82 # Verify the list doesn't contain the deleted agent.
ghanshyam5805ccc2015-08-04 14:06:20 +090083 agents = self.client.list_agents()['agents']
Benny Kopilovc1daa122016-09-26 14:19:50 +030084 self.assertNotIn(body['agent_id'], map(lambda x: x['agent_id'],
85 agents))
Yuiko Takada420f2eb2014-04-02 19:53:38 +090086
Chris Hoge7579c1a2015-02-26 14:12:15 -080087 @test.idempotent_id('6a326c69-654b-438a-80a3-34bcc454e138')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090088 def test_list_agents(self):
Benny Kopilovc1daa122016-09-26 14:19:50 +030089 # Create an agent and list all agents.
90 body = self.client.create_agent(**self.params_agent)['agent']
91 self.addCleanup(self.client.delete_agent, body['agent_id'])
ghanshyam5805ccc2015-08-04 14:06:20 +090092 agents = self.client.list_agents()['agents']
Béla Vancsics64862f72016-11-08 09:12:31 +010093 self.assertGreater(len(agents), 0,
94 'Cannot get any agents.(%s)' % agents)
Benny Kopilovc1daa122016-09-26 14:19:50 +030095 self.assertIn(body['agent_id'], map(lambda x: x['agent_id'], agents))
Yuiko Takada420f2eb2014-04-02 19:53:38 +090096
Chris Hoge7579c1a2015-02-26 14:12:15 -080097 @test.idempotent_id('eabadde4-3cd7-4ec4-a4b5-5a936d2d4408')
Yuiko Takada420f2eb2014-04-02 19:53:38 +090098 def test_list_agents_with_filter(self):
Benny Kopilovc1daa122016-09-26 14:19:50 +030099 # Create agents and list the agent builds by the filter.
100 body = self.client.create_agent(**self.params_agent)['agent']
101 self.addCleanup(self.client.delete_agent, body['agent_id'])
Yuiko Takada420f2eb2014-04-02 19:53:38 +0900102 params = self._param_helper(
103 hypervisor='xen', os='linux', architecture='x86',
104 version='7.0', url='xxx://xxxx/xxx/xxx1',
105 md5hash='add6bb58e139be103324d04d82d8f546')
ghanshyam5805ccc2015-08-04 14:06:20 +0900106 agent_xen = self.client.create_agent(**params)['agent']
Yuiko Takada420f2eb2014-04-02 19:53:38 +0900107 self.addCleanup(self.client.delete_agent, agent_xen['agent_id'])
108
109 agent_id_xen = agent_xen['agent_id']
ghanshyam5805ccc2015-08-04 14:06:20 +0900110 agents = (self.client.list_agents(hypervisor=agent_xen['hypervisor'])
111 ['agents'])
Béla Vancsics64862f72016-11-08 09:12:31 +0100112 self.assertGreater(len(agents), 0,
113 'Cannot get any agents.(%s)' % agents)
Yuiko Takada420f2eb2014-04-02 19:53:38 +0900114 self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents))
Benny Kopilovc1daa122016-09-26 14:19:50 +0300115 self.assertNotIn(body['agent_id'], map(lambda x: x['agent_id'],
116 agents))