summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2019-04-24 13:20:29 +0000
committerGerrit Code Review <review@openstack.org>2019-04-24 13:20:29 +0000
commit2e1fc7090b936c3e5f1a690e1c749e594b0f8a59 (patch)
tree46deb7ffb2e0aca26853149acf1966d81fdca4b0
parent820da96142391a863eda479d869df2ea1a6ca936 (diff)
parent4bf72620c3cf9cef5905a07132510df2cec5de41 (diff)
downloadcharm-nova-lxd-2e1fc7090b936c3e5f1a690e1c749e594b0f8a59.zip
charm-nova-lxd-2e1fc7090b936c3e5f1a690e1c749e594b0f8a59.tar.gz
charm-nova-lxd-2e1fc7090b936c3e5f1a690e1c749e594b0f8a59.tar.bz2
Merge "Fix detection of already initialised lxc storage pool"
-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