Permalink
Browse files

Mostly test fixes.

  • Loading branch information...
1 parent c6ea04e commit 5eb3bb72e7b6a2cc1b5c5a4b89f57a8a30155e77 @dnephin dnephin committed Apr 1, 2012
@@ -5,7 +5,7 @@
from testify.test_case import class_setup, class_teardown
from tron import node
-from tron.core.actionrun import ActionCommand, ActionRunContext, ActionRun
+from tron.core.actionrun import ActionCommand, ActionRunContext, ActionRun, ActionRunCollection
from tron.core.actionrun import InvalidStartStateError
from tron.utils import timeutils
@@ -45,30 +45,24 @@ class ActionRunTestCase(TestCase):
@setup
def setup_action_run(self):
anode = turtle.Turtle()
- output_path = "random_dir"
+ output_path = ["random_dir"]
self.command = "do command"
self.action_run = ActionRun(
- "id", anode,
- timeutils.current_time(),
- self.command,
- output_path=output_path)
+ "id",
+ "action_name",
+ anode,
+ timeutils.current_time(),
+ self.command,
+ output_path=output_path)
def test_init_state(self):
assert_equal(self.action_run.state, ActionRun.STATE_SCHEDULED)
- def test_attempt_start(self):
- assert self.action_run.attempt_start()
- assert_equal(self.action_run.state, ActionRun.STATE_STARTING)
-
- def test_attempt_start_failed(self):
- self.action_run.machine.transition('queue')
- assert not self.action_run.attempt_start()
- assert_equal(self.action_run.state, ActionRun.STATE_QUEUED)
-
def test_start(self):
self.action_run.machine.transition('ready')
assert self.action_run.start()
assert self.action_run.is_starting
+ assert self.action_run.start_time
def test_start_bad_state(self):
self.action_run.fail()
@@ -102,12 +96,14 @@ def test_build_action_command(self):
def test_watcher_running(self):
self.action_run.build_action_command()
self.action_run.machine.transition('start')
- assert self.action_run.watcher(self.action_run.action_command, ActionCommand.RUNNING)
+ assert self.action_run.watcher(
+ self.action_run.action_command, ActionCommand.RUNNING)
assert self.action_run.is_running
def test_watcher_failstart(self):
self.action_run.build_action_command()
- assert self.action_run.watcher(self.action_run.action_command, ActionCommand.FAILSTART)
+ assert self.action_run.watcher(
+ self.action_run.action_command, ActionCommand.FAILSTART)
assert self.action_run.is_failed
def test_watcher_exiting_fail(self):
@@ -145,7 +141,8 @@ def test_watcher_unhandled(self):
assert self.action_run.is_scheduled
def test_success(self):
- assert self.action_run.attempt_start()
+ assert self.action_run.ready()
+ self.action_run.machine.transition('start')
self.action_run.machine.transition('started')
assert self.action_run.is_running
@@ -173,7 +170,8 @@ def test_failure_bad_state(self):
def test_skip(self):
assert not self.action_run.is_running
- assert self.action_run.attempt_start()
+ self.action_run.ready()
+ assert self.action_run.start()
assert self.action_run.fail(-1)
assert self.action_run.skip()
@@ -201,6 +199,7 @@ def test_command_failed_render(self):
def test__getattr__(self):
assert self.action_run.is_succeeded is not None
+ assert self.action_run.cancel()
def test__getattr__missing_attribute(self):
assert_raises(AttributeError,
@@ -211,38 +210,62 @@ class ActionRunStateRestoreTestCase(TestCase):
@setup
def setup_action_run(self):
- anode = turtle.Turtle()
- output_path = "random_dir"
- self.action_run = ActionRun(
- "id", anode,
- timeutils.current_time(),
- "do command",
- output_path=output_path)
+ self.parent_context = {}
+ self.output_path = ['one', 'two']
self.state_data = {
- 'id': "newid",
- 'state': "running",
- 'run_time': "now",
- 'start_time': "now-1",
- 'end_time': None,
- 'command': "do this",
- }
-
- def test_restore_state_running(self):
- self.action_run.restore_state(self.state_data)
- assert self.action_run.is_unknown
+ 'job_run_id': 'theid',
+ 'action_name': 'theaction',
+ 'node_name': 'anode',
+ 'run_time': 'run_time',
+ 'command': 'do things',
+ 'start_time': 'start_time',
+ 'end_time': 'end_time',
+ 'state': 'succeeded'
+ }
+
+ def test_from_state(self):
+ state_data = self.state_data
+ action_run = ActionRun.from_state(
+ state_data, self.parent_context, self.output_path)
+
for key, value in self.state_data.iteritems():
- if key in ['state']:
+ if key in ['state', 'node_name']:
continue
- assert_equal(getattr(self.action_run, key), value)
+ assert_equal(getattr(action_run, key), value)
- def test_restore_state_complete(self):
- self.state_data['end_time'] = "yesterday"
- self.state_data['state'] = 'succeeded'
- self.action_run.restore_state(self.state_data)
- assert self.action_run.is_succeeded
- assert_equal(self.action_run.end_time, "yesterday")
+ assert action_run.is_succeeded
+ assert not action_run.is_cleanup
+
+ def test_from_state_running(self):
+ self.state_data['state'] = 'running'
+ action_run = ActionRun.from_state(
+ self.state_data, self.parent_context, self.output_path)
+ assert action_run.is_unknown
+
+ def test_from_state_no_node_name(self):
+ del self.state_data['node_name']
+ action_run = ActionRun.from_state(
+ self.state_data, self.parent_context, self.output_path)
+ assert action_run.node is None
+
+ def test_from_state_with_node_exists(self):
+ anode = turtle.Turtle(name="anode", hostname="box")
+ node_store = node.NodePoolStore.get_instance()
+ node_store.put(anode)
+ action_run = ActionRun.from_state(
+ self.state_data, self.parent_context, self.output_path)
+ assert_equal(action_run.node, anode)
+ node_store.clear()
+
+
+class ActionRunCollectionTestCase(TestCase):
+
+ @setup
+ def setup_runs(self):
+ self.run_map = {}
+ self.collection = ActionRunCollection(self.run_map)
if __name__ == "__main__":
run()
View
@@ -8,11 +8,12 @@
from testify.utils import turtle
from tron.core import action, job
-from tron import mcp, scheduler, event
+from tron import mcp, scheduler, event, node
from tests import testingutils
from tron.utils import timeutils
+# TODO: This does not test anything
class TestStateHandler(TestCase):
@class_setup
def class_setup_time(self):
@@ -46,12 +47,13 @@ def teardown_mcp(self):
shutil.rmtree(self.test_dir)
event.EventManager.get_instance().clear()
+
@suite('integration')
def test_reschedule(self):
def callNow(sleep, func, run):
raise NotImplementedError(sleep)
- self.mcp.job_scheduler.next_runs(self.job)
+ #self.mcp.job_scheduler.next_runs(self.job)
#callLate = reactor.callLater
#reactor.callLater = callNow
@@ -141,50 +143,69 @@ def test(self):
assert_raises(mcp.StateFileVersionError, handler._load_data_file, self.data_file)
-class TestMasterControlProgram(TestCase):
+class MasterControlProgramTestCase(TestCase):
@setup
- def build_actions(self):
- self.nodes = turtle.Turtle()
- self.test_dir = tempfile.mkdtemp()
- self.action = action.Action("Test Action", "doit", self.nodes)
- self.job = job.Job("Test Job", self.action)
- self.job.output_path = self.test_dir
- self.mcp = mcp.MasterControlProgram(self.test_dir, "config")
- self.job.node_pool = testingutils.TestPool()
+ def setup_mcp(self):
+ self.working_dir = tempfile.mkdtemp()
+ config_file = tempfile.NamedTemporaryFile(dir=self.working_dir)
+ self.mcp = mcp.MasterControlProgram(self.working_dir, config_file.name)
@teardown
- def teardown_actions(self):
- shutil.rmtree(self.test_dir)
- event.EventManager.get_instance().clear()
+ def teardown_mcp(self):
+ self.mcp.nodes.clear()
+ self.mcp.event_manager.clear()
+
+ def test_live_reconfig(self):
+ pass
+ # TODO: some of these tests are in tests.config.reconfig_test
+
+ def test_load_config(self):
+ pass
+ # TODO
+
+ def config_lines(self):
+ # TODO:
+ pass
+
+ def test_rewrite_config(self):
+ pass
+ # TODO:
+
+ def test_apply_config(self):
+ pass
+ # TODO:
+
+ def test_apply_working_directory(self):
+ pass
+ # TODO
+
+ def test_ssh_options_from_config(self):
+ ssh_conf = turtle.Turtle(agent=False, identities=[])
+ ssh_options = self.mcp._ssh_options_from_config(ssh_conf)
+
+ assert_equal(ssh_options['agent'], False)
+ assert_equal(ssh_options.identitys, [])
+ # TODO: tests with agent and identities
+
+ def test_add_job(self):
+ job_conf = {
+
+ }
+ pass
+
+ def test_add_job_already_exists(self):
+ pass
+
+ def test_remove_job(self):
+ pass
+
+ def test_disable_all(self):
+ pass
+
+ def test_enable_all(self):
+ pass
- def test_schedule_next_run(self):
- act = action.Action("Test Action", "doit", self.nodes)
- jo = job.Job("Test Job", act)
- jo.output_path = self.test_dir
- jo.node_pool = testingutils.TestPool()
- jo.scheduler = scheduler.DailyScheduler()
-
- act.job = jo
- act.command = "Test command"
- act.node = turtle.Turtle()
-
- def call_now(time, func, next):
- next.start()
- next.action_runs[0].succeed()
-
- callLater = mcp.reactor.callLater
- mcp.reactor.callLater = call_now
- try:
- self.mcp.job_scheduler.schedule(jo)
- finally:
- mcp.reactor.callLater = callLater
- next = jo.runs[0]
-
- assert_equal(len(filter(lambda r:r.is_success, jo.runs)), 1)
- assert_equal(jo.topo_actions[0], next.action_runs[0].action)
- assert next.action_runs[0].is_success
- assert next.is_success
View
@@ -130,6 +130,7 @@ def unset_time(self):
timeutils.override_current_time(None)
def hours_until_time(self, run_time, sch):
+ # TODO: use timeutils
tz = sch.time_zone
now = timeutils.current_time()
now = tz.localize(now) if tz else now
@@ -235,8 +235,19 @@ def test_append(self):
self.path.append('four')
assert_equal(self.path.parts, ['two', 'three', 'four'])
+ def test_clone(self):
+ new_path = self.path.clone()
+ assert_equal(str(new_path), str(self.path))
+ self.path.append('alpha')
+ assert_equal(str(new_path), 'one/two/three')
+ new_path.append('beta')
+ assert_equal(str(self.path), 'one/two/three/alpha')
+
+ def test_clone_with_parts(self):
+ new_path = self.path.clone('seven', 'ten')
+ assert_equal(list(new_path), ['one/two/three', 'seven', 'ten'])
if __name__ == "__main__":
run()
Oops, something went wrong.

0 comments on commit 5eb3bb7

Please sign in to comment.