diff options
-rw-r--r-- | cloudinit/__init__.py | 3 | ||||
-rw-r--r-- | tests/unittests/test__init__.py | 12 |
2 files changed, 9 insertions, 6 deletions
diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 82390eeb..f3541ee5 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -589,11 +589,10 @@ def partwalker_handle_handler(pdata, _ctype, _filename, payload): modfname = modname + ".py" util.write_file("%s/%s" % (pdata['handlerdir'], modfname), payload, 0600) - pdata['handlercount'] = curcount + 1 - try: mod = __import__(modname) handler_register(mod, pdata['handlers'], pdata['data'], frequency) + pdata['handlercount'] = curcount + 1 except: util.logexc(log) traceback.print_exc(file=sys.stderr) diff --git a/tests/unittests/test__init__.py b/tests/unittests/test__init__.py index d273748a..e157fa77 100644 --- a/tests/unittests/test__init__.py +++ b/tests/unittests/test__init__.py @@ -49,7 +49,7 @@ class TestPartwalkerHandleHandler(MockerTestCase): self.assertEqual(1, self.data["handlercount"]) def test_import_error(self): - """Payload gets written to file and added to C{pdata}.""" + """Module import errors are logged. No handler added to C{pdata}""" # Mock the __import__ builtin import_mock = self.mocker.replace("__builtin__.__import__") import_mock(self.expected_module_name) @@ -67,8 +67,10 @@ class TestPartwalkerHandleHandler(MockerTestCase): partwalker_handle_handler(self.data, self.ctype, self.filename, self.payload) + self.assertEqual(0, self.data["handlercount"]) + def test_attribute_error(self): - """Payload gets written to file and added to C{pdata}.""" + """Attribute errors are logged. No handler added to C{pdata}""" # Mock the __import__ builtin import_mock = self.mocker.replace("__builtin__.__import__") import_mock(self.expected_module_name) @@ -92,6 +94,8 @@ class TestPartwalkerHandleHandler(MockerTestCase): partwalker_handle_handler(self.data, self.ctype, self.filename, self.payload) + self.assertEqual(0, self.data["handlercount"]) + class TestHandlerHandlePart(MockerTestCase): def setUp(self): @@ -147,9 +151,9 @@ class TestHandlerHandlePart(MockerTestCase): getattr(mod_mock, "frequency") self.mocker.result("always") getattr(mod_mock, "handler_version") - self.mocker.result(2) + self.mocker.result(1) mod_mock.handle_part(self.data, self.ctype, self.filename, - self.payload, self.frequency) + self.payload) self.mocker.replay() handler_handle_part(mod_mock, self.data, self.ctype, self.filename, |