summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudinit/sources/DataSourceSmartOS.py26
-rw-r--r--doc/examples/cloud-config-datasources.txt2
-rw-r--r--doc/sources/smartos/README.rst12
-rw-r--r--tests/unittests/test_datasource/test_smartos.py8
4 files changed, 36 insertions, 12 deletions
diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py
index e0bb871c..1cf9e4f0 100644
--- a/cloudinit/sources/DataSourceSmartOS.py
+++ b/cloudinit/sources/DataSourceSmartOS.py
@@ -35,7 +35,7 @@ import os
import os.path
import serial
-
+DS_NAME = 'SmartOS'
DEF_TTY_LOC = '/dev/ttyS1'
DEF_TTY_TIMEOUT = 60
LOG = logging.getLogger(__name__)
@@ -60,13 +60,14 @@ class DataSourceSmartOS(sources.DataSource):
sources.DataSource.__init__(self, sys_cfg, distro, paths)
self.seed_dir = os.path.join(paths.seed_dir, 'sdc')
self.is_smartdc = None
+ self.base_64_encoded = []
self.seed = self.sys_cfg.get("serial_device", DEF_TTY_LOC)
self.all_base64 = self.sys_cfg.get("decode_base64", False)
- self.base_64_encoded = []
- self.smartos_no_base64 = self.sys_cfg.get("no_base64_decode",
- SMARTOS_NO_BASE64)
self.seed_timeout = self.sys_cfg.get("serial_timeout",
DEF_TTY_TIMEOUT)
+ self.smartos_no_base64 = SMARTOS_NO_BASE64
+ if 'no_base64_decode' in self.ds_cfg:
+ self.smartos_no_base64 = self.ds_cfg['no_base64_decode']
def __str__(self):
root = sources.DataSource.__str__(self)
@@ -137,10 +138,25 @@ class DataSourceSmartOS(sources.DataSource):
def get_instance_id(self):
return self.metadata['instance-id']
+ def not_b64_var(self, var):
+ """Return true if value is read as b64."""
+ if var in self.smartos_no_base64 or \
+ not self.all_base64:
+ return True
+ return False
+
+ def is_b64_var(self, var):
+ """Return true if value is read as b64."""
+ if self.all_base64 or (
+ var not in self.smartos_no_base64 and
+ var in self.base_64_encoded):
+ return True
+ return False
+
def get_serial(seed_device, seed_timeout):
"""This is replaced in unit testing, allowing us to replace
- serial.Serial with a mocked class
+ serial.Serial with a mocked class.
The timeout value of 60 seconds should never be hit. The value
is taken from SmartOS own provisioning tools. Since we are reading
diff --git a/doc/examples/cloud-config-datasources.txt b/doc/examples/cloud-config-datasources.txt
index 6544448e..6ec0d57e 100644
--- a/doc/examples/cloud-config-datasources.txt
+++ b/doc/examples/cloud-config-datasources.txt
@@ -55,5 +55,5 @@ datasource:
# Smart OS datasource works over a serial console interacting with
# a server on the other end. By default, the second serial console is the
# device. SmartOS also uses a serial timeout of 60 seconds.
- serial device: /dev/ttyS1
+ serial_device: /dev/ttyS1
serial timeout: 60
diff --git a/doc/sources/smartos/README.rst b/doc/sources/smartos/README.rst
index 96310857..ba90e7af 100644
--- a/doc/sources/smartos/README.rst
+++ b/doc/sources/smartos/README.rst
@@ -12,8 +12,7 @@ serial console. On Linux, this is /dev/ttyS1. The data is a provided via a
simple protocol, where something queries for the userdata, where the console
responds with the status and if "SUCCESS" returns until a single ".\n".
-The format is lossy. As such, new versions of the SmartOS tooling will include
-support for base64 encoded data.
+New versions of the SmartOS tooling will include support for base64 encoded data.
Userdata
--------
@@ -48,15 +47,16 @@ always supercede any user-script data. This is for consistency.
base64
------
-In order to provide a lossy format, all data except for:
+The following are excempt from base64 encoding, owing to the fact that they
+are provided by SmartOS:
* root_authorized_keys
* enable_motd_sys_info
* iptables_disable
This means that user-script and user-data as well as other values can be
-base64 encoded to provide a lossy format. Since Cloud-init can only guess
-as to whether or not something is truly base64 encoded, the following
-meta-data keys are hints as to whether or not to base64 decode something:
+base64 encoded. Since Cloud-init can only guess as to whether or not something
+is truly base64 encoded, the following meta-data keys are hints as to whether
+or not to base64 decode something:
* decode_base64: Except for excluded keys, attempt to base64 decode
the values. If the value fails to decode properly, it will be
returned in its text
diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py
index ae621433..b9b3a479 100644
--- a/tests/unittests/test_datasource/test_smartos.py
+++ b/tests/unittests/test_datasource/test_smartos.py
@@ -36,6 +36,7 @@ mock_returns = {
'enable_motd_sys_info': None,
'system_uuid': str(uuid.uuid4()),
'smartdc': 'smartdc',
+ 'test-var1': 'some data',
'user-data': """
#!/bin/sh
/bin/true
@@ -156,6 +157,13 @@ class TestSmartOSDataSource(MockerTestCase):
self.assertTrue(ret)
self.assertTrue(dsrc.is_smartdc)
+ def test_no_base64(self):
+ sys_cfg = {'no_base64_decode': ['test_var1'], 'all_base': True}
+ dsrc = self._get_ds(sys_cfg=sys_cfg)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ self.assertTrue(dsrc.not_b64_var('test-var'))
+
def test_uuid(self):
dsrc = self._get_ds()
ret = dsrc.get_data()