Allow tuple as for nics value
`novaclient.servers.boot` accepts 'nics' argument with information about network interfaces to attach. Originally, it accepts a list or a string. In case if a list value, the proper method iterates over it for processing and constructs a right structure for Nova-API. A tuple type is similar to a list type in the processing method and can look more logical for some developers (a tuple is a sequence of immutable python object, which can be ideal for predefined nics) and doensn't require anything to change in code except one validation check. Also, this patch adds more info in the error message for validation step. Change-Id: Ief9d22fefb0a64afc346c56e832c6c0b2b3d8fcb
This commit is contained in:
1 parent
f72e80c054
commit
ec15bf30e7
2 files changed
+17
-4
No files matched your search
@@ -223,7 +223,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
def test_create_server_boot_with_nics_ipv6(self):
|
||||
old_boot = self.cs.servers._boot
|
||||
nics = [{'net-id': '11111111-1111-1111-1111-111111111111',
|
||||
'v6-fixed-ip': '2001:db9:0:1::10'}]
|
||||
'v6-fixed-ip': '2001:db9:0:1::10'}]
|
||||
|
||||
def wrapped_boot(url, key, *boot_args, **boot_kwargs):
|
||||
self.assertEqual(boot_kwargs['nics'], nics)
|
||||
@@ -963,7 +963,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
self.assert_called('POST', '/servers/1234/action')
|
||||
ret = self.cs.servers.evacuate(s, 'fake_target_host',
|
||||
'False', 'NewAdminPassword')
|
||||
'False', 'NewAdminPassword')
|
||||
self.assert_request_id(ret, fakes.FAKE_REQUEST_ID_LIST)
|
||||
self.assert_called('POST', '/servers/1234/action')
|
||||
|
||||
@@ -1034,6 +1034,18 @@ class ServersTest(utils.FixturedTestCase):
|
||||
flavor='1',
|
||||
nics='auto')
|
||||
|
||||
def test__validate_create_nics(self):
|
||||
if self.cs.api_version > api_versions.APIVersion('2.36'):
|
||||
self.assertRaises(ValueError,
|
||||
self.cs.servers._validate_create_nics, None)
|
||||
else:
|
||||
self.cs.servers._validate_create_nics(None)
|
||||
self.assertRaises(ValueError,
|
||||
self.cs.servers._validate_create_nics,
|
||||
mock.Mock())
|
||||
self.cs.servers._validate_create_nics(["foo", "bar"])
|
||||
self.cs.servers._validate_create_nics(("foo", "bar"))
|
||||
|
||||
|
||||
class ServersV26Test(ServersTest):
|
||||
|
||||
|
||||
@@ -1273,8 +1273,9 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
if self.api_version > api_versions.APIVersion('2.36'):
|
||||
if not nics:
|
||||
raise ValueError('nics are required after microversion 2.36')
|
||||
elif nics and not isinstance(nics, list):
|
||||
raise ValueError('nics must be a list')
|
||||
elif nics and not isinstance(nics, (list, tuple)):
|
||||
raise ValueError('nics must be a list or a tuple, not %s' %
|
||||
type(nics))
|
||||
|
||||
def create(self, name, image, flavor, meta=None, files=None,
|
||||
reservation_id=None, min_count=None,
|
||||
|
||||
Reference in new issue
Block a user