def setup(self): self.test_dir = tempfile.mkdtemp() self.action1 = action.Action(name="Test Act1") self.action2 = action.Action(name="Test Act1") self.action2.required_actions.append(self.action1) self.action1.command = "Test Command" self.action2.command = "Test Command" self.job = job.Job("Test Job", self.action1) self.job.output_dir = self.test_dir self.job.topo_actions.append(self.action2) self.job.scheduler = scheduler.DailyScheduler() self.job.node_pool = turtle.Turtle() self.action1.job = self.job self.action2.job = self.job
def build_actions(self): self.test_dir = tempfile.mkdtemp() self.action = action.Action("Test Action") self.job = job.Job("Test Job", self.action) self.job.output_dir = self.test_dir self.mcp = mcp.MasterControlProgram(self.test_dir, "config") self.job.node_pool = node.NodePool('test hostname')
def test_schedule_next_run(self): act = action.Action("Test Action") jo = job.Job("Test Job", act) jo.output_dir = self.test_dir jo.node_pool = turtle.Turtle() jo.scheduler = scheduler.DailyScheduler() act.job = jo act.command = "Test command" act.node = turtle.Turtle() def call_now(time, func, next): next.start() next.runs[0].succeed() callLater = mcp.reactor.callLater mcp.reactor.callLater = call_now self.mcp.schedule_next_run(jo) mcp.reactor.callLater = callLater next = jo.runs[0] assert_equals(len(filter(lambda r: r.is_success, jo.runs)), 1) assert_equals(jo.topo_actions[0], next.runs[0].action) assert next.runs[0].is_success assert next.is_success
def build_job(self): self.test_dir = tempfile.mkdtemp() self.action = action.Action(name="Test Action", node_pool=turtle.Turtle()) self.job = job.Job("Test Job", self.action) self.job.node_pool = turtle.Turtle() self.job.output_dir = self.test_dir self.action.job = self.job self.action.command = "Test command"
def setup(self): self.test_dir = tempfile.mkdtemp() self.action1 = action.Action(name="Test Act1") self.action1.command = "Test Command" self.job = job.Job("Test Job", self.action1) self.job.output_dir = self.test_dir self.job.scheduler = scheduler.DailyScheduler() self.job.node_pool = turtle.Turtle() self.action1.job = self.job self.job.enable_act = action.Action(name='Enable Act') self.job.enable_act.command = 'Enable Command' self.job.enable_act.job = self.job self.job.disable_act = action.Action(name='Disable Act') self.job.disable_act.command = 'Disable Command' self.job.disable_act.job = self.job
def build_scheduler(self): self.test_dir = tempfile.mkdtemp() self.scheduler = scheduler.DailyScheduler() self.action = action.Action("Test Action") self.job = job.Job("Test Job", self.action) self.job.node_pool = turtle.Turtle() self.job.output_dir = self.test_dir self.job.scheduler = self.scheduler self.action.job = self.job
def build_job(self): self.test_dir = tempfile.mkdtemp() self.action = action.Action(name="Test Action") self.action.command = "Test Action Command" self.job = job.Job("Test Job", self.action) self.job.node_pool = node.NodePool("host") self.job.output_dir = self.test_dir self.action.job = self.job self.job.scheduler = scheduler.ConstantScheduler()
def build_scheduler(self): self.test_dir = tempfile.mkdtemp() self.scheduler = scheduler.DailyScheduler( start_time=datetime.time(hour=16, minute=30)) self.action = action.Action("Test Action - Beer Time") self.job = job.Job("Test Job", self.action) self.job.node_pool = turtle.Turtle() self.job.output_dir = self.test_dir self.job.scheduler = self.scheduler self.action.job = self.job
def build_scheduler(self): self.test_dir = tempfile.mkdtemp() self.interval = datetime.timedelta(seconds=1) self.scheduler = scheduler.IntervalScheduler(self.interval) self.action = action.Action("Test Action") self.job = job.Job("Test Job", self.action) self.job.node_pool = turtle.Turtle() self.job.output_dir = self.test_dir self.job.scheduler = self.scheduler self.action.job = self.job
def setup(self): self.test_dir = tempfile.mkdtemp() self.action = action.Action(name="Test Action") self.action.command = "Test Command" self.job = job.Job("Test Job", self.action) self.job.output_dir = self.test_dir self.job.node_pool = turtle.Turtle() self.job.scheduler = scheduler.DailyScheduler() self.action.job = self.job
def setup(self): self.test_dir = tempfile.mkdtemp() self.action = action.Action(name="Test Action", node_pool=turtle.Turtle()) self.job = job.Job("Test Job", self.action) self.job.node_pool = turtle.Turtle() self.job.output_dir = self.test_dir self.job.scheduler = scheduler.DailyScheduler() self.job.queueing = True self.action.job = self.job self.action.command = "Test command" self.job_run = self.job.next_runs()[0] self.run = self.job_run.runs[0]
def build_job(self): self.test_dir = tempfile.mkdtemp() self.action = action.Action(name="Test Action1") self.action.command = "Test command1" self.action.node_pool = turtle.Turtle() self.dep_action = action.Action(name="Test Action2") self.dep_action.command = "Test command2" self.dep_action.node_pool = turtle.Turtle() self.dep_action.required_actions.append(self.action) self.job = job.Job("Test Job", self.action) self.job.node_pool = turtle.Turtle() self.job.output_dir = self.test_dir self.action.job = self.job self.dep_action.job = self.job self.job.topo_actions.append(self.dep_action) self.job.scheduler = scheduler.DailyScheduler() self.job_run = self.job.next_runs()[0] self.run = self.job_run.runs[0] self.dep_run = self.job_run.runs[1]
def build_job(self): self.test_dir = tempfile.mkdtemp() self.action = action.Action(name="Test Action") self.action.command = "Test command" self.action.node_pool = turtle.Turtle() self.action.job = turtle.Turtle() self.action.job.output_dir = None self.run = self.action.build_run(turtle.Turtle(output_dir=self.test_dir)) self.run.job_run = turtle.Turtle() def noop_execute(): pass self.run._execute = noop_execute
def setup(self): self.test_dir = tempfile.mkdtemp() self.mcp = mcp.MasterControlProgram(self.test_dir, "config") self.state_handler = self.mcp.state_handler self.action = action.Action("Test Action") self.action.command = "Test command" self.action.queueing = True self.action.node = turtle.Turtle() self.job = job.Job("Test Job", self.action) self.job.output_dir = self.test_dir self.job.node_pool = turtle.Turtle() self.job.scheduler = scheduler.IntervalScheduler( datetime.timedelta(seconds=5)) self.action.job = self.job
def test_build_run(self): self.job.node_pool = turtle.Turtle() act = action.Action("Action Test2") act.command = "test" act.job = self.job self.job.topo_actions.append(act) run1 = self.job.next_runs()[0] assert_equals(run1.runs[0].action, self.action) assert_equals(run1.runs[1].action, act) run2 = self.job.next_runs()[0] assert_equals(self.job.runs[1], run1) assert_equals(run2.runs[0].action, self.action) assert_equals(run2.runs[1].action, act)
def test_output_logging(self): act = action.Action(name="Test Action") act.command = "echo Hello" jo = job.Job("Test Job", act) jo.output_dir = self.test_dir jo.node_pool = turtle.Turtle() act.job = jo run = jo.build_run() nod = node.Node(hostname="localhost") act_run = run.runs[0] act_run.stdout_file = tempfile.TemporaryFile('w+b') nod.connection = self.TestConnection() nod.run_states = {act_run.id:turtle.Turtle(state=0)} nod.run_states[act_run.id].state = node.RUN_STATE_CONNECTING nod._open_channel(act_run) assert not nod.connection.chan is None nod.connection.chan.dataReceived("test") act_run.stdout_file.seek(0) assert act_run.stdout_file.read(4) == "test" act_run.stdout_file.close()