Rename block-device -> block-devices
Add support for block-devices, but still only accept one block device. Add tests for parsing the device block list. Change-Id: I78fe3b9e617a7da75145a2695bee312cf3685246
This commit is contained in:
parent
4eda2155e6
commit
0e87f8dff4
|
@ -9,7 +9,7 @@ The lxd charm can be used in-conjunction with any principle charm to setup and e
|
|||
juju deploy cs:~openstack-charmers-next/wily/nova-compute
|
||||
juju set nova-compute virt-type=lxd
|
||||
juju deploy cs:~openstack-charmers-next/wily/lxd
|
||||
juju set lxd block-device=/dev/sdb storage-type=lvm
|
||||
juju set lxd block-devices=/dev/sdb storage-type=lvm
|
||||
juju add-relation lxd nova-compute
|
||||
|
||||
At this point in time, LXD is only supported on Ubuntu 15.10 or above, in-conjunction with OpenStack Liberty (provided as part of Ubuntu 15.10).
|
||||
|
|
10
config.yaml
10
config.yaml
|
@ -6,15 +6,15 @@ options:
|
|||
Repository from which to install LXD. May be one of the following:
|
||||
distro (default), ppa:somecustom/ppa, a deb url sources entry,
|
||||
or a supported release pocket
|
||||
block-device:
|
||||
block-devices:
|
||||
type: string
|
||||
default:
|
||||
description: |
|
||||
Device to be used to back LXD storage. May be an valid block
|
||||
device or a path and size to a local file (/path/to/file.img|$sizeG),
|
||||
which will be created and used as a loopback device (for testing only).
|
||||
A space-separated list of devices to use to back the LXD storage. Items
|
||||
in this list should be valid block device paths. Entries that are not
|
||||
found will be ignored.
|
||||
.
|
||||
This will be use to store lxd containers.
|
||||
Currently, only the the first block device in the list will be considered.
|
||||
overwrite:
|
||||
default: False
|
||||
type: boolean
|
||||
|
|
|
@ -143,6 +143,15 @@ def configure_lxd_source(user='ubuntu'):
|
|||
service_start('lxd')
|
||||
|
||||
|
||||
def get_block_devices():
|
||||
"""Returns a list of block devices provided by the config."""
|
||||
lxd_block_devices = config('block-devices')
|
||||
if lxd_block_devices is None:
|
||||
return []
|
||||
else:
|
||||
return lxd_block_devices.split(' ')
|
||||
|
||||
|
||||
def configure_lxd_block():
|
||||
'''Configure a block device for use by LXD for containers'''
|
||||
log('Configuring LXD container storage')
|
||||
|
@ -150,10 +159,13 @@ def configure_lxd_block():
|
|||
log('/var/lib/lxd already configured, skipping')
|
||||
return
|
||||
|
||||
lxd_block_device = config('block-device')
|
||||
if not lxd_block_device:
|
||||
log('block device is not provided - skipping')
|
||||
lxd_block_devices = get_block_devices()
|
||||
if len(lxd_block_devices) < 1:
|
||||
log('block devices not provided - skipping')
|
||||
return
|
||||
if len(lxd_block_devices) > 1:
|
||||
raise NotImplementedError('Multiple block devices are not supported.')
|
||||
lxd_block_device = lxd_block_devices[0]
|
||||
|
||||
dev = None
|
||||
if lxd_block_device.startswith('/dev/'):
|
||||
|
|
|
@ -93,7 +93,7 @@ class LXDBasicDeployment(OpenStackAmuletDeployment):
|
|||
}
|
||||
|
||||
lxd_config = {
|
||||
'block-device': '/dev/vdb',
|
||||
'block-devices': '/dev/vdb',
|
||||
'ephemeral-unmount': '/mnt',
|
||||
'storage-type': 'lvm',
|
||||
'overwrite': True
|
||||
|
|
|
@ -85,3 +85,37 @@ class TestLXDUtilsCreateAndImportBusyboxImage(testing.CharmTestCase):
|
|||
Popen_rv.stdout.read.assert_called_once_with()
|
||||
stat.assert_called_with('/bin/busybox')
|
||||
mock_open.assert_called_once_with('/bin/busybox', 'rb')
|
||||
|
||||
|
||||
class TestGetBlockDevices(testing.CharmTestCase):
|
||||
"""Tests for hooks.lxd_utils.get_block_devices."""
|
||||
|
||||
TO_PATCH = [
|
||||
'config',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
super(TestGetBlockDevices, self).setUp(
|
||||
lxd_utils, self.TO_PATCH)
|
||||
self.config.side_effect = self.test_config.get
|
||||
|
||||
def testEmpty(self):
|
||||
"""When no config is specified, an empty list is returned."""
|
||||
devices = lxd_utils.get_block_devices()
|
||||
|
||||
self.assertEqual([], devices)
|
||||
|
||||
def testSingleDevice(self):
|
||||
"""Return a list with the single device."""
|
||||
self.test_config.set('block-devices', '/dev/vdb')
|
||||
devices = lxd_utils.get_block_devices()
|
||||
|
||||
self.assertEqual(['/dev/vdb'], devices)
|
||||
|
||||
def testMultipleDevices(self):
|
||||
"""Return a list with all devices."""
|
||||
self.test_config.set('block-devices', '/dev/vdb /dev/vdc')
|
||||
|
||||
devices = lxd_utils.get_block_devices()
|
||||
|
||||
self.assertEqual(['/dev/vdb', '/dev/vdc'], devices)
|
||||
|
|
Loading…
Reference in New Issue