Commit 0feb4ee0 authored by Christos Stavrakakis's avatar Christos Stavrakakis

cyclades: Do not pass 'hotplug' if disabled

Fix passing of hotplug argument to GanetiRAPIClient, in case the
GANETI_USE_HOTPLUG is unset. If the Ganeti version does not support
hotplug, passing hotplug=False, will make the jobs fail at Ganeti opcode
validation. This commit fixes this by passing the argument, only when
the setting is set to True.
parent 20eb5fee
......@@ -746,22 +746,34 @@ def connect_to_network(vm, network, address=None):
log.debug("Connecting vm %s to network %s(%s)", vm, network, address)
kwargs = {
"instance": vm.backend_vm_id,
"nics": [("add", nic)],
"depends": depends,
}
if vm.backend.use_hotplug():
kwargs["hotplug"] = True
if settings.TEST:
kwargs["dry_run"] = True
with pooled_rapi_client(vm) as client:
return client.ModifyInstance(vm.backend_vm_id, nics=[('add', nic)],
hotplug=vm.backend.use_hotplug(),
depends=depends,
dry_run=settings.TEST)
return client.ModifyInstance(**kwargs)
def disconnect_from_network(vm, nic):
op = [('remove', nic.index, {})]
log.debug("Removing nic of VM %s, with index %s", vm, str(nic.index))
kwargs = {
"instance": vm.backend_vm_id,
"nics": [("remove", nic.index, {})],
}
if vm.backend.use_hotplug():
kwargs["hotplug"] = True
if settings.TEST:
kwargs["dry_run"] = True
with pooled_rapi_client(vm) as client:
jobID = client.ModifyInstance(vm.backend_vm_id, nics=op,
hotplug=vm.backend.use_hotplug(),
dry_run=settings.TEST)
jobID = client.ModifyInstance(**kwargs)
# If the NIC has a tag for a firewall profile it must be deleted,
# otherwise it may affect another NIC. XXX: Deleting the tag should
# depend on the removing the NIC, but currently RAPI client does not
......
......@@ -94,7 +94,7 @@ class ServerTest(TestCase):
self.assertFalse(pool.is_available("192.168.2.2"))
args, kwargs = mrapi().ModifyInstance.call_args
nics = kwargs["nics"][0]
self.assertEqual(args[0], vm.backend_vm_id)
self.assertEqual(kwargs["instance"], vm.backend_vm_id)
self.assertEqual(nics[0], "add")
self.assertEqual(nics[1]["ip"], "192.168.2.2")
self.assertEqual(nics[1]["network"], net.backend_id)
......@@ -111,7 +111,7 @@ class ServerTest(TestCase):
self.assertTrue(pool.is_available("192.168.2.2"))
args, kwargs = mrapi().ModifyInstance.call_args
nics = kwargs["nics"][0]
self.assertEqual(args[0], vm.backend_vm_id)
self.assertEqual(kwargs["instance"], vm.backend_vm_id)
self.assertEqual(nics[0], "add")
self.assertEqual(nics[1]["ip"], None)
self.assertEqual(nics[1]["network"], net.backend_id)
......@@ -125,7 +125,7 @@ class ServerTest(TestCase):
servers.connect(vm, net)
args, kwargs = mrapi().ModifyInstance.call_args
nics = kwargs["nics"][0]
self.assertEqual(args[0], vm.backend_vm_id)
self.assertEqual(kwargs["instance"], vm.backend_vm_id)
self.assertEqual(nics[0], "add")
self.assertEqual(nics[1]["ip"], None)
self.assertEqual(nics[1]["network"], net.backend_id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment