summaryrefslogtreecommitdiff
path: root/heat_cfntools/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-03-05 03:59:11 +0000
committerGerrit Code Review <review@openstack.org>2014-03-05 03:59:11 +0000
commit31da8a419c3cd2987c35071750e401b7580dbeaa (patch)
treec8124e2932187b7ca55daa7fac1f21b2936e6c44 /heat_cfntools/tests
parent4ece05a829845ccdbf1e78b030719614255bfc28 (diff)
parent3a0993210d7d08392d97903589cf8adba6fb92d2 (diff)
downloadheat-cfntools-31da8a419c3cd2987c35071750e401b7580dbeaa.tar.gz
Merge "Support of ignoreErrors for commands"
Diffstat (limited to 'heat_cfntools/tests')
-rw-r--r--heat_cfntools/tests/test_cfn_helper.py65
1 files changed, 53 insertions, 12 deletions
diff --git a/heat_cfntools/tests/test_cfn_helper.py b/heat_cfntools/tests/test_cfn_helper.py
index ca80190..a661014 100644
--- a/heat_cfntools/tests/test_cfn_helper.py
+++ b/heat_cfntools/tests/test_cfn_helper.py
@@ -800,18 +800,6 @@ class TestMetadataRetrieve(testtools.TestCase):
finally:
m.UnsetStubs()
- def test_cfn_init(self):
-
- with tempfile.NamedTemporaryFile(mode='w+') as foo_file:
- md_data = {"AWS::CloudFormation::Init": {"config": {"files": {
- foo_file.name: {"content": "bar"}}}}}
-
- md = cfn_helper.Metadata('teststack', None)
- self.assertTrue(
- md.retrieve(meta_str=md_data, last_path=self.last_file))
- md.cfn_init()
- self.assertThat(foo_file.name, ttm.FileContains('bar'))
-
def test_nova_meta_with_cache(self):
meta_in = {"uuid": "f9431d18-d971-434d-9044-5b38f5b4646f",
"availability_zone": "nova",
@@ -981,6 +969,59 @@ class TestMetadataRetrieve(testtools.TestCase):
self.m.VerifyAll()
+class TestCfnInit(MockPopenTestCase):
+
+ def setUp(self):
+ super(TestCfnInit, self).setUp()
+ self.tdir = self.useFixture(fixtures.TempDir())
+ self.last_file = os.path.join(self.tdir.path, 'last_metadata')
+
+ def test_cfn_init(self):
+
+ with tempfile.NamedTemporaryFile(mode='w+') as foo_file:
+ md_data = {"AWS::CloudFormation::Init": {"config": {"files": {
+ foo_file.name: {"content": "bar"}}}}}
+
+ md = cfn_helper.Metadata('teststack', None)
+ self.assertTrue(
+ md.retrieve(meta_str=md_data, last_path=self.last_file))
+ md.cfn_init()
+ self.assertThat(foo_file.name, ttm.FileContains('bar'))
+
+ def test_cfn_init_with_ignore_errors_false(self):
+ self.mock_cmd_run(['su', 'root', '-c', '/bin/command1']).AndReturn(
+ FakePOpen('Doing something', 'error', -1))
+ self.m.ReplayAll()
+
+ md_data = {"AWS::CloudFormation::Init": {"config": {"commands": {
+ "00_foo": {"command": "/bin/command1",
+ "ignoreErrors": "false"}}}}}
+
+ md = cfn_helper.Metadata('teststack', None)
+ self.assertTrue(
+ md.retrieve(meta_str=md_data, last_path=self.last_file))
+ self.assertRaises(cfn_helper.CommandsHandlerRunError, md.cfn_init)
+
+ def test_cfn_init_with_ignore_errors_true(self):
+ self.mock_cmd_run(['su', 'root', '-c', '/bin/command1']).AndReturn(
+ FakePOpen('Doing something', 'error', -1))
+ self.mock_cmd_run(['su', 'root', '-c', '/bin/command2']).AndReturn(
+ FakePOpen('All good'))
+ self.m.ReplayAll()
+
+ md_data = {"AWS::CloudFormation::Init": {"config": {"commands": {
+ "00_foo": {"command": "/bin/command1",
+ "ignoreErrors": "true"},
+ "01_bar": {"command": "/bin/command2",
+ "ignoreErrors": "false"}
+ }}}}
+
+ md = cfn_helper.Metadata('teststack', None)
+ self.assertTrue(
+ md.retrieve(meta_str=md_data, last_path=self.last_file))
+ md.cfn_init()
+
+
class TestSourcesHandler(MockPopenTestCase):
def test_apply_sources_empty(self):
sh = cfn_helper.SourcesHandler({})