aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mchucarr...@apache.org
Subject git commit: Log loaded config file at level TRANSCRIPT (aka INFO+1)
Date Tue, 01 Jul 2014 22:10:33 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master f8cb56381 -> b58418ef4


Log loaded config file at level TRANSCRIPT (aka INFO+1)

Have client commands that load config files print the contents of the loaded config file to
log at level TRANSCRIPT (aka INFO+1).

Bugs closed: aurora-567

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


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

Branch: refs/heads/master
Commit: b58418ef414d2972e5563b321d90adf655a57e6c
Parents: f8cb563
Author: Mark Chu-Carroll <mchucarroll@twopensource.com>
Authored: Tue Jul 1 18:07:59 2014 -0400
Committer: Mark Chu-Carroll <mchucarroll@twitter.com>
Committed: Tue Jul 1 18:07:59 2014 -0400

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/context.py  |  5 +++
 .../apache/aurora/client/cli/test_logging.py    | 38 ++++++++++++++++++++
 2 files changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/b58418ef/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 facd52c..0e10589 100644
--- a/src/main/python/apache/aurora/client/cli/context.py
+++ b/src/main/python/apache/aurora/client/cli/context.py
@@ -26,6 +26,7 @@ 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
@@ -60,6 +61,10 @@ class AuroraCommandContext(Context):
     """Loads a job configuration from a config file."""
     jobname = jobkey.name
     try:
+      # 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())
       return get_config(
         jobname,
         config_file,

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/b58418ef/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
index b3c3b8d..6285fbb 100644
--- a/src/test/python/apache/aurora/client/cli/test_logging.py
+++ b/src/test/python/apache/aurora/client/cli/test_logging.py
@@ -130,3 +130,41 @@ class TestLogging(AuroraClientCommandTest):
           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


Mime
View raw message