diff options
author | Scott Moser <smoser@ubuntu.com> | 2014-02-14 00:15:08 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2014-02-14 00:15:08 -0500 |
commit | 12672e77a2881f9a87d2dcb4217e5e56b8b3dfd6 (patch) | |
tree | 311d2acd0e220ffbf316c7d0d75380f160a67518 /tests | |
parent | 053667688d7c2ad51e569c62e00dac1942e46f62 (diff) | |
parent | 1bf99b6fe9d11a9e3b1d452940d21779347ea461 (diff) | |
download | vyos-cloud-init-12672e77a2881f9a87d2dcb4217e5e56b8b3dfd6.tar.gz vyos-cloud-init-12672e77a2881f9a87d2dcb4217e5e56b8b3dfd6.zip |
re-work vendor-data and smartos
This reduces how much cloud-init is explicitly involved in what "vendor-data"
could accomplish. The goal of vendor-data was to provide the vendor with a
channel to run arbitrary code that accomodate for their specific platform.
Much of those accomodations are currently being done in cloud-init.
However, this now moves some of those things to default "vendor-data", instead
of cloud-init proper.
Basically, now we have an 'sdc:vendor-data' key in the metadata.
If that does not exist, then cloud-init will use the default.
The default, provides a boothook. That boothook writes a file into
/var/lib/cloud/per-boot/ . That file will be both written on every boot
and then executed at rc.local time frame (by 'scripts-per-boot').
It will then execute /var/lib/cloud/instance/data/user-script
and /var/lib/cloud/instance/data/operator-script if they exist.
So, the things that cloud-init is now doing outside of the default vendor-data
that I would rather be done in vendor-data is:
* managing the population of instance/data/user-script and
instance/data/operator-script. These could very easily be done
from the boothook, but doing them in cloud-init removes the necessity
for having a 'mdata-get' command in the image (or some other way for
the boothook script to query the datasource).
* managing the LEGACY things.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_datasource/test_smartos.py | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py index ae427bb5..19282bac 100644 --- a/tests/unittests/test_datasource/test_smartos.py +++ b/tests/unittests/test_datasource/test_smartos.py @@ -23,10 +23,12 @@ # import base64 -from cloudinit import helpers +from cloudinit import helpers as c_helpers +from cloudinit import stages +from cloudinit import util from cloudinit.sources import DataSourceSmartOS - -from mocker import MockerTestCase +from cloudinit.settings import (PER_INSTANCE) +from tests.unittests import helpers import os import os.path import re @@ -42,6 +44,7 @@ MOCK_RETURNS = { 'cloud-init:user-data': '\n'.join(['#!/bin/sh', '/bin/true', '']), 'sdc:datacenter_name': 'somewhere2', 'sdc:operator-script': '\n'.join(['bin/true', '']), + 'sdc:vendor-data': '\n'.join(['VENDOR_DATA', '']), 'user-data': '\n'.join(['something', '']), 'user-script': '\n'.join(['/bin/true', '']), } @@ -105,22 +108,37 @@ class MockSerial(object): yield '\n' -class TestSmartOSDataSource(MockerTestCase): +class TestSmartOSDataSource(helpers.FilesystemMockingTestCase): def setUp(self): + helpers.FilesystemMockingTestCase.setUp(self) + # makeDir comes from MockerTestCase self.tmp = self.makeDir() self.legacy_user_d = self.makeDir() + # If you should want to watch the logs... + self._log = None + self._log_file = None + self._log_handler = None + # patch cloud_dir, so our 'seed_dir' is guaranteed empty - self.paths = helpers.Paths({'cloud_dir': self.tmp}) + self.paths = c_helpers.Paths({'cloud_dir': self.tmp}) self.unapply = [] super(TestSmartOSDataSource, self).setUp() def tearDown(self): + helpers.FilesystemMockingTestCase.tearDown(self) + if self._log_handler and self._log: + self._log.removeHandler(self._log_handler) apply_patches([i for i in reversed(self.unapply)]) super(TestSmartOSDataSource, self).tearDown() + def _patchIn(self, root): + self.restore() + self.patchOS(root) + self.patchUtils(root) + def apply_patches(self, patches): ret = apply_patches(patches) self.unapply += ret @@ -327,10 +345,10 @@ class TestSmartOSDataSource(MockerTestCase): there is no script remaining. """ - script_d = os.path.join(self.tmp, "scripts", "per-boot") + script_d = os.path.join(self.tmp, "instance", "data") os.makedirs(script_d) - test_script_f = "%s/99_user_script" % script_d + test_script_f = os.path.join(script_d, 'user-script') with open(test_script_f, 'w') as f: f.write("TEST DATA") @@ -375,6 +393,25 @@ class TestSmartOSDataSource(MockerTestCase): self.assertFalse(found_new) + def test_vendor_data_not_default(self): + dsrc = self._get_ds(mockdata=MOCK_RETURNS) + ret = dsrc.get_data() + self.assertTrue(ret) + self.assertEquals(MOCK_RETURNS['sdc:vendor-data'], + dsrc.metadata['vendor-data']) + + def test_default_vendor_data(self): + my_returns = MOCK_RETURNS.copy() + def_op_script = my_returns['sdc:vendor-data'] + del my_returns['sdc:vendor-data'] + dsrc = self._get_ds(mockdata=my_returns) + ret = dsrc.get_data() + self.assertTrue(ret) + self.assertNotEquals(def_op_script, dsrc.metadata['vendor-data']) + + # we expect default vendor-data is a boothook + self.assertTrue(dsrc.vendordata_raw.startswith("#cloud-boothook")) + def test_disable_iptables_flag(self): dsrc = self._get_ds(mockdata=MOCK_RETURNS) ret = dsrc.get_data() |