Allow passing negative values for the locked search_opt in cs.servers.list

This patch adds support for novaclient to pass the "locked" search_opts
with a "False" value upto the server side. This is required for the OSC
change[1] to support the "unlocked" filter parameter.

[1] https://review.opendev.org/#/c/659124/

Related to blueprint add-locked-reason

Change-Id: I0907f4ad2decb308c9db8b0cf9e7962bf1b517b5
This commit is contained in:
Surya Seetharaman
2019-05-17 14:04:17 +02:00
committed by Matt Riedemann
parent f0388977c1
commit f78a4706d3
2 changed files with 24 additions and 2 deletions

View File

@@ -76,6 +76,15 @@ class ServersTest(utils.FixturedTestCase):
for s in sl:
self.assertIsInstance(s, servers.Server)
def test_filter_servers_unlocked(self):
# calling the cs.servers.list python binding
# will fail before 2.73 microversion.
e = self.assertRaises(exceptions.UnsupportedAttribute,
self.cs.servers.list,
search_opts={'locked': False})
self.assertIn("'locked' argument is only allowed since "
"microversion 2.73.", six.text_type(e))
def test_list_servers_undetailed(self):
sl = self.cs.servers.list(detailed=False)
self.assert_request_id(sl, fakes.FAKE_REQUEST_ID_LIST)
@@ -1726,3 +1735,11 @@ class ServersV273Test(ServersV268Test):
e = self.assertRaises(TypeError,
s.lock, reason='blah')
self.assertIn("unexpected keyword argument 'reason'", six.text_type(e))
def test_filter_servers_unlocked(self):
# support locked=False
sl = self.cs.servers.list(search_opts={'locked': False})
self.assert_request_id(sl, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('GET', '/servers/detail?locked=False')
for s in sl:
self.assertIsInstance(s, servers.Server)

View File

@@ -862,9 +862,14 @@ class ServerManager(base.BootingManagerWithFind):
search_opts = {}
qparams = {}
# In microversion 2.73 we added ``locked`` filtering option
# for listing server details.
if ('locked' in search_opts and
self.api_version < api_versions.APIVersion('2.73')):
raise exceptions.UnsupportedAttribute("locked", "2.73")
for opt, val in search_opts.items():
if val:
# support locked=False from 2.73 microversion
if val or (opt == 'locked' and val is False):
if isinstance(val, six.text_type):
val = val.encode('utf-8')
qparams[opt] = val