diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-02-25 14:37:04 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-02-25 14:37:04 -0500 |
commit | 3b773f7919c86a58956e2fc493512bb2c1ce31a8 (patch) | |
tree | 6ab76ff494ceeb75b567b7c247791d1b6dac03a3 /tests/unittests/test_handler/test_handler_lxd.py | |
parent | df6af3e1433b9e5564bec7cd452cfb3a0fb403e9 (diff) | |
parent | 4d8e7324c7242e1c969c8561462def6c1cda747c (diff) | |
download | vyos-cloud-init-3b773f7919c86a58956e2fc493512bb2c1ce31a8.tar.gz vyos-cloud-init-3b773f7919c86a58956e2fc493512bb2c1ce31a8.zip |
lxd: add support for setting up lxd using 'lxd init'
If lxd key is present in cfg, then run 'lxd init' with values from the
'init' entry in lxd configuration as flags.
Diffstat (limited to 'tests/unittests/test_handler/test_handler_lxd.py')
-rw-r--r-- | tests/unittests/test_handler/test_handler_lxd.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/unittests/test_handler/test_handler_lxd.py b/tests/unittests/test_handler/test_handler_lxd.py new file mode 100644 index 00000000..4d858b8f --- /dev/null +++ b/tests/unittests/test_handler/test_handler_lxd.py @@ -0,0 +1,58 @@ +from cloudinit.config import cc_lxd +from cloudinit import (distros, helpers, cloud) +from cloudinit.sources import DataSourceNoCloud +from .. import helpers as t_help + +import logging + +try: + from unittest import mock +except ImportError: + import mock + +LOG = logging.getLogger(__name__) + + +class TestLxd(t_help.TestCase): + lxd_cfg = { + 'lxd': { + 'init': { + 'network_address': '0.0.0.0', + 'storage_backend': 'zfs', + 'storage_pool': 'poolname', + } + } + } + + def setUp(self): + super(TestLxd, self).setUp() + + def _get_cloud(self, distro): + cls = distros.fetch(distro) + paths = helpers.Paths({}) + d = cls(distro, {}, paths) + ds = DataSourceNoCloud.DataSourceNoCloud({}, d, paths) + cc = cloud.Cloud(ds, paths, {}, d, None) + return cc + + @mock.patch("cloudinit.config.cc_lxd.util") + def test_lxd_init(self, mock_util): + cc = self._get_cloud('ubuntu') + mock_util.which.return_value = True + cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, LOG, []) + self.assertTrue(mock_util.which.called) + init_call = mock_util.subp.call_args_list[0][0][0] + self.assertEquals(init_call, + ['lxd', 'init', '--auto', '--network-address', + '0.0.0.0', '--storage-backend', 'zfs', + '--storage-pool', 'poolname']) + + @mock.patch("cloudinit.config.cc_lxd.util") + def test_lxd_install(self, mock_util): + cc = self._get_cloud('ubuntu') + cc.distro = mock.MagicMock() + mock_util.which.return_value = None + cc_lxd.handle('cc_lxd', self.lxd_cfg, cc, LOG, []) + self.assertTrue(cc.distro.install_packages.called) + install_pkg = cc.distro.install_packages.call_args_list[0][0][0] + self.assertEquals(install_pkg, ('lxd',)) |