diff options
author | Soren Hansen <soren@canonical.com> | 2009-08-25 14:46:16 +0200 |
---|---|---|
committer | Soren Hansen <soren@canonical.com> | 2009-08-25 14:46:16 +0200 |
commit | 76d5d79c0ec119cf5e87e71578125081c40c291d (patch) | |
tree | 91baa01c1772c55c00eb2d4ba5800f79c9a796dc /tests.py | |
parent | c4f3133dc99b68a41353f763a65dee1b323f8868 (diff) | |
download | vyos-cloud-init-76d5d79c0ec119cf5e87e71578125081c40c291d.tar.gz vyos-cloud-init-76d5d79c0ec119cf5e87e71578125081c40c291d.zip |
Added script handling to appliance config handling.
Added test cases for this.
Diffstat (limited to 'tests.py')
-rw-r--r-- | tests.py | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -20,6 +20,48 @@ import unittest +class RunUserDataApplianceConfigScript(unittest.TestCase): + def setUp(self): + self.ec2_run_user_data = __import__('ec2-run-user-data') + self.fake_handle_shell_script_counter = 0 + self.expected_scripts = [] + # Override install_remove_package + self.ec2_run_user_data.content_type_handlers['text/x-shellscript'] = self.fake_handle_shell_script + + def fake_handle_shell_script(self, txt): + self.fake_handle_shell_script_counter += 1 + self.assertEqual(self.expected_scripts.pop(0), txt) + + def handle_xml(self, xml): + msg = self.ec2_run_user_data.parse_user_data(xml) + self.ec2_run_user_data.handle_part(msg) + + def testApplianceConfigPackageScriptSingle(self): + script = '''#!/bin/sh +echo hey''' + xml = '<appliance><script>%s</script></appliance>' % script + self.expected_scripts += [script] + self.handle_xml(xml) + self.assertEqual(self.fake_handle_shell_script_counter, 1) + + def testApplianceConfigPackageScriptMultiple(self): + script1 = '''#!/bin/sh +echo hey''' + script2 = '''#!/usr/bin/python +print "hey"''' + xml = '<appliance><script>%s</script><script>%s</script></appliance>' % (script1, script2) + self.expected_scripts += [script1, script2] + self.handle_xml(xml) + self.assertEqual(self.fake_handle_shell_script_counter, 2) + + def testApplianceConfigPackageScriptCDATA(self): + script = '''#!/bin/sh +echo hey''' + xml = '<appliance><script><![CDATA[%s]]></script></appliance>' % (script, ) + self.expected_scripts += [script] + self.handle_xml(xml) + self.assertEqual(self.fake_handle_shell_script_counter, 1) + class RunUserDataApplianceConfigPackageHandling(unittest.TestCase): def setUp(self): self.fake_install_remove_package_counter = 0 |