Example #1
0
    def get_crontab(self, host, user):
        """Fetches the job entries for a particular host and user and builds
        a crontab style representation.

        Please see crab.util.crontab.write_crontab for more details
        of how the crontab is constructed.
        """

        jobs = self.get_jobs(host, user)

        return write_crontab(jobs)
Example #2
0
    def test_read_write(self):
        """Test crontab read and write functions."""

        crontab_orig = [
            'CRON_TZ=Europe/Berlin',
            '* * * * * CRABID=job_one command_one',
            '0 15 * * * command_two',
            '0 0 1 4 * date +\%Y\%m\%d',
            '59 23 12 31 * echo%a\%b%c\%d',
            '1 2 3 4 * CRABID=cal CRABCLIENTHOSTNAME=b CRABUSERNAME=a cal',
        ]

        (jobs, warnings) = parse_crontab(crontab_orig)

        self.assertEqual(jobs, [
            {
                'crabid': 'job_one',
                'command': 'command_one',
                'time': '* * * * *',
                'timezone': 'Europe/Berlin',
                'input': None,
                'vars': {}
            },
            {
                'crabid': None,
                'command': 'command_two',
                'time': '0 15 * * *',
                'timezone': 'Europe/Berlin',
                'input': None,
                'vars': {}
            },
            {
                'crabid': None,
                'command': 'date +%Y%m%d',
                'time': '0 0 1 4 *',
                'timezone': 'Europe/Berlin',
                'input': None,
                'vars': {}
            },
            {
                'crabid': None,
                'command': 'echo',
                'time': '59 23 12 31 *',
                'timezone': 'Europe/Berlin',
                'input': 'a%b\nc%d',
                'vars': {}
            },
            {
                'crabid': 'cal',
                'command': 'cal',
                'time': '1 2 3 4 *',
                'timezone': 'Europe/Berlin',
                'input': None,
                'vars': {
                    'CRABCLIENTHOSTNAME': 'b',
                    'CRABUSERNAME': '******'
                }
            },
        ])

        self.assertEqual(warnings, [])

        crontab_written = write_crontab(jobs)

        self.assertEqual(crontab_written, crontab_orig)
Example #3
0
    def test_read_write(self):
        """Test crontab read and write functions."""

        crontab_orig = [
            "CRON_TZ=Europe/Berlin",
            "* * * * * CRABID=job_one command_one",
            "0 15 * * * command_two",
            "0 0 1 4 * date +\%Y\%m\%d",
            "59 23 12 31 * echo%a\%b%c\%d",
            "1 2 3 4 * CRABID=cal CRABCLIENTHOSTNAME=b CRABUSERNAME=a cal",
        ]

        (jobs, warnings) = parse_crontab(crontab_orig)

        self.assertEqual(
            jobs,
            [
                {
                    "crabid": "job_one",
                    "command": "command_one",
                    "time": "* * * * *",
                    "timezone": "Europe/Berlin",
                    "input": None,
                    "vars": {},
                },
                {
                    "crabid": None,
                    "command": "command_two",
                    "time": "0 15 * * *",
                    "timezone": "Europe/Berlin",
                    "input": None,
                    "vars": {},
                },
                {
                    "crabid": None,
                    "command": "date +%Y%m%d",
                    "time": "0 0 1 4 *",
                    "timezone": "Europe/Berlin",
                    "input": None,
                    "vars": {},
                },
                {
                    "crabid": None,
                    "command": "echo",
                    "time": "59 23 12 31 *",
                    "timezone": "Europe/Berlin",
                    "input": "a%b\nc%d",
                    "vars": {},
                },
                {
                    "crabid": "cal",
                    "command": "cal",
                    "time": "1 2 3 4 *",
                    "timezone": "Europe/Berlin",
                    "input": None,
                    "vars": {"CRABCLIENTHOSTNAME": "b", "CRABUSERNAME": "******"},
                },
            ],
        )

        self.assertEqual(warnings, [])

        crontab_written = write_crontab(jobs)

        self.assertEqual(crontab_written, crontab_orig)