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 | |
| 15 | from tempest.api.compute import base |
Stephen Finucane | 39fa9c1 | 2020-09-03 17:47:19 +0100 | [diff] [blame] | 16 | from tempest import config |
Ken'ichi Ohmichi | 757833a | 2017-03-10 10:30:30 -0800 | [diff] [blame] | 17 | from tempest.lib.common.utils import data_utils |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 18 | from tempest.lib import decorators |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 19 | |
Stephen Finucane | 39fa9c1 | 2020-09-03 17:47:19 +0100 | [diff] [blame] | 20 | CONF = config.CONF |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 21 | |
Stephen Finucane | 39fa9c1 | 2020-09-03 17:47:19 +0100 | [diff] [blame] | 22 | |
| 23 | # TODO(stephenfin): Remove these tests once the nova Ussuri branch goes EOL |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 24 | class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest): |
zhufl | 4e726a6 | 2020-08-10 16:30:28 +0800 | [diff] [blame] | 25 | """Tests Compute Agents API""" |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 26 | |
| 27 | @classmethod |
Stephen Finucane | 39fa9c1 | 2020-09-03 17:47:19 +0100 | [diff] [blame] | 28 | def skip_checks(cls): |
| 29 | super(AgentsAdminTestJSON, cls).skip_checks() |
| 30 | if not CONF.compute_feature_enabled.xenapi_apis: |
| 31 | raise cls.skipException('The os-agents API is not supported.') |
| 32 | |
| 33 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 34 | def setup_clients(cls): |
| 35 | super(AgentsAdminTestJSON, cls).setup_clients() |
Jordan Pittier | 8160d31 | 2017-04-18 11:52:23 +0200 | [diff] [blame] | 36 | cls.client = cls.os_admin.agents_client |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 37 | |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 38 | @classmethod |
| 39 | def resource_setup(cls): |
| 40 | super(AgentsAdminTestJSON, cls).resource_setup() |
| 41 | cls.params_agent = cls._param_helper( |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 42 | hypervisor='common', os='linux', architecture='x86_64', |
| 43 | version='7.0', url='xxx://xxxx/xxx/xxx', |
| 44 | md5hash='add6bb58e139be103324d04d82d8f545') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 45 | |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 46 | @staticmethod |
| 47 | def _param_helper(**kwargs): |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 48 | rand_key = 'architecture' |
| 49 | if rand_key in kwargs: |
| 50 | # NOTE: The rand_name is for avoiding agent conflicts. |
| 51 | # If you try to create an agent with the same hypervisor, |
Felix Li | 6aebd7e | 2016-01-04 10:11:04 -0500 | [diff] [blame] | 52 | # os and architecture as an existing agent, Nova will return |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 53 | # an HTTPConflict or HTTPServerError. |
| 54 | kwargs[rand_key] = data_utils.rand_name(kwargs[rand_key]) |
| 55 | return kwargs |
| 56 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 57 | @decorators.idempotent_id('1fc6bdc8-0b6d-4cc7-9f30-9b04fabe5b90') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 58 | def test_create_agent(self): |
zhufl | 4e726a6 | 2020-08-10 16:30:28 +0800 | [diff] [blame] | 59 | """Test creating a compute agent""" |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 60 | params = self._param_helper( |
| 61 | hypervisor='kvm', os='win', architecture='x86', |
| 62 | version='7.0', url='xxx://xxxx/xxx/xxx', |
| 63 | md5hash='add6bb58e139be103324d04d82d8f545') |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 64 | body = self.client.create_agent(**params)['agent'] |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 65 | self.addCleanup(self.client.delete_agent, body['agent_id']) |
| 66 | for expected_item, value in params.items(): |
| 67 | self.assertEqual(value, body[expected_item]) |
| 68 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 69 | @decorators.idempotent_id('dc9ffd51-1c50-4f0e-a820-ae6d2a568a9e') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 70 | def test_update_agent(self): |
zhufl | 4e726a6 | 2020-08-10 16:30:28 +0800 | [diff] [blame] | 71 | """Test updating a compute agent""" |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 72 | # Create and update an agent. |
| 73 | body = self.client.create_agent(**self.params_agent)['agent'] |
| 74 | self.addCleanup(self.client.delete_agent, body['agent_id']) |
| 75 | agent_id = body['agent_id'] |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 76 | params = self._param_helper( |
| 77 | version='8.0', url='xxx://xxxx/xxx/xxx2', |
| 78 | md5hash='add6bb58e139be103324d04d82d8f547') |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 79 | body = self.client.update_agent(agent_id, **params)['agent'] |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 80 | for expected_item, value in params.items(): |
| 81 | self.assertEqual(value, body[expected_item]) |
| 82 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 83 | @decorators.idempotent_id('470e0b89-386f-407b-91fd-819737d0b335') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 84 | def test_delete_agent(self): |
zhufl | 4e726a6 | 2020-08-10 16:30:28 +0800 | [diff] [blame] | 85 | """Test deleting a compute agent""" |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 86 | body = self.client.create_agent(**self.params_agent)['agent'] |
| 87 | self.client.delete_agent(body['agent_id']) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 88 | |
| 89 | # Verify the list doesn't contain the deleted agent. |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 90 | agents = self.client.list_agents()['agents'] |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 91 | self.assertNotIn(body['agent_id'], map(lambda x: x['agent_id'], |
| 92 | agents)) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 93 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 94 | @decorators.idempotent_id('6a326c69-654b-438a-80a3-34bcc454e138') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 95 | def test_list_agents(self): |
zhufl | 4e726a6 | 2020-08-10 16:30:28 +0800 | [diff] [blame] | 96 | """Test listing compute agents""" |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 97 | body = self.client.create_agent(**self.params_agent)['agent'] |
| 98 | self.addCleanup(self.client.delete_agent, body['agent_id']) |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 99 | agents = self.client.list_agents()['agents'] |
zhufl | cfa1cd5 | 2017-08-10 10:23:01 +0800 | [diff] [blame] | 100 | self.assertNotEmpty(agents, 'Cannot get any agents.') |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 101 | self.assertIn(body['agent_id'], map(lambda x: x['agent_id'], agents)) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 102 | |
Ken'ichi Ohmichi | ebbfd1c | 2017-01-27 16:37:00 -0800 | [diff] [blame] | 103 | @decorators.idempotent_id('eabadde4-3cd7-4ec4-a4b5-5a936d2d4408') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 104 | def test_list_agents_with_filter(self): |
zhufl | 4e726a6 | 2020-08-10 16:30:28 +0800 | [diff] [blame] | 105 | """Test listing compute agents by the filter""" |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 106 | body = self.client.create_agent(**self.params_agent)['agent'] |
| 107 | self.addCleanup(self.client.delete_agent, body['agent_id']) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 108 | params = self._param_helper( |
| 109 | hypervisor='xen', os='linux', architecture='x86', |
| 110 | version='7.0', url='xxx://xxxx/xxx/xxx1', |
| 111 | md5hash='add6bb58e139be103324d04d82d8f546') |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 112 | agent_xen = self.client.create_agent(**params)['agent'] |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 113 | self.addCleanup(self.client.delete_agent, agent_xen['agent_id']) |
| 114 | |
| 115 | agent_id_xen = agent_xen['agent_id'] |
ghanshyam | 5805ccc | 2015-08-04 14:06:20 +0900 | [diff] [blame] | 116 | agents = (self.client.list_agents(hypervisor=agent_xen['hypervisor']) |
| 117 | ['agents']) |
zhufl | cfa1cd5 | 2017-08-10 10:23:01 +0800 | [diff] [blame] | 118 | self.assertNotEmpty(agents, 'Cannot get any agents.') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 119 | self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents)) |
Benny Kopilov | c1daa12 | 2016-09-26 14:19:50 +0300 | [diff] [blame] | 120 | self.assertNotIn(body['agent_id'], map(lambda x: x['agent_id'], |
| 121 | agents)) |