summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWesley Wiedenmeier <wesley.wiedenmeier@gmail.com>2016-02-03 22:21:40 -0600
committerWesley Wiedenmeier <wesley.wiedenmeier@gmail.com>2016-02-03 22:21:40 -0600
commitee40614b0a34a110265493c176c64db823aa34b3 (patch)
tree56d57c70949e206168a8d22433c55b16a1293c9a /tests
parentf512c0126aac5c8708065c6e8aa5510f83574657 (diff)
downloadvyos-cloud-init-ee40614b0a34a110265493c176c64db823aa34b3.tar.gz
vyos-cloud-init-ee40614b0a34a110265493c176c64db823aa34b3.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')
-rw-r--r--tests/unittests/test_handler/test_handler_lxd.py62
1 files changed, 62 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..89863d52
--- /dev/null
+++ b/tests/unittests/test_handler/test_handler_lxd.py
@@ -0,0 +1,62 @@
+from cloudinit.config import cc_lxd
+from cloudinit import (util, distros, helpers, cloud)
+from cloudinit.sources import DataSourceNoCloud
+from .. import helpers as t_help
+
+import logging
+
+LOG = logging.getLogger(__name__)
+
+
+class TestLxd(t_help.TestCase):
+ def setUp(self):
+ super(TestLxd, self).setUp()
+ self.unapply = []
+ apply_patches([(util, 'subp', self._mock_subp)])
+ self.subp_called = []
+
+ def tearDown(self):
+ apply_patches([i for i in reversed(self.unapply)])
+
+ def _mock_subp(self, *args, **kwargs):
+ if 'args' not in kwargs:
+ kwargs['args'] = args[0]
+ self.subp_called.append(kwargs)
+ return
+
+ 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
+
+ def test_lxd_init(self):
+ cfg = {
+ 'lxd': {
+ 'init': {
+ 'network_address': '0.0.0.0',
+ 'storage_backend': 'zfs',
+ 'storage_pool': 'poolname',
+ }
+ }
+ }
+ cc = self._get_cloud('ubuntu')
+ cc_lxd.handle('cc_lxd', cfg, cc, LOG, [])
+
+ self.assertEqual(
+ self.subp_called[0].get('args'),
+ ['lxd', 'init', '--auto', '--network-address', '0.0.0.0',
+ '--storage-backend', 'zfs', '--storage-pool', 'poolname'])
+
+
+def apply_patches(patches):
+ ret = []
+ for (ref, name, replace) in patches:
+ if replace is None:
+ continue
+ orig = getattr(ref, name)
+ setattr(ref, name, replace)
+ ret.append((ref, name, orig))
+ return ret