From 59d21bb23db06e5e02cbd91ec531b1506ab97fae Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Tue, 25 Aug 2009 23:51:16 +0200 Subject: 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: /var/lib/mysql /etc/alfresco /other/things 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. --- tests.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'tests.py') diff --git a/tests.py b/tests.py index 33c45ec7..84103745 100644 --- a/tests.py +++ b/tests.py @@ -18,9 +18,42 @@ # along with this program. If not, see . # +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 = '/etc/alfresco/var/lib/mysql' + 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 -- cgit v1.2.3