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 | |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 15 | from tempest_lib.common.utils import data_utils |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 16 | from tempest_lib import exceptions as lib_exc |
| 17 | |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 18 | from tempest.api.compute import base |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 19 | from tempest.openstack.common import log |
| 20 | from tempest import test |
| 21 | |
| 22 | LOG = log.getLogger(__name__) |
| 23 | |
| 24 | |
| 25 | class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest): |
| 26 | """ |
| 27 | Tests Agents API |
| 28 | """ |
| 29 | |
| 30 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 31 | def setup_clients(cls): |
| 32 | super(AgentsAdminTestJSON, cls).setup_clients() |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 33 | cls.client = cls.os_adm.agents_client |
| 34 | |
| 35 | def setUp(self): |
| 36 | super(AgentsAdminTestJSON, self).setUp() |
| 37 | params = self._param_helper( |
| 38 | hypervisor='common', os='linux', architecture='x86_64', |
| 39 | version='7.0', url='xxx://xxxx/xxx/xxx', |
| 40 | md5hash='add6bb58e139be103324d04d82d8f545') |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 41 | body = self.client.create_agent(**params) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 42 | self.agent_id = body['agent_id'] |
| 43 | |
| 44 | def tearDown(self): |
| 45 | try: |
| 46 | self.client.delete_agent(self.agent_id) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 47 | except lib_exc.NotFound: |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 48 | pass |
| 49 | except Exception: |
| 50 | LOG.exception('Exception raised deleting agent %s', self.agent_id) |
| 51 | super(AgentsAdminTestJSON, self).tearDown() |
| 52 | |
| 53 | def _param_helper(self, **kwargs): |
| 54 | rand_key = 'architecture' |
| 55 | if rand_key in kwargs: |
| 56 | # NOTE: The rand_name is for avoiding agent conflicts. |
| 57 | # If you try to create an agent with the same hypervisor, |
| 58 | # os and architecture as an exising agent, Nova will return |
| 59 | # an HTTPConflict or HTTPServerError. |
| 60 | kwargs[rand_key] = data_utils.rand_name(kwargs[rand_key]) |
| 61 | return kwargs |
| 62 | |
| 63 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 64 | @test.idempotent_id('1fc6bdc8-0b6d-4cc7-9f30-9b04fabe5b90') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 65 | def test_create_agent(self): |
| 66 | # Create an agent. |
| 67 | params = self._param_helper( |
| 68 | hypervisor='kvm', os='win', architecture='x86', |
| 69 | version='7.0', url='xxx://xxxx/xxx/xxx', |
| 70 | md5hash='add6bb58e139be103324d04d82d8f545') |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 71 | body = self.client.create_agent(**params) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 72 | self.addCleanup(self.client.delete_agent, body['agent_id']) |
| 73 | for expected_item, value in params.items(): |
| 74 | self.assertEqual(value, body[expected_item]) |
| 75 | |
| 76 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 77 | @test.idempotent_id('dc9ffd51-1c50-4f0e-a820-ae6d2a568a9e') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 78 | def test_update_agent(self): |
| 79 | # Update an agent. |
| 80 | params = self._param_helper( |
| 81 | version='8.0', url='xxx://xxxx/xxx/xxx2', |
| 82 | md5hash='add6bb58e139be103324d04d82d8f547') |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 83 | body = self.client.update_agent(self.agent_id, **params) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 84 | for expected_item, value in params.items(): |
| 85 | self.assertEqual(value, body[expected_item]) |
| 86 | |
| 87 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 88 | @test.idempotent_id('470e0b89-386f-407b-91fd-819737d0b335') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 89 | def test_delete_agent(self): |
| 90 | # Delete an agent. |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 91 | self.client.delete_agent(self.agent_id) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 92 | |
| 93 | # Verify the list doesn't contain the deleted agent. |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 94 | agents = self.client.list_agents() |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 95 | self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents)) |
| 96 | |
| 97 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 98 | @test.idempotent_id('6a326c69-654b-438a-80a3-34bcc454e138') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 99 | def test_list_agents(self): |
| 100 | # List all agents. |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 101 | agents = self.client.list_agents() |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 102 | self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents) |
| 103 | self.assertIn(self.agent_id, map(lambda x: x['agent_id'], agents)) |
| 104 | |
| 105 | @test.attr(type='gate') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 106 | @test.idempotent_id('eabadde4-3cd7-4ec4-a4b5-5a936d2d4408') |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 107 | def test_list_agents_with_filter(self): |
| 108 | # List the agent builds by the filter. |
| 109 | params = self._param_helper( |
| 110 | hypervisor='xen', os='linux', architecture='x86', |
| 111 | version='7.0', url='xxx://xxxx/xxx/xxx1', |
| 112 | md5hash='add6bb58e139be103324d04d82d8f546') |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 113 | agent_xen = self.client.create_agent(**params) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 114 | self.addCleanup(self.client.delete_agent, agent_xen['agent_id']) |
| 115 | |
| 116 | agent_id_xen = agent_xen['agent_id'] |
| 117 | params_filter = {'hypervisor': agent_xen['hypervisor']} |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 118 | agents = self.client.list_agents(params_filter) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 119 | self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents) |
| 120 | self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents)) |
| 121 | self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents)) |