aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject git commit: Fixing query command.
Date Thu, 05 Jun 2014 20:58:15 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 467f84285 -> 36cc66628


Fixing query command.

Bugs closed: AURORA-301

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


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

Branch: refs/heads/master
Commit: 36cc66628e54903e99c46048fd221ca95b5fda48
Parents: 467f842
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Thu Jun 5 13:57:26 2014 -0700
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Thu Jun 5 13:57:26 2014 -0700

----------------------------------------------------------------------
 .../apache/aurora/client/commands/admin.py      |  11 +-
 .../python/apache/aurora/client/commands/BUILD  |   1 +
 .../apache/aurora/client/commands/test_admin.py | 106 +++++++++++++++++++
 3 files changed, 114 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/36cc6662/src/main/python/apache/aurora/client/commands/admin.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/commands/admin.py b/src/main/python/apache/aurora/client/commands/admin.py
index a3b5584..48c944e 100644
--- a/src/main/python/apache/aurora/client/commands/admin.py
+++ b/src/main/python/apache/aurora/client/commands/admin.py
@@ -78,7 +78,9 @@ def parse_sla_percentage(percentage):
     help='Format string of job/task items to print out.')
 # TODO(ksweeney): Allow query by environment here.
 def query(args, options):
-  """usage: query [--shards=N[,N,...]]
+  """usage: query [--force]
+                  [--listformat=FORMAT]
+                  [--shards=N[,N,...]]
                   [--states=State[,State,...]]
                   cluster [role [job]]
 
@@ -134,11 +136,11 @@ def query(args, options):
 
   #  Figure out "expensive" queries here and bone if they do not have --force
   #  - Does not specify role
-  if role is None and not options.force:
+  if not role and not options.force:
     die('--force is required for expensive queries (no role specified)')
 
   #  - Does not specify job
-  if job is None and not options.force:
+  if not job and not options.force:
     die('--force is required for expensive queries (no job specified)')
 
   #  - Specifies status outside of ACTIVE_STATES
@@ -147,9 +149,10 @@ def query(args, options):
 
   api = AuroraClientAPI(CLUSTERS[cluster], options.verbosity)
   query_info = api.query(api.build_query(role, job, instances=instances, statuses=states))
-  tasks = query_info.result.scheduleStatusResult.tasks
   if query_info.responseCode != ResponseCode.OK:
     die('Failed to query scheduler: %s' % query_info.messageDEPRECATED)
+
+  tasks = query_info.result.scheduleStatusResult.tasks
   if tasks is None:
     return
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/36cc6662/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 d5e497e..17933de 100644
--- a/src/test/python/apache/aurora/client/commands/BUILD
+++ b/src/test/python/apache/aurora/client/commands/BUILD
@@ -57,6 +57,7 @@ python_tests(
 python_tests(
   name='admin',
   sources = [
+    'test_admin.py',
     'test_admin_sla.py',
   ],
   dependencies = [

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/36cc6662/src/test/python/apache/aurora/client/commands/test_admin.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_admin.py b/src/test/python/apache/aurora/client/commands/test_admin.py
new file mode 100644
index 0000000..40b873b
--- /dev/null
+++ b/src/test/python/apache/aurora/client/commands/test_admin.py
@@ -0,0 +1,106 @@
+#
+# 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 apache.aurora.client.api import AuroraClientAPI
+from apache.aurora.client.commands.admin import query
+from apache.aurora.client.commands.util import AuroraClientCommandTest
+
+from gen.apache.aurora.api.constants import ACTIVE_STATES, TERMINAL_STATES
+from gen.apache.aurora.api.ttypes import (
+    AssignedTask,
+    Identity,
+    Response,
+    ResponseCode,
+    Result,
+    ScheduledTask,
+    ScheduleStatus,
+    ScheduleStatusResult,
+    TaskConfig,
+    TaskQuery
+)
+
+
+class TestAdminQueryCommand(AuroraClientCommandTest):
+
+  @classmethod
+  def setup_mock_options(cls, force=False, shards=None, states='RUNNING', listformat=None):
+    mock_options = Mock(spec=['force', 'shards', 'states', 'listformat'])
+    mock_options.force = force
+    mock_options.shards = shards
+    mock_options.states = states
+    mock_options.listformat = listformat or '%role%/%jobName%/%instanceId% %status%'
+    mock_options.verbosity = False
+    return mock_options
+
+  @classmethod
+  def create_response(cls, tasks, response_code=None):
+    response_code = ResponseCode.OK if response_code is None else response_code
+    resp = Response(responseCode=response_code, messageDEPRECATED='test')
+    resp.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
+    return resp
+
+  @classmethod
+  def create_task(cls):
+    return [ScheduledTask(
+        assignedTask=AssignedTask(
+            instanceId=0,
+            task=TaskConfig(owner=Identity(role='test_role'), jobName='test_job')),
+        status=ScheduleStatus.RUNNING
+    )]
+
+  @classmethod
+  def task_query(cls):
+    return TaskQuery(
+        owner=Identity(role=None),
+        environment=None,
+        jobName=None,
+        instanceIds=set(),
+        statuses=set([ScheduleStatus.RUNNING]))
+
+  def test_query(self):
+    """Tests successful execution of the query command."""
+    mock_options = self.setup_mock_options(force=True)
+    mock_api, mock_scheduler_proxy = self.create_mock_api()
+    with contextlib.nested(
+        patch('twitter.common.app.get_options', return_value=mock_options),
+        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+        patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS)):
+
+      mock_scheduler_proxy.getTasksStatus.return_value = self.create_response(self.create_task())
+
+      query([self.TEST_CLUSTER], mock_options)
+
+      mock_scheduler_proxy.getTasksStatus.assert_called_with(self.task_query())
+
+  def test_query_fails(self):
+    """Tests failed execution of the query command."""
+    mock_options = self.setup_mock_options()
+    mock_api, mock_scheduler_proxy = self.create_mock_api()
+    with contextlib.nested(
+        patch('twitter.common.app.get_options', return_value=mock_options),
+        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+        patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS)):
+
+      mock_scheduler_proxy.getTasksStatus.return_value = self.create_response(self.create_task())
+
+      try:
+        query([self.TEST_CLUSTER], mock_options)
+      except SystemExit:
+        pass
+      else:
+        assert 'Expected exception is not raised'


Mime
View raw message