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