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 |
| 16 | from tempest.common.utils import data_utils |
| 17 | from tempest import exceptions |
| 18 | from tempest.openstack.common import log |
| 19 | from tempest import test |
| 20 | |
| 21 | LOG = log.getLogger(__name__) |
| 22 | |
| 23 | |
| 24 | class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest): |
| 25 | """ |
| 26 | Tests Agents API |
| 27 | """ |
| 28 | |
| 29 | @classmethod |
Andrea Frittoli | 50bb80d | 2014-09-15 12:34:27 +0100 | [diff] [blame] | 30 | def resource_setup(cls): |
| 31 | super(AgentsAdminTestJSON, cls).resource_setup() |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 32 | cls.client = cls.os_adm.agents_client |
| 33 | |
| 34 | def setUp(self): |
| 35 | super(AgentsAdminTestJSON, self).setUp() |
| 36 | params = self._param_helper( |
| 37 | hypervisor='common', os='linux', architecture='x86_64', |
| 38 | version='7.0', url='xxx://xxxx/xxx/xxx', |
| 39 | md5hash='add6bb58e139be103324d04d82d8f545') |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 40 | body = self.client.create_agent(**params) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 41 | self.agent_id = body['agent_id'] |
| 42 | |
| 43 | def tearDown(self): |
| 44 | try: |
| 45 | self.client.delete_agent(self.agent_id) |
| 46 | except exceptions.NotFound: |
| 47 | pass |
| 48 | except Exception: |
| 49 | LOG.exception('Exception raised deleting agent %s', self.agent_id) |
| 50 | super(AgentsAdminTestJSON, self).tearDown() |
| 51 | |
| 52 | def _param_helper(self, **kwargs): |
| 53 | rand_key = 'architecture' |
| 54 | if rand_key in kwargs: |
| 55 | # NOTE: The rand_name is for avoiding agent conflicts. |
| 56 | # If you try to create an agent with the same hypervisor, |
| 57 | # os and architecture as an exising agent, Nova will return |
| 58 | # an HTTPConflict or HTTPServerError. |
| 59 | kwargs[rand_key] = data_utils.rand_name(kwargs[rand_key]) |
| 60 | return kwargs |
| 61 | |
| 62 | @test.attr(type='gate') |
| 63 | def test_create_agent(self): |
| 64 | # Create an agent. |
| 65 | params = self._param_helper( |
| 66 | hypervisor='kvm', os='win', architecture='x86', |
| 67 | version='7.0', url='xxx://xxxx/xxx/xxx', |
| 68 | md5hash='add6bb58e139be103324d04d82d8f545') |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 69 | body = self.client.create_agent(**params) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 70 | self.addCleanup(self.client.delete_agent, body['agent_id']) |
| 71 | for expected_item, value in params.items(): |
| 72 | self.assertEqual(value, body[expected_item]) |
| 73 | |
| 74 | @test.attr(type='gate') |
| 75 | def test_update_agent(self): |
| 76 | # Update an agent. |
| 77 | params = self._param_helper( |
| 78 | version='8.0', url='xxx://xxxx/xxx/xxx2', |
| 79 | md5hash='add6bb58e139be103324d04d82d8f547') |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 80 | body = self.client.update_agent(self.agent_id, **params) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 81 | for expected_item, value in params.items(): |
| 82 | self.assertEqual(value, body[expected_item]) |
| 83 | |
| 84 | @test.attr(type='gate') |
| 85 | def test_delete_agent(self): |
| 86 | # Delete an agent. |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 87 | self.client.delete_agent(self.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. |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 90 | agents = self.client.list_agents() |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 91 | self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents)) |
| 92 | |
| 93 | @test.attr(type='gate') |
| 94 | def test_list_agents(self): |
| 95 | # List all agents. |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 96 | agents = self.client.list_agents() |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 97 | self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents) |
| 98 | self.assertIn(self.agent_id, map(lambda x: x['agent_id'], agents)) |
| 99 | |
| 100 | @test.attr(type='gate') |
| 101 | def test_list_agents_with_filter(self): |
| 102 | # List the agent builds by the filter. |
| 103 | params = self._param_helper( |
| 104 | hypervisor='xen', os='linux', architecture='x86', |
| 105 | version='7.0', url='xxx://xxxx/xxx/xxx1', |
| 106 | md5hash='add6bb58e139be103324d04d82d8f546') |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 107 | agent_xen = self.client.create_agent(**params) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 108 | self.addCleanup(self.client.delete_agent, agent_xen['agent_id']) |
| 109 | |
| 110 | agent_id_xen = agent_xen['agent_id'] |
| 111 | params_filter = {'hypervisor': agent_xen['hypervisor']} |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 112 | agents = self.client.list_agents(params_filter) |
Yuiko Takada | 420f2eb | 2014-04-02 19:53:38 +0900 | [diff] [blame] | 113 | self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents) |
| 114 | self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents)) |
| 115 | self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents)) |