summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Kavanagh <alex@ajkavanagh.co.uk>2019-04-23 15:11:11 +0100
committerAlex Kavanagh <alex@ajkavanagh.co.uk>2019-04-23 21:35:42 +0100
commit4bf72620c3cf9cef5905a07132510df2cec5de41 (patch)
tree3b617faabaf7488316c72aa6cae2587edd46d604
parent77e3b687316e9db3e027f127d644c7b37656da5c (diff)
downloadcharm-nova-lxd-4bf72620c3cf9cef5905a07132510df2cec5de41.zip
charm-nova-lxd-4bf72620c3cf9cef5905a07132510df2cec5de41.tar.gz
charm-nova-lxd-4bf72620c3cf9cef5905a07132510df2cec5de41.tar.bz2
Fix detection of already initialised lxc storage pool
The related bug was caused because the charm did not detect when the lxc storage had already been set up using the `lxc storage` command which is used in the 3.x series, rather than the old way with the 2.x series. Also fixes issue on xenial where linux-image-extra-* has been renamed to linux-modules-extra-* from from -4.4.0-145-generic onwards. Otherwise, the install fails on xenial. Change-Id: If8bdad6f5641ee21fc7860dceeb4c3facbaecc76 Closes-Bug: #1825393
-rw-r--r--hooks/lxd_utils.py31
-rw-r--r--tox.ini2
-rw-r--r--unit_tests/test_lxd_utils.py50
3 files changed, 76 insertions, 7 deletions
diff --git a/hooks/lxd_utils.py b/hooks/lxd_utils.py
index 768366d..aadf2ff 100644
--- a/hooks/lxd_utils.py
+++ b/hooks/lxd_utils.py
@@ -188,8 +188,12 @@ def get_block_devices():
def configure_lxd_block():
'''Configure a block device for use by LXD for containers'''
- log('Configuring LXD container storage')
- if filesystem_mounted('/var/lib/lxd'):
+ log('Configuring LXD container storage if not configured')
+ # determine if the lxd block has already been configured
+ if has_storage(LXD_POOL):
+ log("LXD storage pool {} already configured".format(LXD_POOL))
+ return
+ elif filesystem_mounted('/var/lib/lxd'):
log('/var/lib/lxd already configured, skipping')
return
@@ -308,9 +312,20 @@ def config_zfs(dev):
check_call(cmd)
-def has_storage():
+def has_storage(search_for_pool=None):
try:
- check_call(['lxc', 'storage', 'list'])
+ pools = (check_output(['lxc', 'storage', 'list'])
+ .decode('utf-8')
+ .splitlines())
+ if search_for_pool is not None:
+ for pool in pools:
+ try:
+ name = pool.split(' ')[1]
+ if search_for_pool == name:
+ return True
+ except IndexError:
+ pass
+ return False
return True
except subprocess.CalledProcessError:
return False
@@ -476,8 +491,12 @@ def configure_lxd_host():
# Configure live migration
if cmp_ubuntu_release == 'xenial':
- apt_install('linux-image-extra-%s' % os.uname()[2],
- fatal=True)
+ uname = os.uname()[2]
+ if uname > '4.4.0-122-generic':
+ pkg = "linux-modules-extra-{}"
+ else:
+ pkg = "linux-image-extra-{}"
+ apt_install(pkg.format(uname), fatal=True)
if cmp_ubuntu_release >= 'xenial':
modprobe('netlink_diag')
diff --git a/tox.ini b/tox.ini
index 5786385..d9a94e9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -87,5 +87,5 @@ commands =
bundletester -vl DEBUG -r json -o func-results.json --test-pattern "dev-*" --no-destroy
[flake8]
-ignore = E402,E226
+ignore = E402,E226,W504
exclude = */charmhelpers
diff --git a/unit_tests/test_lxd_utils.py b/unit_tests/test_lxd_utils.py
index 75fe65c..ecfda00 100644
--- a/unit_tests/test_lxd_utils.py
+++ b/unit_tests/test_lxd_utils.py
@@ -14,6 +14,7 @@
"""Tests for hooks.lxd_utils."""
import mock
+import textwrap
import lxd_utils
import testing
@@ -238,3 +239,52 @@ class TestConfigureUIDGID(testing.CharmTestCase):
mock.call('ubuntu:165536:65536\n')
])
self.service_restart.assert_called_with('lxd')
+
+
+class MyProcessError(Exception):
+ pass
+
+
+class TestHasStorage(testing.CharmTestCase):
+ """Tests for hooks.lxd_utils.has_storage"""
+
+ TO_PATCH = [
+ 'check_output',
+ ]
+
+ def setUp(self):
+ super(TestHasStorage, self).setUp(lxd_utils, self.TO_PATCH)
+
+ def test_has_storage_default(self):
+ self.check_output.return_value = b""
+ self.assertTrue(lxd_utils.has_storage())
+
+ @mock.patch('subprocess.CalledProcessError', new=MyProcessError)
+ def test_has_storage_default_error(self):
+ def raise_error(*args, **kwargs):
+ raise MyProcessError()
+
+ self.check_output.side_effect = raise_error
+ self.assertFalse(lxd_utils.has_storage())
+
+ def test_has_storage_by_pool(self):
+ self.check_output.return_value = textwrap.dedent(
+ b"""
+ +---------+-------------+--------+--------------------------------+---------+
+ | NAME | DESCRIPTION | DRIVER | SOURCE | USED BY |
+ +---------+-------------+--------+--------------------------------+---------+
+ | default | | btrfs | /var/lib/lxd/disks/default.img | 1 |
+ +---------+-------------+--------+--------------------------------+---------+
+ """) # NOQA W501
+ self.assertTrue(lxd_utils.has_storage('default'))
+
+ def test_has_storage_missing_pool(self):
+ self.check_output.return_value = textwrap.dedent(
+ b"""
+ +---------+-------------+--------+--------------------------------+---------+
+ | NAME | DESCRIPTION | DRIVER | SOURCE | USED BY |
+ +---------+-------------+--------+--------------------------------+---------+
+ | default | | btrfs | /var/lib/lxd/disks/default.img | 1 |
+ +---------+-------------+--------+--------------------------------+---------+
+ """) # NOQA W501
+ self.assertFalse(lxd_utils.has_storage('btrfs'))

This mirror site include all the OpenStack related repositories under: openstack, openstack-dev and openstack-infra.

NOTE: All repositories are updated every one hour.

Usage

For Git Clone
 git clone http://git.trystack.cn/openstack/nova.git 
For DevStack

Add GIT_BASE, NOVNC_REPO and SPICE_REPO variables to local.conf file.

[[local|localrc]]

# use TryStack git mirror
GIT_BASE=http://git.trystack.cn
NOVNC_REPO=http://git.trystack.cn/kanaka/noVNC.git
SPICE_REPO=http://git.trystack.cn/git/spice/spice-html5.git