From 76d5d79c0ec119cf5e87e71578125081c40c291d Mon Sep 17 00:00:00 2001 From: Soren Hansen Date: Tue, 25 Aug 2009 14:46:16 +0200 Subject: Added script handling to appliance config handling. Added test cases for this. --- ec2-run-user-data.py | 15 +++++++++++++++ tests.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/ec2-run-user-data.py b/ec2-run-user-data.py index 784a1b3f..2917b2fe 100755 --- a/ec2-run-user-data.py +++ b/ec2-run-user-data.py @@ -107,6 +107,21 @@ class ApplianceConfig(object): remove_package(pkg) else: install_package(pkg) + elif node.tagName == 'script': + script = '' + for subnode in node.childNodes: + # If someone went through the trouble of wrapping it in CDATA, + # it's probably the script we want to run.. + if subnode.nodeType == root.CDATA_SECTION_NODE: + script = subnode.nodeValue + # ..however, fall back to whatever TEXT_NODE stuff is between + # the ' % 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 = '' % (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 = '' % (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 -- cgit v1.2.3