blob: b28b9e0ecf061ead5c0545f1257911c1f8f647ac [file] [log] [blame]
Yuiko Takada420f2eb2014-04-02 19:53:38 +09001# 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
Masayuki Igawabfa07602015-01-20 18:47:17 +090015from tempest_lib import exceptions as lib_exc
16
Yuiko Takada420f2eb2014-04-02 19:53:38 +090017from tempest.api.compute import base
18from tempest.common.utils import data_utils
Yuiko Takada420f2eb2014-04-02 19:53:38 +090019from tempest.openstack.common import log
20from tempest import test
21
22LOG = log.getLogger(__name__)
23
24
25class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest):
26 """
27 Tests Agents API
28 """
29
30 @classmethod
Andrea Frittoli50bb80d2014-09-15 12:34:27 +010031 def resource_setup(cls):
32 super(AgentsAdminTestJSON, cls).resource_setup()
Yuiko Takada420f2eb2014-04-02 19:53:38 +090033 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 Kranz0a735172015-01-16 10:51:18 -050041 body = self.client.create_agent(**params)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090042 self.agent_id = body['agent_id']
43
44 def tearDown(self):
45 try:
46 self.client.delete_agent(self.agent_id)
Masayuki Igawabfa07602015-01-20 18:47:17 +090047 except lib_exc.NotFound:
Yuiko Takada420f2eb2014-04-02 19:53:38 +090048 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')
64 def test_create_agent(self):
65 # Create an agent.
66 params = self._param_helper(
67 hypervisor='kvm', os='win', architecture='x86',
68 version='7.0', url='xxx://xxxx/xxx/xxx',
69 md5hash='add6bb58e139be103324d04d82d8f545')
David Kranz0a735172015-01-16 10:51:18 -050070 body = self.client.create_agent(**params)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090071 self.addCleanup(self.client.delete_agent, body['agent_id'])
72 for expected_item, value in params.items():
73 self.assertEqual(value, body[expected_item])
74
75 @test.attr(type='gate')
76 def test_update_agent(self):
77 # Update an agent.
78 params = self._param_helper(
79 version='8.0', url='xxx://xxxx/xxx/xxx2',
80 md5hash='add6bb58e139be103324d04d82d8f547')
David Kranz0a735172015-01-16 10:51:18 -050081 body = self.client.update_agent(self.agent_id, **params)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090082 for expected_item, value in params.items():
83 self.assertEqual(value, body[expected_item])
84
85 @test.attr(type='gate')
86 def test_delete_agent(self):
87 # Delete an agent.
David Kranz0a735172015-01-16 10:51:18 -050088 self.client.delete_agent(self.agent_id)
Yuiko Takada420f2eb2014-04-02 19:53:38 +090089
90 # Verify the list doesn't contain the deleted agent.
David Kranz0a735172015-01-16 10:51:18 -050091 agents = self.client.list_agents()
Yuiko Takada420f2eb2014-04-02 19:53:38 +090092 self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents))
93
94 @test.attr(type='gate')
95 def test_list_agents(self):
96 # List all agents.
David Kranz0a735172015-01-16 10:51:18 -050097 agents = self.client.list_agents()
Yuiko Takada420f2eb2014-04-02 19:53:38 +090098 self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents)
99 self.assertIn(self.agent_id, map(lambda x: x['agent_id'], agents))
100
101 @test.attr(type='gate')
102 def test_list_agents_with_filter(self):
103 # List the agent builds by the filter.
104 params = self._param_helper(
105 hypervisor='xen', os='linux', architecture='x86',
106 version='7.0', url='xxx://xxxx/xxx/xxx1',
107 md5hash='add6bb58e139be103324d04d82d8f546')
David Kranz0a735172015-01-16 10:51:18 -0500108 agent_xen = self.client.create_agent(**params)
Yuiko Takada420f2eb2014-04-02 19:53:38 +0900109 self.addCleanup(self.client.delete_agent, agent_xen['agent_id'])
110
111 agent_id_xen = agent_xen['agent_id']
112 params_filter = {'hypervisor': agent_xen['hypervisor']}
David Kranz0a735172015-01-16 10:51:18 -0500113 agents = self.client.list_agents(params_filter)
Yuiko Takada420f2eb2014-04-02 19:53:38 +0900114 self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents)
115 self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents))
116 self.assertNotIn(self.agent_id, map(lambda x: x['agent_id'], agents))