summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSurya Seetharaman <suryaseetharaman.9@gmail.com>2019-05-17 14:04:17 +0200
committerMatt Riedemann <mriedem.os@gmail.com>2019-05-22 11:06:52 -0400
commitf78a4706d3522e64fd45daaf5e68c017c55c5240 (patch)
treea782cef9f235970eaf1ce69266e84e476494521c
parentf0388977c1cc557f4c7cb5bc73964ffdebe35016 (diff)
downloadpython-novaclient-f78a4706d3522e64fd45daaf5e68c017c55c5240.tar.gz
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
-rw-r--r--novaclient/tests/unit/v2/test_servers.py17
-rw-r--r--novaclient/v2/servers.py9
2 files changed, 24 insertions, 2 deletions
diff --git a/novaclient/tests/unit/v2/test_servers.py b/novaclient/tests/unit/v2/test_servers.py
index 43dbf2c2..5410f1b3 100644
--- a/novaclient/tests/unit/v2/test_servers.py
+++ b/novaclient/tests/unit/v2/test_servers.py
@@ -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)
diff --git a/novaclient/v2/servers.py b/novaclient/v2/servers.py
index afbd5536..e5a33fb6 100644
--- a/novaclient/v2/servers.py
+++ b/novaclient/v2/servers.py
@@ -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