]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Fixed a bug where I wasn't setting machine_type correctly. Also, made
authorAndrew Schoen <aschoen@redhat.com>
Tue, 2 Dec 2014 22:57:03 +0000 (16:57 -0600)
committerAndrew Schoen <aschoen@redhat.com>
Sat, 6 Dec 2014 19:46:47 +0000 (13:46 -0600)
local variables for each of the keys in args to help readability.

Wrote tests for teuthology.run.main. Coverage increased to 94%

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
teuthology/run.py
teuthology/test/test_run.py

index 4866bc804995dbd71e3649a85ac46ed3234582eb..6f20b3abe17c92d177aa33360455fa653a3d965d 100644 (file)
@@ -243,46 +243,59 @@ def report_outcome(config, archive, summary, fake_ctx):
 
 
 def main(args):
-    set_up_logging(args["--verbose"], args["--archive"])
+    verbose = args["--verbose"]
+    archive = args["--archive"]
+    owner = args["--owner"]
+    config = args["<config>"]
+    name = args["--name"]
+    description = args["--description"]
+    machine_type = args["--machine-type"]
+    block = args["--block"]
+    lock = args["--lock"]
+    suite_path = args["--suite-path"]
 
-    if args["--owner"] is None:
-        args["--owner"] = get_user()
+    set_up_logging(verbose, archive)
 
-    args["<config>"] = setup_config(args["<config>"])
+    if owner is None:
+        owner = get_user()
 
-    write_initial_metadata(args["--archive"], args["<config>"], args["--name"], args["--description"], args["--owner"])
-    report.try_push_job_info(args["<config>"], dict(status='running'))
+    config = setup_config(config)
 
-    machine_type = get_machine_type(args["--machine-type"], args["<config>"])
+    write_initial_metadata(archive, config, name, description, owner)
+    report.try_push_job_info(config, dict(status='running'))
 
-    if args["--block"]:
-        assert args["--lock"], \
+    machine_type = get_machine_type(machine_type, config)
+    args["--machine-type"] = machine_type
+
+    if block:
+        assert lock, \
             'the --block option is only supported with the --lock option'
 
-    log.debug('\n  '.join(['Config:', ] + yaml.safe_dump(args["<config>"], default_flow_style=False).splitlines()))
+    log.debug('\n  '.join(['Config:', ] + yaml.safe_dump(config, default_flow_style=False).splitlines()))
 
-    args["summary"] = get_summary(args["--owner"], args["--description"])
+    args["summary"] = get_summary(owner, description)
 
-    args["<config>"]["tasks"] = validate_tasks(args["<config>"])
+    config["tasks"] = validate_tasks(config)
 
-    init_tasks = get_initial_tasks(args["--lock"], args["<config>"], machine_type)
+    init_tasks = get_initial_tasks(lock, config, machine_type)
 
     # prepend init_tasks to the front of the task list
-    args["<config>"]['tasks'][:0] = init_tasks
+    config['tasks'][:0] = init_tasks
 
-    if args["--suite-path"] is not None:
-        args["<config>"]['suite_path'] = args["--suite-path"]
+    if suite_path is not None:
+        config['suite_path'] = suite_path
 
     # fetches the tasks and returns a new suite_path if needed
-    args["<config>"]["suite_path"] = fetch_tasks_if_needed(args["<config>"])
+    config["suite_path"] = fetch_tasks_if_needed(config)
 
     # create a FakeNamespace instance that mimics the old argparse way of doing things
     # we do this so we can pass it to run_tasks without porting those tasks to the
     # new way of doing things right now
+    args["<config>"] = config
     fake_ctx = FakeNamespace(args)
 
     try:
-        run_tasks(tasks=args["<config>"]['tasks'], ctx=fake_ctx)
+        run_tasks(tasks=config['tasks'], ctx=fake_ctx)
     finally:
         # print to stdout the results and possibly send an email on any errors
-        report_outcome(args["<config>"], args["--archive"], args["summary"], fake_ctx)
+        report_outcome(config, archive, args["summary"], fake_ctx)
index a9f874e01d2b30b8f9b1161e7834a6910e845746..460249585a3d70d927fa61bfb8cf8fb4e5a80172 100644 (file)
@@ -1,8 +1,10 @@
 import pytest
+import docopt
 
 from mock import patch, call, Mock
 
 from teuthology import run
+from scripts import run as scripts_run
 
 
 class TestRun(object):
@@ -124,3 +126,56 @@ class TestRun(object):
         assert m_email_results.called
         assert m_file.called
         assert m_sys_exit.called
+
+    @patch("teuthology.run.set_up_logging")
+    @patch("teuthology.run.setup_config")
+    @patch("teuthology.run.get_user")
+    @patch("teuthology.run.write_initial_metadata")
+    @patch("teuthology.report.try_push_job_info")
+    @patch("teuthology.run.get_machine_type")
+    @patch("teuthology.run.get_summary")
+    @patch("yaml.safe_dump")
+    @patch("teuthology.run.validate_tasks")
+    @patch("teuthology.run.get_initial_tasks")
+    @patch("teuthology.run.fetch_tasks_if_needed")
+    @patch("teuthology.run.run_tasks")
+    @patch("teuthology.run.report_outcome")
+    def test_main(self, m_report_outcome, m_run_tasks, m_fetch_tasks_if_needed, m_get_initial_tasks, m_validate_tasks,
+                  m_safe_dump, m_get_summary, m_get_machine_type, m_try_push_job_info, m_write_initial_metadata,
+                  m_get_user, m_setup_config, m_set_up_logging):
+        """ This really should be an integration test of some sort. """
+        config = {"job_id": 1}
+        m_setup_config.return_value = config
+        m_get_machine_type.return_value = "machine_type"
+        doc = scripts_run.__doc__
+        args = docopt.docopt(doc, [
+            "--verbose",
+            "--archive", "some/archive/dir",
+            "--description", "the_description",
+            "--owner", "the_owner",
+            "--lock",
+            "--machine-type", "machine_type",
+            "--os-type", "os_type",
+            "--os-version", "os_version",
+            "--block",
+            "--name", "the_name",
+            "--suite-path", "some/suite/dir",
+            "path/to/config.yml",
+        ])
+        run.main(args)
+        m_set_up_logging.assert_called_with(True, "some/archive/dir")
+        m_setup_config.assert_called_with(["path/to/config.yml"])
+        m_write_initial_metadata.assert_called_with(
+            "some/archive/dir",
+            config,
+            "the_name",
+            "the_description",
+            "the_owner"
+        )
+        m_try_push_job_info.assert_called_with(config, dict(status='running'))
+        m_get_machine_type.assert_called_with("machine_type", config)
+        m_get_summary.assert_called_with("the_owner", "the_description")
+        m_get_initial_tasks.assert_called_with(True, config, "machine_type")
+        m_fetch_tasks_if_needed.assert_called_with(config)
+        assert m_run_tasks.called
+        assert m_report_outcome.called