Merge "[baremetal] Ensure baremetal shard parameter gets passed"

This commit is contained in:
Zuul 2023-10-06 18:50:57 +00:00 committed by Gerrit Code Review
commit 42dbb4e503
3 changed files with 46 additions and 4 deletions

View File

@ -272,6 +272,7 @@ class Proxy(proxy.Proxy):
``provision_state``. ``provision_state``.
* ``resource_class``: Only return those with the specified * ``resource_class``: Only return those with the specified
``resource_class``. ``resource_class``.
* ``shard``: Only return nodes matching the supplied shard key.
* ``sort_dir``: Sorts the response by the requested sort direction. * ``sort_dir``: Sorts the response by the requested sort direction.
A valid value is ``asc`` (ascending) or ``desc`` A valid value is ``asc`` (ascending) or ``desc``
(descending). Default is ``asc``. You can specify multiple (descending). Default is ``asc``. You can specify multiple

View File

@ -93,6 +93,10 @@ FAKE = {
} }
def _fake_assert(self, session, action, expected, error_message=None):
return expected
class TestNode(base.TestCase): class TestNode(base.TestCase):
def test_basic(self): def test_basic(self):
sot = node.Node() sot = node.Node()
@ -154,6 +158,34 @@ class TestNode(base.TestCase):
sot = node.Node(**attrs) sot = node.Node(**attrs)
self.assertEqual('available', sot.provision_state) self.assertEqual('available', sot.provision_state)
@mock.patch.object(node.Node, '_assert_microversion_for', _fake_assert)
@mock.patch.object(exceptions, 'raise_from_response', mock.Mock())
def test_list(self):
self.node = node.Node()
self.session = mock.Mock(
spec=adapter.Adapter, default_microversion=None
)
# Set a default, so we don't try and figure out the microversions
# with additional requests.
self.session.default_microversion = float(self.node._max_microversion)
self.session.get.return_value.json.return_value = {'nodes': []}
result = list(
self.node.list(
self.session,
details=False,
shard='meow',
allow_unknown_params=True,
)
)
self.assertEqual(0, len(result))
self.session.get.assert_called_once_with(
'/nodes',
headers={'Accept': 'application/json'},
params={'shard': 'meow'},
microversion=float(self.node._max_microversion),
)
@mock.patch('time.sleep', lambda _t: None) @mock.patch('time.sleep', lambda _t: None)
@mock.patch.object(node.Node, 'fetch', autospec=True) @mock.patch.object(node.Node, 'fetch', autospec=True)
@ -245,10 +277,6 @@ class TestNodeWaitForProvisionState(base.TestCase):
) )
def _fake_assert(self, session, action, expected, error_message=None):
return expected
@mock.patch.object(node.Node, '_assert_microversion_for', _fake_assert) @mock.patch.object(node.Node, '_assert_microversion_for', _fake_assert)
@mock.patch.object(node.Node, 'fetch', lambda self, session: self) @mock.patch.object(node.Node, 'fetch', lambda self, session: self)
@mock.patch.object(exceptions, 'raise_from_response', mock.Mock()) @mock.patch.object(exceptions, 'raise_from_response', mock.Mock())

View File

@ -93,6 +93,19 @@ class TestNode(TestBaremetalProxy):
self.assertIs(result, mock_list.return_value) self.assertIs(result, mock_list.return_value)
mock_list.assert_called_once_with(self.proxy, details=False, query=1) mock_list.assert_called_once_with(self.proxy, details=False, query=1)
@mock.patch.object(node.Node, 'list')
def test_nodes_sharded(self, mock_list):
kwargs = {"shard": 'meow', "query": 1}
result = self.proxy.nodes(fields=("uuid", "instance_uuid"), **kwargs)
self.assertIs(result, mock_list.return_value)
mock_list.assert_called_once_with(
self.proxy,
details=False,
fields=('uuid', 'instance_uuid'),
shard='meow',
query=1,
)
def test_create_node(self): def test_create_node(self):
self.verify_create(self.proxy.create_node, node.Node) self.verify_create(self.proxy.create_node, node.Node)