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