aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject git commit: Increase robustness when reading PEX-INFO
Date Wed, 05 Nov 2014 23:34:11 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 98a4f42d5 -> 0ad2fcabb


Increase robustness when reading PEX-INFO

Bugs closed: AURORA-456

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


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

Branch: refs/heads/master
Commit: 0ad2fcabb6444c2da9d156b0117ee8ae8e3b713f
Parents: 98a4f42
Author: Zameer Manji <zmanji@twopensource.com>
Authored: Wed Nov 5 14:29:26 2014 -0800
Committer: Bill Farner <wfarner@apache.org>
Committed: Wed Nov 5 14:29:26 2014 -0800

----------------------------------------------------------------------
 .../apache/aurora/client/commands/core.py       | 14 ++++--
 .../python/apache/aurora/client/commands/BUILD  |  3 +-
 .../aurora/client/commands/test_version.py      | 45 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0ad2fcab/src/main/python/apache/aurora/client/commands/core.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/commands/core.py b/src/main/python/apache/aurora/client/commands/core.py
index e634362..852b6b1 100644
--- a/src/main/python/apache/aurora/client/commands/core.py
+++ b/src/main/python/apache/aurora/client/commands/core.py
@@ -25,6 +25,7 @@ import sys
 import time
 from datetime import datetime
 from tempfile import NamedTemporaryFile
+from zipfile import BadZipfile
 
 from twitter.common import app, log
 from twitter.common.python.pex import PexInfo
@@ -155,10 +156,17 @@ def version(args):
   """
   try:
     pex_info = PexInfo.from_pex(sys.argv[0])
+    properties = pex_info.build_properties
+    # Different versions of pants/pex set different keys in the PEX-INFO file. This approach
+    # attempts to work regardless of the pants/pex version used.
+    build_sha = properties.get('sha', properties.get('revision'))
+    build_date = properties.get('date', properties.get('datetime'))
+
     print("Aurora client build info:")
-    print("\tsha: %s" % pex_info.build_properties['sha'])
-    print("\tdate: %s" % pex_info.build_properties['date'])
-  except (IOError, OSError):
+    print("\tsha: %s" % build_sha)
+    print("\tdate: %s" % build_date)
+
+  except (IOError, OSError, BadZipfile):
     print("Aurora client build info not available")
   print("Aurora API version: %s" % CURRENT_API_VERSION)
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0ad2fcab/src/test/python/apache/aurora/client/commands/BUILD
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/BUILD b/src/test/python/apache/aurora/client/commands/BUILD
index 57ac843..000eafa 100644
--- a/src/test/python/apache/aurora/client/commands/BUILD
+++ b/src/test/python/apache/aurora/client/commands/BUILD
@@ -33,7 +33,8 @@ python_tests(
     'test_listjobs.py',
     'test_restart.py',
     'test_status.py',
-    'test_update.py'
+    'test_update.py',
+    'test_version.py'
   ],
   dependencies = [
     ':util',

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0ad2fcab/src/test/python/apache/aurora/client/commands/test_version.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_version.py b/src/test/python/apache/aurora/client/commands/test_version.py
new file mode 100644
index 0000000..5c3c45a
--- /dev/null
+++ b/src/test/python/apache/aurora/client/commands/test_version.py
@@ -0,0 +1,45 @@
+#
+# 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.
+#
+from __future__ import print_function
+
+from mock import patch, PropertyMock
+
+from apache.aurora.client.commands.core import version
+
+from .util import AuroraClientCommandTest
+
+
+class TestVersionCommand(AuroraClientCommandTest):
+
+  @patch('__builtin__.print')
+  @patch('twitter.common.python.pex.PexInfo.build_properties', new_callable=PropertyMock)
+  def test_version_with_old_pants(self, mock_buildinfo, mock_print):
+    # Old versions of pants wrote out sha and date keys
+    mock_buildinfo.return_value = {'sha': 'foo', 'date': 'somedate'}
+    version([])
+    assert mock_print.call_count == 4
+    calls = mock_print.mock_calls
+    assert "foo" in calls[1][1][0]
+    assert "somedate" in calls[2][1][0]
+
+  @patch('__builtin__.print')
+  @patch('twitter.common.python.pex.PexInfo.build_properties', new_callable=PropertyMock)
+  def test_version_with_new_pants(self, mock_buildinfo, mock_print):
+    # New versions of pants write out revision and datetime
+    mock_buildinfo.return_value = {'revision': 'bar', 'datetime': 'somedatetime'}
+    version([])
+    assert mock_print.call_count == 4
+    calls = mock_print.mock_calls
+    assert "bar" in calls[1][1][0]
+    assert "somedatetime" in calls[2][1][0]


Mime
View raw message