Commit 6b0da54a by Bach Dániel Committed by Őry Máté

vm: fix disappearing vnc port + node

parent 041646aa
......@@ -389,15 +389,14 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
except ActivityInProgressError:
pass # discard state change if another activity is in progress.
else:
act.finished = act.started
act.resultant_state = new_state
act.succeeded = True
act.save()
if new_state == 'STOPPED':
self.vnc_port = None
self.node = None
self.save()
act.finished = act.started
act.resultant_state = new_state
act.succeeded = True
act.save()
@permalink
def get_absolute_url(self):
......
from django.test import TestCase
from mock import Mock
from mock import Mock, MagicMock, patch
from ..models.common import (
Lease
)
from ..models.instance import (
find_unused_port, InstanceTemplate, Instance
find_unused_port, InstanceTemplate, Instance, ActivityInProgressError
)
from ..models.network import (
Interface
......@@ -39,6 +39,17 @@ class InstanceTestCase(TestCase):
inst = Mock(state='RUNNING')
assert Instance.is_running.getter(inst)
def test_mon_stopped_while_activity_running(self):
node = Mock()
port = Mock()
inst = MagicMock(spec=Instance, node=node, vnc_port=port)
inst.save.side_effect = AssertionError
with patch('vm.models.instance.InstanceActivity') as ia:
ia.create.side_effect = ActivityInProgressError(MagicMock())
Instance.vm_state_changed(inst, 'STOPPED')
self.assertEquals(inst.node, node)
self.assertEquals(inst.vnc_port, port)
class InterfaceTestCase(TestCase):
......
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 sign in to comment