Tidy, drop storage config

This commit is contained in:
james.page@ubuntu.com 2015-04-22 10:21:01 +01:00
commit ff332297f6
5 changed files with 69 additions and 19 deletions

View File

@ -75,7 +75,7 @@ options:
virt-type:
default: kvm
type: string
description: "Virtualization flavor. Supported: kvm, xen, uml, lxc. qemu"
description: "Virtualization flavor. Supported: kvm, xen, uml, lxc, qemu, lxd"
multi-host:
default: "yes"
type: string

View File

@ -60,6 +60,7 @@ from nova_compute_utils import (
QUANTUM_CONF, NEUTRON_CONF,
ceph_config_file, CEPH_SECRET,
enable_shell, disable_shell,
configure_lxd,
fix_path_ownership,
get_topics,
assert_charm_supports_ipv6,
@ -129,6 +130,9 @@ def config_changed():
fp = config('instances-path')
fix_path_ownership(fp, user='nova')
if config('virt-type').lower() == 'lxd':
configure_lxd(user='nova')
[compute_joined(rid) for rid in relation_ids('cloud-compute')]
for rid in relation_ids('zeromq-configuration'):
zeromq_configuration_relation_joined(rid)

View File

@ -122,6 +122,7 @@ GIT_PACKAGE_BLACKLIST = [
'quantum-server',
]
DEFAULT_INSTANCE_PATH = '/var/lib/nova/instances'
NOVA_CONF_DIR = "/etc/nova"
QEMU_CONF = '/etc/libvirt/qemu.conf'
LIBVIRTD_CONF = '/etc/libvirt/libvirtd.conf'
@ -130,22 +131,6 @@ LIBVIRT_BIN_OVERRIDES = '/etc/init/libvirt-bin.override'
NOVA_CONF = '%s/nova.conf' % NOVA_CONF_DIR
BASE_RESOURCE_MAP = {
QEMU_CONF: {
'services': ['libvirt-bin'],
'contexts': [],
},
LIBVIRTD_CONF: {
'services': ['libvirt-bin'],
'contexts': [NovaComputeLibvirtContext()],
},
LIBVIRT_BIN: {
'services': ['libvirt-bin'],
'contexts': [NovaComputeLibvirtContext()],
},
LIBVIRT_BIN_OVERRIDES: {
'services': ['libvirt-bin'],
'contexts': [NovaComputeLibvirtOverrideContext()],
},
NOVA_CONF: {
'services': ['nova-compute'],
'contexts': [context.AMQPContext(ssl_dir=NOVA_CONF_DIR),
@ -171,6 +156,27 @@ BASE_RESOURCE_MAP = {
},
}
LIBVIRT_RESOURCE_MAP = {
QEMU_CONF: {
'services': ['libvirt-bin'],
'contexts': [],
},
LIBVIRTD_CONF: {
'services': ['libvirt-bin'],
'contexts': [NovaComputeLibvirtContext()],
},
LIBVIRT_BIN: {
'services': ['libvirt-bin'],
'contexts': [NovaComputeLibvirtContext()],
},
LIBVIRT_BIN_OVERRIDES: {
'services': ['libvirt-bin'],
'contexts': [NovaComputeLibvirtOverrideContext()],
},
}
LIBVIRT_RESOURCE_MAP.update(BASE_RESOURCE_MAP)
CHARM_CEPH_CONF = '/var/lib/charm/{}/ceph.conf'
CEPH_SECRET = '/etc/ceph/secret.xml'
CEPH_RESOURCES = {
@ -212,6 +218,7 @@ VIRT_TYPES = {
'xen': ['nova-compute-xen'],
'uml': ['nova-compute-uml'],
'lxc': ['nova-compute-lxc'],
'lxd': ['nova-compute-lxd'],
}
# Maps virt-type config to a libvirt URI.
@ -230,7 +237,10 @@ def resource_map():
hook execution.
'''
# TODO: Cache this on first call?
resource_map = deepcopy(BASE_RESOURCE_MAP)
if config('virt-type').lower() != 'lxd':
resource_map = deepcopy(LIBVIRT_RESOURCE_MAP)
else:
resource_map = deepcopy(BASE_RESOURCE_MAP)
net_manager = network_manager()
plugin = neutron_plugin()
@ -554,6 +564,26 @@ def create_libvirt_secret(secret_file, secret_uuid, key):
check_call(cmd)
def configure_lxd(user='nova'):
''' Configures lxd '''
configure_subuid(user='nova')
configure_lxd_daemon(user='nova')
service_restart('nova-compute')
def configure_lxd_daemon(user):
add_user_to_group('nova', 'lxd')
service_restart('lxd')
cmd = ['sudo', '-u', user, 'lxc', 'list']
check_call(cmd)
def configure_subuid(user):
cmd = ['usermod', '-v', '100000-200000', '-w', '100000-200000', user]
check_call(cmd)
def enable_shell(user):
cmd = ['usermod', '-s', '/bin/bash', user]
check_call(cmd)

View File

@ -19,7 +19,6 @@ ec2_private_dns_show_ip=True
api_paste_config=/etc/nova/api-paste.ini
enabled_apis=ec2,osapi_compute,metadata
auth_strategy=keystone
compute_driver=libvirt.LibvirtDriver
my_ip = {{ host_ip }}
{% if arch == 'aarch64' -%}

View File

@ -23,8 +23,10 @@ TO_PATCH = [
'related_units',
'relation_ids',
'relation_get',
'service_restart',
'mkdir',
'install_alternative',
'add_user_to_group',
'MetadataServiceContext',
]
@ -396,6 +398,12 @@ class NovaComputeUtilsTests(CharmTestCase):
_check_call.assert_called_with(['usermod', '-s', '/bin/false',
'dummy'])
@patch.object(utils, 'check_call')
def test_configure_subuid(self, _check_call):
utils.configure_subuid('dummy')
_check_call.assert_called_with(['usermod', '-v', '100000-200000',
'-w', '100000-200000', 'dummy'])
@patch.object(utils, 'check_call')
@patch.object(utils, 'check_output')
def test_create_libvirt_key(self, _check_output, _check_call):
@ -448,6 +456,15 @@ class NovaComputeUtilsTests(CharmTestCase):
compute_context.CEPH_SECRET_UUID,
'--base64', key])
@patch.object(utils, 'check_call')
@patch.object(utils, 'check_output')
def test_configure_lxd_daemon(self, _check_output, _check_call):
self.test_config.set('virt-type', 'lxd')
utils.configure_lxd_daemon('nova')
self.add_user_to_group.assert_called_with('nova', 'lxd')
self.service_restart.assert_called_with('lxd')
_check_output.assert_called_wth(['sudo', '-u', 'nova', 'lxc', 'list'])
def test_enable_nova_metadata(self):
class DummyContext():