~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/tests/test_cloud.py

  • Committer: Tarmac
  • Author(s): Brian Lamar, Dan Prince
  • Date: 2011-08-31 22:55:34 UTC
  • mfrom: (1443.3.61 instance_states)
  • Revision ID: tarmac-20110831225534-upfhtsvcsafyql6x
Fixed and improved the way instance "states" are set. Instead of relying on solely the power_state of a VM, there are now explicitly defined VM states and VM task states which respectively define the current state of the VM and the task which is currently being performed by the VM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from nova import utils
39
39
from nova.api.ec2 import cloud
40
40
from nova.api.ec2 import ec2utils
 
41
from nova.compute import vm_states
41
42
from nova.image import fake
42
43
 
43
44
 
1161
1162
            self.compute = self.start_service('compute')
1162
1163
 
1163
1164
    def _wait_for_state(self, ctxt, instance_id, predicate):
1164
 
        """Wait for an stopping instance to be a given state"""
 
1165
        """Wait for a stopped instance to be a given state"""
1165
1166
        id = ec2utils.ec2_id_to_id(instance_id)
1166
1167
        while True:
1167
1168
            info = self.cloud.compute_api.get(context=ctxt, instance_id=id)
1172
1173
 
1173
1174
    def _wait_for_running(self, instance_id):
1174
1175
        def is_running(info):
1175
 
            return info['state_description'] == 'running'
 
1176
            vm_state = info["vm_state"]
 
1177
            task_state = info["task_state"]
 
1178
            return vm_state == vm_states.ACTIVE and task_state == None
1176
1179
        self._wait_for_state(self.context, instance_id, is_running)
1177
1180
 
1178
1181
    def _wait_for_stopped(self, instance_id):
1179
1182
        def is_stopped(info):
1180
 
            return info['state_description'] == 'stopped'
 
1183
            vm_state = info["vm_state"]
 
1184
            task_state = info["task_state"]
 
1185
            return vm_state == vm_states.STOPPED and task_state == None
1181
1186
        self._wait_for_state(self.context, instance_id, is_stopped)
1182
1187
 
1183
1188
    def _wait_for_terminate(self, instance_id):
1560
1565
                'id': 0,
1561
1566
                'root_device_name': '/dev/sdh',
1562
1567
                'security_groups': [{'name': 'fake0'}, {'name': 'fake1'}],
1563
 
                'state_description': 'stopping',
 
1568
                'vm_state': vm_states.STOPPED,
1564
1569
                'instance_type': {'name': 'fake_type'},
1565
1570
                'kernel_id': 1,
1566
1571
                'ramdisk_id': 2,
1604
1609
        self.assertEqual(groupSet, expected_groupSet)
1605
1610
        self.assertEqual(get_attribute('instanceInitiatedShutdownBehavior'),
1606
1611
                         {'instance_id': 'i-12345678',
1607
 
                          'instanceInitiatedShutdownBehavior': 'stop'})
 
1612
                          'instanceInitiatedShutdownBehavior': 'stopped'})
1608
1613
        self.assertEqual(get_attribute('instanceType'),
1609
1614
                         {'instance_id': 'i-12345678',
1610
1615
                          'instanceType': 'fake_type'})