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/03/08 03:21:33 UTC

git commit: Move and unit test Maintenance module and commands

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 62f0aad4b -> 172f30124


Move and unit test Maintenance module and commands

Bugs closed: AURORA-223

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


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

Branch: refs/heads/master
Commit: 172f3012401e5962b85553ffe2bc962b0fba7132
Parents: 62f0aad
Author: Joe Smith <ya...@gmail.com>
Authored: Fri Mar 7 18:14:15 2014 -0800
Committer: Maxim Khutornenko <ma...@apache.org>
Committed: Fri Mar 7 18:14:15 2014 -0800

----------------------------------------------------------------------
 src/main/python/apache/aurora/admin/BUILD       |   4 +-
 .../apache/aurora/admin/host_maintenance.py     | 128 ++++++++++++++
 .../apache/aurora/admin/mesos_maintenance.py    | 129 ---------------
 src/main/python/apache/aurora/client/base.py    |  53 ++++++
 src/main/python/apache/aurora/client/bin/BUILD  |   1 +
 .../python/apache/aurora/client/commands/BUILD  |  13 +-
 .../apache/aurora/client/commands/admin.py      | 156 ++----------------
 .../aurora/client/commands/maintenance.py       | 123 ++++++++++++++
 src/test/python/apache/aurora/admin/BUILD       |   8 +-
 .../aurora/admin/test_host_maintenance.py       | 102 ++++++++++++
 .../aurora/admin/test_mesos_maintenance.py      | 103 ------------
 .../python/apache/aurora/client/commands/BUILD  |  20 ++-
 .../aurora/client/commands/test_maintenance.py  | 165 +++++++++++++++++++
 13 files changed, 620 insertions(+), 385 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/main/python/apache/aurora/admin/BUILD
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/admin/BUILD b/src/main/python/apache/aurora/admin/BUILD
index 480dad6..b133868 100644
--- a/src/main/python/apache/aurora/admin/BUILD
+++ b/src/main/python/apache/aurora/admin/BUILD
@@ -15,8 +15,8 @@
 #
 
 python_library(
-  name = 'mesos_maintenance',
-  sources = 'mesos_maintenance.py',
+  name = 'host_maintenance',
+  sources = 'host_maintenance.py',
   dependencies = [
     pants('3rdparty/python:twitter.common.log'),
     pants('3rdparty/python:twitter.common.quantity'),

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/main/python/apache/aurora/admin/host_maintenance.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/admin/host_maintenance.py b/src/main/python/apache/aurora/admin/host_maintenance.py
new file mode 100644
index 0000000..6a21dde
--- /dev/null
+++ b/src/main/python/apache/aurora/admin/host_maintenance.py
@@ -0,0 +1,128 @@
+#
+# Copyright 2013 Apache Software Foundation
+#
+# 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 collections import defaultdict
+import time
+
+from apache.aurora.client.api import AuroraClientAPI
+from apache.aurora.client.base import check_and_log_response
+
+from gen.apache.aurora.ttypes import Hosts, MaintenanceMode
+
+from twitter.common import log
+from twitter.common.quantity import Amount, Time
+
+
+def group_by_host(hostname):
+  return hostname
+
+
+class HostMaintenance(object):
+  """Submit requests to the scheduler to put hosts into and out of maintenance
+  mode so they can be operated upon without causing LOST tasks.
+  """
+
+  DEFAULT_GROUPING = 'by_host'
+  GROUPING_FUNCTIONS = {
+    'by_host': group_by_host,
+  }
+  START_MAINTENANCE_DELAY = Amount(30, Time.SECONDS)
+
+  @classmethod
+  def group_hosts(cls, hostnames, grouping_function=DEFAULT_GROUPING):
+    try:
+      grouping_function = cls.GROUPING_FUNCTIONS[grouping_function]
+    except KeyError:
+      raise ValueError('Unknown grouping function %s!' % grouping_function)
+    groups = defaultdict(set)
+    for hostname in hostnames:
+      groups[grouping_function(hostname)].add(hostname)
+    return groups
+
+  @classmethod
+  def iter_batches(cls, hostnames, groups_per_batch, grouping_function=DEFAULT_GROUPING):
+    if groups_per_batch <= 0:
+      raise ValueError('Batch size must be > 0!')
+    groups = cls.group_hosts(hostnames, grouping_function)
+    groups = sorted(groups.items(), key=lambda v: v[0])
+    for k in range(0, len(groups), groups_per_batch):
+      yield Hosts(set.union(*(hostset for (key, hostset) in groups[k:k + groups_per_batch])))
+
+  def __init__(self, cluster, verbosity):
+    self._client = AuroraClientAPI(cluster, verbosity == 'verbose')
+
+  def _drain_hosts(self, drainable_hosts, clock=time):
+    """This will actively turn down tasks running on hosts."""
+    check_and_log_response(self._client.drain_hosts(drainable_hosts))
+    not_ready_hosts = [hostname for hostname in drainable_hosts.hostNames]
+    while not_ready_hosts:
+      log.info("Sleeping for %s." % self.START_MAINTENANCE_DELAY)
+      clock.sleep(self.START_MAINTENANCE_DELAY.as_(Time.SECONDS))
+      resp = self._client.maintenance_status(Hosts(not_ready_hosts))
+      if not resp.result.maintenanceStatusResult.statuses:
+        not_ready_hosts = None
+      for host_status in resp.result.maintenanceStatusResult.statuses:
+        if host_status.mode != MaintenanceMode.DRAINED:
+          log.warning('%s is currently in status %s' %
+              (host_status.host, MaintenanceMode._VALUES_TO_NAMES[host_status.mode]))
+        else:
+          not_ready_hosts.remove(host_status.host)
+
+  def _complete_maintenance(self, drained_hosts):
+    """End the maintenance status for a give set of hosts."""
+    check_and_log_response(self._client.end_maintenance(drained_hosts))
+    resp = self._client.maintenance_status(drained_hosts)
+    for host_status in resp.result.maintenanceStatusResult.statuses:
+      if host_status.mode != MaintenanceMode.NONE:
+        log.warning('%s is DRAINING or in DRAINED' % host_status.host)
+
+  def _operate_on_hosts(self, drained_hosts, callback):
+    """Perform a given operation on a list of hosts that are ready for maintenance."""
+    for host in drained_hosts.hostNames:
+      callback(host)
+
+  def end_maintenance(self, hosts):
+    """Pull a list of hosts out of maintenance mode."""
+    self._complete_maintenance(Hosts(set(hosts)))
+
+  def start_maintenance(self, hosts):
+    """Put a list of hosts into maintenance mode, to de-prioritize scheduling."""
+    check_and_log_response(self._client.start_maintenance(Hosts(set(hosts))))
+
+  def perform_maintenance(self, hosts, groups_per_batch=1, grouping_function=DEFAULT_GROUPING,
+                          callback=None):
+    """The wrap a callback in between sending hosts into maintenance mode and back.
+
+    Walk through the process of putting hosts into maintenance, draining them of tasks,
+    performing an action on them once drained, then removing them from maintenance mode
+    so tasks can schedule.
+    """
+    self._complete_maintenance(Hosts(set(hosts)))
+    self.start_maintenance(hosts)
+
+    for hosts in self.iter_batches(hosts, groups_per_batch, grouping_function):
+      self._drain_hosts(hosts)
+      if callback:
+        self._operate_on_hosts(hosts, callback)
+      self._complete_maintenance(hosts)
+
+  def check_status(self, hosts):
+    resp = self._client.maintenance_status(Hosts(set(hosts)))
+    check_and_log_response(resp)
+    statuses = []
+    for host_status in resp.result.maintenanceStatusResult.statuses:
+      statuses.append((host_status.host, MaintenanceMode._VALUES_TO_NAMES[host_status.mode]))
+    return statuses

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/main/python/apache/aurora/admin/mesos_maintenance.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/admin/mesos_maintenance.py b/src/main/python/apache/aurora/admin/mesos_maintenance.py
deleted file mode 100644
index d8ffdec..0000000
--- a/src/main/python/apache/aurora/admin/mesos_maintenance.py
+++ /dev/null
@@ -1,129 +0,0 @@
-#
-# Copyright 2013 Apache Software Foundation
-#
-# 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 collections import defaultdict
-import time
-
-from apache.aurora.client.api import AuroraClientAPI
-from apache.aurora.client.base import check_and_log_response
-
-from gen.apache.aurora.ttypes import Hosts, MaintenanceMode
-
-from twitter.common import log
-from twitter.common.quantity import Amount, Time
-
-
-def group_by_host(hostname):
-  return hostname
-
-
-class MesosMaintenance(object):
-  """This class provides more methods to interact with the mesos cluster and perform
-  maintenance.
-  """
-
-  DEFAULT_GROUPING = 'by_host'
-  GROUPING_FUNCTIONS = {
-    'by_host': group_by_host,
-  }
-  START_MAINTENANCE_DELAY = Amount(30, Time.SECONDS)
-
-  @classmethod
-  def group_hosts(cls, hostnames, grouping_function=DEFAULT_GROUPING):
-    try:
-      grouping_function = cls.GROUPING_FUNCTIONS[grouping_function]
-    except KeyError:
-      raise ValueError('Unknown grouping function %s!' % grouping_function)
-    groups = defaultdict(set)
-    for hostname in hostnames:
-      groups[grouping_function(hostname)].add(hostname)
-    return groups
-
-  @classmethod
-  def iter_batches(cls, hostnames, batch_size, grouping_function=DEFAULT_GROUPING):
-    if batch_size <= 0:
-      raise ValueError('Batch size must be > 0!')
-    groups = cls.group_hosts(hostnames, grouping_function)
-    groups = sorted(groups.items(), key=lambda v: v[0])
-    for k in range(0, len(groups), batch_size):
-      yield Hosts(set.union(*(hostset for (key, hostset) in groups[k:k+batch_size])))
-
-  def __init__(self, cluster, verbosity):
-    self._client = AuroraClientAPI(cluster, verbosity == 'verbose')
-
-  def _drain_hosts(self, drainable_hosts, clock=time):
-    """This will actively turn down tasks running on hosts."""
-    check_and_log_response(self._client.drain_hosts(drainable_hosts))
-    not_ready_hosts = [hostname for hostname in drainable_hosts.hostNames]
-    while not_ready_hosts:
-      log.info("Sleeping for %s." % self.START_MAINTENANCE_DELAY)
-      clock.sleep(self.START_MAINTENANCE_DELAY.as_(Time.SECONDS))
-      resp = self._client.maintenance_status(Hosts(not_ready_hosts))
-      #TODO(jsmith): Workaround until scheduler responds with unknown slaves in MESOS-3454
-      if not resp.result.maintenanceStatusResult.statuses:
-        not_ready_hosts = None
-      for host_status in resp.result.maintenanceStatusResult.statuses:
-        if host_status.mode != MaintenanceMode.DRAINED:
-          log.warning('%s is currently in status %s' %
-              (host_status.host, MaintenanceMode._VALUES_TO_NAMES[host_status.mode]))
-        else:
-          not_ready_hosts.remove(host_status.host)
-
-  def _complete_maintenance(self, drained_hosts):
-    """End the maintenance status for a give set of hosts."""
-    check_and_log_response(self._client.end_maintenance(drained_hosts))
-    resp = self._client.maintenance_status(drained_hosts)
-    for host_status in resp.result.maintenanceStatusResult.statuses:
-      if host_status.mode != MaintenanceMode.NONE:
-        log.warning('%s is DRAINING or in DRAINED' % host_status.host)
-
-  def _operate_on_hosts(self, drained_hosts, callback):
-    """Perform a given operation on a list of hosts that are ready for maintenance."""
-    for host in drained_hosts.hostNames:
-      callback(host)
-
-  def end_maintenance(self, hosts):
-    """Pull a list of hosts out of maintenance mode."""
-    self._complete_maintenance(Hosts(set(hosts)))
-
-  def start_maintenance(self, hosts):
-    """Put a list of hosts into maintenance mode, to de-prioritize scheduling."""
-    check_and_log_response(self._client.start_maintenance(Hosts(set(hosts))))
-
-  def perform_maintenance(self, hosts, batch_size=1, grouping_function=DEFAULT_GROUPING,
-                          callback=None):
-    """The wrap a callback in between sending hosts into maintenance mode and back.
-
-    Walk through the process of putting hosts into maintenance, draining them of tasks,
-    performing an action on them once drained, then removing them from maintenance mode
-    so tasks can schedule.
-    """
-    self._complete_maintenance(Hosts(set(hosts)))
-    self.start_maintenance(hosts)
-
-    for hosts in self.iter_batches(hosts, batch_size, grouping_function):
-      self._drain_hosts(hosts)
-      if callback:
-        self._operate_on_hosts(hosts, callback)
-      self._complete_maintenance(hosts)
-
-  def check_status(self, hosts):
-    resp = self._client.maintenance_status(Hosts(set(hosts)))
-    check_and_log_response(resp)
-    statuses = []
-    for host_status in resp.result.maintenanceStatusResult.statuses:
-      statuses.append((host_status.host, MaintenanceMode._VALUES_TO_NAMES[host_status.mode]))
-    return statuses

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/main/python/apache/aurora/client/base.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/base.py b/src/main/python/apache/aurora/client/base.py
index c5c969f..a33e65c 100644
--- a/src/main/python/apache/aurora/client/base.py
+++ b/src/main/python/apache/aurora/client/base.py
@@ -16,6 +16,7 @@
 
 from collections import defaultdict
 import functools
+import optparse
 import sys
 from urlparse import urljoin
 
@@ -93,6 +94,58 @@ class requires(object):
     return real_fn
 
 
+FILENAME_OPTION = optparse.Option(
+    '--filename',
+    dest='filename',
+    default=None,
+    help='Name of the file with hostnames')
+
+
+HOSTS_OPTION = optparse.Option(
+    '--hosts',
+    dest='hosts',
+    default=None,
+    help='Comma separated list of hosts')
+
+
+def parse_host_list(host_list):
+  hosts = [hostname.strip() for hostname in host_list.split(",")]
+  if not hosts:
+    die('No valid hosts found.')
+  return hosts
+
+
+def parse_host_file(filename):
+  with open(filename, 'r') as hosts:
+    hosts = [hostname.strip() for hostname in hosts]
+  if not hosts:
+    die('No valid hosts found in %s.' % filename)
+  return hosts
+
+
+def parse_hosts_optional(list_option, file_option):
+  if bool(list_option) and bool(file_option):
+    die('Cannot specify both filename and list for the same option.')
+  hosts = None
+  if file_option:
+    hosts = parse_host_file(file_option)
+  elif list_option:
+    hosts = parse_host_list(list_option)
+  return hosts
+
+
+def parse_hosts(filename, hosts):
+  if bool(filename) == bool(hosts):
+    die('Please specify either --filename or --hosts')
+  if filename:
+    hosts = parse_host_file(filename)
+  elif hosts:
+    hosts = parse_host_list(hosts)
+  if not hosts:
+    die('No valid hosts found.')
+  return hosts
+
+
 def synthesize_url(scheduler_url, role=None, env=None, job=None):
   if not scheduler_url:
     log.warning("Unable to find scheduler web UI!")

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/main/python/apache/aurora/client/bin/BUILD
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/bin/BUILD b/src/main/python/apache/aurora/client/bin/BUILD
index dbabfd0..f19256a 100644
--- a/src/main/python/apache/aurora/client/bin/BUILD
+++ b/src/main/python/apache/aurora/client/bin/BUILD
@@ -42,6 +42,7 @@ python_binary(
     pants('3rdparty/python:twitter.common.log'),
     pants('src/main/python/apache/aurora/client/commands:admin'),
     pants('src/main/python/apache/aurora/client/commands:help'),
+    pants('src/main/python/apache/aurora/client/commands:maintenance'),
     pants('src/main/python/apache/aurora/client:base'),
     pants('src/main/python/apache/aurora/client:options'),
   ]

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/main/python/apache/aurora/client/commands/BUILD
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/commands/BUILD b/src/main/python/apache/aurora/client/commands/BUILD
index 14bbdd4..ae037c4 100644
--- a/src/main/python/apache/aurora/client/commands/BUILD
+++ b/src/main/python/apache/aurora/client/commands/BUILD
@@ -31,7 +31,6 @@ python_library(
     pants('3rdparty/python:twitter.common.app'),
     pants('3rdparty/python:twitter.common.log'),
     pants('3rdparty/python:twitter.common.quantity'),
-    pants('src/main/python/apache/aurora/admin:mesos_maintenance'),
     pants('src/main/python/apache/aurora/client/api'),
     pants('src/main/python/apache/aurora/client:base'),
     pants('src/main/python/apache/aurora/common:clusters'),
@@ -40,6 +39,18 @@ python_library(
 )
 
 python_library(
+  name = 'maintenance',
+  sources = ['maintenance.py'],
+  dependencies = [
+    pants('3rdparty/python:twitter.common.app'),
+    pants('3rdparty/python:twitter.common.log'),
+    pants('src/main/python/apache/aurora/admin:host_maintenance'),
+    pants('src/main/python/apache/aurora/client:base'),
+    pants('src/main/python/apache/aurora/common:clusters'),
+  ]
+)
+
+python_library(
   name = 'core',
   sources = ['core.py'],
   dependencies = [

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/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 d6f571b..f411b79 100644
--- a/src/main/python/apache/aurora/client/commands/admin.py
+++ b/src/main/python/apache/aurora/client/commands/admin.py
@@ -20,13 +20,19 @@ from __future__ import print_function
 """
 
 import os
-import optparse
 import subprocess
 
-from apache.aurora.admin.mesos_maintenance import MesosMaintenance
 from apache.aurora.client.api import AuroraClientAPI
 from apache.aurora.client.api.sla import DomainUpTimeSlaVector
-from apache.aurora.client.base import check_and_log_response, die, requires
+from apache.aurora.client.base import (
+    check_and_log_response,
+    die,
+    FILENAME_OPTION,
+    HOSTS_OPTION,
+    parse_hosts,
+    parse_hosts_optional,
+    requires
+)
 from apache.aurora.common.aurora_job_key import AuroraJobKey
 from apache.aurora.common.clusters import CLUSTERS
 
@@ -42,55 +48,6 @@ from twitter.common.quantity import Amount, Data, Time
 from twitter.common.quantity.parse_simple import parse_data, parse_time
 
 
-GROUPING_OPTION = optparse.Option(
-    '--grouping',
-    type='choice',
-    choices=MesosMaintenance.GROUPING_FUNCTIONS.keys(),
-    metavar='GROUPING',
-    default=MesosMaintenance.DEFAULT_GROUPING,
-    dest='grouping',
-    help='Grouping function to use to group hosts.  Options: %s.  Default: %%default' % (
-        ', '.join(MesosMaintenance.GROUPING_FUNCTIONS.keys())))
-
-
-def parse_host_file(filename):
-  with open(filename, 'r') as hosts:
-    hosts = [hostname.strip() for hostname in hosts]
-  if not hosts:
-    die('No valid hosts found in %s.' % filename)
-  return hosts
-
-
-def parse_host_list(host_list):
-  hosts = [hostname.strip() for hostname in host_list.split(",")]
-  if not hosts:
-    die('No valid hosts found.')
-  return hosts
-
-
-def parse_hosts_optional(list_option, file_option):
-  if bool(list_option) and bool(file_option):
-    die('Cannot specify both filename and list for the same option.')
-  hosts = None
-  if file_option:
-    hosts = parse_host_file(file_option)
-  elif list_option:
-    hosts = parse_host_list(list_option)
-  return hosts
-
-
-def parse_hosts(options):
-  if bool(options.filename) == bool(options.hosts):
-    die('Please specify either --filename or --hosts')
-  if options.filename:
-    hosts = parse_host_file(options.filename)
-  elif options.hosts:
-    hosts = parse_host_list(options.hosts)
-  if not hosts:
-    die('No valid hosts found.')
-  return hosts
-
-
 def print_results(results):
   for line in results:
     print(line)
@@ -226,93 +183,6 @@ def set_quota(cluster, role, cpu_str, ram, disk):
 
 
 @app.command
-@app.command_option('--filename', dest='filename', default=None,
-    help='Name of the file with hostnames')
-@app.command_option('--hosts', dest='hosts', default=None,
-    help='Comma separated list of hosts')
-@requires.exactly('cluster')
-def start_maintenance_hosts(cluster):
-  """usage: start_maintenance_hosts {--filename=filename | --hosts=hosts}
-                                    cluster
-  """
-  options = app.get_options()
-  MesosMaintenance(CLUSTERS[cluster], options.verbosity).start_maintenance(parse_hosts(options))
-
-
-@app.command
-@app.command_option('--filename', dest='filename', default=None,
-    help='Name of the file with hostnames')
-@app.command_option('--hosts', dest='hosts', default=None,
-    help='Comma separated list of hosts')
-@requires.exactly('cluster')
-def end_maintenance_hosts(cluster):
-  """usage: end_maintenance_hosts {--filename=filename | --hosts=hosts}
-                                  cluster
-  """
-  options = app.get_options()
-  MesosMaintenance(CLUSTERS[cluster], options.verbosity).end_maintenance(parse_hosts(options))
-
-
-@app.command
-@app.command_option('--filename', dest='filename', default=None,
-    help='Name of the file with hostnames')
-@app.command_option('--hosts', dest='hosts', default=None,
-    help='Comma separated list of hosts')
-@app.command_option('--batch_size', dest='batch_size', default=1,
-    help='Number of groups to operate on at a time.')
-@app.command_option('--post_drain_script', dest='post_drain_script', default=None,
-    help='Path to a script to run for each host.')
-@app.command_option(GROUPING_OPTION)
-@requires.exactly('cluster')
-def perform_maintenance_hosts(cluster):
-  """usage: perform_maintenance_hosts {--filename=filename | --hosts=hosts}
-                                      [--batch_size=num]
-                                      [--post_drain_script=path]
-                                      [--grouping=function]
-                                      cluster
-
-  Asks the scheduler to remove any running tasks from the machine and remove it
-  from service temporarily, perform some action on them, then return the machines
-  to service.
-  """
-  options = app.get_options()
-  drainable_hosts = parse_hosts(options)
-
-  if options.post_drain_script:
-    if not os.path.exists(options.post_drain_script):
-      die("No such file: %s" % options.post_drain_script)
-    cmd = os.path.abspath(options.post_drain_script)
-    drained_callback = lambda host: subprocess.Popen([cmd, host])
-  else:
-    drained_callback = None
-
-  MesosMaintenance(CLUSTERS[cluster], options.verbosity).perform_maintenance(
-      drainable_hosts,
-      batch_size=int(options.batch_size),
-      callback=drained_callback,
-      grouping_function=options.grouping)
-
-
-@app.command
-@app.command_option('--filename', dest='filename', default=None,
-    help='Name of the file with hostnames')
-@app.command_option('--hosts', dest='hosts', default=None,
-    help='Comma separated list of hosts')
-@requires.exactly('cluster')
-def host_maintenance_status(cluster):
-  """usage: host_maintenance_status {--filename=filename | --hosts=hosts}
-                                    cluster
-
-  Check on the schedulers maintenance status for a list of hosts in the cluster.
-  """
-  options = app.get_options()
-  checkable_hosts = parse_hosts(options)
-  statuses = MesosMaintenance(CLUSTERS[cluster], options.verbosity).check_status(checkable_hosts)
-  for pair in statuses:
-    log.info("%s is in state: %s" % pair)
-
-
-@app.command
 @requires.exactly('cluster', 'role', 'cpu', 'ram', 'disk')
 def increase_quota(cluster, role, cpu_str, ram_str, disk_str):
   """usage: increase_quota cluster role cpu ram[unit] disk[unit]
@@ -540,10 +410,8 @@ def sla_list_safe_domain(cluster, percentage, duration):
 
 
 @app.command
-@app.command_option('--filename', dest='filename', default=None,
-                    help='Name of the file with host names (one per line).')
-@app.command_option('--hosts', dest='hosts', default=None,
-                    help='Comma separated list of host names.')
+@app.command_option(FILENAME_OPTION)
+@app.command_option(HOSTS_OPTION)
 @requires.exactly('cluster', 'percentage', 'duration')
 def sla_probe_hosts(cluster, percentage, duration):
   """usage: sla_probe_hosts
@@ -570,7 +438,7 @@ def sla_probe_hosts(cluster, percentage, duration):
 
   sla_percentage = parse_sla_percentage(percentage)
   sla_duration = parse_time(duration)
-  hosts = parse_hosts(options)
+  hosts = parse_hosts(options.filename, options.hosts)
 
   vector = AuroraClientAPI(CLUSTERS[cluster], options.verbosity).sla_get_safe_domain_vector(hosts)
   probed_hosts = vector.probe_hosts(sla_percentage, sla_duration.as_(Time.SECONDS), hosts)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/main/python/apache/aurora/client/commands/maintenance.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/commands/maintenance.py b/src/main/python/apache/aurora/client/commands/maintenance.py
new file mode 100644
index 0000000..f3c0591
--- /dev/null
+++ b/src/main/python/apache/aurora/client/commands/maintenance.py
@@ -0,0 +1,123 @@
+#
+# Copyright 2013 Apache Software Foundation
+#
+# 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 os
+import optparse
+import subprocess
+
+from apache.aurora.admin.host_maintenance import HostMaintenance
+from apache.aurora.client.base import (
+    die,
+    FILENAME_OPTION,
+    HOSTS_OPTION,
+    parse_hosts,
+    requires
+)
+from apache.aurora.common.clusters import CLUSTERS
+
+from twitter.common import app, log
+
+
+GROUPING_OPTION = optparse.Option(
+    '--grouping',
+    type='choice',
+    choices=HostMaintenance.GROUPING_FUNCTIONS.keys(),
+    metavar='GROUPING',
+    default=HostMaintenance.DEFAULT_GROUPING,
+    dest='grouping',
+    help='Grouping function to use to group hosts.  Options: %s.  Default: %%default' % (
+        ', '.join(HostMaintenance.GROUPING_FUNCTIONS.keys())))
+
+
+@app.command
+@app.command_option(FILENAME_OPTION)
+@app.command_option(HOSTS_OPTION)
+@requires.exactly('cluster')
+def start_maintenance_hosts(cluster):
+  """usage: start_maintenance_hosts {--filename=filename | --hosts=hosts}
+                                    cluster
+  """
+  options = app.get_options()
+  HostMaintenance(CLUSTERS[cluster], options.verbosity).start_maintenance(
+      parse_hosts(options.filename, options.hosts))
+
+
+@app.command
+@app.command_option(FILENAME_OPTION)
+@app.command_option(HOSTS_OPTION)
+@requires.exactly('cluster')
+def end_maintenance_hosts(cluster):
+  """usage: end_maintenance_hosts {--filename=filename | --hosts=hosts}
+                                  cluster
+  """
+  options = app.get_options()
+  HostMaintenance(CLUSTERS[cluster], options.verbosity).end_maintenance(
+      parse_hosts(options.filename, options.hosts))
+
+
+@app.command
+@app.command_option('--groups_per_batch', dest='groups_per_batch', default=1,
+    help='Number of groups to operate on at a time.')
+@app.command_option('--post_drain_script', dest='post_drain_script', default=None,
+    help='Path to a script to run for each host.')
+@app.command_option(FILENAME_OPTION)
+@app.command_option(HOSTS_OPTION)
+@app.command_option(GROUPING_OPTION)
+@requires.exactly('cluster')
+def perform_maintenance_hosts(cluster):
+  """usage: perform_maintenance_hosts {--filename=filename | --hosts=hosts}
+                                      [--groups_per_batch=num]
+                                      [--post_drain_script=path]
+                                      [--grouping=function]
+                                      cluster
+
+  Asks the scheduler to remove any running tasks from the machine and remove it
+  from service temporarily, perform some action on them, then return the machines
+  to service.
+  """
+  options = app.get_options()
+  drainable_hosts = parse_hosts(options.filename, options.hosts)
+
+  if options.post_drain_script:
+    if not os.path.exists(options.post_drain_script):
+      die("No such file: %s" % options.post_drain_script)
+    cmd = os.path.abspath(options.post_drain_script)
+    drained_callback = lambda host: subprocess.Popen([cmd, host])
+  else:
+    drained_callback = None
+
+  HostMaintenance(CLUSTERS[cluster], options.verbosity).perform_maintenance(
+      drainable_hosts,
+      groups_per_batch=int(options.groups_per_batch),
+      callback=drained_callback,
+      grouping_function=options.grouping)
+
+
+@app.command
+@app.command_option(FILENAME_OPTION)
+@app.command_option(HOSTS_OPTION)
+@requires.exactly('cluster')
+def host_maintenance_status(cluster):
+  """usage: host_maintenance_status {--filename=filename | --hosts=hosts}
+                                    cluster
+
+  Check on the schedulers maintenance status for a list of hosts in the cluster.
+  """
+  options = app.get_options()
+  checkable_hosts = parse_hosts(options.filename, options.hosts)
+  statuses = HostMaintenance(CLUSTERS[cluster], options.verbosity).check_status(checkable_hosts)
+  for pair in statuses:
+    log.info("%s is in state: %s" % pair)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/test/python/apache/aurora/admin/BUILD
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/admin/BUILD b/src/test/python/apache/aurora/admin/BUILD
index 258b1eb..17aac54 100644
--- a/src/test/python/apache/aurora/admin/BUILD
+++ b/src/test/python/apache/aurora/admin/BUILD
@@ -16,16 +16,16 @@
 
 python_test_suite(name = 'all',
   dependencies = [
-    pants(':mesos_maintenance'),
+    pants(':host_maintenance'),
   ],
 )
 
-python_tests(name = 'mesos_maintenance',
-  sources = ['test_mesos_maintenance.py'],
+python_tests(name = 'host_maintenance',
+  sources = ['test_host_maintenance.py'],
   dependencies = [
     pants('3rdparty/python:mock'),
     pants('src/main/python/apache/aurora/common:cluster'),
-    pants('src/main/python/apache/aurora/admin:mesos_maintenance'),
+    pants('src/main/python/apache/aurora/admin:host_maintenance'),
     pants('src/main/thrift/org/apache/aurora/gen:py-thrift'),
   ],
 )

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/test/python/apache/aurora/admin/test_host_maintenance.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/admin/test_host_maintenance.py b/src/test/python/apache/aurora/admin/test_host_maintenance.py
new file mode 100644
index 0000000..95497ae
--- /dev/null
+++ b/src/test/python/apache/aurora/admin/test_host_maintenance.py
@@ -0,0 +1,102 @@
+#
+# Copyright 2013 Apache Software Foundation
+#
+# 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 unittest
+
+from apache.aurora.admin.host_maintenance import HostMaintenance
+from apache.aurora.common.cluster import Cluster
+
+from gen.apache.aurora.ttypes import (
+    Hosts,
+    Response,
+    ResponseCode,
+)
+
+import mock
+import pytest
+
+
+DEFAULT_CLUSTER = Cluster(
+    name='us-west',
+    scheduler_uri='us-west-234.example.com:8888',
+)
+MOCK_TEST_HOSTS = ['us-west-001.example.com']
+
+
+class TestHostMaintenance(unittest.TestCase):
+  @mock.patch("apache.aurora.client.api.AuroraClientAPI.start_maintenance")
+  def test_start_maintenance(self, mock_api):
+    mock_api.return_value = Response(responseCode=ResponseCode.OK)
+    maintenance = HostMaintenance(DEFAULT_CLUSTER, 'quiet')
+    maintenance.start_maintenance(MOCK_TEST_HOSTS)
+
+
+def test_default_grouping():
+  example_host_list = [
+    'xyz321.example.com',
+    'bar337.example.com',
+    'foo001.example.com',
+  ]
+
+  batches = list(HostMaintenance.iter_batches(example_host_list, 1))
+  assert batches[0] == Hosts(set(['bar337.example.com']))
+  assert batches[1] == Hosts(set(['foo001.example.com']))
+  assert batches[2] == Hosts(set(['xyz321.example.com']))
+
+  batches = list(HostMaintenance.iter_batches(example_host_list, 2))
+  assert batches[0] == Hosts(set(['bar337.example.com', 'foo001.example.com']))
+  assert batches[1] == Hosts(set(['xyz321.example.com']))
+
+
+def rack_grouping(hostname):
+  return hostname.split('-')[1]
+
+
+def test_rack_grouping():
+  old_grouping_functions = HostMaintenance.GROUPING_FUNCTIONS.copy()
+  HostMaintenance.GROUPING_FUNCTIONS['by_rack'] = rack_grouping
+
+  example_host_list = [
+    'west-aaa-001.example.com',
+    'west-aaa-002.example.com',
+    'west-xyz-002.example.com',
+    'east-xyz-003.example.com',
+    'east-xyz-004.example.com',
+  ]
+
+  try:
+    batches = list(HostMaintenance.iter_batches(example_host_list, 1, 'by_rack'))
+    assert batches[0] == Hosts(set([
+        'west-aaa-001.example.com',
+        'west-aaa-002.example.com'
+    ]))
+    assert batches[1] == Hosts(set([
+        'west-xyz-002.example.com',
+        'east-xyz-003.example.com',
+        'east-xyz-004.example.com',
+    ]))
+
+    batches = list(HostMaintenance.iter_batches(example_host_list, 2, 'by_rack'))
+    assert batches[0] == Hosts(set(example_host_list))
+
+    batches = list(HostMaintenance.iter_batches(example_host_list, 3, 'by_rack'))
+    assert batches[0] == Hosts(set(example_host_list))
+
+    with pytest.raises(ValueError):
+      list(HostMaintenance.iter_batches(example_host_list, 0))
+
+  finally:
+    HostMaintenance.GROUPING_FUNCTIONS = old_grouping_functions

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/test/python/apache/aurora/admin/test_mesos_maintenance.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/admin/test_mesos_maintenance.py b/src/test/python/apache/aurora/admin/test_mesos_maintenance.py
deleted file mode 100644
index 000fbe5..0000000
--- a/src/test/python/apache/aurora/admin/test_mesos_maintenance.py
+++ /dev/null
@@ -1,103 +0,0 @@
-#
-# Copyright 2013 Apache Software Foundation
-#
-# 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 unittest
-
-from apache.aurora.admin.mesos_maintenance import MesosMaintenance
-from apache.aurora.common.cluster import Cluster
-
-from gen.apache.aurora.ttypes import (
-    Hosts,
-    Response,
-    ResponseCode,
-)
-
-import mock
-import pytest
-
-
-DEFAULT_CLUSTER = Cluster(
-    name = 'us-west',
-    scheduler_uri = 'us-west-234.example.com:8888',
-)
-MOCK_TEST_HOSTS = ['us-west-001.example.com']
-
-
-class TestMesosMaintenance(unittest.TestCase):
-  @mock.patch("apache.aurora.client.api.AuroraClientAPI.start_maintenance")
-  def test_start_maintenance(self, mock_api):
-    mock_api.return_value = Response(responseCode=ResponseCode.OK)
-    maintenance = MesosMaintenance(DEFAULT_CLUSTER, 'quiet')
-    maintenance.start_maintenance(MOCK_TEST_HOSTS)
-
-
-def test_default_grouping():
-  example_host_list = [
-    'xyz321.example.com',
-    'bar337.example.com',
-    'foo001.example.com',
-  ]
-
-  batches = list(MesosMaintenance.iter_batches(example_host_list, 1))
-  assert batches[0] == Hosts(set(['bar337.example.com']))
-  assert batches[1] == Hosts(set(['foo001.example.com']))
-  assert batches[2] == Hosts(set(['xyz321.example.com']))
-
-  batches = list(MesosMaintenance.iter_batches(example_host_list, 2))
-  assert batches[0] == Hosts(set(['bar337.example.com', 'foo001.example.com']))
-  assert batches[1] == Hosts(set(['xyz321.example.com']))
-
-
-
-def rack_grouping(hostname):
-  return hostname.split('-')[1]
-
-
-def test_rack_grouping():
-  old_grouping_functions = MesosMaintenance.GROUPING_FUNCTIONS.copy()
-  MesosMaintenance.GROUPING_FUNCTIONS['by_rack'] = rack_grouping
-
-  example_host_list = [
-    'west-aaa-001.example.com',
-    'west-aaa-002.example.com',
-    'west-xyz-002.example.com',
-    'east-xyz-003.example.com',
-    'east-xyz-004.example.com',
-  ]
-
-  try:
-    batches = list(MesosMaintenance.iter_batches(example_host_list, 1, 'by_rack'))
-    assert batches[0] == Hosts(set([
-        'west-aaa-001.example.com',
-        'west-aaa-002.example.com'
-    ]))
-    assert batches[1] == Hosts(set([
-        'west-xyz-002.example.com',
-        'east-xyz-003.example.com',
-        'east-xyz-004.example.com',
-    ]))
-
-    batches = list(MesosMaintenance.iter_batches(example_host_list, 2, 'by_rack'))
-    assert batches[0] == Hosts(set(example_host_list))
-
-    batches = list(MesosMaintenance.iter_batches(example_host_list, 3, 'by_rack'))
-    assert batches[0] == Hosts(set(example_host_list))
-
-    with pytest.raises(ValueError):
-      list(MesosMaintenance.iter_batches(example_host_list, 0))
-
-  finally:
-    MesosMaintenance.GROUPING_FUNCTIONS = old_grouping_functions

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/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 6d448d7..7c80808 100644
--- a/src/test/python/apache/aurora/client/commands/BUILD
+++ b/src/test/python/apache/aurora/client/commands/BUILD
@@ -16,8 +16,13 @@
 
 python_test_suite(
   name = 'all',
-  dependencies = [ pants(':core'), pants(':run'), pants(':ssh'), pants(':admin') ]
-)
+  dependencies = [
+    pants(':admin'),
+    pants(':core'),
+    pants(':maintenance'),
+    pants(':run'),
+    pants(':ssh'),
+  ])
 
 python_tests(
   name='core',
@@ -78,6 +83,17 @@ python_tests(
     pants('src/main/thrift/org/apache/aurora/gen:py-thrift'),
   ])
 
+python_tests(
+  name='maintenance',
+  sources = [
+    'test_maintenance.py',
+  ],
+  dependencies = [
+    pants(':util'),
+    pants('3rdparty/python:mock'),
+    pants('src/main/python/apache/aurora/client/commands:maintenance'),
+  ])
+
 python_library(
   name='util',
   sources = [ 'util.py' ],

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/172f3012/src/test/python/apache/aurora/client/commands/test_maintenance.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_maintenance.py b/src/test/python/apache/aurora/client/commands/test_maintenance.py
new file mode 100644
index 0000000..df368e2
--- /dev/null
+++ b/src/test/python/apache/aurora/client/commands/test_maintenance.py
@@ -0,0 +1,165 @@
+#
+# Copyright 2013 Apache Software Foundation
+#
+# 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 apache.aurora.client.commands.util import AuroraClientCommandTest
+from apache.aurora.client.commands.maintenance import (
+    end_maintenance_hosts,
+    host_maintenance_status,
+    perform_maintenance_hosts,
+    start_maintenance_hosts,
+)
+
+from gen.apache.aurora.ttypes import (
+    DrainHostsResult,
+    EndMaintenanceResult,
+    Hosts,
+    HostStatus,
+    MaintenanceMode,
+    MaintenanceStatusResult,
+    StartMaintenanceResult,
+)
+
+from mock import Mock, patch
+
+
+class TestMaintenanceCommands(AuroraClientCommandTest):
+  HOSTNAMES = ['us-grf-20', 'us-jim-47', 'us-suz-01']
+
+  def make_mock_options(self):
+    mock_options = Mock()
+    mock_options.filename = None
+    mock_options.hosts = ','.join(self.HOSTNAMES)
+    mock_options.cluster = self.TEST_CLUSTER
+    mock_options.verbosity = False
+    return mock_options
+
+  def create_host_statuses(self, maintenance_mode):
+    return [HostStatus(host=hostname, mode=maintenance_mode) for hostname in self.HOSTNAMES]
+
+  def create_start_maintenance_result(self):
+    host_statuses = self.create_host_statuses(MaintenanceMode.SCHEDULED)
+    response = self.create_simple_success_response()
+    response.result.maintenanceStatusResult = StartMaintenanceResult(statuses=set(host_statuses))
+    return response
+
+  def create_end_maintenance_result(self):
+    host_statuses = self.create_host_statuses(MaintenanceMode.NONE)
+    response = self.create_simple_success_response()
+    response.result.endMaintenanceResult = EndMaintenanceResult(statuses=set(host_statuses))
+    return response
+
+  def create_drain_hosts_result(self):
+    host_statuses = self.create_host_statuses(MaintenanceMode.DRAINING)
+    response = self.create_simple_success_response()
+    response.result.drainHostsResult = DrainHostsResult(statuses=set(host_statuses))
+    return response
+
+  def create_maintenance_status_result(self):
+    host_statuses = self.create_host_statuses(MaintenanceMode.NONE)
+    response = self.create_simple_success_response()
+    response.result.maintenanceStatusResult = MaintenanceStatusResult(statuses=set(host_statuses))
+    return response
+
+  def create_drained_status_result(self, hosts):
+    host_statuses = [
+        HostStatus(host=hostname, mode=MaintenanceMode.DRAINED) for hostname in hosts.hostNames]
+    response = self.create_simple_success_response()
+    response.result.maintenanceStatusResult = MaintenanceStatusResult(statuses=set(host_statuses))
+    return response
+
+  def test_start_maintenance_hosts(self):
+    mock_options = self.make_mock_options()
+    mock_api, mock_scheduler_proxy = self.create_mock_api()
+    mock_scheduler_proxy.startMaintenance.return_value = self.create_start_maintenance_result()
+    with contextlib.nested(
+        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+        patch('apache.aurora.client.commands.maintenance.CLUSTERS', new=self.TEST_CLUSTERS),
+        patch('twitter.common.app.get_options', return_value=mock_options)) as (
+            mock_scheduler_proxy_class,
+            mock_clusters_maintenancepatch,
+            options):
+      start_maintenance_hosts([self.TEST_CLUSTER])
+
+      mock_scheduler_proxy.startMaintenance.assert_called_with(Hosts(set(self.HOSTNAMES)))
+
+  def test_end_maintenance_hosts(self):
+    mock_options = self.make_mock_options()
+    mock_api, mock_scheduler_proxy = self.create_mock_api()
+    mock_scheduler_proxy.endMaintenance.return_value = self.create_end_maintenance_result()
+    mock_scheduler_proxy.maintenanceStatus.return_value = self.create_maintenance_status_result()
+    with contextlib.nested(
+        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+        patch('apache.aurora.client.commands.maintenance.CLUSTERS', new=self.TEST_CLUSTERS),
+        patch('twitter.common.app.get_options', return_value=mock_options)) as (
+            mock_scheduler_proxy_class,
+            mock_clusters_maintenancepatch,
+            options):
+      end_maintenance_hosts([self.TEST_CLUSTER])
+
+      mock_scheduler_proxy.endMaintenance.assert_called_with(Hosts(set(self.HOSTNAMES)))
+      mock_scheduler_proxy.maintenanceStatus.assert_called_with(Hosts(set(self.HOSTNAMES)))
+
+  def test_perform_maintenance_hosts(self):
+    mock_options = self.make_mock_options()
+    mock_options.post_drain_script = None
+    mock_options.groups_per_batch = '1'
+    mock_options.grouping = 'by_host'
+
+    def host_status_results(hostnames):
+      if isinstance(hostnames, Hosts):
+        return self.create_drained_status_result(hostnames)
+      return self.create_maintenance_status_result()
+
+    mock_api, mock_scheduler_proxy = self.create_mock_api()
+    mock_scheduler_proxy.endMaintenance.return_value = self.create_end_maintenance_result()
+    mock_scheduler_proxy.maintenanceStatus.side_effect = host_status_results
+    mock_scheduler_proxy.startMaintenance.return_value = self.create_start_maintenance_result()
+    mock_scheduler_proxy.drainHosts.return_value = self.create_start_maintenance_result()
+
+    with contextlib.nested(
+        patch('time.sleep'),
+        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+        patch('apache.aurora.client.commands.maintenance.CLUSTERS', new=self.TEST_CLUSTERS),
+        patch('twitter.common.app.get_options', return_value=mock_options)) as (
+            mock_sleep,
+            mock_scheduler_proxy_class,
+            mock_clusters_maintenancepatch,
+            options):
+      perform_maintenance_hosts([self.TEST_CLUSTER])
+
+      mock_scheduler_proxy.startMaintenance.assert_called_with(Hosts(set(self.HOSTNAMES)))
+      #TODO(jsmith): Consider not mocking out sleep and instead refactoring
+      assert mock_sleep.call_count == 3
+      assert mock_scheduler_proxy.maintenanceStatus.call_count == 7
+      assert mock_scheduler_proxy.drainHosts.call_count == 3
+      assert mock_scheduler_proxy.endMaintenance.call_count == 4
+
+  def test_host_maintenance_status(self):
+    mock_options = self.make_mock_options()
+    mock_api, mock_scheduler_proxy = self.create_mock_api()
+    mock_scheduler_proxy.maintenanceStatus.return_value = self.create_maintenance_status_result()
+    with contextlib.nested(
+        patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
+        patch('apache.aurora.client.commands.maintenance.CLUSTERS', new=self.TEST_CLUSTERS),
+        patch('twitter.common.app.get_options', return_value=mock_options)) as (
+            mock_scheduler_proxy_class,
+            mock_clusters_maintenancepatch,
+            options):
+      host_maintenance_status([self.TEST_CLUSTER])
+
+      mock_scheduler_proxy.maintenanceStatus.assert_called_with(Hosts(set(self.HOSTNAMES)))