You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by mc...@apache.org on 2014/08/14 20:40:46 UTC

git commit: Fix bug in "aurora job inspect".

Repository: incubator-aurora
Updated Branches:
  refs/heads/master aa5c6ebd6 -> 9bc993b84


Fix bug in "aurora job inspect".

Inspect was using context.print_out() to add blank lines, but the
print_out method takes a mandatory string parameter.

Bugs closed: aurora-642

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


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

Branch: refs/heads/master
Commit: 9bc993b847ce64db0c22efe3e6aca2c33e8d4732
Parents: aa5c6eb
Author: Mark Chu-Carroll <mc...@twopensource.com>
Authored: Thu Aug 14 14:36:02 2014 -0400
Committer: Mark Chu-Carroll <mc...@twitter.com>
Committed: Thu Aug 14 14:36:02 2014 -0400

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/__init__.py |  10 +-
 .../python/apache/aurora/client/cli/jobs.py     |  26 ++---
 src/test/python/apache/aurora/client/cli/BUILD  |  13 +++
 .../apache/aurora/client/cli/test_inspect.py    | 102 +++++++++++++++++++
 .../python/apache/aurora/client/cli/util.py     |  10 +-
 .../org/apache/aurora/e2e/test_end_to_end_v2.sh |   3 +
 6 files changed, 143 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9bc993b8/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 08590d0..6e553d8 100644
--- a/src/main/python/apache/aurora/client/cli/__init__.py
+++ b/src/main/python/apache/aurora/client/cli/__init__.py
@@ -240,11 +240,13 @@ class CommandLine(object):
   def name(self):
     """Returns the name of this command-line tool"""
 
-  def print_out(self, str):
-    print(str)
+  def print_out(self, s, indent=0):
+    indent_str = " " * indent
+    print("%s%s" % (indent_str, s))
 
-  def print_err(self, str):
-    print(str, file=sys.stderr)
+  def print_err(self, s, indent=0):
+    indent_str = " " * indent
+    print("%s%s" % (indent_str, s), file=sys.stderr)
 
   def __init__(self):
     self.nouns = None

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9bc993b8/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 3cb39b2..109ce59 100644
--- a/src/main/python/apache/aurora/client/cli/jobs.py
+++ b/src/main/python/apache/aurora/client/cli/jobs.py
@@ -228,37 +228,37 @@ the parsed configuration."""
     job = config.raw()
     job_thrift = config.job()
     context.print_out("Job level information")
-    context.print_out("name:       %s" % job.name(), indent=2)
-    context.print_out("role:       %s" % job.role(), indent=2)
-    context.print_out("contact:    %s" % job.contact(), indent=2)
-    context.print_out("cluster:    %s" % job.cluster(), indent=2)
-    context.print_out("instances:  %s" % job.instances(), indent=2)
+    context.print_out("name:       '%s'" % job.name(), indent=2)
+    context.print_out("role:       '%s'" % job.role(), indent=2)
+    context.print_out("contact:    '%s'" % job.contact(), indent=2)
+    context.print_out("cluster:    '%s'" % job.cluster(), indent=2)
+    context.print_out("instances:  '%s'" % job.instances(), indent=2)
     if job.has_cron_schedule():
       context.print_out("cron:", indent=2)
-      context.print_out("schedule: %s" % job.cron_schedule(), ident=4)
-      context.print_out("policy:   %s" % job.cron_collision_policy(), indent=4)
+      context.print_out("schedule: '%s'" % job.cron_schedule(), indent=4)
+      context.print_out("policy:   '%s'" % job.cron_collision_policy(), indent=4)
     if job.has_constraints():
       context.print_out("constraints:", indent=2)
       for constraint, value in job.constraints().get().items():
-        context.print_out("%s: %s" % (constraint, value), indent=4)
+        context.print_out("'%s': '%s'" % (constraint, value), indent=4)
     context.print_out("service:    %s" % job_thrift.taskConfig.isService, indent=2)
     context.print_out("production: %s" % bool(job.production().get()), indent=2)
-    context.print_out()
+    context.print_out("")
 
     task = job.task()
     context.print_out("Task level information")
-    context.print_out("name: %s" % task.name(), indent=2)
+    context.print_out("name: '%s'" % task.name(), indent=2)
 
     if len(task.constraints().get()) > 0:
       context.print_out("constraints:", indent=2)
       for constraint in task.constraints():
         context.print_out("%s" % (" < ".join(st.get() for st in constraint.order() or [])),
             indent=2)
-    context.print_out()
+    context.print_out("")
 
     processes = task.processes()
     for process in processes:
-      context.print_out("Process %s:" % process.name())
+      context.print_out("Process '%s':" % process.name())
       if process.daemon().get():
         context.print_out("daemon", indent=2)
       if process.ephemeral().get():
@@ -268,7 +268,7 @@ the parsed configuration."""
       context.print_out("cmdline:", indent=2)
       for line in process.cmdline().get().splitlines():
         context.print_out(line, indent=4)
-      context.print_out()
+      context.print_out("")
     return EXIT_OK
 
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9bc993b8/src/test/python/apache/aurora/client/cli/BUILD
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/BUILD b/src/test/python/apache/aurora/client/cli/BUILD
index 3c88ed7..e1f9ebf 100644
--- a/src/test/python/apache/aurora/client/cli/BUILD
+++ b/src/test/python/apache/aurora/client/cli/BUILD
@@ -20,6 +20,7 @@ python_test_suite(
     pants(':command_hooks'),
     pants(':cron'),
     pants(':help'),
+    pants(':inspect'),
     pants(':job'),
     pants(':config'),
     pants(':logging'),
@@ -40,6 +41,18 @@ python_library(
 )
 
 python_tests(
+  name='inspect',
+  sources = [ 'test_inspect.py' ],
+  dependencies = [
+    pants(':util'),
+    pants('3rdparty/python:mock'),
+    pants('3rdparty/python:twitter.common.contextutil'),
+    pants('src/main/python/apache/aurora/client/cli'),
+    pants('src/main/python/apache/aurora/client/cli:client_lib'),
+  ]
+)
+
+python_tests(
   name = 'help',
   sources = [ 'test_help.py' ],
   dependencies = [

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9bc993b8/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
new file mode 100644
index 0000000..fd35fe0
--- /dev/null
+++ b/src/test/python/apache/aurora/client/cli/test_inspect.py
@@ -0,0 +1,102 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import contextlib
+
+from mock import Mock, patch
+from twitter.common.contextutil import temporary_file
+
+from apache.aurora.client.cli.client import AuroraCommandLine
+from apache.aurora.client.cli.context import AuroraCommandContext
+from apache.aurora.client.cli.util import AuroraClientCommandTest
+from apache.aurora.config import AuroraConfig
+
+from gen.apache.aurora.api.ttypes import CronCollisionPolicy
+
+
+class TestInspectCommand(AuroraClientCommandTest):
+  def get_mock_config(self):
+    config = Mock(spec=AuroraConfig)
+    # TODO(mchucarroll): 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
+    return config
+
+  def test_inspect_job(self):
+    (mock_api, mock_scheduler_proxy) = self.create_mock_api()
+    AuroraCommandContext.enable_reveal_errors()
+    mock_transcript = []
+    def mock_print_out(msg, indent=0):
+      indent_str = " " * indent
+      mock_transcript.append("%s%s" % (indent_str, msg))
+    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', '--reveal-errors', '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",
+            ""]

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9bc993b8/src/test/python/apache/aurora/client/cli/util.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/util.py b/src/test/python/apache/aurora/client/cli/util.py
index 5d2e72d..552537a 100644
--- a/src/test/python/apache/aurora/client/cli/util.py
+++ b/src/test/python/apache/aurora/client/cli/util.py
@@ -67,11 +67,13 @@ class FakeAuroraCommandContext(AuroraCommandContext):
     mock_api.scheduler_proxy = mock_scheduler_proxy
     return mock_api
 
-  def print_out(self, str):
-    self.out.append(str)
+  def print_out(self, msg, indent=0):
+    indent_str = " " * indent
+    self.out.append("%s%s" % (indent_str, msg))
 
-  def print_err(self, str):
-    self.err.append(str)
+  def print_err(self, msg, indent=0):
+    indent_str = " " * indent
+    self.err.append("%s%s" % (indent_str, msg))
 
   def get_out(self):
     return self.out

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9bc993b8/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh
----------------------------------------------------------------------
diff --git a/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh b/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh
index ea5ae8d..8e18e52 100755
--- a/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh
+++ b/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh
@@ -33,6 +33,9 @@ test_http_example() {
   local _cluster=$1 _role=$2 _env=$3 _job=$4 _sched_ip=$5
   local _base_config=$6 _updated_config=$7
   jobkey="$_cluster/$_role/$_env/$_job"
+
+  vagrant ssh -c "aurora job inspect $jobkey $_base_config"
+
   echo '== Creating job'
   vagrant ssh -c "aurora2 job create $jobkey $_base_config"