Commit e6120d41 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Add check for net action with no hotplug

In case hotplug is disabled, via GANETI_USE_HOTPLUG setting, network
actions should be allowed only on STOPPED vms. This commit adds this
check and a unittest for this case. Also it makes some other checks
regarding actions and states of vms more strict.

Finally, this commit changes the default value of GANETI_USE_HOTPLUG to
True.
parent 5b5573c5
......@@ -31,7 +31,7 @@ GANETI_CREATEINSTANCE_KWARGS = {
# If True, qemu-kvm will hotplug a NIC when connecting a vm to
# a network. This requires qemu-kvm=1.0.
GANETI_USE_HOTPLUG = False
GANETI_USE_HOTPLUG = True
# This module implements the strategy for allocating a vm to a backend
BACKEND_ALLOCATOR_MODULE = "synnefo.logic.allocators.default_allocator"
......
......@@ -44,9 +44,11 @@ def validate_server_action(vm, action):
operstate = vm.operstate
if operstate == "BUILD":
raise faults.BuildInProgress("Server '%s' is being build." % vm.id)
elif (action == "START" and operstate == "STARTED") or\
(action == "STOP" and operstate == "STOPPED") or\
(action == "RESIZE" and operstate == "STARTED"):
elif (action == "START" and operstate != "STOPPED") or\
(action == "STOP" and operstate != "STARTED") or\
(action == "RESIZE" and operstate != "STOPPED") or\
(action in ["CONNECT", "DISCONNECT"] and operstate != "STOPPED"
and not settings.GANETI_USE_HOTPLUG):
raise faults.BadRequest("Can not perform '%s' action while server is"
" in '%s' state." % (action, operstate))
return
......
......@@ -86,7 +86,7 @@ class ServerTest(TestCase):
state="ACTIVE",
dhcp=True,
flavor="CUSTOM")
vm = mfactory.VirtualMachineFactory(operstate="ACTIVE")
vm = mfactory.VirtualMachineFactory(operstate="STARTED")
mfactory.BackendNetworkFactory(network=net, backend=vm.backend)
mrapi().ModifyInstance.return_value = 42
servers.connect(vm, net)
......@@ -100,7 +100,7 @@ class ServerTest(TestCase):
self.assertEqual(nics[1]["network"], net.backend_id)
# No dhcp
vm = mfactory.VirtualMachineFactory(operstate="ACTIVE")
vm = mfactory.VirtualMachineFactory(operstate="STARTED")
net = mfactory.NetworkFactory(subnet="192.168.2.0/24",
gateway="192.168.2.1",
state="ACTIVE",
......@@ -117,7 +117,7 @@ class ServerTest(TestCase):
self.assertEqual(nics[1]["network"], net.backend_id)
# Test connect to IPv6 only network
vm = mfactory.VirtualMachineFactory(operstate="ACTIVE")
vm = mfactory.VirtualMachineFactory(operstate="STARTED")
net = mfactory.NetworkFactory(subnet6="2000::/64",
state="ACTIVE",
gateway="2000::1")
......@@ -158,9 +158,16 @@ class ServerCommandTest(TestCase):
self.assertRaises(faults.BadRequest, servers.stop, vm)
vm = mfactory.VirtualMachineFactory(operstate="STARTED")
self.assertRaises(faults.BadRequest, servers.resize, vm)
vm = mfactory.VirtualMachineFactory(operstate="STOPPED")
self.assertRaises(faults.BadRequest, servers.stop, vm)
# Check that connect/disconnect is allowed only in STOPPED vms
# if hotplug is disabled.
vm = mfactory.VirtualMachineFactory(operstate="STARTED")
network = mfactory.NetworkFactory(state="ACTIVE")
with override_settings(settings, GANETI_USE_HOTPLUG=False):
self.assertRaises(faults.BadRequest, servers.connect, vm, network)
self.assertRaises(faults.BadRequest, servers.disconnect, vm,
network)
#test valid
vm = mfactory.VirtualMachineFactory(operstate="STOPPED")
mrapi().StartupInstance.return_value = 1
with mocked_quotaholder():
servers.start(vm)
......
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