diff options
author | Soren Hansen <soren@canonical.com> | 2009-08-25 23:51:16 +0200 |
---|---|---|
committer | Soren Hansen <soren@canonical.com> | 2009-08-25 23:51:16 +0200 |
commit | 59d21bb23db06e5e02cbd91ec531b1506ab97fae (patch) | |
tree | 8743a08d8e959f2a4b5648f55452aa1079218c58 /tests.py | |
parent | 85f6e6168beb89436ebc20c67d329581f7155f5c (diff) | |
download | vyos-cloud-init-59d21bb23db06e5e02cbd91ec531b1506ab97fae.tar.gz vyos-cloud-init-59d21bb23db06e5e02cbd91ec531b1506ab97fae.zip |
Implement EBS volume mounting
This can either be invoked by instrumenting the user-data with a mime
part with content-type 'text/x-ebs-mount-description' with a body like
so:
device=/dev/sde:/var/lib/mysql,/etc/alfresco
device=/dev/sdf:/other/things
or by using the appliance config XML format like so:
<appliance>
<storage device="/dev/sde">
<path>/var/lib/mysql</path>
<path>/etc/alfresco</path>
</storage>
<storage device="/dev/sdf">
<path>/other/things</path>
</appliance>
</appliance>
In either case, if the volume does not yet have a filesystem, one will be created.
For each path that is to live on the volume, a directory is created, and
populated with the data currently in the target directory (e.g.
/var/lib/mysql is copied to ${ebs_volume_path}/_var_lib_mysql). Once
this is done, the directories are bind-mounted to the relevant paths.
If the directories in question already exist, they will just be bind-mounted.
Diffstat (limited to 'tests.py')
-rw-r--r-- | tests.py | 37 |
1 files changed, 35 insertions, 2 deletions
@@ -18,9 +18,42 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +import re +import os import unittest -class RunUserDataApplianceConfigScript(unittest.TestCase): +class RunUserDataApplianceTestCase(unittest.TestCase): + def handle_xml(self, xml): + msg = self.ec2_run_user_data.parse_user_data(xml) + self.ec2_run_user_data.handle_part(msg) + +class RunUserDataApplianceConfigEBS(RunUserDataApplianceTestCase): + def setUp(self): + self.ec2_run_user_data = __import__('ec2-run-user-data') + reload(self.ec2_run_user_data) + self.real_mount_ebs_volume = self.ec2_run_user_data.mount_ebs_volume + self.ec2_run_user_data.mount_ebs_volume = self.fake_mount_ebs_volume + + def fake_mount_ebs_volume(self, device, paths): + self.assertEqual(device, '/dev/sdc') + self.assertEqual(paths, ['/etc/alfresco', '/var/lib/mysql']) + + def testApplianceConfigEBS(self): + os.environ['EBSMOUNT_DEBUG'] = 'yes, please' + xml = '<appliance><storage device="/dev/sdc"><path>/etc/alfresco</path><path>/var/lib/mysql</path></storage></appliance>' + self.handle_xml(xml) + + def testMountEBSVolume(self): + output = self.real_mount_ebs_volume('/dev/sdh', ['/foo', '/bar']) + lines = output.strip().split('\n') + self.assertEqual(len(lines), 11) + match = re.match('mount /dev/sdh (/var/run/ec2-init/tmp.[a-zA-Z0-9]+)', lines[0]) + self.assertNotEqual(match, None) + tmpdir = match.group(1) + for (i, s) in zip(range(10), ['mkdir %s/_foo', 'cp -a /foo %s/_foo', 'chown --reference /foo %s/_foo', 'chmod --reference /foo %s/_foo', 'mount --bind %s/_foo /foo', 'mkdir %s/_bar', 'cp -a /bar %s/_bar', 'chown --reference /bar %s/_bar', 'chmod --reference /bar %s/_bar', 'mount --bind %s/_bar /bar']): + self.assertEqual(s % tmpdir, lines[i+1]) + +class RunUserDataApplianceConfigScript(RunUserDataApplianceTestCase): def setUp(self): self.ec2_run_user_data = __import__('ec2-run-user-data') self.fake_handle_shell_script_counter = 0 @@ -62,7 +95,7 @@ echo hey''' self.handle_xml(xml) self.assertEqual(self.fake_handle_shell_script_counter, 1) -class RunUserDataApplianceConfigPackageHandling(unittest.TestCase): +class RunUserDataApplianceConfigPackageHandling(RunUserDataApplianceTestCase): def setUp(self): self.fake_install_remove_package_counter = 0 |