ec2 api run_instances checks for image status must be 'available'. Overhauled test_run_instances for working set of test assertions
This commit is contained in:
@@ -36,12 +36,12 @@ from nova import rpc
|
|||||||
from nova import service
|
from nova import service
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova import utils
|
from nova import utils
|
||||||
|
from nova import exception
|
||||||
from nova.auth import manager
|
from nova.auth import manager
|
||||||
from nova.compute import power_state
|
from nova.compute import power_state
|
||||||
from nova.api.ec2 import cloud
|
from nova.api.ec2 import cloud
|
||||||
from nova.api.ec2 import ec2utils
|
from nova.api.ec2 import ec2utils
|
||||||
from nova.image import local
|
from nova.image import local
|
||||||
from nova.exception import NotFound
|
|
||||||
|
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
@@ -226,7 +226,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
'type': 'machine'}}]
|
'type': 'machine'}}]
|
||||||
|
|
||||||
def fake_show_none(meh, context, id):
|
def fake_show_none(meh, context, id):
|
||||||
raise NotFound
|
raise exception.NotFound
|
||||||
|
|
||||||
self.stubs.Set(local.LocalImageService, 'detail', fake_detail)
|
self.stubs.Set(local.LocalImageService, 'detail', fake_detail)
|
||||||
# list all
|
# list all
|
||||||
@@ -244,7 +244,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
self.stubs.Set(local.LocalImageService, 'show', fake_show_none)
|
self.stubs.Set(local.LocalImageService, 'show', fake_show_none)
|
||||||
self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show_none)
|
self.stubs.Set(local.LocalImageService, 'show_by_name', fake_show_none)
|
||||||
self.assertRaises(NotFound, describe_images,
|
self.assertRaises(exception.NotFound, describe_images,
|
||||||
self.context, ['ami-fake'])
|
self.context, ['ami-fake'])
|
||||||
|
|
||||||
def test_console_output(self):
|
def test_console_output(self):
|
||||||
@@ -307,39 +307,41 @@ class CloudTestCase(test.TestCase):
|
|||||||
self.cloud.delete_key_pair(self.context, 'test')
|
self.cloud.delete_key_pair(self.context, 'test')
|
||||||
|
|
||||||
def test_run_instances(self):
|
def test_run_instances(self):
|
||||||
if FLAGS.connection_type == 'fake':
|
allinst = db.instance_get_all(context.get_admin_context())
|
||||||
LOG.debug(_("Can't test instances without a real virtual env."))
|
self.assertEqual(0, len(allinst))
|
||||||
return
|
def fake_show_decrypt(meh, context, id):
|
||||||
|
return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
|
||||||
|
'type': 'machine', 'image_state': 'decrypting'}}
|
||||||
|
|
||||||
|
def fake_show_avail(meh, context, id):
|
||||||
|
return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1,
|
||||||
|
'type': 'machine', 'image_state': 'available'}}
|
||||||
|
|
||||||
image_id = FLAGS.default_image
|
image_id = FLAGS.default_image
|
||||||
instance_type = FLAGS.default_instance_type
|
instance_type = FLAGS.default_instance_type
|
||||||
max_count = 1
|
max_count = 1
|
||||||
kwargs = {'image_id': image_id,
|
kwargs = {'image_id': image_id,
|
||||||
'instance_type': instance_type,
|
'instance_type': instance_type,
|
||||||
'max_count': max_count}
|
'max_count': max_count}
|
||||||
rv = self.cloud.run_instances(self.context, **kwargs)
|
run_instances = self.cloud.run_instances
|
||||||
# TODO: check for proper response
|
# when image doesn't have 'image_state' attr at all
|
||||||
instance_id = rv['reservationSet'][0].keys()[0]
|
self.assertRaises(exception.ApiError, run_instances,
|
||||||
instance = rv['reservationSet'][0][instance_id][0]
|
self.context, **kwargs)
|
||||||
LOG.debug(_("Need to watch instance %s until it's running..."),
|
# when image has 'image_state' yet not 'available'
|
||||||
instance['instance_id'])
|
self.stubs.UnsetAll()
|
||||||
while True:
|
self.stubs.Set(local.LocalImageService, 'show', fake_show_decrypt)
|
||||||
greenthread.sleep(1)
|
self.assertRaises(exception.ApiError, run_instances,
|
||||||
info = self.cloud._get_instance(instance['instance_id'])
|
self.context, **kwargs)
|
||||||
LOG.debug(info['state'])
|
# when image has valid image_state
|
||||||
if info['state'] == power_state.RUNNING:
|
self.stubs.UnsetAll()
|
||||||
break
|
self.stubs.Set(local.LocalImageService, 'show', fake_show_avail)
|
||||||
self.assert_(rv)
|
result = run_instances(self.context, **kwargs)
|
||||||
|
instance = result['instancesSet'][0]
|
||||||
if FLAGS.connection_type != 'fake':
|
self.assertEqual(instance['imageId'], 'ami-00000001')
|
||||||
time.sleep(45) # Should use boto for polling here
|
self.assertEqual(instance['displayName'], 'Server 1')
|
||||||
for reservations in rv['reservationSet']:
|
self.assertEqual(instance['instanceId'], 'i-00000001')
|
||||||
# for res_id in reservations.keys():
|
self.assertEqual(instance['instanceState']['name'], 'scheduling')
|
||||||
# LOG.debug(reservations[res_id])
|
self.assertEqual(instance['instanceType'], 'm1.small')
|
||||||
# for instance in reservations[res_id]:
|
|
||||||
for instance in reservations[reservations.keys()[0]]:
|
|
||||||
instance_id = instance['instance_id']
|
|
||||||
LOG.debug(_("Terminating instance %s"), instance_id)
|
|
||||||
rv = self.compute.terminate_instance(instance_id)
|
|
||||||
|
|
||||||
def test_update_of_instance_display_fields(self):
|
def test_update_of_instance_display_fields(self):
|
||||||
inst = db.instance_create(self.context, {})
|
inst = db.instance_create(self.context, {})
|
||||||
|
|||||||
Reference in New Issue
Block a user