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/06/09 22:49:43 UTC

git commit: Fixing quota check for non-prod/prod job transition.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 92e32ec8c -> 4af90f161


Fixing quota check for non-prod/prod job transition.

Bugs closed: AURORA-512

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


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

Branch: refs/heads/master
Commit: 4af90f1610fe76e6cc3b94401e65d6aab11a6237
Parents: 92e32ec
Author: Maxim Khutornenko <ma...@apache.org>
Authored: Mon Jun 9 13:44:41 2014 -0700
Committer: Maxim Khutornenko <ma...@apache.org>
Committed: Mon Jun 9 13:44:41 2014 -0700

----------------------------------------------------------------------
 .../apache/aurora/client/api/quota_check.py     |  4 +-
 .../python/apache/aurora/client/api/updater.py  |  9 ++++-
 .../apache/aurora/client/api/test_updater.py    | 41 +++++++++++++++++++-
 3 files changed, 48 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/4af90f16/src/main/python/apache/aurora/client/api/quota_check.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/api/quota_check.py b/src/main/python/apache/aurora/client/api/quota_check.py
index f0b4462..5877cba 100644
--- a/src/main/python/apache/aurora/client/api/quota_check.py
+++ b/src/main/python/apache/aurora/client/api/quota_check.py
@@ -70,8 +70,8 @@ class QuotaCheck(object):
     Arguments:
     job_key -- job key.
     production -- production flag.
-    released -- CapacityRequest to be released (in case of job update).
-    acquired -- CapacityRequest to be acquired.
+    released -- production CapacityRequest to be released (in case of job update).
+    acquired -- production CapacityRequest to be acquired.
 
     Returns: ResponseCode.OK if check is successful.
     """

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/4af90f16/src/main/python/apache/aurora/client/api/updater.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/api/updater.py b/src/main/python/apache/aurora/client/api/updater.py
index de7912c..c592651 100644
--- a/src/main/python/apache/aurora/client/api/updater.py
+++ b/src/main/python/apache/aurora/client/api/updater.py
@@ -329,8 +329,13 @@ class Updater(object):
     )
 
     def _aggregate_quota(ops_list, config_map):
-      return sum(CapacityRequest.from_task(config_map[instance])
-                    for instance in ops_list) or CapacityRequest()
+      request = CapacityRequest()
+      for instance in ops_list:
+        task = config_map[instance]
+        if task.production:
+          request += CapacityRequest.from_task(task)
+
+      return request
 
     to_kill, to_add = self._create_kill_add_lists(
         instance_configs.instances_to_process,

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/4af90f16/src/test/python/apache/aurora/client/api/test_updater.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_updater.py b/src/test/python/apache/aurora/client/api/test_updater.py
index 0ee342c..48f82c8 100644
--- a/src/test/python/apache/aurora/client/api/test_updater.py
+++ b/src/test/python/apache/aurora/client/api/test_updater.py
@@ -244,7 +244,7 @@ class UpdaterTest(TestCase):
     self._quota_check.validate_quota_from_requested(
         self._job_key, prod, released, acquired).AndReturn(response)
 
-  def make_task_configs(self, count=1):
+  def make_task_configs(self, count=1, prod=True):
     return [TaskConfig(
         owner=Identity(role=self._job_key.role),
         environment=self._job_key.environment,
@@ -254,7 +254,7 @@ class UpdaterTest(TestCase):
         diskMb=self._num_disk,
         priority=0,
         maxTaskFailures=1,
-        production=True,
+        production=prod,
         taskLinks={'task': 'link'},
         contactEmail='foo@bar.com',
         executorConfig=ExecutorConfig(name='test', data='test data')
@@ -314,6 +314,43 @@ class UpdaterTest(TestCase):
     self.update_and_expect_response(expected_code=ResponseCode.ERROR)
     self.verify_mocks()
 
+  def test_non_to_prod_fails_quota_check(self):
+    """Update with shrinking with non->prod transition fails quota check."""
+    old_configs = self.make_task_configs(4, prod=False)
+    new_config = deepcopy(old_configs[0])
+    new_config.production = True
+    job_config = self.make_job_config(new_config, 2)
+    self._config.job_config = job_config
+    self.expect_start()
+    self.expect_get_tasks(old_configs)
+    self.expect_populate(job_config)
+    self.expect_quota_check(0, 2, response_code=ResponseCode.INVALID_REQUEST)
+    self.expect_finish()
+    self.replay_mocks()
+
+    self.update_and_expect_response(expected_code=ResponseCode.ERROR)
+    self.verify_mocks()
+
+  def test_prod_to_non_always_passes_quota_check(self):
+    """Update with growth with prod->non transition always passes."""
+    old_configs = self.make_task_configs(1, prod=True)
+    new_config = deepcopy(old_configs[0])
+    new_config.production = False
+    job_config = self.make_job_config(new_config, 3)
+    self._config.job_config = job_config
+    self.expect_start()
+    self.expect_get_tasks(old_configs)
+    self.expect_populate(job_config)
+    self.expect_quota_check(1, 0, prod=False)
+    self.expect_kill([0])
+    self.expect_add([0, 1, 2], new_config)
+    self.expect_watch_instances([0, 1, 2])
+    self.expect_finish()
+    self.replay_mocks()
+
+    self.update_and_expect_ok()
+    self.verify_mocks()
+
   def test_shrink(self):
     """Reduces the number of instances of the job."""
     old_configs = self.make_task_configs(10)