You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by ma...@apache.org on 2014/12/09 00:37:43 UTC

incubator-aurora git commit: Simplify logging in the client.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master a9e12171c -> 9926af3ae


Simplify logging in the client.

Bugs closed: AURORA-919

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


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

Branch: refs/heads/master
Commit: 9926af3ae02fb392a46dfb66dd21718b9eea583d
Parents: a9e1217
Author: Zameer Manji <zm...@twopensource.com>
Authored: Mon Dec 8 15:37:24 2014 -0800
Committer: -l <ma...@apache.org>
Committed: Mon Dec 8 15:37:24 2014 -0800

----------------------------------------------------------------------
 src/main/python/apache/aurora/client/cli/BUILD  |   2 +-
 .../python/apache/aurora/client/cli/__init__.py |  47 +-----
 .../python/apache/aurora/client/cli/client.py   |  49 ++----
 .../apache/aurora/client/cli/command_hooks.py   |  10 +-
 .../python/apache/aurora/client/cli/context.py  |   9 +-
 .../python/apache/aurora/client/cli/jobs.py     |   4 +-
 .../python/apache/aurora/client/cli/logsetup.py |  64 -------
 .../python/apache/aurora/client/cli/task.py     |   4 +-
 src/test/python/apache/aurora/client/cli/BUILD  |  22 +--
 .../apache/aurora/client/cli/test_client.py     |  33 ++++
 .../apache/aurora/client/cli/test_logging.py    | 165 -------------------
 .../apache/aurora/client/cli/test_plugins.py    |  37 -----
 .../apache/aurora/client/cli/test_task.py       |  10 --
 13 files changed, 75 insertions(+), 381 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/main/python/apache/aurora/client/cli/BUILD
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/BUILD b/src/main/python/apache/aurora/client/cli/BUILD
index 2167c71..e61cdfb 100644
--- a/src/main/python/apache/aurora/client/cli/BUILD
+++ b/src/main/python/apache/aurora/client/cli/BUILD
@@ -49,7 +49,6 @@ python_library(
     'command_hooks.py',
     'cron.py',
     'jobs.py',
-    'logsetup.py',
     'options.py',
     'quota.py',
     'sla.py',
@@ -58,6 +57,7 @@ python_library(
   ],
   dependencies = [
     '3rdparty/python:requests',
+    '3rdparty/python:twitter.common.log',
     '3rdparty/python:twitter.common.python',
     '3rdparty/python:twitter.common.quantity',
     'src/main/python/apache/aurora/client/api:command_runner',

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/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 e3ed31e..c2eb89c 100644
--- a/src/main/python/apache/aurora/client/cli/__init__.py
+++ b/src/main/python/apache/aurora/client/cli/__init__.py
@@ -31,19 +31,16 @@ For example:
 from __future__ import print_function
 
 import argparse
-import getpass
 import logging
 import sys
 import traceback
 from abc import abstractmethod, abstractproperty
-from uuid import uuid1
 from zipfile import BadZipfile
 
 from twitter.common.lang import AbstractClass
 from twitter.common.python.pex import PexInfo
 
 from .command_hooks import GlobalCommandHookRegistry
-from .logsetup import TRANSCRIPT
 from .options import CommandOption
 
 # Constants for standard return codes.
@@ -59,33 +56,12 @@ EXIT_TIMEOUT = 9
 EXIT_API_ERROR = 10
 EXIT_UNKNOWN_ERROR = 20
 
-
-# Set up a logging call that adds a unique identifier for this invocation
-# of the client. Log messages sent via this call will contain two additional
-# fields in the log record: "clientid", which contains a UUID for the client
-# invocation, and "user", which contains the username of the user who invoked
-# the client.
-
-LOGGER_NAME = "aurora_client"
-logger = logging.getLogger(LOGGER_NAME)
-CLIENT_ID = uuid1()
-
-
 # A location where you can find a site-specific file containing
 # global hook skip rules. This can be something like a link into a file stored in a git
 # repos.
 GLOBAL_HOOK_SKIP_RULES_URL = None
 
 
-def print_aurora_log(sev, msg, *args, **kwargs):
-  extra = kwargs.get("extra", {})
-  extra["clientid"] = CLIENT_ID
-  extra["user"] = getpass.getuser()
-  extra["logger_name"] = LOGGER_NAME
-  kwargs["extra"] = extra
-  logger.log(sev, msg, *args, **kwargs)
-
-
 def get_client_version():
   try:
     pexpath = sys.argv[0]
@@ -108,7 +84,6 @@ class Context(object):
 
   def __init__(self):
     self._options = None
-    self.logging_level = None
 
   @classmethod
   def exit(cls, code, msg):
@@ -144,15 +119,6 @@ class Context(object):
     for line in lines:
       print("%s%s" % (indent_str, line), file=sys.stderr)
 
-  def print_log(self, severity, msg, *args, **kwargs):
-    """Print a message to a log.
-    Logging with this method is intended for generating output for aurora developers/maintainers.
-    Log output isn't for users - information much more detailed than users want may be logged.
-    Logs generated for clients of a cluster may be gathered in a centralized database by the
-    aurora admins for that cluster.
-    """
-    print_aurora_log(severity, msg, *args, **kwargs)
-
 
 class ConfigurationPlugin(AbstractClass):
   """A component that can be plugged in to a command-line to add new configuration options.
@@ -378,7 +344,7 @@ class CommandLine(AbstractClass):
       try:
         plugin.after_execution(context, result)
       except ConfigurationPlugin.Error as e:
-        print_aurora_log(logging.INFO, "Error executing post-execution plugin: %s", e.msg)
+        logging.info("Error executing post-execution plugin: %s", e.msg)
 
   def _execute(self, args):
     """Execute a command.
@@ -393,7 +359,7 @@ class CommandLine(AbstractClass):
     if args[0] == "help":
       return self.help_cmd(args[1:])
     noun, context = self._parse_args(args)
-    print_aurora_log(TRANSCRIPT, "Command=(%s)", args)
+    logging.debug("Command=(%s)", args)
     pre_result = self._run_pre_hooks_and_plugins(context, args)
     if pre_result is not EXIT_OK:
       return pre_result
@@ -401,15 +367,14 @@ class CommandLine(AbstractClass):
       result = noun.execute(context)
       assert result is not None, "Noun return value is None!"
       if result == EXIT_OK:
-        print_aurora_log(TRANSCRIPT, "Command terminated successfully")
+        logging.debug("Command terminated successfully")
         GlobalCommandHookRegistry.run_post_hooks(context, context.options.noun,
             context.options.verb, result)
       else:
-        print_aurora_log(logging.INFO, "Command terminated with error code %s", result)
+        logging.info("Command terminated with error code %s", result)
       self._run_post_plugins(context, result)
       return result
     except Context.CommandError as c:
-      print_aurora_log(logging.INFO, "Error executing command: %s", c.msg)
       self.print_err("Error executing command: %s" % c.msg)
       return c.code
     except Exception:
@@ -421,10 +386,10 @@ class CommandLine(AbstractClass):
     try:
       return self._execute(args)
     except KeyboardInterrupt:
-      print_aurora_log(logging.ERROR, "Command interrupted by user")
+      logging.error("Command interrupted by user")
       return EXIT_INTERRUPTED
     except Exception as e:
-      print_aurora_log(logging.ERROR, "Unknown error: %s" % e)
+      logging.error("Unknown error: %s" % e)
       return EXIT_UNKNOWN_ERROR
 
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/main/python/apache/aurora/client/cli/client.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/client.py b/src/main/python/apache/aurora/client/cli/client.py
index 93120a1..c8768c7 100644
--- a/src/main/python/apache/aurora/client/cli/client.py
+++ b/src/main/python/apache/aurora/client/cli/client.py
@@ -16,54 +16,39 @@ from __future__ import print_function
 import logging
 import sys
 
+from twitter.common.log.formatters.plain import PlainFormatter
+
 from apache.aurora.client.cli import CommandLine, ConfigurationPlugin
-from apache.aurora.client.cli.logsetup import setup_default_log_handlers
 from apache.aurora.client.cli.options import CommandOption
 
 
 class AuroraLogConfigurationPlugin(ConfigurationPlugin):
   """Plugin for configuring log level settings for the aurora client."""
 
-  def __init__(self):
-    super(AuroraLogConfigurationPlugin, self).__init__()
-    self.logging_level = None
-
   def get_options(self):
     return [
-        CommandOption("--verbose-logging", "-v", default=False, action="store_true",
-          help=("Show verbose logging, including all logs up to level INFO (equivalent to "
-              "--logging-level=20)")),
-        CommandOption("--logging-level", default=None, type=int, metavar="numeric_level",
-          help="Set logging to a specific numeric level, using the standard python log-levels.")
+      CommandOption("--verbose",
+                    "-v",
+                    default=False,
+                    action="store_true",
+                    help=("Show verbose output"))
     ]
 
   def before_dispatch(self, raw_args):
-    # We need to process the loglevel arguments before dispatch, so that we can
-    # do logging during dispatch. That means that we need to cheat, and manually
-    # check for the logging arguments. (We still register them in get_options,
-    # so that they'll show up in the help message.)
-    loglevel = logging.WARN
+    #TODO(zmanji): Consider raising the default log level to WARN.
+    loglevel = logging.INFO
     for arg in raw_args:
-      if arg == "--verbose-logging" or arg == "-v":
-        if loglevel > logging.INFO:
-          loglevel = logging.INFO
-      if arg.startswith("--logging-level="):
-        arg_bits = arg.split("=")
-        # If the format here is wrong, argparse will generate error, so we just skip
-        # it if it's incorrect.
-        if len(arg_bits) == 2:
-          try:
-            loglevel = int(arg_bits[1])
-          except ValueError:
-            print("Invalid value for log level; must be an integer, but got %s" % arg_bits[1],
-                file=sys.stderr)
-            raise
-    setup_default_log_handlers(loglevel)
-    self.logging_level = loglevel
+      if arg == "--verbose" or arg == "-v":
+        loglevel = logging.DEBUG
+
+    logging.getLogger().setLevel(loglevel)
+    handler = logging.StreamHandler()
+    handler.setFormatter(PlainFormatter())
+    logging.getLogger().addHandler(handler)
     return raw_args
 
   def before_execution(self, context):
-    context.logging_level = self.logging_level
+    pass
 
   def after_execution(self, context, result_code):
     pass

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/main/python/apache/aurora/client/cli/command_hooks.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/command_hooks.py b/src/main/python/apache/aurora/client/cli/command_hooks.py
index aa850bf..122042c 100644
--- a/src/main/python/apache/aurora/client/cli/command_hooks.py
+++ b/src/main/python/apache/aurora/client/cli/command_hooks.py
@@ -235,8 +235,7 @@ class GlobalCommandHookRegistry(object):
     for desired_skip in desired_skips:
       if not any(rule.allow_hook_skip(desired_skip, user, noun, verb, context.args)
           for name, rule in cls.SKIP_HOOK_RULES.items()):
-        context.print_log(logging.INFO, "Hook %s cannot be skipped by user %s" %
-            (desired_skip, user))
+        logging.info("Hook %s cannot be skipped by user %s" % (desired_skip, user))
         raise context.CommandError(EXIT_PERMISSION_VIOLATION,
             "Hook %s cannot be skipped by user %s" % (desired_skip, user))
     selected_hook_names = set(selected_hook_names) - desired_skips
@@ -258,13 +257,11 @@ class GlobalCommandHookRegistry(object):
       for hook in pre_hooks:
         result = hook.pre_command(noun, verb, context, context.args)
         if result != 0:
-          context.print_log(logging.INFO, "Command hook %s aborted operation with error code %s" %
-              (hook.name, result))
-          context.print_out("Command aborted by command hook %s" % hook.name)
+          context.print_out("Command aborted by command hook %s with error code %s"
+                            % (hook.name, result))
           return result
       return 0
     except CommandHook.Error as c:
-      context.print_log(logging.INFO, "Error executing command hook %s: %s" % (hook.name, c))
       context.print_err("Error executing command hook %s: %s; aborting" % hook.name, c.msg)
       return c.code
 
@@ -277,7 +274,6 @@ class GlobalCommandHookRegistry(object):
         hook.post_command(noun, verb, context, context.args, result)
         return 0
     except CommandHook.Error as c:
-      context.print_log(logging.INFO, "Error executing post-command hook %s: %s" % (hook.name, c))
       context.print_err("Error executing command hook %s: %s; aborting" % hook.name, c.msg)
       return c.code
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/main/python/apache/aurora/client/cli/context.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/context.py b/src/main/python/apache/aurora/client/cli/context.py
index 5e89296..ad27eb5 100644
--- a/src/main/python/apache/aurora/client/cli/context.py
+++ b/src/main/python/apache/aurora/client/cli/context.py
@@ -29,7 +29,6 @@ from apache.aurora.client.cli import (
     EXIT_INVALID_CONFIGURATION,
     EXIT_INVALID_PARAMETER
 )
-from apache.aurora.client.cli.logsetup import TRANSCRIPT
 from apache.aurora.client.config import get_config
 from apache.aurora.client.factory import make_client
 from apache.aurora.common.aurora_job_key import AuroraJobKey
@@ -91,7 +90,7 @@ class AuroraCommandContext(Context):
       # TODO(mchucarroll): pull request to pystachio, to make it possible to log the loaded
       # file without double-reading.
       with open(config_file, "r") as fp:
-        self.print_log(TRANSCRIPT, "Config: %s" % fp.readlines())
+        logging.debug("Config: %s" % fp.readlines())
       bindings = bindings_to_list(self.options.bindings) if self.options.bindings else None
       result = get_config(
         jobname,
@@ -141,10 +140,8 @@ class AuroraCommandContext(Context):
     if resp.responseCode != ResponseCode.OK:
       for m in resp.details:
         self.print_err("\t%s" % m.message)
-        self.print_log(TRANSCRIPT, "Message from scheduler: %s" % m.message)
-    if resp.details is not None:
-      for m in resp.details:
-        self.print_log(logging.INFO, "Message from scheduler: %s" % m.message)
+    else:
+      logging.info(combine_messages(resp))
 
   def check_and_log_response(self, resp, err_code=EXIT_API_ERROR, err_msg=None):
     if resp.responseCode != ResponseCode.OK:

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/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 987a736..8bdb7f4 100644
--- a/src/main/python/apache/aurora/client/cli/jobs.py
+++ b/src/main/python/apache/aurora/client/cli/jobs.py
@@ -491,8 +491,6 @@ class RestartCommand(Verb):
     if context.options.max_total_failures < 0:
       context.print_err("max_total_failures option must be >0, but you specified %s" %
           context.options.max_total_failures)
-      context.print_log(logging.INFO, "Error: max_total_failures option=%s" %
-          context.options.max_total_failures)
       return EXIT_INVALID_PARAMETER
 
     job = context.options.instance_spec.jobkey
@@ -614,7 +612,7 @@ class StatusCommand(Verb):
     for jk in jobkeys:
       job_tasks = context.get_job_status(jk)
       if job_tasks is None or job_tasks is []:
-        context.print_log(logging.INFO, "No tasks were found for jobkey %s" % jk)
+        logging.info("No tasks were found for jobkey %s" % jk)
         continue
       active_tasks = sorted([t for t in job_tasks if is_active(t)],
                             key=lambda task: task.assignedTask.instanceId)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/main/python/apache/aurora/client/cli/logsetup.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/logsetup.py b/src/main/python/apache/aurora/client/cli/logsetup.py
deleted file mode 100644
index 55d99c4..0000000
--- a/src/main/python/apache/aurora/client/cli/logsetup.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#
-# 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 logging
-import sys
-
-# A new log level, for information that's slightly more important than debugging.
-# This is the level of log information that will be sent to a distibuted
-# log to gather information about user behavior.
-TRANSCRIPT = logging.DEBUG + 1
-logging.addLevelName(TRANSCRIPT, "TRANSCRIPT")
-
-
-class PlainFormatter(logging.Formatter):
-  """
-    Format a log in a simple style:
-    type] msg
-  """
-  SCHEME = "plain"
-
-  LEVEL_MAP = {
-    logging.FATAL: "FATAL",
-    logging.ERROR: "ERROR",
-    logging.WARN: "WARN",
-    logging.INFO: "info",
-    TRANSCRIPT: "transcript",
-    logging.DEBUG: "debug"
-  }
-
-  def __init__(self):
-    logging.Formatter.__init__(self)
-
-  def format(self, record):
-    try:
-      record_message = "%s" % (record.msg % record.args)
-    except TypeError:
-      record_message = record.msg
-    try:
-      level = self.LEVEL_MAP[record.levelno]
-    except Exception:
-      level = "?????"
-    record_message = "log(%s): %s" % (level, record_message)
-    record.getMessage = lambda: record_message
-    return logging.Formatter.format(self, record)
-
-
-def setup_default_log_handlers(level):
-  stderr_handler = logging.StreamHandler(sys.stderr)
-  stderr_handler.setLevel(level)
-  stderr_handler.setFormatter(PlainFormatter())
-  root_logger = logging.getLogger()
-  root_logger.addHandler(stderr_handler)
-  root_logger.setLevel(logging.INFO)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/main/python/apache/aurora/client/cli/task.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/task.py b/src/main/python/apache/aurora/client/cli/task.py
index c92111e..a70f908 100644
--- a/src/main/python/apache/aurora/client/cli/task.py
+++ b/src/main/python/apache/aurora/client/cli/task.py
@@ -24,7 +24,7 @@ from apache.aurora.client.api.command_runner import (
     InstanceDistributedCommandRunner
 )
 from apache.aurora.client.base import combine_messages
-from apache.aurora.client.cli import EXIT_INVALID_PARAMETER, EXIT_OK, Noun, print_aurora_log, Verb
+from apache.aurora.client.cli import EXIT_INVALID_PARAMETER, EXIT_OK, Noun, Verb
 from apache.aurora.client.cli.context import AuroraCommandContext
 from apache.aurora.client.cli.options import (
     CommandOption,
@@ -67,7 +67,7 @@ class RunCommand(Verb):
     (cluster_name, role, env, name), instances = context.options.instance_spec
     cluster = CLUSTERS[cluster_name]
     dcr = InstanceDistributedCommandRunner(cluster, role, env, name,
-        context.options.ssh_user, instances, print_aurora_log)
+        context.options.ssh_user, instances)
     dcr.run(context.options.cmd, parallelism=context.options.num_threads,
         executor_sandbox=context.options.executor_sandbox)
     return EXIT_OK

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/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 b24c616..4b5817e 100644
--- a/src/test/python/apache/aurora/client/cli/BUILD
+++ b/src/test/python/apache/aurora/client/cli/BUILD
@@ -17,13 +17,13 @@ python_test_suite(
   dependencies = [
     ':api',
     ':bridge',
+    ':client',
     ':command_hooks',
     ':cron',
     ':help',
     ':inspect',
     ':job',
     ':config',
-    ':logging',
     ':plugins',
     ':quota',
     ':sla',
@@ -92,18 +92,6 @@ python_tests(
 )
 
 python_tests(
-  name = 'logging',
-  sources = [ 'test_logging.py' ],
-  dependencies = [
-    ':util',
-    '3rdparty/python:mock',
-    '3rdparty/python:twitter.common.contextutil',
-    'src/main/python/apache/aurora/client/cli',
-    'src/main/python/apache/aurora/client/cli:client_lib',
-  ]
-)
-
-python_tests(
   name = 'bridge',
   sources = [ 'test_bridge.py' ],
   dependencies = [
@@ -239,3 +227,11 @@ python_tests(
     'src/test/python/apache/aurora/client/commands:util'
   ]
 )
+
+python_tests(
+  name = 'client',
+  sources = [ 'test_client.py' ],
+  dependencies = [
+    'src/main/python/apache/aurora/client/cli',
+  ]
+)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/test/python/apache/aurora/client/cli/test_client.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_client.py b/src/test/python/apache/aurora/client/cli/test_client.py
new file mode 100644
index 0000000..49f050c
--- /dev/null
+++ b/src/test/python/apache/aurora/client/cli/test_client.py
@@ -0,0 +1,33 @@
+#
+# 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 logging
+
+from apache.aurora.client.cli.client import AuroraLogConfigurationPlugin
+
+
+def test_log_plugin_enabled():
+  plugin = AuroraLogConfigurationPlugin()
+
+  plugin.before_dispatch(["aurora", "version", "--verbose"])
+
+  assert logging.getLogger().getEffectiveLevel() == logging.DEBUG
+
+
+def test_log_plugin_disabled():
+  plugin = AuroraLogConfigurationPlugin()
+
+  plugin.before_dispatch(["aurora", "version"])
+
+  assert logging.getLogger().getEffectiveLevel() == logging.INFO

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/test/python/apache/aurora/client/cli/test_logging.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_logging.py b/src/test/python/apache/aurora/client/cli/test_logging.py
deleted file mode 100644
index 401d091..0000000
--- a/src/test/python/apache/aurora/client/cli/test_logging.py
+++ /dev/null
@@ -1,165 +0,0 @@
-#
-# 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 logging
-from logging import Handler
-
-from mock import create_autospec, patch
-from twitter.common.contextutil import temporary_file
-
-from apache.aurora.client.cli.client import AuroraCommandLine
-from apache.aurora.config import AuroraConfig
-
-from .util import AuroraClientCommandTest, FakeAuroraCommandContext
-
-from gen.apache.aurora.api.ttypes import (
-    AssignedTask,
-    Result,
-    ScheduledTask,
-    ScheduleStatus,
-    ScheduleStatusResult,
-    TaskEvent
-)
-
-
-class MockHandler(Handler):
-  def __init__(self):
-    Handler.__init__(self)
-    self.logs = []
-
-  def emit(self, record):
-    self.logs.append(record)
-
-
-class TestLogging(AuroraClientCommandTest):
-
-  @classmethod
-  def create_mock_task(cls, task_id, instance_id, initial_time, status):
-    mock_task = create_autospec(spec=ScheduledTask, instance=True)
-    mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
-    mock_task.assignedTask.taskId = task_id
-    mock_task.assignedTask.instanceId = instance_id
-    mock_task.status = status
-    mock_task_event = create_autospec(spec=TaskEvent, instance=True)
-    mock_task_event.timestamp = initial_time
-    mock_task.taskEvents = [mock_task_event]
-    return mock_task
-
-  @classmethod
-  def create_mock_status_query_result(cls, scheduleStatus):
-    mock_query_result = cls.create_simple_success_response()
-    if scheduleStatus == ScheduleStatus.INIT:
-      # status query result for before job is launched.
-      tasks = []
-    else:
-      mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
-      mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
-      tasks = [mock_task_one, mock_task_two]
-    mock_query_result.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
-    return mock_query_result
-
-  @classmethod
-  def get_createjob_response(cls):
-    # Then, we call api.create_job(config)
-    return cls.create_simple_success_response()
-
-  @classmethod
-  def get_failed_createjob_response(cls):
-    return cls.create_error_response()
-
-  @classmethod
-  def assert_create_job_called(cls, mock_api):
-    # Check that create_job was called exactly once, with an AuroraConfig parameter.
-    assert mock_api.create_job.call_count == 1
-    assert isinstance(mock_api.create_job.call_args_list[0][0][0], AuroraConfig)
-
-  @classmethod
-  def assert_scheduler_called(cls, mock_api, mock_query, num_queries):
-    assert mock_api.scheduler_proxy.getTasksStatus.call_count == num_queries
-    mock_api.scheduler_proxy.getTasksStatus.assert_called_with(mock_query)
-
-  def test_command_invocation_logging(self):
-    """Sets up a log handler, registers it with the logger, and then verifies that calls
-    to the client logging methods correctly get captured in the logs.
-    """
-    mock_log_handler = MockHandler()
-    logger = logging.getLogger('aurora_client')
-    logger.setLevel(logging.DEBUG)
-    logger.addHandler(mock_log_handler)
-    # We'll patch out create_context, which will give us a fake context
-    # object, and everything can be stubbed through that.
-    mock_context = FakeAuroraCommandContext()
-    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
-      # After making the client, create sets up a job monitor.
-      # The monitor uses TaskQuery to get the tasks. It's called at least twice:once before
-      # the job is created, and once after. So we need to set up mocks for the query results.
-      mock_context.add_expected_status_query_result(
-        self.create_mock_status_query_result(ScheduleStatus.INIT))
-      mock_context.add_expected_status_query_result(
-        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
-      api = mock_context.get_api('west')
-      api.create_job.return_value = self.get_createjob_response()
-
-      with temporary_file() as fp:
-        fp.write(self.get_valid_config())
-        fp.flush()
-        cmd = AuroraCommandLine()
-        cmd.execute(['job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello',
-            fp.name])
-
-      # Check that things were logged correctly:
-      # there should be at least two entries, with the clientid and username;
-      # and one entry should log the command being invoked.
-      assert any(("'job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello'" in
-          r.getMessage()) for r in mock_log_handler.logs)
-      assert mock_log_handler.logs[0].clientid == mock_log_handler.logs[1].clientid
-      assert mock_log_handler.logs[0].user == mock_log_handler.logs[1].user
-
-  def test_configuration_logging(self):
-    """Sets up a log handler, registers it with the logger, and then verifies that calls
-    to the client logging methods correctly get captured in the logs.
-    """
-    mock_log_handler = MockHandler()
-    logger = logging.getLogger('aurora_client')
-    logger.setLevel(logging.DEBUG)
-    logger.addHandler(mock_log_handler)
-    mock_context = FakeAuroraCommandContext()
-    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
-      mock_context.add_expected_status_query_result(
-        self.create_mock_status_query_result(ScheduleStatus.INIT))
-      mock_context.add_expected_status_query_result(
-        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
-      api = mock_context.get_api('west')
-      api.create_job.return_value = self.get_createjob_response()
-
-      with temporary_file() as fp:
-        fp.write(self.get_valid_config())
-        fp.flush()
-        with open(fp.name, "r") as rp:
-          lines = rp.readlines()
-        cmd = AuroraCommandLine()
-        cmd.execute(['job', 'create', 'west/bozo/test/hello',
-            fp.name])
-        # Check that the contents of the config file were logged, as expected.
-        expected_config_msg = "Config: %s" % lines
-        assert any(expected_config_msg == r.getMessage() for r in mock_log_handler.logs)
-
-      # Check that things were logged correctly:
-      # there should be at least two entries, with the clientid and username;
-      # and one entry should log the command being invoked.
-      assert any(("'job', 'create', 'west/bozo/test/hello'" in
-          r.getMessage()) for r in mock_log_handler.logs)
-
-      assert mock_log_handler.logs[0].clientid == mock_log_handler.logs[1].clientid
-      assert mock_log_handler.logs[0].user == mock_log_handler.logs[1].user

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/test/python/apache/aurora/client/cli/test_plugins.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_plugins.py b/src/test/python/apache/aurora/client/cli/test_plugins.py
index a64759c..cf742a3 100644
--- a/src/test/python/apache/aurora/client/cli/test_plugins.py
+++ b/src/test/python/apache/aurora/client/cli/test_plugins.py
@@ -12,8 +12,6 @@
 # limitations under the License.
 #
 
-import logging
-
 from mock import create_autospec, patch
 from twitter.common.contextutil import temporary_file
 
@@ -167,38 +165,3 @@ class TestPlugins(AuroraClientCommandTest):
       assert not any('list' in t for t in self.transcript)
       assert "Options:" in self.transcript
       assert any('bogosity' in t for t in self.transcript)
-
-  def test_verbose_logging_plugin_in_create_job(self):
-    """Run a test of the "create" command against a mocked-out API:
-    Verifies that the creation command sends the right API RPCs, and performs the correct
-    tests on the result."""
-
-    # We'll patch out create_context, which will give us a fake context
-    # object, and everything can be stubbed through that.
-    mock_context = FakeAuroraCommandContext()
-    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
-      # After making the client, create sets up a job monitor.
-      # The monitor uses TaskQuery to get the tasks. It's called at least twice:once before
-      # the job is created, and once after. So we need to set up mocks for the query results.
-      mock_query = self.create_mock_query()
-      mock_context.add_expected_status_query_result(
-        self.create_mock_status_query_result(ScheduleStatus.INIT))
-      mock_context.add_expected_status_query_result(
-        self.create_mock_status_query_result(ScheduleStatus.RUNNING))
-      api = mock_context.get_api('west')
-      api.create_job.return_value = self.get_createjob_response()
-
-      # This is the real test: invoke create as if it had been called by the command line.
-      with temporary_file() as fp:
-        fp.write(self.get_valid_config())
-        fp.flush()
-        cmd = AuroraCommandLine()
-        cmd.execute(['job', 'create', '-v', '--wait-until=RUNNING',
-            'west/bozo/test/hello', fp.name])
-
-      # Now check that the right API calls got made.
-      # Check that create_job was called exactly once, with an AuroraConfig parameter.
-      self.assert_create_job_called(api)
-      self.assert_scheduler_called(api, mock_query, 1)
-      # Check that the plugin did its job.
-      assert mock_context.logging_level == logging.INFO

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9926af3a/src/test/python/apache/aurora/client/cli/test_task.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_task.py b/src/test/python/apache/aurora/client/cli/test_task.py
index c69a624..2580664 100644
--- a/src/test/python/apache/aurora/client/cli/test_task.py
+++ b/src/test/python/apache/aurora/client/cli/test_task.py
@@ -30,12 +30,6 @@ from gen.apache.aurora.api.ttypes import (
     TaskQuery
 )
 
-MOCK_LOG_CONTENTS = []
-
-
-def mock_log(level, msg):
-  MOCK_LOG_CONTENTS.append((level, msg))
-
 
 class TestRunCommand(AuroraClientCommandTest):
 
@@ -77,7 +71,6 @@ class TestRunCommand(AuroraClientCommandTest):
     mock_scheduler_proxy.getTasksStatus.return_value = self.create_status_response()
     sandbox_args = {'slave_root': '/slaveroot', 'slave_run_directory': 'slaverun'}
     with contextlib.nested(
-        patch('apache.aurora.client.cli.task.print_aurora_log', side_effect=mock_log),
         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.task.CLUSTERS', new=self.TEST_CLUSTERS),
@@ -85,7 +78,6 @@ class TestRunCommand(AuroraClientCommandTest):
               'InstanceDistributedCommandRunner.sandbox_args',
             return_value=sandbox_args),
         patch('subprocess.Popen', return_value=self.create_mock_process())) as (
-            _,
             mock_scheduler_proxy_class,
             mock_clusters,
             mock_clusters_cli,
@@ -108,8 +100,6 @@ class TestRunCommand(AuroraClientCommandTest):
           'cd /slaveroot/slaves/*/frameworks/*/executors/thermos-1287391823/runs/'
           'slaverun/sandbox;ls'],
           stderr=-2, stdout=-1)
-      # Check that logging worked properly:
-      assert any("Running command" in entry[1] for entry in MOCK_LOG_CONTENTS)
 
 
 class TestSshCommand(AuroraClientCommandTest):