pep8
This commit is contained in:
@@ -934,7 +934,7 @@ class CloudController(object):
|
||||
def _do_instances(self, action, context, instance_id):
|
||||
for ec2_id in instance_id:
|
||||
self._do_instance(action, context, ec2_id)
|
||||
|
||||
|
||||
def terminate_instances(self, context, instance_id, **kwargs):
|
||||
"""Terminate each instance in instance_id, which is a list of ec2 ids.
|
||||
instance_id is a kwarg so its name cannot be modified."""
|
||||
|
||||
@@ -264,7 +264,7 @@ class API(base.Base):
|
||||
# BlockDeviceMapping
|
||||
for bdm in block_device_mapping:
|
||||
LOG.debug(_('bdm %s'), bdm)
|
||||
assert bdm.has_key('device_name')
|
||||
assert 'device_name' in bdm
|
||||
values = {
|
||||
'instance_id': instance_id,
|
||||
'device_name': bdm['device_name'],
|
||||
@@ -451,7 +451,7 @@ class API(base.Base):
|
||||
instance = self._get_instance(context, instance_id, 'stopping')
|
||||
if not _is_able_to_shutdown(instance, instance_id):
|
||||
return
|
||||
|
||||
|
||||
self.update(context,
|
||||
instance['id'],
|
||||
state_description='stopping',
|
||||
|
||||
@@ -1300,7 +1300,6 @@ class ComputeManager(manager.SchedulerDependentManager):
|
||||
vm_state = vm_instance.state
|
||||
vms_not_found_in_db.remove(name)
|
||||
|
||||
|
||||
if (db_instance['state_description'] in ['migrating', 'stopping']):
|
||||
# A situation which db record exists, but no instance"
|
||||
# sometimes occurs while live-migration at src compute,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
from nova import exception
|
||||
from nova import volume
|
||||
|
||||
|
||||
def terminate_volumes(db, context, instance_id):
|
||||
"""delete volumes of delete_on_termination=True in block device mapping"""
|
||||
try:
|
||||
|
||||
@@ -929,10 +929,12 @@ def block_device_mapping_create(context, values):
|
||||
"""Create an entry of block device mapping"""
|
||||
return IMPL.block_device_mapping_create(context, values)
|
||||
|
||||
|
||||
def block_device_mapping_update(context, bdm_id, values):
|
||||
"""Create an entry of block device mapping"""
|
||||
return IMPL.block_device_mapping_update(context, bdm_id, values)
|
||||
|
||||
|
||||
def block_device_mapping_get_all_by_instance(context, instance_id):
|
||||
"""Get all block device mapping belonging to a instance"""
|
||||
return IMPL.block_device_mapping_get_all_by_instance(context, instance_id)
|
||||
|
||||
@@ -832,6 +832,7 @@ def instance_destroy(context, instance_id):
|
||||
'deleted_at': datetime.datetime.utcnow(),
|
||||
'updated_at': literal_column('updated_at')})
|
||||
|
||||
|
||||
@require_context
|
||||
def instance_stop(context, instance_id):
|
||||
session = get_session()
|
||||
@@ -1892,6 +1893,7 @@ def block_device_mapping_create(context, values):
|
||||
with session.begin():
|
||||
bdm_ref.save(session=session)
|
||||
|
||||
|
||||
@require_context
|
||||
def block_device_mapping_update(context, bdm_id, values):
|
||||
session = get_session()
|
||||
@@ -1901,6 +1903,7 @@ def block_device_mapping_update(context, bdm_id, values):
|
||||
filter_by(deleted=False).\
|
||||
update(values)
|
||||
|
||||
|
||||
@require_context
|
||||
def block_device_mapping_get_all_by_instance(context, instance_id):
|
||||
session = get_session()
|
||||
@@ -1912,6 +1915,7 @@ def block_device_mapping_get_all_by_instance(context, instance_id):
|
||||
raise exception.NotFound()
|
||||
return result
|
||||
|
||||
|
||||
@require_context
|
||||
def block_device_mapping_destroy(context, bdm_id):
|
||||
session = get_session()
|
||||
@@ -1922,6 +1926,7 @@ def block_device_mapping_destroy(context, bdm_id):
|
||||
'deleted_at': datetime.datetime.utcnow(),
|
||||
'updated_at': literal_column('updated_at')})
|
||||
|
||||
|
||||
@require_context
|
||||
def block_device_mapping_destroy_by_instance_and_volume(context, instance_id,
|
||||
volume_id):
|
||||
|
||||
@@ -60,7 +60,8 @@ block_device_mapping = Table('block_device_mapping', meta,
|
||||
Integer(),
|
||||
ForeignKey('snapshots.id'),
|
||||
nullable=True),
|
||||
Column('volume_id', Integer(), ForeignKey('volumes.id'), nullable=True),
|
||||
Column('volume_id', Integer(), ForeignKey('volumes.id'),
|
||||
nullable=True),
|
||||
Column('volume_size', Integer(), nullable=True),
|
||||
Column('no_device',
|
||||
Boolean(create_constraint=True, name=None),
|
||||
@@ -79,7 +80,8 @@ def upgrade(migrate_engine):
|
||||
logging.exception('Exception while creating table')
|
||||
meta.drop_all(tables=[block_device_mapping])
|
||||
raise
|
||||
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
# Operations to reverse the above upgrade go here.
|
||||
block_device_mapping.drop()
|
||||
|
||||
@@ -385,12 +385,12 @@ class BlockDeviceMapping(BASE, NovaBase):
|
||||
# outer join
|
||||
snapshot = relationship(Snapshot,
|
||||
foreign_keys=snapshot_id)
|
||||
|
||||
|
||||
volume_id = Column(Integer, ForeignKey('volumes.id'), nullable=True)
|
||||
volume = relationship(Volume,
|
||||
foreign_keys=volume_id)
|
||||
volume_size = Column(Integer, nullable=True)
|
||||
|
||||
|
||||
# for no device to suppress devices.
|
||||
no_device = Column(Boolean, nullable=True)
|
||||
|
||||
|
||||
@@ -541,7 +541,7 @@ class CloudTestCase(test.TestCase):
|
||||
|
||||
kwargs = {'image_id': 'ami-1',
|
||||
'instance_type': FLAGS.default_instance_type,
|
||||
'max_count': 1,}
|
||||
'max_count': 1, }
|
||||
instance_id = self._run_instance_wait(**kwargs)
|
||||
|
||||
# a running instance can't be started. It is just ignored.
|
||||
@@ -553,7 +553,7 @@ class CloudTestCase(test.TestCase):
|
||||
greenthread.sleep(0.3)
|
||||
self.assertTrue(result)
|
||||
self._wait_for_stopped(instance_id)
|
||||
|
||||
|
||||
result = self.cloud.start_instances(self.context, [instance_id])
|
||||
greenthread.sleep(0.3)
|
||||
self.assertTrue(result)
|
||||
@@ -563,18 +563,18 @@ class CloudTestCase(test.TestCase):
|
||||
greenthread.sleep(0.3)
|
||||
self.assertTrue(result)
|
||||
self._wait_for_stopped(instance_id)
|
||||
|
||||
|
||||
result = self.cloud.terminate_instances(self.context, [instance_id])
|
||||
greenthread.sleep(0.3)
|
||||
self.assertTrue(result)
|
||||
|
||||
|
||||
self._restart_compute_service()
|
||||
|
||||
def _volume_create(self):
|
||||
kwargs = {'status': 'available',
|
||||
'host': self.volume.host,
|
||||
'size': 1,
|
||||
'attach_status': 'detached',}
|
||||
'attach_status': 'detached', }
|
||||
return db.volume_create(self.context, kwargs)
|
||||
|
||||
def _assert_volume_attached(self, vol, instance_id, mountpoint):
|
||||
@@ -582,7 +582,7 @@ class CloudTestCase(test.TestCase):
|
||||
self.assertEqual(vol['mountpoint'], mountpoint)
|
||||
self.assertEqual(vol['status'], "in-use")
|
||||
self.assertEqual(vol['attach_status'], "attached")
|
||||
|
||||
|
||||
def _assert_volume_detached(self, vol):
|
||||
self.assertEqual(vol['instance_id'], None)
|
||||
self.assertEqual(vol['mountpoint'], None)
|
||||
@@ -604,8 +604,8 @@ class CloudTestCase(test.TestCase):
|
||||
'volume_id': vol1['id'],
|
||||
'delete_on_termination': False,},
|
||||
{'device_name': '/dev/vdc',
|
||||
'volume_id': vol2['id'],
|
||||
'delete_on_termination': True,},
|
||||
'volume_id': vol2['id'],
|
||||
'delete_on_termination': True, },
|
||||
]}
|
||||
ec2_instance_id = self._run_instance_wait(**kwargs)
|
||||
instance_id = ec2utils.ec2_id_to_id(ec2_instance_id)
|
||||
@@ -629,7 +629,7 @@ class CloudTestCase(test.TestCase):
|
||||
self._assert_volume_detached(vol)
|
||||
vol = db.volume_get(self.context, vol2['id'])
|
||||
self._assert_volume_detached(vol)
|
||||
|
||||
|
||||
self.cloud.start_instances(self.context, [ec2_instance_id])
|
||||
self._wait_for_running(ec2_instance_id)
|
||||
vols = db.volume_get_all_by_instance(self.context, instance_id)
|
||||
@@ -654,7 +654,7 @@ class CloudTestCase(test.TestCase):
|
||||
admin_ctxt = context.get_admin_context(read_deleted=True)
|
||||
vol = db.volume_get(admin_ctxt, vol2['id'])
|
||||
self.assertTrue(vol['deleted'])
|
||||
|
||||
|
||||
self._restart_compute_service()
|
||||
|
||||
def test_stop_with_attached_volume(self):
|
||||
@@ -669,7 +669,7 @@ class CloudTestCase(test.TestCase):
|
||||
'max_count': 1,
|
||||
'block_device_mapping': [{'device_name': '/dev/vdb',
|
||||
'volume_id': vol1['id'],
|
||||
'delete_on_termination': True,},]}
|
||||
'delete_on_termination': True}]}
|
||||
ec2_instance_id = self._run_instance_wait(**kwargs)
|
||||
instance_id = ec2utils.ec2_id_to_id(ec2_instance_id)
|
||||
|
||||
@@ -695,7 +695,7 @@ class CloudTestCase(test.TestCase):
|
||||
greenthread.sleep(0.3)
|
||||
vol = db.volume_get(self.context, vol1['id'])
|
||||
self._assert_volume_detached(vol)
|
||||
|
||||
|
||||
result = self.cloud.stop_instances(self.context, [ec2_instance_id])
|
||||
self.assertTrue(result)
|
||||
self._wait_for_stopped(ec2_instance_id)
|
||||
@@ -703,7 +703,7 @@ class CloudTestCase(test.TestCase):
|
||||
for vol_id in (vol1['id'], vol2['id']):
|
||||
vol = db.volume_get(self.context, vol_id)
|
||||
self._assert_volume_detached(vol)
|
||||
|
||||
|
||||
self.cloud.start_instances(self.context, [ec2_instance_id])
|
||||
self._wait_for_running(ec2_instance_id)
|
||||
vols = db.volume_get_all_by_instance(self.context, instance_id)
|
||||
@@ -723,15 +723,15 @@ class CloudTestCase(test.TestCase):
|
||||
self.assertEqual(vol['id'], vol_id)
|
||||
self._assert_volume_detached(vol)
|
||||
db.volume_destroy(self.context, vol_id)
|
||||
|
||||
|
||||
self._restart_compute_service()
|
||||
|
||||
|
||||
def _create_snapshot(self, ec2_volume_id):
|
||||
result = self.cloud.create_snapshot(self.context,
|
||||
volume_id=ec2_volume_id)
|
||||
greenthread.sleep(0.3)
|
||||
return result['snapshotId']
|
||||
|
||||
|
||||
def test_run_with_snapshot(self):
|
||||
"""Makes sure run/stop/start instance with snapshot works."""
|
||||
vol = self._volume_create()
|
||||
@@ -747,10 +747,10 @@ class CloudTestCase(test.TestCase):
|
||||
'max_count': 1,
|
||||
'block_device_mapping': [{'device_name': '/dev/vdb',
|
||||
'snapshot_id': snapshot1_id,
|
||||
'delete_on_termination': False,},
|
||||
'delete_on_termination': False, },
|
||||
{'device_name': '/dev/vdc',
|
||||
'snapshot_id': snapshot2_id,
|
||||
'delete_on_termination': True,},],}
|
||||
'delete_on_termination': True}]}
|
||||
ec2_instance_id = self._run_instance_wait(**kwargs)
|
||||
instance_id = ec2utils.ec2_id_to_id(ec2_instance_id)
|
||||
|
||||
@@ -778,14 +778,14 @@ class CloudTestCase(test.TestCase):
|
||||
greenthread.sleep(0.3)
|
||||
self._wait_for_terminate(ec2_instance_id)
|
||||
|
||||
greenthread.sleep(0.3)
|
||||
greenthread.sleep(0.3)
|
||||
admin_ctxt = context.get_admin_context(read_deleted=False)
|
||||
vol = db.volume_get(admin_ctxt, vol1_id)
|
||||
self._assert_volume_detached(vol)
|
||||
self.assertFalse(vol['deleted'])
|
||||
db.volume_destroy(self.context, vol1_id)
|
||||
|
||||
greenthread.sleep(0.3)
|
||||
greenthread.sleep(0.3)
|
||||
admin_ctxt = context.get_admin_context(read_deleted=True)
|
||||
vol = db.volume_get(admin_ctxt, vol2_id)
|
||||
self.assertTrue(vol['deleted'])
|
||||
|
||||
@@ -942,8 +942,9 @@ class LibvirtConnection(driver.ComputeDriver):
|
||||
|
||||
return result
|
||||
|
||||
root_mount_device = 'vda' # FIXME for now. it's hard coded.
|
||||
local_mount_device = 'vdb' # FIXME for now. it's hard coded.
|
||||
root_mount_device = 'vda' # FIXME for now. it's hard coded.
|
||||
local_mount_device = 'vdb' # FIXME for now. it's hard coded.
|
||||
|
||||
def _volume_in_mapping(self, mount_device, block_device_mapping):
|
||||
mount_device_ = _strip_dev(mount_device)
|
||||
for vol in block_device_mapping:
|
||||
|
||||
Reference in New Issue
Block a user