Add snapped version of LXD support to nova-lxd
If LXD is installed via a snap, then the location of the console log
changes from the package version. This patchset detects whether LXD is
snapped, and if so, provides a slightly different path for the console.
(cherry picked from commit e2aab580bd
)
Change-Id: Id5c0ca2fd4b70f06b683c75ce5162b3f1a709187
This commit is contained in:
parent
1060782cbf
commit
539efa3ad0
|
@ -36,31 +36,49 @@ class InstanceAttributesTest(test.NoDBTestCase):
|
|||
super(InstanceAttributesTest, self).tearDown()
|
||||
self.CONF_patcher.stop()
|
||||
|
||||
def test_instance_dir(self):
|
||||
def test_is_snap_lxd(self):
|
||||
with mock.patch('os.path.isfile') as isfile:
|
||||
isfile.return_value = False
|
||||
self.assertFalse(common.is_snap_lxd())
|
||||
isfile.return_value = True
|
||||
self.assertTrue(common.is_snap_lxd())
|
||||
|
||||
@mock.patch.object(common, 'is_snap_lxd')
|
||||
def test_instance_dir(self, is_snap_lxd):
|
||||
ctx = context.get_admin_context()
|
||||
instance = fake_instance.fake_instance_obj(
|
||||
ctx, name='test', memory_mb=0)
|
||||
is_snap_lxd.return_value = False
|
||||
|
||||
attributes = common.InstanceAttributes(instance)
|
||||
|
||||
self.assertEqual(
|
||||
'/i/instance-00000001', attributes.instance_dir)
|
||||
|
||||
def test_console_path(self):
|
||||
@mock.patch.object(common, 'is_snap_lxd')
|
||||
def test_console_path(self, is_snap_lxd):
|
||||
ctx = context.get_admin_context()
|
||||
instance = fake_instance.fake_instance_obj(
|
||||
ctx, name='test', memory_mb=0)
|
||||
is_snap_lxd.return_value = False
|
||||
|
||||
attributes = common.InstanceAttributes(instance)
|
||||
|
||||
self.assertEqual(
|
||||
'/var/log/lxd/instance-00000001/console.log',
|
||||
attributes.console_path)
|
||||
|
||||
def test_storage_path(self):
|
||||
is_snap_lxd.return_value = True
|
||||
attributes = common.InstanceAttributes(instance)
|
||||
self.assertEqual(
|
||||
'/var/snap/lxd/common/lxd/logs/instance-00000001/console.log',
|
||||
attributes.console_path)
|
||||
|
||||
@mock.patch.object(common, 'is_snap_lxd')
|
||||
def test_storage_path(self, is_snap_lxd):
|
||||
ctx = context.get_admin_context()
|
||||
instance = fake_instance.fake_instance_obj(
|
||||
ctx, name='test', memory_mb=0)
|
||||
is_snap_lxd.return_value = False
|
||||
|
||||
attributes = common.InstanceAttributes(instance)
|
||||
|
||||
|
|
|
@ -24,10 +24,25 @@ _InstanceAttributes = collections.namedtuple('InstanceAttributes', [
|
|||
|
||||
def InstanceAttributes(instance):
|
||||
"""An instance adapter for nova-lxd specific attributes."""
|
||||
if is_snap_lxd():
|
||||
prefix = '/var/snap/lxd/common/lxd/logs'
|
||||
else:
|
||||
prefix = '/var/log/lxd'
|
||||
instance_dir = os.path.join(conf.CONF.instances_path, instance.name)
|
||||
console_path = os.path.join('/var/log/lxd/', instance.name, 'console.log')
|
||||
console_path = os.path.join(prefix, instance.name, 'console.log')
|
||||
storage_path = os.path.join(instance_dir, 'storage')
|
||||
container_path = os.path.join(
|
||||
conf.CONF.lxd.root_dir, 'containers', instance.name)
|
||||
return _InstanceAttributes(
|
||||
instance_dir, console_path, storage_path, container_path)
|
||||
|
||||
|
||||
def is_snap_lxd():
|
||||
"""Determine whether it's a snap installed lxd or a package installed lxd
|
||||
|
||||
This is easily done by checking if the bin file is /snap/bin/lxc
|
||||
|
||||
:returns: True if snap installed, otherwise False
|
||||
:rtype: bool
|
||||
"""
|
||||
return os.path.isfile('/snap/bin/lxc')
|
||||
|
|
Loading…
Reference in New Issue