Basic API tests for sharding

Validates:
- Filtering by a single shard
- Filtering by >1 shards
- Filtering by sharded nodes
- Filtering by unsharded nodes

Change-Id: Id37e8d6db098bb8decae87b6184bab4482321316
This commit is contained in:
Jay Faulkner 2024-01-25 10:04:51 -08:00
parent 53039461b0
commit 3ceeb84b23
1 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,105 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from tempest import config
from tempest.lib import decorators
from ironic_tempest_plugin.tests.api import base
CONF = config.CONF
class TestAddShardsToNode(base.BaseBaremetalTest):
"""Tests for baremetal shards."""
min_microversion = '1.82'
def setUp(self):
super(TestAddShardsToNode, self).setUp()
# set a minimum API version
_, self.chassis = self.create_chassis()
@decorators.idempotent_id('6f1e241d-4386-4730-b9ff-28c6a3dcad31')
def test_add_shard_to_node_at_create(self):
shard = 'at-create'
_, body = self.create_node(self.chassis['uuid'], shard=shard)
self.assertEqual(shard, body['shard'])
@decorators.idempotent_id('2eb91d29-e0a5-472b-aeb8-ef6d98eb0f3c')
def test_add_shard_to_node_post_create(self):
shard = 'post-create'
_, node = self.create_node(self.chassis['uuid'])
_, before = self.client.show_node(node['uuid'])
self.assertIsNone(before['shard'])
self.client.update_node(node['uuid'], {'shard': shard})
_, after = self.client.show_node(node['uuid'])
self.assertEqual(shard, after['shard'])
class TestNodeShardQueries(base.BaseBaremetalTest):
"""Tests for baremetal shards."""
min_microversion = '1.82'
def setUp(self):
super(TestNodeShardQueries, self).setUp()
_, self.chassis = self.create_chassis()
self.good_node_ids = []
self.good_shard = 'shard1'
for i in range(2):
_, node = self.create_node(self.chassis['uuid'], shard=self.good_shard)
self.good_node_ids.append(node['uuid'])
self.bad_shard = 'bad'
_, self.bad_node = self.create_node(self.chassis['uuid'], shard='bad')
_, self.none_node = self.create_node(self.chassis['uuid'], shard=None) # explicitly none
@decorators.idempotent_id('6f1e241d-4386-4730-b9ff-28c6a3dcad31')
def test_only_show_requested_shard(self):
"""Validate filtering nodes by shard."""
_, fetched_nodes = self.client.list_nodes(shard=self.good_shard)
fetched_node_ids = [node['uuid'] for node in fetched_nodes]
self.assertItemsEqual(self.good_node_ids, [fetched_node_ids])
@decorators.idempotent_id('6f1e241d-4386-4730-b9ff-28c6a3dcad31')
def test_only_show_multiple_requested_shards(self):
"""Validate filtering nodes by multiple shards."""
_, fetched_nodes = self.client.list_nodes(shard=[self.good_shard, self.bad_shard])
fetched_node_ids = [node['uuid'] for node in fetched_nodes['nodes']]
self.assertIn(self.good_node_ids, fetched_node_ids)
self.assertIn(self.bad_node['uuid'], fetched_node_ids)
self.assertNotIn(self.none_node['uuid'], fetched_node_ids)
@decorators.idempotent_id('f7a2eeb7-d16e-480c-b698-3448491c73a1')
def test_show_sharded_nodes(self):
_, fetched_nodes = self.client.list_nodes(sharded=True)
fetched_node_ids = [node['uuid'] for node in fetched_nodes['nodes']]
self.assertIn(self.good_node_ids, fetched_node_ids)
self.assertIn(self.bad_node['uuid'], fetched_node_ids)
self.assertNotIn(self.none_node['uuid'], fetched_node_ids)
@decorators.idempotent_id('f7a2eeb7-d16e-480c-b698-3448491c73a1')
def test_show_unsharded_nodes(self):
_, fetched_nodes = self.client.list_nodes(sharded=False)
fetched_node_ids = [node['uuid'] for node in fetched_nodes['nodes']]
self.assertIn(self.none_node['uuid'], fetched_node_ids)
self.assertNotIn(self.good_node_ids, fetched_node_ids)
self.assertNotIn(self.bad_node['uuid'], fetched_node_ids)