def test_issue_11935_with_id(self): set_crontab('# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:1\n' '0 2 * * * find /var/www -type f ' '-mtime -7 -print0 | xargs -0 ' 'clamscan -i --no-summary 2>/dev/null') cmd = ('find /var/www -type f -mtime -7 -print0 ' '| xargs -0 clamscan -i --no-summary 2>/dev/null') self.assertEqual( cron._check_cron('root', cmd, hour='2', minute='0', identifier=1), 'present') ret = cron.present(cmd, 'root', minute='0', hour='2', identifier='1') self.assertEqual(ret['changes'], {}) self.assertEqual( ret['comment'], 'Cron find /var/www -type f -mtime -7 -print0 ' '| xargs -0 clamscan -i --no-summary 2>/dev/null already present') self.assertEqual( cron._check_cron('root', cmd, hour='3', minute='0', identifier='1'), 'update') ret = cron.present(cmd, 'root', minute='0', hour='3', identifier='1') self.assertEqual( ret['changes'], { 'root': 'find /var/www -type f -mtime -7 -print0 | ' 'xargs -0 clamscan -i --no-summary 2>/dev/null' }) self.assertEqual( ret['comment'], 'Cron find /var/www -type f -mtime -7 -print0 ' '| xargs -0 clamscan -i --no-summary 2>/dev/null updated') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:1\n' '0 3 * * * find /var/www -type f -mtime -7 -print0 |' ' xargs -0 clamscan -i --no-summary 2>/dev/null')
def test_issue_11935(self): set_crontab( '# Lines below here are managed by Salt, do not edit\n' '0 2 * * * find /var/www -type f ' '-mtime -7 -print0 | xargs -0 ' 'clamscan -i --no-summary 2>/dev/null' ) cmd = ( 'find /var/www -type f -mtime -7 -print0 ' '| xargs -0 clamscan -i --no-summary 2>/dev/null' ) self.assertEqual(cron._check_cron('root', cmd, hour='2', minute='0'), 'present') ret = cron.present(cmd, 'root', minute='0', hour='2') self.assertEqual(ret['changes'], {}) self.assertEqual( ret['comment'], 'Cron find /var/www -type f -mtime -7 -print0 ' '| xargs -0 clamscan -i --no-summary 2>/dev/null already present') self.assertEqual(cron._check_cron('root', cmd, hour='3', minute='0'), 'update') ret = cron.present(cmd, 'root', minute='0', hour='3') self.assertEqual(ret['changes'], {'root': 'find /var/www -type f -mtime -7 -print0 | ' 'xargs -0 clamscan -i --no-summary 2>/dev/null'}) self.assertEqual( ret['comment'], 'Cron find /var/www -type f -mtime -7 -print0 ' '| xargs -0 clamscan -i --no-summary 2>/dev/null updated') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '0 3 * * * find /var/www -type f -mtime -7 -print0 |' ' xargs -0 clamscan -i --no-summary 2>/dev/null')
def test_existing_noid_jobs_are_updated_with_identifier(self): set_crontab('# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:NO ID SET\n' '1 * * * * foo') ret = cron._check_cron('root', 'foo', minute=1) self.assertEqual(ret, 'present') ret = cron.present('foo', 'root', minute=1) self.assertEqual(ret['changes'], {'root': 'foo'}) self.assertEqual(ret['comment'], 'Cron foo updated') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:foo\n' '1 * * * * foo')
def test_existing_noid_jobs_are_updated_with_identifier(self): set_crontab("# Lines below here are managed by Salt, do not edit\n" "# SALT_CRON_IDENTIFIER:NO ID SET\n" "1 * * * * foo") ret = cron._check_cron("root", "foo", minute=1) self.assertEqual(ret, "present") ret = cron.present("foo", "root", minute=1) self.assertEqual(ret["changes"], {"root": "foo"}) self.assertEqual(ret["comment"], "Cron foo updated") self.assertEqual( get_crontab(), "# Lines below here are managed by Salt, do not edit\n" "# SALT_CRON_IDENTIFIER:foo\n" "1 * * * * foo", )
def test_existing_unmanaged_jobs_are_made_managed(self): set_crontab('# Lines below here are managed by Salt, do not edit\n' '0 2 * * * foo') ret = cron._check_cron('root', 'foo', hour='2', minute='0') self.assertEqual(ret, 'present') ret = cron.present('foo', 'root', minute='0', hour='2') self.assertEqual(ret['changes'], {'root': 'foo'}) self.assertEqual(ret['comment'], 'Cron foo updated') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:foo\n' '0 2 * * * foo') ret = cron.present('foo', 'root', minute='0', hour='2') self.assertEqual(ret['changes'], {}) self.assertEqual(ret['comment'], 'Cron foo already present')
def test_existing_noid_jobs_are_updated_with_identifier(self): set_crontab( '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:NO ID SET\n' '1 * * * * foo' ) ret = cron._check_cron('root', 'foo', minute=1) self.assertEqual(ret, 'present') ret = cron.present('foo', 'root', minute=1) self.assertEqual(ret['changes'], {'root': 'foo'}) self.assertEqual(ret['comment'], 'Cron foo updated') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:foo\n' '1 * * * * foo')
def test_existing_unmanaged_jobs_are_made_managed(self): set_crontab("# Lines below here are managed by Salt, do not edit\n" "0 2 * * * foo") ret = cron._check_cron("root", "foo", hour="2", minute="0") self.assertEqual(ret, "present") ret = cron.present("foo", "root", minute="0", hour="2") self.assertEqual(ret["changes"], {"root": "foo"}) self.assertEqual(ret["comment"], "Cron foo updated") self.assertEqual( get_crontab(), "# Lines below here are managed by Salt, do not edit\n" "# SALT_CRON_IDENTIFIER:foo\n" "0 2 * * * foo", ) ret = cron.present("foo", "root", minute="0", hour="2") self.assertEqual(ret["changes"], {}) self.assertEqual(ret["comment"], "Cron foo already present")
def test_existing_unmanaged_jobs_are_made_managed(self): set_crontab( '# Lines below here are managed by Salt, do not edit\n' '0 2 * * * foo' ) ret = cron._check_cron('root', 'foo', hour='2', minute='0') self.assertEqual(ret, 'present') ret = cron.present('foo', 'root', minute='0', hour='2') self.assertEqual(ret['changes'], {'root': 'foo'}) self.assertEqual(ret['comment'], 'Cron foo updated') self.assertEqual( get_crontab(), '# Lines below here are managed by Salt, do not edit\n' '# SALT_CRON_IDENTIFIER:foo\n' '0 2 * * * foo') ret = cron.present('foo', 'root', minute='0', hour='2') self.assertEqual(ret['changes'], {}) self.assertEqual(ret['comment'], 'Cron foo already present')