freezer/tests/test_scheduler_daemon.py
Fabrizio Vanni d4b9399e9b freezer scheduler
The freezer scheduler is to be executed
as daemon process on the client machines

It has the following responsibilities:

  * when using the api:
    - register -if necessary- as a client in the api
    - download the list of jobs from the api
    - schedule the jobs for execution
    - launch the freezer client at the scheduled time
    - collect metadata and exit codes and upload them to the api
    - periodically poll the api for new/updated jobs
    - if a job is part of a session (a coordinated group of jobs)
      it updates the session status when job starts/stops

  * when not using the api
    - load jobs configurations from files
    - schedule the jobs for execution
    - launch the freezer client at the scheduled time

The freezer scheduler can also be used to manage jobs
and sessions using the following positional parameters:

  job-list
  job-get
  job-create
  job-delete
  job-start
  job-stop
  session-list
  session-get
  session-create
  session-delete
  session-list-job
  session-add-job
  session-remove-job

or to register the client in the api using the positional parameter:

  register

Implements blueprint: freezer-scheduler-start

Change-Id: I06ae202a0f464f7240c137744a5b54d1177cabd9
2015-07-10 18:51:17 +01:00

57 lines
2.0 KiB
Python

# Copyright 2015 Hewlett-Packard
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
import unittest
from mock import Mock, patch
import signal
from freezer.scheduler import daemon
class TestOpenstackOptions(unittest.TestCase):
def setUp(self):
self.daemonizable = Mock()
self.daemon = daemon.Daemon(daemonizable=self.daemonizable)
def test_create(self):
self.assertIsInstance(self.daemon, daemon.Daemon)
@patch('freezer.scheduler.daemon.logging')
def test_setup_logging_default(self, mock_logging):
res = self.daemon.setup_logging(None)
self.assertEqual(res, '/var/log/freezer-scheduler.log')
@patch('freezer.scheduler.daemon.create_dir')
@patch('freezer.scheduler.daemon.logging')
def test_setup_logging_userdefined(self, mock_logging, mock_createdir):
res = self.daemon.setup_logging('mylogfile')
self.assertEqual(res, 'mylogfile')
def test_handle_program_exit_calls_scheduler_stop(self):
self.daemon.handle_program_exit(Mock(), Mock())
self.daemonizable.stop.assert_called_with()
def test_handle_program_reload_calls_scheduler_reload(self):
self.daemon.handle_reload(Mock(), Mock())
self.daemonizable.reload.assert_called_with()
def test_signal_map_handlers(self):
signal_map = self.daemon.signal_map
self.assertEqual(signal_map[signal.SIGTERM], self.daemon.handle_program_exit)
self.assertEqual(signal_map[signal.SIGHUP], self.daemon.handle_reload)
@patch('freezer.scheduler.daemon.gettempdir')
@patch('freezer.scheduler.daemon.os.path.expanduser')
def test_pid_fname_in_tempdir(self, mock_expanduser, mock_gettempdir):
mock_expanduser.return_value = '/home/chet'
mock_gettempdir.return_value = '/tempus_fugit'
retval = self.daemon.pid_fname
self.assertEqual(retval, '/tempus_fugit/freezer_sched_chet.pid')