def test_add_syslog(self): root = logging.getLogger('') test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) assert_equal(len(root.handlers), 2) assert_equal(root.handlers[-1].__class__, handlers.SysLogHandler) test_reconfig = config.load_config(StringIO.StringIO(self.config)) test_reconfig.apply(self.my_mcp) assert_equal(len(root.handlers), 1) assert_equal(root.handlers[0].__class__, logging.StreamHandler)
def test_job_changed(self): assert 'test_change' in self.my_mcp.jobs job2 = self.my_mcp.jobs['test_change'] run0 = job2.next_runs()[0] run0.start() run1 = job2.next_runs()[0] assert_equal(len(job2.runs), 2) assert_equal(job2.name, "test_change") assert_equal(len(job2.topo_actions), 2) assert_equal(job2.topo_actions[0].name, 'action_change') assert_equal(job2.topo_actions[1].name, 'action_remove2') assert_equal(job2.topo_actions[0].command, 'command_change') assert_equal(job2.topo_actions[1].command, 'command_remove2') test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) job2 = self.my_mcp.jobs['test_change'] assert_equal(job2.name, "test_change") assert_equal(len(job2.topo_actions), 1) assert_equal(job2.topo_actions[0].name, 'action_change') assert_equal(job2.topo_actions[0].command, 'command_changed') assert_equal(len(job2.runs), 3) assert job2.runs[2].is_running assert job2.runs[1].is_cancelled assert job2.runs[0].is_scheduled
def test_bad_requires(self): test_config = BASE_CONFIG + """ jobs: - &job0 name: "test_job0" node: *node0 schedule: "interval 20s" actions: - &action0_0 name: "action0_0" command: "test_command0.0" - &action0_1 name: "action0_1" command: "test_command0.1" - &job1 name: "test_job1" node: *node0 schedule: "interval 20s" actions: - name: "action1_0" command: "test_command1.0" requires: *action0_0 """ test_config = config.load_config(StringIO.StringIO(test_config)) assert_raises(config.ConfigError, test_config.apply, self.my_mcp)
def test_job_list(self): assert_equal(len(self.my_mcp.jobs), 4) test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) assert_equal(len(self.my_mcp.jobs), 4)
def test_job_unchanged(self): assert 'test_unchanged' in self.my_mcp.jobs job0 = self.my_mcp.jobs['test_unchanged'] run0 = job0.next_runs()[0] run0.start() run1 = job0.next_runs()[0] assert_equal(job0.name, "test_unchanged") assert_equal(len(job0.topo_actions), 1) assert_equal(job0.topo_actions[0].name, 'action_unchanged') assert_equal(str(job0.scheduler), "DAILY") test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) job0 = self.my_mcp.jobs['test_unchanged'] assert_equal(job0.name, "test_unchanged") assert_equal(len(job0.topo_actions), 1) assert_equal(job0.topo_actions[0].name, 'action_unchanged') assert_equal(str(job0.scheduler), "DAILY") assert_equal(len(job0.runs), 2) assert_equal(job0.runs[1], run0) assert_equal(job0.runs[0], run1) assert run1.is_scheduled
def test_job_changed(self): assert 'test_change' in self.my_mcp.jobs job2 = self.my_mcp.jobs['test_change'] run0 = job2.next_runs()[0] run0.start() job2.next_runs() assert_equal(len(job2.runs), 2) assert_equal(job2.name, "test_change") assert_equal(len(job2.topo_actions), 2) assert_equal(job2.topo_actions[0].name, 'action_change') assert_equal(job2.topo_actions[1].name, 'action_remove2') assert_equal(job2.topo_actions[0].command, 'command_change') assert_equal(job2.topo_actions[1].command, 'command_remove2') test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) job2 = self.my_mcp.jobs['test_change'] assert_equal(job2.name, "test_change") assert_equal(len(job2.topo_actions), 1) assert_equal(job2.topo_actions[0].name, 'action_change') assert_equal(job2.topo_actions[0].command, 'command_changed') assert_equal(len(job2.runs), 2) assert job2.runs[1].is_starting, job2.runs[1].action_runs[0].state assert job2.runs[0].is_scheduled
def test_job_list(self): assert_equal(len(self.my_mcp.jobs), 3) test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) assert_equal(len(self.my_mcp.jobs), 3)
def test_no_actions(self): test_config = BASE_CONFIG + """ jobs: - &job0 name: "test_job0" node: *node0 schedule: "interval 20s" """ test_config = config.load_config(StringIO.StringIO(test_config)) assert_raises(config.ConfigError, test_config.apply, self.my_mcp)
def test_job_new(self): assert not 'test_new' in self.my_mcp.jobs test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) assert 'test_new' in self.my_mcp.jobs job3 = self.my_mcp.jobs['test_new'] assert_equal(job3.name, "test_new") assert_equal(len(job3.topo_actions), 1) assert_equal(job3.topo_actions[0].name, 'action_new') assert_equal(job3.topo_actions[0].command, 'command_new')
def test_job_removed(self): assert 'test_remove' in self.my_mcp.jobs job1 = self.my_mcp.jobs['test_remove'] run0 = job1.next_runs()[0] run0.start() run1 = job1.next_runs()[0] assert_equal(job1.name, "test_remove") assert_equal(len(job1.topo_actions), 1) assert_equal(job1.topo_actions[0].name, 'action_remove') test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) assert not 'test_remove' in self.my_mcp.jobs
def test_config_name_collision(self): test_config = BASE_CONFIG + """ jobs: - &job0 name: "test_job0" node: *node0 schedule: "interval 20s" actions: - name: "%s" command: "test_command0.0" """ % config.CLEANUP_ACTION_NAME test_config = config.load_config(StringIO.StringIO(test_config)) assert_raises(config.ConfigError, test_config.apply, self.my_mcp)
def test_job_in_services(self): test_config = BASE_CONFIG + """ services: - !Job name: "test_job0" node: *node0 schedule: "interval 20s" actions: - &intAction !Action name: "action0_0" command: "test_command0.0" cleanup_action: !CleanupAction command: "test_command0.1" """ test_config = config.load_config(StringIO.StringIO(test_config)) assert_raises(config.ConfigError, test_config.apply, self.my_mcp)
def test_job_removed(self): assert 'test_remove' in self.my_mcp.jobs job1 = self.my_mcp.jobs['test_remove'] run0 = job1.next_runs()[0] run0.start() run1 = job1.next_runs()[0] assert_equal(job1.name, "test_remove") assert_equal(len(job1.topo_actions), 1) assert_equal(job1.topo_actions[0].name, 'action_remove') test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) assert not 'test_remove' in self.my_mcp.jobs assert not job1.enabled assert not run1.is_scheduled
def test_config_name(self): test_config = BASE_CONFIG + """ jobs: - &job0 name: "test_job0" node: *node0 schedule: "interval 20s" actions: - name: "action0_0" command: "test_command0.0" cleanup_action: name: "gerald" command: "test_command0.1" """ test_config = config.load_config(StringIO.StringIO(test_config)) assert_raises(config.ConfigError, test_config.apply, self.my_mcp)
def setup(self): self.test_dir = tempfile.mkdtemp() self.test_config = config.load_config(StringIO.StringIO(self.config)) self.my_mcp = mcp.MasterControlProgram(self.test_dir, 'config') self.test_config.apply(self.my_mcp) self.node0 = self.my_mcp.nodes[0] self.node1 = self.my_mcp.nodes[1] self.job0 = self.my_mcp.jobs['test_job0'] self.job1 = self.my_mcp.jobs['test_job1'] self.job2 = self.my_mcp.jobs['test_job2'] self.job3 = self.my_mcp.jobs['test_job3'] self.job4 = self.my_mcp.jobs['test_job4'] self.serv = self.my_mcp.services['service0'] self.all_jobs = [self.job0, self.job1, self.job2, self.job3, self.job4]
def setup(self): self.test_dir = tempfile.mkdtemp() self.test_config = config.load_config(StringIO.StringIO(self.config)) self.my_mcp = mcp.MasterControlProgram(self.test_dir, "config") self.test_config.apply(self.my_mcp) self.node0 = self.my_mcp.nodes[0] self.node1 = self.my_mcp.nodes[1] self.job0 = self.my_mcp.jobs["test_job0"] self.job1 = self.my_mcp.jobs["test_job1"] self.job2 = self.my_mcp.jobs["test_job2"] self.job3 = self.my_mcp.jobs["test_job3"] self.job4 = self.my_mcp.jobs["test_job4"] self.serv = self.my_mcp.jobs["service0"] self.all_jobs = [self.job0, self.job1, self.job2, self.job3, self.job4]
def setup(self): self.test_dir = tempfile.mkdtemp() self.test_config = config.load_config(StringIO.StringIO(self.config)) self.my_mcp = mcp.MasterControlProgram(self.test_dir, 'config') self.test_config.apply(self.my_mcp) self.node0 = self.my_mcp.nodes[0] self.node1 = self.my_mcp.nodes[1] self.job0 = self.my_mcp.jobs['test_job0'] self.job1 = self.my_mcp.jobs['test_job1'] self.job2 = self.my_mcp.jobs['test_job2'] self.job3 = self.my_mcp.jobs['test_job3'] self.job4 = self.my_mcp.jobs['test_job4'] self.serv = self.my_mcp.jobs['service0'] self.all_jobs = [self.job0, self.job1, self.job2, self.job3, self.job4]
def test_daily_reschedule(self): job4 = self.my_mcp.jobs['test_daily_change'] job4.next_runs() assert_equal(len(job4.runs), 1) run = job4.runs[0] assert run.is_scheduled test_reconfig = config.load_config(StringIO.StringIO(self.reconfig)) test_reconfig.apply(self.my_mcp) assert run.job is None assert_equal(len(job4.runs), 1) next_run = job4.runs[0] assert next_run is not run assert next_run.is_scheduled assert_equal(run.run_time, next_run.run_time)
def hours_to_job_at_datetime(self, job_name, *args, **kwargs): """Return the number of hours until the next *two* runs of a job with the given scheduler """ # if you need to print a datetime with tz info, use this: # fmt = '%Y-%m-%d %H:%M:%S %Z%z' # my_datetime.strftime(fmt) test_dir = tempfile.mkdtemp() self.tmp_dirs.append(test_dir) test_config = config.load_config(StringIO.StringIO(self.config)) my_mcp = mcp.MasterControlProgram(test_dir, 'config') test_config.apply(my_mcp) now = datetime.datetime(*args, **kwargs) timeutils.override_current_time(now) next_run = my_mcp.jobs[job_name].next_runs()[0] t1 = round(next_run.seconds_until_run_time()/60/60, 1) next_run = my_mcp.jobs[job_name].next_runs()[0] t2 = round(next_run.seconds_until_run_time()/60/60, 1) return t1, t2
def setup(self): self.test_dir = tempfile.mkdtemp() self.test_config = config.load_config(StringIO.StringIO(self.config)) self.my_mcp = mcp.MasterControlProgram(self.test_dir, 'config') self.test_config.apply(self.my_mcp)
def test_bad_syslog(self): logging.getLogger('') test_reconfig = config.load_config(StringIO.StringIO(self.bad_config)) assert_raises(config.ConfigError, test_reconfig.apply, self.my_mcp)
def load_config(self): log.info("Loading configuration from %s" % self.config_file) opened_config = open(self.config_file, "r") configuration = config.load_config(opened_config) configuration.apply(self) opened_config.close()