aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject incubator-aurora git commit: Fix bad call to print_out causing 'job inspect --raw' to fail.
Date Fri, 09 Jan 2015 18:45:58 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 47e6e68de -> c7afcf046


Fix bad call to print_out causing 'job inspect --raw' to fail.

Bugs closed: AURORA-990

Reviewed at https://reviews.apache.org/r/29696/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/c7afcf04
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/c7afcf04
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/c7afcf04

Branch: refs/heads/master
Commit: c7afcf046fe5f4e4ad878e03899b0191c3e0dcc3
Parents: 47e6e68
Author: Bill Farner <wfarner@apache.org>
Authored: Fri Jan 9 10:44:53 2015 -0800
Committer: Bill Farner <wfarner@apache.org>
Committed: Fri Jan 9 10:44:53 2015 -0800

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/__init__.py |   4 +-
 .../python/apache/aurora/client/cli/jobs.py     |   2 +-
 .../apache/aurora/client/cli/test_inspect.py    | 139 ++++++++++---------
 3 files changed, 74 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/c7afcf04/src/main/python/apache/aurora/client/cli/__init__.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/__init__.py b/src/main/python/apache/aurora/client/cli/__init__.py
index 5060577..2999883 100644
--- a/src/main/python/apache/aurora/client/cli/__init__.py
+++ b/src/main/python/apache/aurora/client/cli/__init__.py
@@ -36,7 +36,7 @@ import sys
 import traceback
 from abc import abstractmethod, abstractproperty
 
-from twitter.common.lang import AbstractClass
+from twitter.common.lang import AbstractClass, Compatibility
 
 from apache.aurora.common.pex_version import pex_version, UnknownVersion
 
@@ -108,6 +108,8 @@ class Context(object):
     """Prints output to standard out with indent.
     For debugging purposes, it's nice to be able to patch this and capture output.
     """
+    if not isinstance(msg, Compatibility.string):
+      raise TypeError('msg must be a string')
     indent_str = " " * indent
     lines = msg.split("\n")
     for line in lines:

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/c7afcf04/src/main/python/apache/aurora/client/cli/jobs.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/jobs.py b/src/main/python/apache/aurora/client/cli/jobs.py
index 9a2b47a..508c9be 100644
--- a/src/main/python/apache/aurora/client/cli/jobs.py
+++ b/src/main/python/apache/aurora/client/cli/jobs.py
@@ -248,7 +248,7 @@ class InspectCommand(Verb):
   def execute(self, context):
     config = context.get_job_config(context.options.jobspec, context.options.config_file)
     if context.options.raw:
-      context.print_out(config.job())
+      context.print_out(str(config.job()))
       return EXIT_OK
 
     job = config.raw()

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/c7afcf04/src/test/python/apache/aurora/client/cli/test_inspect.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_inspect.py b/src/test/python/apache/aurora/client/cli/test_inspect.py
index 1c07d91..ae04776 100644
--- a/src/test/python/apache/aurora/client/cli/test_inspect.py
+++ b/src/test/python/apache/aurora/client/cli/test_inspect.py
@@ -14,88 +14,89 @@
 
 import contextlib
 
-from mock import create_autospec, Mock, patch
-from twitter.common.contextutil import temporary_file
+from mock import patch
 
 from apache.aurora.client.cli.client import AuroraCommandLine
 from apache.aurora.config import AuroraConfig
+from apache.aurora.config.schema.base import Job
+from apache.thermos.config.schema_base import MB, Process, Resources, Task
 
 from .util import AuroraClientCommandTest
 
-from gen.apache.aurora.api.ttypes import CronCollisionPolicy
-
 
 class TestInspectCommand(AuroraClientCommandTest):
-  def get_mock_config(self):
-    config = create_autospec(spec=AuroraConfig, instance=True)
-    # TODO(wfarner): figure out how to spec this. The raw_config is a Pystachio spec, and
that seems
-    # to blow up mock.
-    raw_config = Mock()
-    config.raw.return_value = raw_config
-    raw_config.contact.return_value = "bozo@the.clown"
-    raw_config.name.return_value = "the_job"
-    raw_config.role.return_value = "bozo"
-    raw_config.cluster.return_value = "west"
-    raw_config.instances.return_value = 3
-    raw_config.has_cron_schedule.return_value = True
-    raw_config.cron_schedule.return_value = "* * * * *"
-    raw_config.cron_collision_policy.return_value = CronCollisionPolicy.KILL_EXISTING
-    raw_config.has_constraints.return_value = False
-    raw_config.production.return_value.get.return_value = False
-    mock_task = Mock()
-    raw_config.task.return_value = mock_task
-    mock_task.name.return_value = "task"
-    mock_task.constraints.return_value.get.return_value = {}
-    mock_process = Mock()
-    mock_processes = [mock_process]
-    mock_task.processes.return_value = mock_processes
-    mock_process.name.return_value = "process"
-    mock_process.daemon.return_value.get.return_value = False
-    mock_process.ephemeral.return_value.get.return_value = False
-    mock_process.final.return_value.get.return_value = False
-    mock_process.cmdline.return_value.get.return_value = "ls -la"
-    config.job.return_value.taskConfig.isService = False
+  def get_job_config(self):
+    config = AuroraConfig(job=Job(
+      cluster='west',
+      role='bozo',
+      environment='test',
+      name='the_job',
+      service=False,
+      task=Task(
+        name='task',
+        processes=[Process(cmdline='ls -la', name='process')],
+        resources=Resources(cpu=1.0, ram=1024 * MB, disk=1024 * MB)
+      ),
+      contact='bozo@the.clown',
+      instances=3,
+      cron_schedule='* * * * *'
+    ))
     return config
 
   def test_inspect_job(self):
-    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
-    mock_transcript = []
+    mock_stdout = []
+    def mock_print_out(msg, indent=0):
+      indent_str = " " * indent
+      mock_stdout.append("%s%s" % (indent_str, msg))
+    with contextlib.nested(
+        patch('apache.aurora.client.cli.context.AuroraCommandContext.print_out',
+            side_effect=mock_print_out),
+        patch('apache.aurora.client.cli.context.AuroraCommandContext.get_job_config',
+            return_value=self.get_job_config())):
+      cmd = AuroraCommandLine()
+      assert cmd.execute(['job', 'inspect', 'west/bozo/test/hello', 'config.aurora']) ==
0
+      output = '\n'.join(mock_stdout)
+      assert output == '''Job level information
+  name:       'the_job'
+  role:       'bozo'
+  contact:    'bozo@the.clown'
+  cluster:    'west'
+  instances:  '3'
+  cron:
+    schedule: '* * * * *'
+    policy:   'KILL_EXISTING'
+  service:    False
+  production: False
+
+Task level information
+  name: 'task'
+
+Process 'process':
+  cmdline:
+    ls -la
+'''
+
+  def test_inspect_job_raw(self):
+    mock_stdout = []
     def mock_print_out(msg, indent=0):
       indent_str = " " * indent
-      mock_transcript.append("%s%s" % (indent_str, msg))
+      mock_stdout.append("%s%s" % (indent_str, msg))
+    job_config = self.get_job_config()
     with contextlib.nested(
-        patch('threading._Event.wait'),
-        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
-        patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
         patch('apache.aurora.client.cli.context.AuroraCommandContext.print_out',
             side_effect=mock_print_out),
-        patch('apache.aurora.client.cli.context.get_config', return_value=self.get_mock_config())):
-      with temporary_file() as fp:
-        fp.write(self.get_valid_config())
-        fp.flush()
-        cmd = AuroraCommandLine()
-        result = cmd.execute(['job', 'inspect', 'west/bozo/test/hello', fp.name])
-        # inspect command should run without errors, and return 0.
-        assert result == 0
-        # The command output for the mock should look right.
-        print(mock_transcript)
-        assert mock_transcript == [
-            "Job level information",
-            "  name:       'the_job'",
-            "  role:       'bozo'",
-            "  contact:    'bozo@the.clown'",
-            "  cluster:    'west'",
-            "  instances:  '3'",
-            "  cron:",
-            "    schedule: '* * * * *'",
-            "    policy:   '0'",
-            "  service:    False",
-            "  production: False",
-            "",
-            "Task level information",
-            "  name: 'task'",
-            "",
-            "Process 'process':",
-            "  cmdline:",
-            "    ls -la",
-            ""]
+        patch('apache.aurora.client.cli.context.AuroraCommandContext.get_job_config',
+            return_value=job_config)):
+      cmd = AuroraCommandLine()
+      assert cmd.execute(['job', 'inspect', '--raw', 'west/bozo/test/hello', 'config.aurora'])
== 0
+      output = '\n'.join(mock_stdout)
+      assert output == str(job_config.job())
+
+  # AURORA-990: Prevent regression of client passing invalid arguments to print_out.
+  # Since print_out is the final layer before print(), there's not much else we can do than
+  # ensure the command exits normally.
+  def test_inspect_job_raw_success(self):
+    with patch('apache.aurora.client.cli.context.AuroraCommandContext.get_job_config',
+            return_value=self.get_job_config()):
+      cmd = AuroraCommandLine()
+      assert cmd.execute(['job', 'inspect', '--raw', 'west/bozo/test/hello', 'config.aurora'])
== 0


Mime
View raw message