summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Howard <ben.howard@canonical.com>2013-09-26 08:18:29 -0600
committerBen Howard <ben.howard@canonical.com>2013-09-26 08:18:29 -0600
commitb55a9606e9455056a4280b06ef3785964af6d3df (patch)
treee7f76449f5f1b26d2ced7afe8ef16610c6544bf8
parent35469c11703b1df66b3b14ad06b583d672f39ff5 (diff)
downloadvyos-cloud-init-b55a9606e9455056a4280b06ef3785964af6d3df.tar.gz
vyos-cloud-init-b55a9606e9455056a4280b06ef3785964af6d3df.zip
Added support for formating the ephemeral disk on Windows Azure.
-rw-r--r--cloudinit/sources/DataSourceAzure.py27
-rw-r--r--doc/examples/cloud-config-disk-setup.txt8
-rw-r--r--tests/unittests/test_datasource/test_azure.py45
3 files changed, 74 insertions, 6 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index a77c3d9a..3f96a0a5 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -44,8 +44,17 @@ BUILTIN_DS_CONFIG = {
'policy': True,
'command': BOUNCE_COMMAND,
'hostname_command': 'hostname',
- }
+ },
+ 'ephemeral_disk': '/dev/sdb1',
+ 'disk_setup': {
+ 'ephemeral0': {'table_type': 'mbr',
+ 'layout': True,
+ 'overwrite': False}
+ },
+ 'fs_setup': [{'filesystem': 'ext4', 'device': '/dev/sdb',
+ 'partition': 'auto'}],
}
+
DS_CFG_PATH = ['datasource', DS_NAME]
@@ -111,11 +120,22 @@ class DataSourceAzureNet(sources.DataSource):
if seed:
self.metadata['random_seed'] = seed
+
# now update ds_cfg to reflect contents pass in config
usercfg = util.get_cfg_by_path(self.cfg, DS_CFG_PATH, {})
self.ds_cfg = util.mergemanydict([usercfg, self.ds_cfg])
mycfg = self.ds_cfg
+ # Put the disk format elements into the config object
+ if 'disk_setup' in mycfg:
+ self.cfg['disk_setup'] = mycfg['disk_setup']
+
+ if 'fs_setup' in mycfg:
+ self.cfg['fs_setup'] = mycfg['fs_setup']
+
+ if 'ephemeral_disk' in mycfg:
+ self.cfg['ephemeral_disk'] = mycfg['ephemeral_disk']
+
# walinux agent writes files world readable, but expects
# the directory to be protected.
write_files(mycfg['data_dir'], files, dirmode=0700)
@@ -161,9 +181,12 @@ class DataSourceAzureNet(sources.DataSource):
pubkeys = pubkeys_from_crt_files(fp_files)
self.metadata['public-keys'] = pubkeys
-
return True
+ def device_name_to_device(self, name):
+ if 'ephemeral0' in name and 'ephemeral_disk' in self.cfg:
+ return self.cfg['ephemeral_disk']
+
def get_config_obj(self):
return self.cfg
diff --git a/doc/examples/cloud-config-disk-setup.txt b/doc/examples/cloud-config-disk-setup.txt
index db2c52a7..0ca65fd0 100644
--- a/doc/examples/cloud-config-disk-setup.txt
+++ b/doc/examples/cloud-config-disk-setup.txt
@@ -19,8 +19,8 @@ Default disk definitions for AWS
Default disk definitions for Windows Azure
------------------------------------------
-(Not implemented yet due to conflict with WALinuxAgent in Ubuntu)
+ephemeral_disk: /dev/sdb1
disk_setup:
/dev/sdb:
type: mbr
@@ -29,15 +29,15 @@ disk_setup:
fs_setup:
- label: ephemeral0
- filesystem: ext3
+ filesystem: ext4
device: ephemeral0
- partition: any
+ partition: auto
Default disk definitions for SmartOS
------------------------------------
-ephemeral_disk: /dev/vdb
+ephemeral_disk: /dev/vdb1
disk_setup:
/dev/vdb:
type: mbr
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 1ca6a79d..aa37337c 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -290,6 +290,51 @@ 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/sdb1")
+ assert 'disk_setup' in cfg
+ assert 'fs_setup' in cfg
+ self.assertIsInstance(cfg['disk_setup'], dict)
+ self.assertIsInstance(cfg['fs_setup'], list)
+
+ def test_overriden_ephemeral(self):
+ # Make sure that the merge happens correctly
+ dscfg = {'ephemeral_disk': '/dev/sdc',
+ 'disk_setup': {'/dev/sdc': {'something': '...'},
+ 'ephemeral0': False,
+ },
+ 'fs_setup': [{'label': 'something'}]}
+ odata = {'HostName': "myhost", 'UserName': "myuser",
+ 'dscfg': {'text': yaml.dump(dscfg), 'encoding': 'plain'}}
+ data = {'ovfcontent': construct_valid_ovf_env(data=odata),
+ 'sys_cfg': {}}
+
+ dsrc = self._get_ds(data)
+ ret = dsrc.get_data()
+ cfg = dsrc.get_config_obj()
+ self.assertTrue(ret)
+ self.assertTrue(cfg)
+ self.assertEquals(dsrc.device_name_to_device("ephemeral0"),
+ "/dev/sdc")
+ assert 'disk_setup' in cfg
+ assert 'fs_setup' in cfg
+ self.assertIsInstance(cfg['disk_setup'], dict)
+ self.assertIsInstance(cfg['fs_setup'], list)
+ assert 'ephemeral0' in cfg['disk_setup']
+ assert '/dev/sdc' in cfg['disk_setup']
+ self.assertFalse(cfg['disk_setup']['ephemeral0'])
+
class TestReadAzureOvf(MockerTestCase):
def test_invalid_xml_raises_non_azure_ds(self):