Debian Codegraph @

ironic_tempest_plugin/tests/api/admin/test_shards.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from tempest import config
14 from tempest.lib import decorators
15
16 from ironic_tempest_plugin.tests.api import base
17
18
19 CONF = config.CONF
20
21
22 class TestAddShardsToNode(base.BaseBaremetalTest):
23 """Tests for baremetal shards."""
24
25 min_microversion = '1.82'
26
27 def setUp(self):
28 super(TestAddShardsToNode, self).setUp()
29 # set a minimum API version
30 _, self.chassis = self.create_chassis()
31
32 @decorators.idempotent_id('6f1e241d-4386-4730-b9ff-28c6a3dcad31')
33 def test_add_shard_to_node_at_create(self):
34 shard = 'at-create'
35
36 _, body = self.create_node(self.chassis['uuid'], shard=shard)
37 self.assertEqual(shard, body['shard'])
38
39 @decorators.idempotent_id('2eb91d29-e0a5-472b-aeb8-ef6d98eb0f3c')
40 def test_add_shard_to_node_post_create(self):
41 shard = 'post-create'
42
43 _, node = self.create_node(self.chassis['uuid'])
44 _, before = self.client.show_node(node['uuid'])
45 self.assertIsNone(before['shard'])
46
47 self.client.update_node(node['uuid'], shard=shard)
48
49 _, after = self.client.show_node(node['uuid'])
50 self.assertEqual(shard, after['shard'])
51
52
53 class TestNodeShardQueries(base.BaseBaremetalTest):
54 """Tests for baremetal shards."""
55
56 min_microversion = '1.82'
57
58 def setUp(self):
59 super(TestNodeShardQueries, self).setUp()
60 _, self.chassis = self.create_chassis()
61 _, bad_node = self.create_node(self.chassis['uuid'], shard='bad')
62 _, none_node = self.create_node(self.chassis['uuid']) # shard=None
63 self.bad_node_id = bad_node['uuid']
64 self.none_node_id = none_node['uuid']
65
66 def _setup_nodes(self, good_shard, num=2):
67 good_node_ids = []
68 for i in range(num):
69 _, node = self.create_node(self.chassis['uuid'], shard=good_shard)
70 good_node_ids.append(node['uuid'])
71
72 return good_node_ids
73
74 @decorators.idempotent_id('df74c989-6972-4104-a8d6-bd8e8d811353')
75 def test_show_all_nodes(self):
76 """Validate unfiltered API query will return nodes with a shard."""
77 shard = "oneshardtest"
78 good_node_ids = self._setup_nodes(shard)
79
80 _, fetched_nodes = self.client.list_nodes()
81 fetched_node_ids = [node['uuid'] for node in fetched_nodes['nodes']]
82
83 for node_id in good_node_ids:
84 self.assertIn(node_id, fetched_node_ids)
85
86 @decorators.idempotent_id('6f1e241d-4386-4730-b9ff-28c6a3dcad31')
87 def test_only_show_requested_shard(self):
88 """Validate filtering nodes by shard."""
89 shard = "oneshardtest"
90 good_node_ids = self._setup_nodes(shard)
91
92 _, fetched_nodes = self.client.list_nodes(shard=shard)
93 fetched_node_ids = [node['uuid'] for node in fetched_nodes['nodes']]
94
95 self.assertCountEqual(good_node_ids, fetched_node_ids)
96
97 @decorators.idempotent_id('6f1e241d-4386-4730-b9ff-28c6a3dcad31')
98 def test_only_show_multiple_requested_shards(self):
99 """Validate filtering nodes by multiple shards."""
100 shard = "multishardtest"
101 second_shard = "multishardtest2"
102 good_node_ids = self._setup_nodes(shard)
103 _, second_shard_node = self.create_node(
104 self.chassis['uuid'], shard=second_shard)
105 good_node_ids.append(second_shard_node['uuid'])
106
107 _, fetched_nodes = self.client.list_nodes(
108 shard=','.join([shard, second_shard]))
109 fetched_node_ids = [node['uuid'] for node in fetched_nodes['nodes']]
110
111 self.assertCountEqual(good_node_ids, fetched_node_ids)
112 self.assertNotIn(self.bad_node_id, fetched_node_ids)
113 self.assertNotIn(self.none_node_id, fetched_node_ids)
114
115 @decorators.idempotent_id('f7a2eeb7-d16e-480c-b698-3448491c73a1')
116 def test_show_sharded_nodes(self):
117 _, fetched_nodes = self.client.list_nodes(sharded=True)
118 fetched_node_ids = [node['uuid'] for node in fetched_nodes['nodes']]
119
120 # NOTE(JayF): All other nodes under test are sharded
121 self.assertNotIn(self.none_node_id, fetched_node_ids)
122
123 @decorators.idempotent_id('f7a2eeb7-d16e-480c-b698-3448491c73a1')
124 def test_show_unsharded_nodes(self):
125 _, fetched_nodes = self.client.list_nodes(sharded=False)
126 fetched_node_ids = [node['uuid'] for node in fetched_nodes['nodes']]
127
128 self.assertIn(self.none_node_id, fetched_node_ids)
129 self.assertNotIn(self.bad_node_id, fetched_node_ids)
130
131
132 class TestGetAllShards(base.BaseBaremetalTest):
133 """Tests for baremetal shards."""
134
135 min_microversion = '1.82'
136
137 def setUp(self):
138 super(TestGetAllShards, self).setUp()
139 _, self.chassis = self.create_chassis()
140 self.shards = {"shard1", "shard2", "shard3"}
141 self.node_ids = []
142 for shard in self.shards:
143 _, node = self.create_node(self.chassis['uuid'], shard=shard)
144 self.node_ids.append(node['uuid'])
145
146 @decorators.idempotent_id('fc786196-63c7-4e0d-bd14-3e478d4d1e3e')
147 def test_get_all_shards(self):
148 _, fetched_shards = self.client.get_shards()
149 fetched_shards = {shard['name'] for shard in fetched_shards['shards']}
150
151 self.assertTrue(self.shards.issubset(fetched_shards))