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/04/26 01:35:16 UTC

git commit: Fix a plugins glitch.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 6148ae397 -> 0a8f9ca84


Fix a plugins glitch.

The before_dispatch method in configuration plugins is allowed to alter
command line arguments, to add or remove arguments needed to support
specific environments. The default implementation of plugins doesn't
provide any return value for the plugin methods. For before_dispatch,
this meant that the default plugin method effectively removed all command
line parameters!

This change just turns the default before_dispatch plugin method into an
effective no-op. If the user doesn't provide a before_dispatch method,
the default implementation will leave the arguments correctly unchanged.

Bugs closed: aurora-362

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


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

Branch: refs/heads/master
Commit: 0a8f9ca84d977bf6b229c04753eeeaa0d9a31024
Parents: 6148ae3
Author: Mark Chu-Carroll <mc...@twopensource.com>
Authored: Fri Apr 25 19:31:50 2014 -0400
Committer: Mark Chu-Carroll <mc...@twitter.com>
Committed: Fri Apr 25 19:31:50 2014 -0400

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/__init__.py |  2 ++
 .../apache/aurora/client/cli/test_plugins.py    | 26 ++++++++++++++++++++
 2 files changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0a8f9ca8/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 8f68501..78c109d 100644
--- a/src/main/python/apache/aurora/client/cli/__init__.py
+++ b/src/main/python/apache/aurora/client/cli/__init__.py
@@ -147,6 +147,7 @@ class ConfigurationPlugin(object):
   @abstractmethod
   def get_options(self):
     """Return the set of options processed by this plugin"""
+    return []
 
   @abstractmethod
   def before_dispatch(self, raw_args):
@@ -154,6 +155,7 @@ class ConfigurationPlugin(object):
     Returns a potentially modified version of the command line arguments.
     If a ConfigurationPlugin.Error exception is thrown, it aborts command execution.
     """
+    return raw_args
 
   @abstractmethod
   def before_execution(self, context):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0a8f9ca8/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 0ec2ed3..2dab749 100644
--- a/src/test/python/apache/aurora/client/cli/test_plugins.py
+++ b/src/test/python/apache/aurora/client/cli/test_plugins.py
@@ -66,6 +66,8 @@ class BogusPlugin(ConfigurationPlugin):
     context.after = True
     raise self.Error("Oops")
 
+class EmptyPlugin(ConfigurationPlugin):
+  pass
 
 class TestPlugins(AuroraClientCommandTest):
 
@@ -152,6 +154,30 @@ class TestPlugins(AuroraClientCommandTest):
       assert mock_context.bogosity == "maximum"
       assert mock_context.after == True
 
+  def test_empty_plugins_in_create_job(self):
+    """Installs a plugin that doesn't implement any of the plugin methods.
+    Prior to AURORA-362, this would cause the client to crash with an empty
+    argument list.
+    """
+    mock_context = FakeAuroraCommandContext()
+    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
+      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()
+
+      with temporary_file() as fp:
+        fp.write(self.get_valid_config())
+        fp.flush()
+        cmd = AuroraCommandLine()
+        cmd.register_plugin(EmptyPlugin())
+        cmd.execute(['job', 'create', '--wait-until=RUNNING',
+            'west/bozo/test/hello', fp.name])
+      self.assert_create_job_called(api)
+      self.assert_scheduler_called(api, mock_query, 2)
 
   def mock_print(self, str):
     for str in str.split('\n'):