Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 1 | # 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 Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 15 | from oslo_log import log |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 16 | |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 17 | from tempest.api.compute import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 18 | from tempest.common.utils import data_utils |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 19 | from tempest import test |
| 20 | |
| 21 | LOG = log.getLogger(__name__) |
| 22 | |
| 23 | |
| 24 | class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest): |
Ken'ichi Ohmichi | 88363cb | 2015-11-19 08:00:54 +0000 | [diff] [blame] | 25 | """Tests Agents API""" |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 26 | |
| 27 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 28 | def setup_clients(cls): |
| 29 | super(AgentsAdminTestJSON, cls).setup_clients() |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 30 | cls.client = cls.os_adm.agents_client |
| 31 | |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 32 | @classmethod |
| 33 | def resource_setup(cls): |
| 34 | super(AgentsAdminTestJSON, cls).resource_setup() |
| 35 | cls.params_agent = cls._param_helper( |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 36 | hypervisor='common', os='linux', architecture='x86_64', |
| 37 | version='7.0', url='xxx://xxxx/xxx/xxx', |
| 38 | md5hash='add6bb58e139be103324d04d82d8f545') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 39 | |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 40 | @staticmethod |
| 41 | def _param_helper(**kwargs): |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 42 | 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 Li | 6aebd7e | 2016-01-04 10:11:04 -0500 | [diff] [blame] | 46 | # os and architecture as an existing agent, Nova will return |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 47 | # an HTTPConflict or HTTPServerError. |
| 48 | kwargs[rand_key] = data_utils.rand_name(kwargs[rand_key]) |
| 49 | return kwargs |
| 50 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 51 | @test.idempotent_id('1fc6bdc8-0b6d-4cc7-9f30-9b04fabe5b90') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 52 | 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') |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 58 | body = self.client.create_agent(**params)['agent'] |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 59 | 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 Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 63 | @test.idempotent_id('dc9ffd51-1c50-4f0e-a820-ae6d2a568a9e') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 64 | def test_update_agent(self): |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 65 | # 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 Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 69 | params = self._param_helper( |
| 70 | version='8.0', url='xxx://xxxx/xxx/xxx2', |
| 71 | md5hash='add6bb58e139be103324d04d82d8f547') |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 72 | body = self.client.update_agent(agent_id, **params)['agent'] |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 73 | for expected_item, value in params.items(): |
| 74 | self.assertEqual(value, body[expected_item]) |
| 75 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 76 | @test.idempotent_id('470e0b89-386f-407b-91fd-819737d0b335') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 77 | def test_delete_agent(self): |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 78 | # 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 Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 81 | |
| 82 | # Verify the list doesn't contain the deleted agent. |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 83 | agents = self.client.list_agents()['agents'] |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 84 | self.assertNotIn(body['agent_id'], map(lambda x: x['agent_id'], |
| 85 | agents)) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 86 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 87 | @test.idempotent_id('6a326c69-654b-438a-80a3-34bcc454e138') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 88 | def test_list_agents(self): |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 89 | # 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']) |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 92 | agents = self.client.list_agents()['agents'] |
Béla Vancsics | 64862f7 | 2016-11-08 09:12:31 +0100 | [diff] [blame] | 93 | self.assertGreater(len(agents), 0, |
| 94 | 'Cannot get any agents.(%s)' % agents) |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 95 | self.assertIn(body['agent_id'], map(lambda x: x['agent_id'], agents)) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 96 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 97 | @test.idempotent_id('eabadde4-3cd7-4ec4-a4b5-5a936d2d4408') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 98 | def test_list_agents_with_filter(self): |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 99 | # 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 Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 102 | params = self._param_helper( |
| 103 | hypervisor='xen', os='linux', architecture='x86', |
| 104 | version='7.0', url='xxx://xxxx/xxx/xxx1', |
| 105 | md5hash='add6bb58e139be103324d04d82d8f546') |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 106 | agent_xen = self.client.create_agent(**params)['agent'] |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 107 | self.addCleanup(self.client.delete_agent, agent_xen['agent_id']) |
| 108 | |
| 109 | agent_id_xen = agent_xen['agent_id'] |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 110 | agents = (self.client.list_agents(hypervisor=agent_xen['hypervisor']) |
| 111 | ['agents']) |
Béla Vancsics | 64862f7 | 2016-11-08 09:12:31 +0100 | [diff] [blame] | 112 | self.assertGreater(len(agents), 0, |
| 113 | 'Cannot get any agents.(%s)' % agents) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 114 | self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents)) |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 115 | self.assertNotIn(body['agent_id'], map(lambda x: x['agent_id'], |
| 116 | agents)) |