24
24
from nova.compute import instance_types
25
25
from nova.compute import manager as compute_manager
26
26
from nova.compute import power_state
27
from nova.compute import vm_states
27
28
from nova import context
28
29
from nova import db
29
30
from nova.db.sqlalchemy import models
763
764
'block_migration': False,
764
765
'disk': None}}).\
765
766
AndRaise(rpc.RemoteError('', '', ''))
766
dbmock.instance_update(c, i_ref['id'], {'state_description': 'running',
767
'state': power_state.RUNNING,
767
dbmock.instance_update(c, i_ref['id'], {'vm_state': vm_states.ACTIVE,
768
769
'host': i_ref['host']})
769
770
for v in i_ref['volumes']:
770
771
dbmock.volume_update(c, v['id'], {'status': 'in-use'})
795
796
'block_migration': False,
796
797
'disk': None}}).\
797
798
AndRaise(rpc.RemoteError('', '', ''))
798
dbmock.instance_update(c, i_ref['id'], {'state_description': 'running',
799
'state': power_state.RUNNING,
799
dbmock.instance_update(c, i_ref['id'], {'vm_state': vm_states.ACTIVE,
800
801
'host': i_ref['host']})
802
803
self.compute.db = dbmock
841
842
c = context.get_admin_context()
842
843
instance_id = self._create_instance()
843
844
i_ref = db.instance_get(c, instance_id)
844
db.instance_update(c, i_ref['id'], {'state_description': 'migrating',
845
'state': power_state.PAUSED})
845
db.instance_update(c, i_ref['id'], {'vm_state': vm_states.MIGRATING,
846
'power_state': power_state.PAUSED})
846
847
v_ref = db.volume_create(c, {'size': 1, 'instance_id': instance_id})
847
848
fix_addr = db.fixed_ip_create(c, {'address': '1.1.1.1',
848
849
'instance_id': instance_id})
903
904
instances = db.instance_get_all(context.get_admin_context())
904
905
LOG.info(_("After force-killing instances: %s"), instances)
905
906
self.assertEqual(len(instances), 1)
906
self.assertEqual(power_state.SHUTOFF, instances[0]['state'])
907
self.assertEqual(power_state.NOSTATE, instances[0]['power_state'])
908
909
def test_get_all_by_name_regexp(self):
909
910
"""Test searching instances by name (display_name)"""
1323
1324
"""Test searching instances by state"""
1325
1326
c = context.get_admin_context()
1326
instance_id1 = self._create_instance({'state': power_state.SHUTDOWN})
1327
instance_id1 = self._create_instance({
1328
'power_state': power_state.SHUTDOWN,
1327
1330
instance_id2 = self._create_instance({
1329
'state': power_state.RUNNING})
1332
'power_state': power_state.RUNNING,
1330
1334
instance_id3 = self._create_instance({
1332
'state': power_state.RUNNING})
1336
'power_state': power_state.RUNNING,
1334
1338
instances = self.compute_api.get_all(c,
1335
search_opts={'state': power_state.SUSPENDED})
1339
search_opts={'power_state': power_state.SUSPENDED})
1336
1340
self.assertEqual(len(instances), 0)
1338
1342
instances = self.compute_api.get_all(c,
1339
search_opts={'state': power_state.SHUTDOWN})
1343
search_opts={'power_state': power_state.SHUTDOWN})
1340
1344
self.assertEqual(len(instances), 1)
1341
1345
self.assertEqual(instances[0].id, instance_id1)
1343
1347
instances = self.compute_api.get_all(c,
1344
search_opts={'state': power_state.RUNNING})
1348
search_opts={'power_state': power_state.RUNNING})
1345
1349
self.assertEqual(len(instances), 2)
1346
1350
instance_ids = [instance.id for instance in instances]
1347
1351
self.assertTrue(instance_id2 in instance_ids)
1350
1354
# Test passing a list as search arg
1351
1355
instances = self.compute_api.get_all(c,
1352
search_opts={'state': [power_state.SHUTDOWN,
1356
search_opts={'power_state': [power_state.SHUTDOWN,
1353
1357
power_state.RUNNING]})
1354
1358
self.assertEqual(len(instances), 3)