summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Still <michael.still@canonical.com>2012-12-06 14:04:51 +1100
committerMichael Still <michael.still@canonical.com>2012-12-07 12:50:33 +1100
commite28d7870fa8633fddd5fe92d2fbcc34ae392bd85 (patch)
treec0b3e35af69436f969e036b9c65f1a0a23bd3436
parentf495b95d0ee28141bd067ca64a0176189f5d8293 (diff)
downloadnova-e28d7870fa8633fddd5fe92d2fbcc34ae392bd85.tar.gz
nova-e28d7870fa8633fddd5fe92d2fbcc34ae392bd85.tar.xz
nova-e28d7870fa8633fddd5fe92d2fbcc34ae392bd85.zip
Simplify how ephemeral disks are created and named.
Resolves bug 1087028. Change-Id: Ife7ec43cf76cf04a98f1db2135f9149a2eefb55d
-rw-r--r--nova/tests/test_libvirt.py3
-rw-r--r--nova/virt/libvirt/driver.py45
-rw-r--r--nova/virt/libvirt/imagebackend.py8
3 files changed, 26 insertions, 30 deletions
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py
index 5df7d920d..872c0498d 100644
--- a/nova/tests/test_libvirt.py
+++ b/nova/tests/test_libvirt.py
@@ -2295,6 +2295,9 @@ class LibvirtConnTestCase(test.TestCase):
self.stubs.Set(imagebackend.Image,
'cache',
fake_none)
+ self.stubs.Set(libvirt_driver.LibvirtDriver,
+ '_create_ephemeral',
+ fake_none)
conn.spawn(self.context, instance, None, [], 'herp',
network_info=network_info)
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 750ffb0a2..b2a90e862 100644
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -251,6 +251,8 @@ MIN_LIBVIRT_VERSION = (0, 9, 6)
# delete it & corresponding code using it
MIN_LIBVIRT_HOST_CPU_VERSION = (0, 9, 10)
+ONE_GIGABYTE = 1024 * 1024 * 1024
+
def _get_eph_disk(ephemeral):
return 'disk.eph' + str(ephemeral['num'])
@@ -1269,9 +1271,15 @@ class LibvirtDriver(driver.ComputeDriver):
if fs_format:
utils.mkfs(fs_format, target, label)
- def _create_ephemeral(self, target, ephemeral_size, fs_label, os_type):
- self._create_local(target, ephemeral_size)
- disk.mkfs(os_type, fs_label, target)
+ def _create_ephemeral(self, instance, disk_name, size_in_gb, number):
+ fname = os.path.join(CONF.instances_path, instance['name'],
+ disk_name)
+
+ LOG.info(_('Creating ephemeral disk named %(disk_name)s of size '
+ '%(size_in_gb)s gb at %(fname)s'), locals(),
+ instance=instance)
+ self._create_local(fname, size_in_gb)
+ disk.mkfs(instance['os_type'], 'ephemeral%d' % number, fname)
@staticmethod
def _create_swap(target, swap_mb):
@@ -1349,7 +1357,7 @@ class LibvirtDriver(driver.ComputeDriver):
project_id=instance['project_id'])
root_fname = hashlib.sha1(str(disk_images['image_id'])).hexdigest()
- size = instance['root_gb'] * 1024 * 1024 * 1024
+ size = instance['root_gb'] * ONE_GIGABYTE
inst_type = instance['instance_type']
if size == 0 or suffix == '.rescue':
@@ -1365,36 +1373,19 @@ class LibvirtDriver(driver.ComputeDriver):
user_id=instance['user_id'],
project_id=instance['project_id'])
+ # NOTE(mikal): we don't go through imagebackend here, as ephemeral
+ # disks aren't cached in _base, they're new images each time
ephemeral_gb = instance['ephemeral_gb']
if ephemeral_gb and not self._volume_in_mapping(
self.default_second_device, block_device_info):
swap_device = self.default_third_device
- fn = functools.partial(self._create_ephemeral,
- fs_label='ephemeral0',
- os_type=instance["os_type"])
- fname = "ephemeral_%s_%s_%s" % ("0",
- ephemeral_gb,
- instance["os_type"])
- size = ephemeral_gb * 1024 * 1024 * 1024
- image('disk.local').cache(fetch_func=fn,
- filename=fname,
- size=size,
- ephemeral_size=ephemeral_gb)
+ self._create_ephemeral(instance, 'disk.local', ephemeral_gb, 0)
else:
swap_device = self.default_second_device
for eph in driver.block_device_info_get_ephemerals(block_device_info):
- fn = functools.partial(self._create_ephemeral,
- fs_label='ephemeral%d' % eph['num'],
- os_type=instance["os_type"])
- size = eph['size'] * 1024 * 1024 * 1024
- fname = "ephemeral_%s_%s_%s" % (eph['num'],
- eph['size'],
- instance["os_type"])
- image(_get_eph_disk(eph)).cache(fetch_func=fn,
- filename=fname,
- size=size,
- ephemeral_size=eph['size'])
+ self._create_ephemeral(instance, _get_eph_disk(eph), eph['size'],
+ eph['num'])
swap_mb = 0
@@ -2935,7 +2926,7 @@ class LibvirtDriver(driver.ComputeDriver):
size = instance['ephemeral_gb']
else:
size = 0
- size *= 1024 * 1024 * 1024
+ size *= ONE_GIGABYTE
# If we have a non partitioned image that we can extend
# then ensure we're in 'raw' format so we can extend file system.
diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py
index a77e9e74f..86502ee9e 100644
--- a/nova/virt/libvirt/imagebackend.py
+++ b/nova/virt/libvirt/imagebackend.py
@@ -49,6 +49,8 @@ CONF = cfg.CONF
CONF.register_opts(__imagebackend_opts)
CONF.import_opt('base_dir_name', 'nova.virt.libvirt.imagecache')
+ONE_GIGABYTE = 1024 * 1024 * 1024
+
class Image(object):
__metaclass__ = abc.ABCMeta
@@ -103,9 +105,9 @@ class Image(object):
return info
def cache(self, fetch_func, filename, size=None, *args, **kwargs):
- """Creates image from template.
+ """Creates an image from a template.
- Ensures that template and image not already exists.
+ Ensures that template and image do not already exist.
Ensures that base directory exists.
Synchronizes on template fetching.
@@ -179,7 +181,7 @@ class Qcow2(Image):
def copy_qcow2_image(base, target, size):
qcow2_base = base
if size:
- size_gb = size / (1024 * 1024 * 1024)
+ size_gb = size / (ONE_GIGABYTE)
qcow2_base += '_%d' % size_gb
if not os.path.exists(qcow2_base):
with utils.remove_path_on_error(qcow2_base):