Fix problem with 'storage.zfs_pool_name' being removed from lxd 3

LXD 3.x onwards removes the key 'storage.zfs_pool_name' from the config.
This means the storage_pool API needs to be used to get the name of the
pool that juju is using for ZFS.  This is a temporary fix until storage
pools can be threaded into nova-lxd properly. This occurs on bionic due
to LXD 3 being shipped as standard.

Change-Id: I6527640438331b86f2140cf0a772f7d207a6fd40
Closes-Bug: #1782329
This commit is contained in:
Alex Kavanagh 2018-07-19 15:04:30 +01:00
parent a02fce0d31
commit f1bbc03b65
5 changed files with 48 additions and 10 deletions

View File

@ -79,6 +79,11 @@ r="$r|(?:tempest\.api\.compute\.volumes\.test_attach_volume\.AttachVolumeShelveT
r="$r|(?:.*test_get_server_diagnostics.*)"
#test_get_server_diagnostics
# XXX: ajkavanagh (2018-07-23): disable test_show_update_rebuild_list_server as nova-lxd doesn't have the
# 'supports_trusted_certs' capability, and the test uses it.
# BUG: https://bugs.launchpad.net/nova-lxd/+bug/1783080
r="$r|(?:.*ServerShowV263Test.test_show_update_rebuild_list_server.*)"
r="$r).*$"
export DEVSTACK_GATE_TEMPEST_REGEX="$r"

View File

@ -14,6 +14,7 @@
import ddt
import mock
import uuid
from nova import context
from nova.tests.unit import fake_instance
@ -101,7 +102,7 @@ def _fake_instance():
_instance_values = {
'display_name': 'fake_display_name',
'name': 'fake_name',
'uuid': 'fake_uuid',
'uuid': uuid.uuid1(),
'image_ref': 'fake_image',
'vcpus': 1,
'memory_mb': 512,

View File

@ -213,7 +213,9 @@ class TestDetachEphemeral(test.NoDBTestCase):
lxd_config = {'environment': {'storage': 'zfs'},
'config': {'storage.zfs_pool_name': 'zfs'}}
storage.detach_ephemeral(block_device_info, lxd_config, instance)
client = mock.Mock()
storage.detach_ephemeral(
client, block_device_info, lxd_config, instance)
block_device_info_get_ephemerals.assert_called_once_with(
block_device_info)
@ -239,7 +241,9 @@ class TestDetachEphemeral(test.NoDBTestCase):
lxd_config = {'environment': {'storage': 'lvm'},
'config': {'storage.lvm_vg_name': 'lxd'}}
storage.detach_ephemeral(block_device_info, lxd_config, instance)
client = mock.Mock()
storage.detach_ephemeral(
client, block_device_info, lxd_config, instance)
block_device_info_get_ephemerals.assert_called_once_with(
block_device_info)

View File

@ -661,7 +661,10 @@ class LXDDriver(driver.ComputeDriver):
self.firewall_driver.unfilter_instance(instance, network_info)
lxd_config = self.client.host_info
storage.detach_ephemeral(block_device_info, lxd_config, instance)
storage.detach_ephemeral(self.client,
block_device_info,
lxd_config,
instance)
name = pwd.getpwuid(os.getuid()).pw_name
@ -1039,9 +1042,15 @@ class LXDDriver(driver.ComputeDriver):
# to support LXD storage pools
storage_driver = lxd_config['environment']['storage']
if storage_driver == 'zfs':
local_disk_info = _get_zpool_info(
lxd_config['config']['storage.zfs_pool_name']
)
# NOTE(ajkavanagh) - BUG/1782329 - this is temporary until storage
# pools is implemented. LXD 3 removed the storage.zfs_pool_name
# key from the config. So, if it fails, we need to grab the
# configured storage pool and use that as the name instead.
try:
pool_name = lxd_config['config']['storage.zfs_pool_name']
except KeyError:
pool_name = CONF.lxd.pool
local_disk_info = _get_zpool_info(pool_name)
else:
local_disk_info = _get_fs_info(CONF.lxd.root_dir)

View File

@ -14,6 +14,7 @@
# under the License.
import os
from oslo_config import cfg
from oslo_utils import fileutils
from nova import exception
from nova import utils
@ -21,6 +22,8 @@ from nova.virt import driver
from nova.virt.lxd import common
CONF = cfg.CONF
def attach_ephemeral(client, block_device_info, lxd_config, instance):
"""Attach ephemeral storage to an instance."""
@ -39,7 +42,15 @@ def attach_ephemeral(client, block_device_info, lxd_config, instance):
storage_dir = os.path.join(
instance_attrs.storage_path, ephemeral['virtual_name'])
if storage_driver == 'zfs':
zfs_pool = lxd_config['config']['storage.zfs_pool_name']
# NOTE(ajkavanagh) - BUG/1782329 - this is temporary until
# storage pools is implemented. LXD 3 removed the
# storage.zfs_pool_name key from the config. So, if it fails,
# we need to grab the configured storage pool and use that as
# the name instead.
try:
zfs_pool = lxd_config['config']['storage.zfs_pool_name']
except KeyError:
zfs_pool = CONF.lxd.pool
utils.execute(
'zfs', 'create',
@ -92,7 +103,7 @@ def attach_ephemeral(client, block_device_info, lxd_config, instance):
storage_dir, run_as_root=True)
def detach_ephemeral(block_device_info, lxd_config, instance):
def detach_ephemeral(client, block_device_info, lxd_config, instance):
"""Detach ephemeral device from the instance."""
ephemeral_storage = driver.block_device_info_get_ephemerals(
block_device_info)
@ -101,7 +112,15 @@ def detach_ephemeral(block_device_info, lxd_config, instance):
for ephemeral in ephemeral_storage:
if storage_driver == 'zfs':
zfs_pool = lxd_config['config']['storage.zfs_pool_name']
# NOTE(ajkavanagh) - BUG/1782329 - this is temporary until
# storage pools is implemented. LXD 3 removed the
# storage.zfs_pool_name key from the config. So, if it fails,
# we need to grab the configured storage pool and use that as
# the name instead.
try:
zfs_pool = lxd_config['config']['storage.zfs_pool_name']
except KeyError:
zfs_pool = CONF.lxd.pool
utils.execute(
'zfs', 'destroy',