summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-09-27 19:38:05 -0400
committerScott Moser <smoser@ubuntu.com>2013-09-27 19:38:05 -0400
commitcafa32eb35e6ef7eba70a49e56dfeda51fd1f8a1 (patch)
tree25596b8dc52d4e355805dfdff2032763e57d73cc /tests
parent4063358ec2f20bcff4328fb659cecbed668a9a48 (diff)
parentfdf5a48420b670b4b07c745b2b80c1cb23f253db (diff)
downloadvyos-cloud-init-cafa32eb35e6ef7eba70a49e56dfeda51fd1f8a1.tar.gz
vyos-cloud-init-cafa32eb35e6ef7eba70a49e56dfeda51fd1f8a1.zip
Enable filesystem creation on Azure, many disk_setup cleanups
There are a lot of cleanups here around Azure, SmartOS and disk_setup. disk_setup correctly identifies disk "aliases" (block device mappings from ec2), anywhere where you would use a device name. You can also specify these mappings to the Azure or SmartOS datasource in their datasource config (device_aliases). Also, stop Azure from calling blkid repeatedly in its tests, which really pounded my laptop.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_datasource/test_azure.py60
-rw-r--r--tests/unittests/test_datasource/test_smartos.py28
2 files changed, 68 insertions, 20 deletions
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 1ca6a79d..86e2ed8c 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -120,8 +120,7 @@ class TestAzureDataSource(MockerTestCase):
mod = DataSourceAzure
- if data.get('dsdevs'):
- self.apply_patches([(mod, 'list_possible_azure_ds_devs', dsdevs)])
+ self.apply_patches([(mod, 'list_possible_azure_ds_devs', dsdevs)])
self.apply_patches([(mod, 'invoke_agent', _invoke_agent),
(mod, 'write_files', _write_files),
@@ -154,9 +153,12 @@ class TestAzureDataSource(MockerTestCase):
def test_user_cfg_set_agent_command_plain(self):
# set dscfg in via plaintext
- cfg = {'agent_command': "my_command"}
+ # we must have friendly-to-xml formatted plaintext in yaml_cfg
+ # not all plaintext is expected to work.
+ yaml_cfg = "{agent_command: my_command}\n"
+ cfg = yaml.safe_load(yaml_cfg)
odata = {'HostName': "myhost", 'UserName': "myuser",
- 'dscfg': {'text': yaml.dump(cfg), 'encoding': 'plain'}}
+ 'dscfg': {'text': yaml_cfg, 'encoding': 'plain'}}
data = {'ovfcontent': construct_valid_ovf_env(data=odata)}
dsrc = self._get_ds(data)
@@ -290,11 +292,59 @@ class TestAzureDataSource(MockerTestCase):
self.assertEqual(data.get('apply_hostname_bounce', "N/A"), "N/A")
+ def test_default_ephemeral(self):
+ # make sure the ephemeral device works
+ odata = {}
+ data = {'ovfcontent': construct_valid_ovf_env(data=odata),
+ 'sys_cfg': {}}
+
+ dsrc = self._get_ds(data)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ cfg = dsrc.get_config_obj()
+
+ self.assertEquals(dsrc.device_name_to_device("ephemeral0"),
+ "/dev/sdb")
+ assert 'disk_setup' in cfg
+ assert 'fs_setup' in cfg
+ self.assertIsInstance(cfg['disk_setup'], dict)
+ self.assertIsInstance(cfg['fs_setup'], list)
+
+ def test_provide_disk_aliases(self):
+ # Make sure that user can affect disk aliases
+ dscfg = {'disk_aliases': {'ephemeral0': '/dev/sdc'}}
+ odata = {'HostName': "myhost", 'UserName': "myuser",
+ 'dscfg': {'text': base64.b64encode(yaml.dump(dscfg)),
+ 'encoding': 'base64'}}
+ usercfg = {'disk_setup': {'/dev/sdc': {'something': '...'},
+ 'ephemeral0': False}}
+ userdata = '#cloud-config' + yaml.dump(usercfg) + "\n"
+
+ ovfcontent = construct_valid_ovf_env(data=odata, userdata=userdata)
+ data = {'ovfcontent': ovfcontent, 'sys_cfg': {}}
+
+ dsrc = self._get_ds(data)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ cfg = dsrc.get_config_obj()
+ self.assertTrue(cfg)
+ self.assertEquals(dsrc.device_name_to_device("ephemeral0"),
+ "/dev/sdc")
+
+ def test_userdata_arrives(self):
+ userdata = "This is my user-data"
+ xml = construct_valid_ovf_env(data={}, userdata=userdata)
+ data = {'ovfcontent': xml}
+ dsrc = self._get_ds(data)
+ dsrc.get_data()
+
+ self.assertEqual(userdata, dsrc.userdata_raw)
+
class TestReadAzureOvf(MockerTestCase):
def test_invalid_xml_raises_non_azure_ds(self):
invalid_xml = "<foo>" + construct_valid_ovf_env(data={})
- self.assertRaises(DataSourceAzure.NonAzureDataSource,
+ self.assertRaises(DataSourceAzure.BrokenAzureDataSource,
DataSourceAzure.read_azure_ovf, invalid_xml)
def test_load_with_pubkeys(self):
diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py
index 56fe811e..956767d8 100644
--- a/tests/unittests/test_datasource/test_smartos.py
+++ b/tests/unittests/test_datasource/test_smartos.py
@@ -79,7 +79,6 @@ class MockSerial(object):
if self.last in self.mockdata:
if not self.mocked_out:
self.mocked_out = [x for x in self._format_out()]
- print self.mocked_out
if len(self.mocked_out) > self.count:
self.count += 1
@@ -275,26 +274,25 @@ class TestSmartOSDataSource(MockerTestCase):
self.assertIsInstance(cfg['disk_setup'], dict)
self.assertIsInstance(cfg['fs_setup'], list)
- def test_override_builtin_ds(self):
+ def test_override_disk_aliases(self):
# Test to make sure that the built-in DS is overriden
- data = {}
- data['disk_setup'] = {'test_dev': {}}
- data['fs_setup'] = [{'label': 'test_dev'}]
- data['serial_device'] = '/dev/ttyS2'
- dsrc = self._get_ds(ds_cfg=data)
- cfg = dsrc.get_config_obj()
+ builtin = DataSourceSmartOS.BUILTIN_DS_CONFIG
+
+ mydscfg = {'disk_aliases': {'FOO': '/dev/bar'}}
+ # expect that these values are in builtin, or this is pointless
+ for k in mydscfg:
+ self.assertIn(k, builtin)
+
+ dsrc = self._get_ds(ds_cfg=mydscfg)
ret = dsrc.get_data()
self.assertTrue(ret)
- assert 'disk_setup' in cfg
- assert 'fs_setup' in cfg
- self.assertIsInstance(cfg['disk_setup'], dict)
- self.assertIsInstance(cfg['fs_setup'], list)
- assert 'test_dev' in cfg['disk_setup']
- assert 'test_dev' in cfg['fs_setup'][0]['label']
+ self.assertEqual(mydscfg['disk_aliases']['FOO'],
+ dsrc.ds_cfg['disk_aliases']['FOO'])
- self.assertEquals(data['serial_device'], dsrc.seed)
+ self.assertEqual(dsrc.device_name_to_device('FOO'),
+ mydscfg['disk_aliases']['FOO'])
def apply_patches(patches):