diff --git a/hooks/neutron_ovs_utils.py b/hooks/neutron_ovs_utils.py index b3f0eb9c..a18303e1 100644 --- a/hooks/neutron_ovs_utils.py +++ b/hooks/neutron_ovs_utils.py @@ -67,6 +67,8 @@ from charmhelpers.core.host import ( service_running, CompareHostReleases, init_is_systemd, + group_exists, + user_exists, ) from charmhelpers.fetch import ( @@ -445,7 +447,10 @@ def enable_ovs_dpdk(): def install_tmpfilesd(): '''Install systemd-tmpfiles configuration for ovs vhost-user sockets''' - if init_is_systemd(): + # NOTE(jamespage): Only do this if libvirt is actually installed + if (init_is_systemd() and + user_exists('libvirt-qemu') and + group_exists('kvm')): shutil.copy('files/nova-ovs-vhost-user.conf', '/etc/tmpfiles.d') subprocess.check_call(['systemd-tmpfiles', '--create']) diff --git a/unit_tests/test_neutron_ovs_utils.py b/unit_tests/test_neutron_ovs_utils.py index 3f784598..ceca2637 100644 --- a/unit_tests/test_neutron_ovs_utils.py +++ b/unit_tests/test_neutron_ovs_utils.py @@ -61,6 +61,9 @@ TO_PATCH = [ 'disable_ipfix', 'ovs_has_late_dpdk_init', 'parse_data_port_mappings', + 'user_exists', + 'group_exists', + 'init_is_systemd', ] head_pkg = 'linux-headers-3.15.0-5-generic' @@ -782,6 +785,28 @@ class TestNeutronOVSUtils(CharmTestCase): self.assertTrue(self.remote_restart.called) + @patch.object(nutils, 'subprocess') + @patch.object(nutils, 'shutil') + def test_install_tmpfilesd_lxd(self, mock_shutil, mock_subprocess): + self.init_is_systemd.return_value = True + self.group_exists.return_value = False + self.user_exists.return_value = False + nutils.install_tmpfilesd() + mock_shutil.copy.assert_not_called() + mock_subprocess.check_call.assert_not_called() + + @patch.object(nutils, 'subprocess') + @patch.object(nutils, 'shutil') + def test_install_tmpfilesd_libvirt(self, mock_shutil, mock_subprocess): + self.init_is_systemd.return_value = True + self.group_exists.return_value = True + self.user_exists.return_value = True + nutils.install_tmpfilesd() + mock_shutil.copy.assert_called_once() + mock_subprocess.check_call.assert_called_once_with( + ['systemd-tmpfiles', '--create'] + ) + class TestDPDKBridgeBondMap(CharmTestCase):