diff --git a/salt/modules/cron.py b/salt/modules/cron.py index da0dc7b3ae..26ea7524aa 100644 --- a/salt/modules/cron.py +++ b/salt/modules/cron.py @@ -130,7 +130,7 @@ def _render_tab(lst): comment = '#' if cron['comment']: comment += ' {0}'.format( - cron['comment'].rstrip().replace('\n', '\n# ')) + cron['comment'].replace('\n', '\n# ')) if cron['identifier']: comment += ' {0}:{1}'.format(SALT_CRON_IDENTIFIER, cron['identifier']) diff --git a/tests/support/mixins.py b/tests/support/mixins.py index 804feb4196..38601d81ff 100644 --- a/tests/support/mixins.py +++ b/tests/support/mixins.py @@ -514,9 +514,10 @@ class SaltReturnAssertsMixin(object): def __getWithinSaltReturn(self, ret, keys): self.assertReturnNonEmptySaltType(ret) - keys = self.__return_valid_keys(keys) - okeys = keys[:] + ret_data = [] for part in six.itervalues(ret): + keys = self.__return_valid_keys(keys) + okeys = keys[:] try: ret_item = part[okeys.pop(0)] except (KeyError, TypeError): @@ -534,11 +535,13 @@ class SaltReturnAssertsMixin(object): ''.join(['[\'{0}\']'.format(k) for k in keys]), part ) ) - return ret_item + ret_data.append(ret_item) + return ret_data def assertSaltTrueReturn(self, ret): try: - self.assertTrue(self.__getWithinSaltReturn(ret, 'result')) + for saltret in self.__getWithinSaltReturn(ret, 'result'): + self.assertTrue(saltret) except AssertionError: log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret))) try: @@ -556,7 +559,8 @@ class SaltReturnAssertsMixin(object): def assertSaltFalseReturn(self, ret): try: - self.assertFalse(self.__getWithinSaltReturn(ret, 'result')) + for saltret in self.__getWithinSaltReturn(ret, 'result'): + self.assertFalse(saltret) except AssertionError: log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret))) try: @@ -572,7 +576,8 @@ class SaltReturnAssertsMixin(object): def assertSaltNoneReturn(self, ret): try: - self.assertIsNone(self.__getWithinSaltReturn(ret, 'result')) + for saltret in self.__getWithinSaltReturn(ret, 'result'): + self.assertIsNone(saltret) except AssertionError: log.info('Salt Full Return:\n{0}'.format(pprint.pformat(ret))) try: @@ -587,54 +592,45 @@ class SaltReturnAssertsMixin(object): ) def assertInSaltComment(self, in_comment, ret): - return self.assertIn( - in_comment, self.__getWithinSaltReturn(ret, 'comment') - ) + for saltret in self.__getWithinSaltReturn(ret, 'comment'): + self.assertIn(in_comment, saltret) def assertNotInSaltComment(self, not_in_comment, ret): - return self.assertNotIn( - not_in_comment, self.__getWithinSaltReturn(ret, 'comment') - ) + for saltret in self.__getWithinSaltReturn(ret, 'comment'): + self.assertNotIn(not_in_comment, saltret) def assertSaltCommentRegexpMatches(self, ret, pattern): return self.assertInSaltReturnRegexpMatches(ret, pattern, 'comment') def assertInSaltStateWarning(self, in_comment, ret): - return self.assertIn( - in_comment, self.__getWithinSaltReturn(ret, 'warnings') - ) + for saltret in self.__getWithinSaltReturn(ret, 'warnings'): + self.assertIn(in_comment, saltret) def assertNotInSaltStateWarning(self, not_in_comment, ret): - return self.assertNotIn( - not_in_comment, self.__getWithinSaltReturn(ret, 'warnings') - ) + for saltret in self.__getWithinSaltReturn(ret, 'warnings'): + self.assertNotIn(not_in_comment, saltret) def assertInSaltReturn(self, item_to_check, ret, keys): - return self.assertIn( - item_to_check, self.__getWithinSaltReturn(ret, keys) - ) + for saltret in self.__getWithinSaltReturn(ret, keys): + self.assertIn(item_to_check, saltret) def assertNotInSaltReturn(self, item_to_check, ret, keys): - return self.assertNotIn( - item_to_check, self.__getWithinSaltReturn(ret, keys) - ) + for saltret in self.__getWithinSaltReturn(ret, keys): + self.assertNotIn(item_to_check, saltret) def assertInSaltReturnRegexpMatches(self, ret, pattern, keys=()): - return self.assertRegex( - self.__getWithinSaltReturn(ret, keys), pattern - ) + for saltret in self.__getWithinSaltReturn(ret, keys): + self.assertRegex(saltret, pattern) def assertSaltStateChangesEqual(self, ret, comparison, keys=()): keys = ['changes'] + self.__return_valid_keys(keys) - return self.assertEqual( - self.__getWithinSaltReturn(ret, keys), comparison - ) + for saltret in self.__getWithinSaltReturn(ret, keys): + self.assertEqual(saltret, comparison) def assertSaltStateChangesNotEqual(self, ret, comparison, keys=()): keys = ['changes'] + self.__return_valid_keys(keys) - return self.assertNotEqual( - self.__getWithinSaltReturn(ret, keys), comparison - ) + for saltret in self.__getWithinSaltReturn(ret, keys): + self.assertNotEqual(saltret, comparison) class SaltMinionEventAssertsMixin(object): diff --git a/tests/unit/states/test_cron.py b/tests/unit/states/test_cron.py index d3e6d83c7a..58e50ff0b0 100644 --- a/tests/unit/states/test_cron.py +++ b/tests/unit/states/test_cron.py @@ -260,10 +260,12 @@ class CronTestCase(TestCase, LoaderModuleMockMixin): get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '# First crontab\n' - '# second multi-line comment SALT_CRON_IDENTIFIER:1\n' + '# second multi-line comment\n' + '# SALT_CRON_IDENTIFIER:1\n' '* 1 * * * foo\n' '# Second crontab\n' - '# multi-line comment SALT_CRON_IDENTIFIER:2\n' + '# multi-line comment\n' + '# SALT_CRON_IDENTIFIER:2\n' '* 1 * * * foo') def test_existing_unmanaged_jobs_are_made_managed(self):