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 2015/01/08 02:07:14 UTC
[2/5] incubator-aurora git commit: Removing client v1 code.
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9a817f24/src/test/python/apache/aurora/client/commands/test_admin_sla.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_admin_sla.py b/src/test/python/apache/aurora/client/commands/test_admin_sla.py
deleted file mode 100644
index ec558f8..0000000
--- a/src/test/python/apache/aurora/client/commands/test_admin_sla.py
+++ /dev/null
@@ -1,410 +0,0 @@
-#
-# 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 collections import defaultdict
-
-from mock import create_autospec, patch
-from twitter.common.contextutil import temporary_file
-
-from apache.aurora.client.api import AuroraClientAPI
-from apache.aurora.client.api.sla import DomainUpTimeSlaVector, JobUpTimeDetails, JobUpTimeLimit
-from apache.aurora.client.base import DEFAULT_GROUPING
-from apache.aurora.client.commands.admin import sla_list_safe_domain, sla_probe_hosts
-from apache.aurora.common.aurora_job_key import AuroraJobKey
-
-from .util import AuroraClientCommandTest
-
-MIN_INSTANCE_COUNT = 1
-
-
-class TestAdminSlaListSafeDomainCommand(AuroraClientCommandTest):
-
- @classmethod
- def setup_mock_options(cls, exclude=None, include=None, override=None,
- exclude_list=None, include_list=None, list_jobs=False, grouping=None):
- mock_options = create_autospec(spec=['exclude_filename', 'exclude_hosts', 'include_filename',
- 'include_hosts', 'override_filename', 'list_jobs', 'verbosity', 'disable_all_hooks',
- 'min_instance_count', 'grouping'], instance=True)
-
- mock_options.exclude_filename = exclude
- mock_options.exclude_hosts = exclude_list
- mock_options.include_filename = include
- mock_options.include_hosts = include_list
- mock_options.override_filename = override
- mock_options.list_jobs = list_jobs
- mock_options.verbosity = False
- mock_options.disable_all_hooks = False
- mock_options.min_instance_count = MIN_INSTANCE_COUNT
- mock_options.grouping = grouping or DEFAULT_GROUPING
- return mock_options
-
- @classmethod
- def create_hosts(cls, num_hosts, percentage, duration):
- hosts = defaultdict(list)
- for i in range(num_hosts):
- host_name = 'h%s' % i
- job = AuroraJobKey.from_path('west/role/env/job%s' % i)
- hosts[host_name].append(JobUpTimeLimit(job, percentage, duration))
- return [hosts]
-
- @classmethod
- def create_mock_vector(cls, result):
- mock_vector = create_autospec(spec=DomainUpTimeSlaVector, instance=True)
- mock_vector.get_safe_hosts.return_value = result
- return mock_vector
-
- def test_safe_domain_no_options(self):
- """Tests successful execution of the sla_list_safe_domain command without extra options."""
- mock_options = self.setup_mock_options()
- mock_vector = self.create_mock_vector(self.create_hosts(3, 80, 100))
- with contextlib.nested(
- patch('apache.aurora.client.commands.admin.make_client',
- new=create_autospec(spec=AuroraClientAPI)),
- patch('apache.aurora.client.commands.admin.print_results'),
- patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)
- ) as (
- mock_api,
- mock_print_results,
- test_clusters,
- mock_options):
-
- mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
- sla_list_safe_domain(['west', '50', '100s'])
-
- mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, {}, DEFAULT_GROUPING)
- mock_print_results.assert_called_once_with(['h0', 'h1', 'h2'])
-
- def test_safe_domain_exclude_hosts(self):
- """Test successful execution of the sla_list_safe_domain command with exclude hosts option."""
- mock_vector = self.create_mock_vector(self.create_hosts(3, 80, 100))
- with temporary_file() as fp:
- fp.write('h1')
- fp.flush()
- mock_options = self.setup_mock_options(exclude=fp.name)
- with contextlib.nested(
- patch('apache.aurora.client.commands.admin.make_client',
- new=create_autospec(spec=AuroraClientAPI)),
- patch('apache.aurora.client.commands.admin.print_results'),
- patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)
- ) as (
- mock_api,
- mock_print_results,
- test_clusters,
- mock_options):
-
- mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
-
- sla_list_safe_domain(['west', '50', '100s'])
-
- mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, {}, DEFAULT_GROUPING)
- mock_print_results.assert_called_once_with(['h0', 'h2'])
-
- def test_safe_domain_exclude_hosts_from_list(self):
- """Test successful execution of the sla_list_safe_domain command with exclude list option."""
- mock_vector = self.create_mock_vector(self.create_hosts(3, 80, 100))
- mock_options = self.setup_mock_options(exclude_list=','.join(['h0', 'h1']))
- with contextlib.nested(
- patch('apache.aurora.client.commands.admin.make_client',
- new=create_autospec(spec=AuroraClientAPI)),
- patch('apache.aurora.client.commands.admin.print_results'),
- patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)
- ) as (
- mock_api,
- mock_print_results,
- test_clusters,
- mock_options):
-
- mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
-
- sla_list_safe_domain(['west', '50', '100s'])
-
- mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, {}, DEFAULT_GROUPING)
- mock_print_results.assert_called_once_with(['h2'])
-
- def test_safe_domain_include_hosts(self):
- """Test successful execution of the sla_list_safe_domain command with include hosts option."""
- mock_vector = self.create_mock_vector(self.create_hosts(1, 80, 100))
- hostname = 'h0'
- with temporary_file() as fp:
- fp.write(hostname)
- fp.flush()
- mock_options = self.setup_mock_options(include=fp.name)
- with contextlib.nested(
- patch('apache.aurora.client.commands.admin.make_client',
- new=create_autospec(spec=AuroraClientAPI)),
- patch('apache.aurora.client.commands.admin.print_results'),
- patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)
- ) as (
- mock_api,
- mock_print_results,
- test_clusters,
- mock_options):
-
- mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
-
- sla_list_safe_domain(['west', '50', '100s'])
-
- mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
- MIN_INSTANCE_COUNT, [hostname])
- mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, {}, DEFAULT_GROUPING)
- mock_print_results.assert_called_once_with([hostname])
-
- def test_safe_domain_include_hosts_from_list(self):
- """Test successful execution of the sla_list_safe_domain command with include list option."""
- mock_vector = self.create_mock_vector(self.create_hosts(2, 80, 100))
- hosts = ['h0', 'h1']
- mock_options = self.setup_mock_options(include_list=','.join(hosts))
- with contextlib.nested(
- patch('apache.aurora.client.commands.admin.make_client',
- new=create_autospec(spec=AuroraClientAPI)),
- patch('apache.aurora.client.commands.admin.print_results'),
- patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)
- ) as (
- mock_api,
- mock_print_results,
- test_clusters,
- mock_options):
-
- mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
-
- sla_list_safe_domain(['west', '50', '100s'])
-
- mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
- MIN_INSTANCE_COUNT, hosts)
- mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, {}, DEFAULT_GROUPING)
- mock_print_results.assert_called_once_with(hosts)
-
- def test_safe_domain_override_jobs(self):
- """Test successful execution of the sla_list_safe_domain command with override_jobs option."""
- mock_vector = self.create_mock_vector(self.create_hosts(3, 80, 100))
- with temporary_file() as fp:
- fp.write('west/role/env/job1 30 200s')
- fp.flush()
- mock_options = self.setup_mock_options(override=fp.name)
- with contextlib.nested(
- patch('apache.aurora.client.commands.admin.make_client',
- new=create_autospec(spec=AuroraClientAPI)),
- patch('apache.aurora.client.commands.admin.print_results'),
- patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)
- ) as (
- mock_api,
- mock_print_results,
- test_clusters,
- mock_options):
-
- mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
-
- sla_list_safe_domain(['west', '50', '100s'])
-
- job_key = AuroraJobKey.from_path('west/role/env/job1')
- override = {job_key: JobUpTimeLimit(job_key, 30, 200)}
- mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, override, DEFAULT_GROUPING)
- mock_print_results.assert_called_once_with(['h0', 'h1', 'h2'])
-
- def test_safe_domain_list_jobs(self):
- """Tests successful execution of the sla_list_safe_domain command with list_jobs option."""
- mock_options = self.setup_mock_options(list_jobs=True)
- mock_vector = self.create_mock_vector(self.create_hosts(3, 50, 100))
- with contextlib.nested(
- patch('apache.aurora.client.commands.admin.make_client',
- new=create_autospec(spec=AuroraClientAPI)),
- patch('apache.aurora.client.commands.admin.print_results'),
- patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)
- ) as (
- mock_api,
- mock_print_results,
- test_clusters,
- mock_options):
-
- mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
- sla_list_safe_domain(['west', '50', '100s'])
-
- mock_vector.get_safe_hosts.assert_called_once_with(50.0, 100.0, {}, DEFAULT_GROUPING)
- mock_print_results.assert_called_once_with([
- 'h0\twest/role/env/job0\t50.00\t100',
- 'h1\twest/role/env/job1\t50.00\t100',
- 'h2\twest/role/env/job2\t50.00\t100'])
-
- def test_safe_domain_invalid_percentage(self):
- """Tests execution of the sla_list_safe_domain command with invalid percentage"""
- mock_options = self.setup_mock_options()
- with patch('twitter.common.app.get_options', return_value=mock_options):
- try:
- sla_list_safe_domain(['west', '0', '100s'])
- except SystemExit:
- pass
- else:
- assert 'Expected error is not raised.'
-
- def test_safe_domain_malformed_job_override(self):
- """Tests execution of the sla_list_safe_domain command with invalid job_override file"""
- with temporary_file() as fp:
- fp.write('30 200s')
- fp.flush()
- mock_options = self.setup_mock_options(override=fp.name)
- with patch('twitter.common.app.get_options', return_value=mock_options):
-
- try:
- sla_list_safe_domain(['west', '50', '100s'])
- except SystemExit:
- pass
- else:
- assert 'Expected error is not raised.'
-
- def test_safe_domain_hosts_error(self):
- """Tests execution of the sla_list_safe_domain command with both include file and list"""
- mock_options = self.setup_mock_options(include='file', include_list='list')
- with patch('twitter.common.app.get_options', return_value=mock_options):
-
- try:
- sla_list_safe_domain(['west', '50', '100s'])
- except SystemExit:
- pass
- else:
- assert 'Expected error is not raised.'
-
- def test_safe_domain_grouping_error(self):
- """Tests execution of the sla_list_safe_domain command invalid grouping"""
- mock_options = self.setup_mock_options(grouping='foo')
- with patch('twitter.common.app.get_options', return_value=mock_options):
-
- try:
- sla_list_safe_domain(['west', '50', '100s'])
- except SystemExit:
- pass
- else:
- assert 'Expected error is not raised.'
-
-
-class TestAdminSlaProbeHostsCommand(AuroraClientCommandTest):
-
- @classmethod
- def setup_mock_options(cls, hosts=None, filename=None, grouping=None):
- mock_options = create_autospec(
- spec=['hosts', 'filename', 'verbosity', 'min_instance_count', 'grouping'],
- spec_set=False,
- instance=True)
- mock_options.hosts = hosts
- mock_options.filename = filename
- mock_options.verbosity = False
- mock_options.grouping = grouping or DEFAULT_GROUPING
- mock_options.min_instance_count = 1
- return mock_options
-
- @classmethod
- def create_mock_vector(cls, result):
- mock_vector = create_autospec(spec=DomainUpTimeSlaVector, instance=True)
- mock_vector.probe_hosts.return_value = result
- return mock_vector
-
- @classmethod
- def create_probe_hosts(cls, num_hosts, predicted, safe, safe_in):
- hosts = defaultdict(list)
- for i in range(num_hosts):
- host_name = 'h%s' % i
- job = AuroraJobKey.from_path('west/role/env/job%s' % i)
- hosts[host_name].append(JobUpTimeDetails(job, predicted, safe, safe_in))
- return [hosts]
-
- def test_probe_hosts_with_list(self):
- """Tests successful execution of the sla_probe_hosts command with host list."""
- hosts = ['h0', 'h1']
- mock_options = self.setup_mock_options(hosts=','.join(hosts))
- mock_vector = self.create_mock_probe_hosts_vector([self.create_probe_hosts(2, 80, True, 0)])
- with contextlib.nested(
- patch('apache.aurora.client.commands.admin.make_client',
- new=create_autospec(spec=AuroraClientAPI)),
- patch('apache.aurora.client.commands.admin.print_results'),
- patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)
- ) as (
- mock_api,
- mock_print_results,
- test_clusters,
- options):
-
- mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
- sla_probe_hosts(['west', '90', '200s'])
-
- mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
- mock_options.min_instance_count, hosts)
- mock_vector.probe_hosts.assert_called_once_with(90.0, 200.0, mock_options.grouping)
- mock_print_results.assert_called_once_with([
- 'h0\twest/role/env/job0\t80.00\tTrue\t0',
- 'h1\twest/role/env/job1\t80.00\tTrue\t0'
- ])
-
- def test_probe_hosts_with_file(self):
- """Tests successful execution of the sla_probe_hosts command with host filename."""
- mock_vector = self.create_mock_probe_hosts_vector([self.create_probe_hosts(1, 80, False, None)])
- with temporary_file() as fp:
- fp.write('h0')
- fp.flush()
- mock_options = self.setup_mock_options(filename=fp.name)
- with contextlib.nested(
- patch('apache.aurora.client.commands.admin.make_client',
- new=create_autospec(spec=AuroraClientAPI)),
- patch('apache.aurora.client.commands.admin.print_results'),
- patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)
- ) as (
- mock_api,
- mock_print_results,
- test_clusters,
- options):
-
- mock_api.return_value.sla_get_safe_domain_vector.return_value = mock_vector
- sla_probe_hosts(['west', '90', '200s'])
-
- mock_api.return_value.sla_get_safe_domain_vector.assert_called_once_with(
- mock_options.min_instance_count, ['h0'])
- mock_vector.probe_hosts.assert_called_once_with(90.0, 200.0, mock_options.grouping)
- mock_print_results.assert_called_once_with([
- 'h0\twest/role/env/job0\t80.00\tFalse\tn/a'
- ])
-
- def test_probe_hosts_error(self):
- """Tests execution of the sla_probe_hosts command with both host and filename provided."""
- with temporary_file() as fp:
- fp.write('h0')
- fp.flush()
- mock_options = self.setup_mock_options(hosts='h0', filename=fp.name)
- with patch('twitter.common.app.get_options', return_value=mock_options):
-
- try:
- sla_probe_hosts(['west', '50', '100s'])
- except SystemExit:
- pass
- else:
- assert 'Expected error is not raised.'
-
- def test_probe_grouping_error(self):
- """Tests execution of the sla_probe_hosts command with invalid grouping."""
- mock_options = self.setup_mock_options(hosts='h0', grouping='foo')
- with patch('twitter.common.app.get_options', return_value=mock_options):
-
- try:
- sla_probe_hosts(['west', '50', '100s'])
- except SystemExit:
- pass
- else:
- assert 'Expected error is not raised.'
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9a817f24/src/test/python/apache/aurora/client/commands/test_cancel_update.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_cancel_update.py b/src/test/python/apache/aurora/client/commands/test_cancel_update.py
deleted file mode 100644
index e827b38..0000000
--- a/src/test/python/apache/aurora/client/commands/test_cancel_update.py
+++ /dev/null
@@ -1,115 +0,0 @@
-#
-# 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 twitter.common.contextutil import temporary_file
-
-from apache.aurora.client.commands.core import cancel_update
-from apache.aurora.common.aurora_job_key import AuroraJobKey
-
-from .util import AuroraClientCommandTest
-
-from gen.apache.aurora.api.ttypes import JobKey, TaskQuery
-
-
-class TestClientCancelUpdateCommand(AuroraClientCommandTest):
-
- @classmethod
- def setup_mock_options(cls):
- """set up to get a mock options object."""
- mock_options = Mock()
- mock_options.open_browser = False
- mock_options.shards = None
- mock_options.cluster = None
- mock_options.json = False
- mock_options.disable_all_hooks = False
- return mock_options
-
- @classmethod
- def setup_mock_api_factory(cls):
- mock_api_factory, mock_api = cls.create_mock_api_factory()
- mock_api_factory('fake').cancel_update.return_value = cls.get_cancel_update_response()
- return mock_api_factory
-
- @classmethod
- def get_cancel_update_response(cls):
- return cls.create_simple_success_response()
-
- @classmethod
- def assert_cancel_update_called(cls, mock_api):
- # Running cancel update should result in calling the API cancel_update
- # method once, with an AuroraJobKey parameter.
- assert mock_api.cancel_update.call_count == 1
- mock_api.cancel_update.assert_called_with(
- AuroraJobKey(cls.TEST_CLUSTER, cls.TEST_ROLE, cls.TEST_ENV, cls.TEST_JOB),
- config=None)
-
- def test_simple_successful_cancel_update(self):
- """Run a test of the "kill" command against a mocked-out API:
- Verifies that the kill command sends the right API RPCs, and performs the correct
- tests on the result."""
- mock_options = self.setup_mock_options()
- mock_config = Mock()
- mock_api_factory = self.setup_mock_api_factory()
- with contextlib.nested(
- patch('apache.aurora.client.commands.core.make_client_factory',
- return_value=mock_api_factory),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
- mock_api = mock_api_factory('fake')
-
- cancel_update(['west/mchucarroll/test/hello'], mock_options)
- self.assert_cancel_update_called(mock_api)
-
- @classmethod
- def get_expected_task_query(cls, shards=None):
- instance_ids = frozenset(shards) if shards is not None else None
- # Helper to create the query that will be a parameter to job kill.
- return TaskQuery(
- taskIds=None,
- jobKeys=[JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=cls.TEST_JOB)],
- instanceIds=instance_ids)
-
- @classmethod
- def get_release_lock_response(cls):
- """Set up the response to a startUpdate API call."""
- return cls.create_simple_success_response()
-
- def test_cancel_update_api_level(self):
- """Test kill client-side API logic."""
- mock_options = self.setup_mock_options()
-
- mock_config = Mock()
- mock_config.hooks = []
- mock_config.raw.return_value.enable_hooks.return_value.get.return_value = False
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_scheduler_proxy.releaseLock.return_value = self.get_release_lock_response()
- with contextlib.nested(
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)) as (
- mock_scheduler_proxy_class, mock_clusters, options, mock_get_job_config):
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- cancel_update(['west/mchucarroll/test/hello'], mock_options)
-
- # All that cancel_update really does is release the update lock.
- # So that's all we really need to check.
- assert mock_scheduler_proxy.releaseLock.call_count == 1
- assert mock_scheduler_proxy.releaseLock.call_args[0][0].key.job == JobKey(environment='test',
- role='mchucarroll', name='hello')
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9a817f24/src/test/python/apache/aurora/client/commands/test_create.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_create.py b/src/test/python/apache/aurora/client/commands/test_create.py
deleted file mode 100644
index 2a61d6e..0000000
--- a/src/test/python/apache/aurora/client/commands/test_create.py
+++ /dev/null
@@ -1,275 +0,0 @@
-#
-# 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 create_autospec, patch
-from pystachio.config import Config
-from twitter.common.contextutil import temporary_file
-
-from apache.aurora.client.commands.core import create
-from apache.aurora.config import AuroraConfig
-
-from .util import AuroraClientCommandTest
-
-from gen.apache.aurora.api.ttypes import (
- AssignedTask,
- JobKey,
- ScheduledTask,
- ScheduleStatus,
- ScheduleStatusResult,
- TaskEvent,
- TaskQuery
-)
-
-
-class TestClientCreateCommand(AuroraClientCommandTest):
- @classmethod
- def setup_mock_options(cls):
- """set up to get a mock options object."""
- mock_options = create_autospec(spec={}, instance=True)
- mock_options.json = False
- mock_options.bindings = {}
- mock_options.open_browser = False
- mock_options.cluster = None
- mock_options.wait_until = 'RUNNING' # or 'FINISHED' for other tests
- mock_options.disable_all_hooks = False
- mock_options.disable_all_hooks_reason = None
- return mock_options
-
- @classmethod
- def create_mock_task(cls, task_id, instance_id, initial_time, status):
- mock_task = create_autospec(spec=ScheduledTask, instance=True)
- mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
- mock_task.assignedTask.taskId = task_id
- mock_task.assignedTask.instanceId = instance_id
- mock_task.status = status
- mock_task_event = create_autospec(spec=TaskEvent, instance=True)
- mock_task_event.timestamp = initial_time
- mock_task.taskEvents = [mock_task_event]
- return mock_task
-
- @classmethod
- def create_mock_status_query_result(cls, scheduleStatus):
- mock_query_result = cls.create_simple_success_response()
- mock_query_result.result.scheduleStatusResult = create_autospec(
- spec=ScheduleStatusResult,
- spec_set=False,
- instance=True)
- mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
- mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
- mock_query_result.result.scheduleStatusResult.tasks = [mock_task_one, mock_task_two]
- return mock_query_result
-
- @classmethod
- def create_mock_query(cls):
- return TaskQuery(
- jobKeys=[JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=cls.TEST_JOB)])
-
- @classmethod
- def get_createjob_response(cls):
- # Then, we call api.create_job(config)
- return cls.create_simple_success_response()
-
- @classmethod
- def get_failed_createjob_response(cls):
- return cls.create_error_response()
-
- @classmethod
- def assert_create_job_called(cls, mock_api):
- # Check that create_job was called exactly once, with an AuroraConfig parameter.
- assert mock_api.create_job.call_count == 1
- assert isinstance(mock_api.create_job.call_args_list[0][0][0], AuroraConfig)
-
- @classmethod
- def assert_scheduler_called(cls, mock_api, mock_query, num_queries):
- # scheduler.scheduler() is called once, as a part of the handle_open call.
- assert mock_api.scheduler_proxy.getTasksWithoutConfigs.call_count == num_queries
- mock_api.scheduler_proxy.getTasksWithoutConfigs.assert_called_with(mock_query)
-
- def test_simple_successful_create_job(self):
- """Run a test of the "create" command against a mocked-out API:
- Verifies that the creation command sends the right API RPCs, and performs the correct
- tests on the result."""
- mock_options = self.setup_mock_options()
-
- # create first calls get_job_config, which calls get_config. As long as we've got the options
- # set up correctly, this should work.
-
- # Next, create gets an API object via make_client. We need to replace that with a mock API.
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('apache.aurora.client.commands.core.make_v1_client', return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options)) as (make_client,
- options):
-
- # After making the client, create sets up a job monitor.
- # The monitor uses TaskQuery to get the tasks. It's called at least twice:once before
- # the job is created, and once after. So we need to set up mocks for the query results.
- mock_query = self.create_mock_query()
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = [
- self.create_mock_status_query_result(ScheduleStatus.RUNNING)
- ]
-
- # With the monitor set up, create finally gets around to calling create_job.
- mock_api.create_job.return_value = self.get_createjob_response()
-
- # Finally, it calls the monitor to watch and make sure the jobs started;
- # but we already set that up in the side-effects list for the query mock.
-
- # This is the real test: invoke create as if it had been called by the command line.
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- create(['west/mchucarroll/test/hello', fp.name])
-
- # Now check that the right API calls got made.
- # Check that create_job was called exactly once, with an AuroraConfig parameter.
- self.assert_create_job_called(mock_api)
- self.assert_scheduler_called(mock_api, mock_query, 1)
- # make_client should have been called once.
- make_client.assert_called_with('west')
-
- def test_create_job_wait_until_finished(self):
- """Run a test of the "create" command against a mocked-out API:
- this time, make the monitor check status several times before successful completion.
- """
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('threading._Event.wait'),
- patch('apache.aurora.client.commands.core.make_v1_client', return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options)) as (sleep, make_client,
- options):
- mock_query = self.create_mock_query()
- mock_options.wait_until = 'FINISHED'
- mock_query_results = [
- self.create_mock_status_query_result(ScheduleStatus.PENDING),
- self.create_mock_status_query_result(ScheduleStatus.PENDING),
- self.create_mock_status_query_result(ScheduleStatus.RUNNING),
- self.create_mock_status_query_result(ScheduleStatus.FINISHED),
- ]
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = mock_query_results
- mock_api.create_job.return_value = self.get_createjob_response()
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- create(['west/mchucarroll/test/hello', fp.name])
-
- # Now check that the right API calls got made.
- # Check that create_job was called exactly once, with an AuroraConfig parameter.
- self.assert_create_job_called(mock_api)
- self.assert_scheduler_called(mock_api, mock_query, 4)
- # make_client should have been called once.
- make_client.assert_called_with('west')
-
- def test_create_job_failed(self):
- """Run a test of the "create" command against a mocked-out API:
- this time, make the monitor check status several times before successful completion.
- """
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('apache.aurora.client.commands.core.make_v1_client', return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options)) as (make_client,
- options):
- mock_api.create_job.return_value = self.get_failed_createjob_response()
- # This is the real test: invoke create as if it had been called by the command line.
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- self.assertRaises(SystemExit, create, (['west/mchucarroll/test/hello', fp.name]))
-
- # Now check that the right API calls got made.
- # Check that create_job was called exactly once, with an AuroraConfig parameter.
- self.assert_create_job_called(mock_api)
-
- # make_client should have been called once.
- make_client.assert_called_with('west')
-
- def test_delayed_job(self):
- """Run a test of the "create" command against a mocked-out API:
- this time, make the monitor check status several times before successful completion.
- """
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('threading._Event.wait'),
- patch('apache.aurora.client.commands.core.make_v1_client', return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options)) as (sleep, make_client,
- options):
- mock_query = self.create_mock_query()
- mock_query_results = [
- self.create_mock_status_query_result(ScheduleStatus.PENDING),
- self.create_mock_status_query_result(ScheduleStatus.PENDING),
- self.create_mock_status_query_result(ScheduleStatus.RUNNING)
- ]
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = mock_query_results
- mock_api.create_job.return_value = self.get_createjob_response()
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- create(['west/mchucarroll/test/hello', fp.name])
-
- # Now check that the right API calls got made.
- self.assert_create_job_called(mock_api)
- self.assert_scheduler_called(mock_api, mock_query, 3)
- # make_client should have been called once.
- make_client.assert_called_with('west')
-
- def test_create_job_failed_invalid_config(self):
- """Run a test of the "create" command against a mocked-out API, with a configuration
- containing a syntax error"""
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('apache.aurora.client.commands.core.make_v1_client', return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options)) as (make_client,
- options):
- with temporary_file() as fp:
- fp.write(self.get_invalid_config('invalid_clause=oops'))
- fp.flush()
- self.assertRaises(Config.InvalidConfigError, create, (['west/mchucarroll/test/hello',
- fp.name]))
-
- # Now check that the right API calls got made.
- # Check that create_job was not called.
- assert mock_api.create_job.call_count == 0
-
- assert mock_scheduler_proxy.getTasksWithoutConfigs.call_count == 0
- # make_client should not have been called.
- assert make_client.call_count == 0
-
- def test_create_job_failed_invalid_config_two(self):
- """Run a test of the "create" command against a mocked-out API:
- this time, make the monitor check status several times before successful completion.
- """
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('apache.aurora.client.commands.core.make_v1_client', return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options)) as (make_client,
- options):
- with temporary_file() as fp:
- fp.write(self.get_invalid_config('invalid_clause=\'oops\','))
- fp.flush()
- self.assertRaises(AttributeError, create, (['west/mchucarroll/test/hello', fp.name]))
-
- # Now check that the right API calls got made.
- # Check that create_job was not called.
- assert mock_api.create_job.call_count == 0
- # getTasksWithoutConfigs was called once, before the create_job
- assert mock_scheduler_proxy.getTasksWithoutConfigs.call_count == 0
- # make_client should not have been called.
- assert make_client.call_count == 0
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9a817f24/src/test/python/apache/aurora/client/commands/test_diff.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_diff.py b/src/test/python/apache/aurora/client/commands/test_diff.py
deleted file mode 100644
index 79e02b2..0000000
--- a/src/test/python/apache/aurora/client/commands/test_diff.py
+++ /dev/null
@@ -1,205 +0,0 @@
-#
-# 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
-import os
-
-from mock import Mock, patch
-from pystachio.config import Config
-from twitter.common.contextutil import temporary_file
-
-from apache.aurora.client.commands.core import diff
-
-from .util import AuroraClientCommandTest
-
-from gen.apache.aurora.api.constants import ACTIVE_STATES
-from gen.apache.aurora.api.ttypes import (
- AssignedTask,
- ExecutorConfig,
- Identity,
- JobConfiguration,
- JobKey,
- PopulateJobResult,
- ResponseCode,
- Result,
- ScheduledTask,
- ScheduleStatus,
- ScheduleStatusResult,
- TaskConfig,
- TaskEvent,
- TaskQuery
-)
-
-
-class TestDiffCommand(AuroraClientCommandTest):
- @classmethod
- def setup_mock_options(cls):
- """set up to get a mock options object."""
- mock_options = Mock()
- mock_options.env = None
- mock_options.json = False
- mock_options.bindings = {}
- mock_options.open_browser = False
- mock_options.rename_from = None
- mock_options.cluster = None
- mock_options.disable_all_hooks = False
- return mock_options
-
- @classmethod
- def create_mock_scheduled_tasks(cls):
- jobs = []
- for name in ['foo', 'bar', 'baz']:
- job = ScheduledTask()
- job.failure_count = 0
- job.assignedTask = AssignedTask()
- job.assignedTask.slaveHost = 'slavehost'
- job.assignedTask.task = TaskConfig()
- job.assignedTask.task.maxTaskFailures = 1
- job.assignedTask.task.executorConfig = ExecutorConfig(name='name', data='fake data')
- job.assignedTask.task.metadata = []
- job.assignedTask.task.job = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
- job.assignedTask.task.owner = Identity(role='mchucarroll')
- job.assignedTask.task.environment = 'test'
- job.assignedTask.task.jobName = 'woops'
- job.assignedTask.task.numCpus = 2
- job.assignedTask.task.ramMb = 2
- job.assignedTask.task.diskMb = 2
- job.assignedTask.instanceId = 4237894
- job.assignedTask.assignedPorts = None
- job.status = ScheduleStatus.RUNNING
- event = TaskEvent()
- event.timestamp = 28234726395
- event.status = ScheduleStatus.RUNNING
- event.message = "Hi there"
- job.taskEvents = [event]
- jobs.append(job)
- return jobs
-
- @classmethod
- def create_status_response(cls):
- resp = cls.create_simple_success_response()
- resp.result = Result(
- scheduleStatusResult=ScheduleStatusResult(tasks=set(cls.create_mock_scheduled_tasks())))
- return resp
-
- @classmethod
- def create_failed_status_response(cls):
- return cls.create_blank_response(ResponseCode.INVALID_REQUEST, 'No tasks found for query')
-
- @classmethod
- def setup_populate_job_config(cls, api):
- populate = cls.create_simple_success_response()
-
- api.populateJobConfig.return_value = populate
- tasks = set(task.assignedTask.task for task in cls.create_mock_scheduled_tasks())
- populate.result = Result(populateJobResult=PopulateJobResult(
- populatedDEPRECATED=tasks,
- taskConfig=list(tasks)[0]
- ))
- return populate
-
- def test_successful_diff(self):
- """Test the diff command."""
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_scheduler_proxy.getTasksStatus.return_value = self.create_status_response()
- self.setup_populate_job_config(mock_scheduler_proxy)
- with contextlib.nested(
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('subprocess.call', return_value=0),
- patch('json.loads', return_value=Mock())) as (
- mock_scheduler_proxy_class,
- mock_clusters,
- options,
- subprocess_patch,
- json_patch):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- diff(['west/mchucarroll/test/hello', fp.name])
-
- # Diff should get the task status, populate a config, and run diff.
- mock_scheduler_proxy.getTasksStatus.assert_called_with(
- TaskQuery(
- jobKeys=[JobKey(role='mchucarroll', environment='test', name='hello')],
- statuses=ACTIVE_STATES))
- assert mock_scheduler_proxy.populateJobConfig.call_count == 1
- assert isinstance(mock_scheduler_proxy.populateJobConfig.call_args[0][0], JobConfiguration)
- assert (mock_scheduler_proxy.populateJobConfig.call_args[0][0].key ==
- JobKey(environment=u'test', role=u'mchucarroll', name=u'hello'))
- # Subprocess should have been used to invoke diff with two parameters.
- assert subprocess_patch.call_count == 1
- assert len(subprocess_patch.call_args[0][0]) == 3
- assert subprocess_patch.call_args[0][0][0] == os.environ.get('DIFF_VIEWER', 'diff')
-
- def test_diff_invalid_config(self):
- """Test the diff command if the user passes a config with an error in it."""
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_scheduler_proxy.getTasksStatus.return_value = self.create_status_response()
- self.setup_populate_job_config(mock_scheduler_proxy)
- with contextlib.nested(
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('subprocess.call', return_value=0),
- patch('json.loads', return_value=Mock())) as (
- mock_scheduler_proxy_class,
- mock_clusters,
- options,
- subprocess_patch,
- json_patch):
- with temporary_file() as fp:
- fp.write(self.get_invalid_config('stupid="me"',))
- fp.flush()
- self.assertRaises(Config.InvalidConfigError, diff,
- ['west/mchucarroll/test/hello', fp.name])
- assert mock_scheduler_proxy.getTasksStatus.call_count == 0
- assert mock_scheduler_proxy.populateJobConfig.call_count == 0
- assert subprocess_patch.call_count == 0
-
- def test_diff_server_error(self):
- """Test the diff command if the user passes a config with an error in it."""
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_scheduler_proxy.getTasksStatus.return_value = self.create_failed_status_response()
- self.setup_populate_job_config(mock_scheduler_proxy)
- with contextlib.nested(
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('subprocess.call', return_value=0),
- patch('json.loads', return_value=Mock())) as (
- mock_scheduler_proxy_class,
- mock_clusters,
- options,
- subprocess_patch,
- json_patch):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- self.assertRaises(SystemExit, diff,
- ['west/mchucarroll/test/hello', fp.name])
- # In this error case, we should have called the server getTasksStatus;
- # but since it fails, we shouldn't call populateJobConfig or subprocess.
- mock_scheduler_proxy.getTasksStatus.assert_called_with(
- TaskQuery(
- jobKeys=[JobKey(role='mchucarroll', environment='test', name='hello')],
- statuses=ACTIVE_STATES))
- assert mock_scheduler_proxy.populateJobConfig.call_count == 0
- assert subprocess_patch.call_count == 0
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9a817f24/src/test/python/apache/aurora/client/commands/test_hooks.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_hooks.py b/src/test/python/apache/aurora/client/commands/test_hooks.py
deleted file mode 100644
index de1781e..0000000
--- a/src/test/python/apache/aurora/client/commands/test_hooks.py
+++ /dev/null
@@ -1,229 +0,0 @@
-#
-# 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 create_autospec, patch
-from twitter.common.contextutil import temporary_file
-
-from apache.aurora.client.commands.core import create
-from apache.aurora.client.config import AuroraConfig, GlobalHookRegistry
-from apache.aurora.client.hooks.hooked_api import HookedAuroraClientAPI
-
-from .util import AuroraClientCommandTest
-
-from gen.apache.aurora.api.ttypes import (
- AssignedTask,
- Result,
- ScheduledTask,
- ScheduleStatus,
- ScheduleStatusResult,
- TaskEvent
-)
-
-
-class CreateHookForTesting(object):
- def __init__(self, succeed):
- self.created_jobs = []
- self.succeed = succeed
-
- def pre_create_job(self, api, config):
- self.created_jobs.append(config)
- return self.succeed
-
-
-class TestClientCreateCommand(AuroraClientCommandTest):
-
- def setUp(self):
- GlobalHookRegistry.reset()
-
- @classmethod
- def setup_mock_options(cls):
- """set up to get a mock options object."""
- mock_options = create_autospec(spec={}, instance=True)
- mock_options.json = False
- mock_options.bindings = {}
- mock_options.open_browser = False
- mock_options.cluster = None
- mock_options.wait_until = 'RUNNING' # or 'FINISHED' for other tests
- mock_options.disable_all_hooks_reason = None
- return mock_options
-
- @classmethod
- def create_mock_task(cls, task_id, instance_id, initial_time, status):
- mock_task = create_autospec(spec=ScheduledTask, instance=True)
- mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
- mock_task.assignedTask.taskId = task_id
- mock_task.assignedTask.instanceId = instance_id
- mock_task.status = status
- mock_task_event = create_autospec(spec=TaskEvent, instance=True)
- mock_task_event.timestamp = initial_time
- mock_task.taskEvents = [mock_task_event]
- return mock_task
-
- @classmethod
- def create_mock_status_query_result(cls, scheduleStatus):
- mock_query_result = cls.create_simple_success_response()
-
- if scheduleStatus == ScheduleStatus.INIT:
- # status query result for before job is launched.
- tasks = []
- else:
- mock_task_one = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
- mock_task_two = cls.create_mock_task('hello', 1, 1004, scheduleStatus)
- tasks = [mock_task_one, mock_task_two]
- mock_query_result.result = Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
- return mock_query_result
-
- @classmethod
- def get_createjob_response(cls):
- # Then, we call api.create_job(config)
- return cls.create_simple_success_response()
-
- @classmethod
- def get_failed_createjob_response(cls):
- return cls.create_error_response()
-
- @classmethod
- def assert_create_job_called(cls, mock_api):
- # Check that create_job was called exactly once, with an AuroraConfig parameter.
- assert mock_api.create_job.call_count == 1
- assert isinstance(mock_api.create_job.call_args_list[0][0][0], AuroraConfig)
-
- @classmethod
- def assert_scheduler_called(cls, mock_api, mock_query, num_queries):
- # scheduler.scheduler() is called once, as a part of the handle_open call.
- assert mock_api.scheduler_proxy.getTasksWithoutConfigs.call_count == num_queries
- mock_api.scheduler_proxy.getTasksWithoutConfigs.assert_called_with(mock_query)
-
- def test_create_job_hook_called(self):
- """Run a test of the "create" command against a mocked API;
- verifies that a required hook runs, even though the config doesn't mention it.
- """
- # Create a hook on "create_job" that just adds something to a list in the test.
- # Patch in HookedAuroraClientAPI to replace the UnhookedAuroraClientAPI with a mock.
-
- mock_options = self.setup_mock_options()
- hook = CreateHookForTesting(True)
- GlobalHookRegistry.register_global_hook(hook)
-
- # create first calls get_job_config, which calls get_config. As long as we've got the options
- # set up correctly, this should work.
-
- # Next, create gets an API object via make_client. We need to replace that with a mock API.
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('twitter.common.app.get_options', return_value=mock_options)):
-
- mock_scheduler_proxy.createJob.return_value = self.get_createjob_response()
-
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = [
- self.create_mock_status_query_result(ScheduleStatus.INIT),
- self.create_mock_status_query_result(ScheduleStatus.RUNNING)
- ]
- # Finally, it calls the monitor to watch and make sure the jobs started;
- # but we already set that up in the side-effects list for the query mock.
-
- # This is the real test: invoke create as if it had been called by the command line.
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- create(['west/mchucarroll/test/hello', fp.name])
-
- # Now check that the right API calls got made.
- assert mock_scheduler_proxy.createJob.call_count == 1
- assert len(hook.created_jobs) == 1
-
- def test_create_job_hook_aborts(self):
- """Run a test of the "create" command against a mocked API;
- verifies that a required hook runs, even though the config doesn't mention it.
- """
- # Create a hook on "create_job" that just adds something to a list in the test.
- # Patch in HookedAuroraClientAPI to replace the UnhookedAuroraClientAPI with a mock.
- mock_options = self.setup_mock_options()
- hook = CreateHookForTesting(False)
- GlobalHookRegistry.register_global_hook(hook)
-
- # create first calls get_job_config, which calls get_config. As long as we've got the options
- # set up correctly, this should work.
-
- # Next, create gets an API object via make_client. We need to replace that with a mock API.
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('twitter.common.app.get_options', return_value=mock_options)):
-
- mock_scheduler_proxy.createJob.return_value = self.get_createjob_response()
-
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = [
- self.create_mock_status_query_result(ScheduleStatus.INIT),
- self.create_mock_status_query_result(ScheduleStatus.RUNNING)
- ]
-
- # Finally, it calls the monitor to watch and make sure the jobs started;
- # but we already set that up in the side-effects list for the query mock.
-
- # This is the real test: invoke create as if it had been called by the command line.
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- self.assertRaises(HookedAuroraClientAPI.PreHooksStoppedCall, create,
- ['west/mchucarroll/test/hello', fp.name])
-
- # Now check that the right API calls got made.
- assert mock_scheduler_proxy.createJob.call_count == 0
- assert len(hook.created_jobs) == 1
-
- def test_block_hooks(self):
- """Run a test of the "create" command against a mocked API;
- verifies that a required hook runs, even though the config doesn't mention it.
- """
- # Create a hook on "create_job" that just adds something to a list in the test.
- # Patch in HookedAuroraClientAPI to replace the UnhookedAuroraClientAPI with a mock.
-
- mock_options = self.setup_mock_options()
- hook = CreateHookForTesting(True)
- GlobalHookRegistry.register_global_hook(hook)
- mock_options.disable_all_hooks_reason = "Because I said so."
-
- # create first calls get_job_config, which calls get_config. As long as we've got the options
- # set up correctly, this should work.
- # Next, create gets an API object via make_client. We need to replace that with a mock API.
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('twitter.common.app.get_options', return_value=mock_options)):
-
- mock_scheduler_proxy.createJob.return_value = self.get_createjob_response()
-
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = [
- self.create_mock_status_query_result(ScheduleStatus.INIT),
- self.create_mock_status_query_result(ScheduleStatus.RUNNING)
- ]
- # Finally, it calls the monitor to watch and make sure the jobs started;
- # but we already set that up in the side-effects list for the query mock.
-
- # This is the real test: invoke create as if it had been called by the command line.
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- create(['west/mchucarroll/test/hello', fp.name])
-
- # Now check that the right API calls got made.
- assert mock_scheduler_proxy.createJob.call_count == 1
- assert len(hook.created_jobs) == 0
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9a817f24/src/test/python/apache/aurora/client/commands/test_kill.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_kill.py b/src/test/python/apache/aurora/client/commands/test_kill.py
deleted file mode 100644
index 52732ea..0000000
--- a/src/test/python/apache/aurora/client/commands/test_kill.py
+++ /dev/null
@@ -1,464 +0,0 @@
-#
-# 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
-import threading
-
-from mock import create_autospec, Mock, patch
-from twitter.common.contextutil import temporary_file
-
-from apache.aurora.client.commands.core import CoreCommandHook, kill, killall
-from apache.aurora.common.aurora_job_key import AuroraJobKey
-
-from .util import AuroraClientCommandTest
-
-from gen.apache.aurora.api.ttypes import (
- AssignedTask,
- JobKey,
- Response,
- ResponseCode,
- ResponseDetail,
- Result,
- ScheduledTask,
- ScheduleStatus,
- ScheduleStatusResult,
- TaskConfig,
- TaskEvent,
- TaskQuery
-)
-
-
-class TestClientKillCommand(AuroraClientCommandTest):
-
- @classmethod
- def setup_mock_options(cls):
- """set up to get a mock options object."""
- mock_options = create_autospec(spec=[], instance=True)
- mock_options.open_browser = False
- mock_options.shards = None
- mock_options.cluster = None
- mock_options.json = False
- mock_options.batch_size = None
- mock_options.max_total_failures = 1
- mock_options.disable_all_hooks = False
- mock_options.disable_all_hooks_reason = None
- mock_options.max_failures_option = None
- return mock_options
-
- @classmethod
- def setup_mock_api_factory(cls):
- mock_api_factory, mock_api = cls.create_mock_api_factory()
- mock_api_factory('x').return_value.kill_job.return_value = cls.get_kill_job_response()
- return mock_api_factory
-
- @classmethod
- def get_kill_job_response(cls):
- return cls.create_simple_success_response()
-
- @classmethod
- def get_kill_job_error_response(cls):
- return cls.create_error_response()
-
- @classmethod
- def assert_kill_job_called(cls, mock_api):
- assert mock_api.kill_job.call_count == 1
-
- @classmethod
- def create_mock_task(cls, task_id, instance_id, initial_time, status):
- mock_task = create_autospec(spec=ScheduledTask, instance=True)
- mock_task.assignedTask = create_autospec(spec=AssignedTask, instance=True)
- mock_task.assignedTask.taskId = task_id
- mock_task.assignedTask.instanceId = instance_id
- mock_task.status = status
- mock_task_event = create_autospec(spec=TaskEvent, instance=True)
- mock_task_event.timestamp = initial_time
- mock_task.taskEvents = [mock_task_event]
- return mock_task
-
- @classmethod
- def create_mock_status_query_result(cls, scheduleStatus):
- mock_query_result = cls.create_simple_success_response()
- mock_query_result.result.scheduleStatusResult = create_autospec(
- spec=ScheduleStatusResult,
- spec_set=False,
- instance=True)
- task = cls.create_mock_task('hello', 0, 1000, scheduleStatus)
- mock_query_result.result.scheduleStatusResult.tasks = [task]
- return mock_query_result
-
- @classmethod
- def assert_scheduler_called(cls, mock_api, mock_query, num_queries):
- assert mock_api.scheduler_proxy.getTasksWithoutConfigs.call_count == num_queries
- mock_api.scheduler_proxy.getTasksWithoutConfigs.assert_called_with(mock_query)
-
- def test_kill_job_tasks_not_killed_in_time(self):
- """Test kill timed out waiting in job monitor."""
- mock_options = self.setup_mock_options()
- mock_config = Mock()
- mock_config.hooks = []
- mock_config.raw.return_value.enable_hooks.return_value.get.return_value = False
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_scheduler_proxy.killTasks.return_value = self.get_kill_job_response()
- mock_query_results = [
- self.create_mock_status_query_result(ScheduleStatus.RUNNING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- ]
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = mock_query_results
- with contextlib.nested(
- patch('threading._Event.wait'),
- patch('apache.aurora.client.factory.make_client', return_value=mock_api),
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- self.assertRaises(
- SystemExit, killall, ['west/mchucarroll/test/hello', fp.name], mock_options)
-
- # Now check that the right API calls got made.
- assert mock_scheduler_proxy.killTasks.call_count == 1
- query = self.get_expected_task_query()
- mock_scheduler_proxy.killTasks.assert_called_with(query, None)
- self.assert_scheduler_called(mock_api, query, 8)
-
- def test_kill_job_noshards_fail(self):
- mock_options = self.setup_mock_options()
- mock_config = Mock()
- mock_api_factory = self.setup_mock_api_factory()
- with contextlib.nested(
- patch('apache.aurora.client.commands.core.make_client_factory',
- return_value=mock_api_factory),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
-
- mock_api = mock_api_factory('x').return_value
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- self.assertRaises(SystemExit, kill, ['west/mchucarroll/test/hello', fp.name], mock_options)
-
- assert mock_api.kill_job.call_count == 0
-
- def test_simple_successful_killall_job(self):
- """Run a test of the "kill" command against a mocked-out API:
- Verifies that the kill command sends the right API RPCs, and performs the correct
- tests on the result."""
-
- mock_options = self.setup_mock_options()
- mock_config = Mock()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_api.kill_job.return_value = self.get_kill_job_response()
- mock_scheduler_proxy.killTasks.return_value = self.get_kill_job_response()
- mock_query_results = [
- self.create_mock_status_query_result(ScheduleStatus.RUNNING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLED),
- ]
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = mock_query_results
- mock_event = create_autospec(spec=threading.Event)
- with contextlib.nested(
- patch('time.sleep'),
- patch('apache.aurora.client.commands.core.make_client',
- return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config),
- patch('threading._Event.wait', return_value=mock_event)):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- killall(['west/mchucarroll/test/hello', fp.name], mock_options)
-
- self.assert_kill_job_called(mock_api)
- mock_api.kill_job.assert_called_with(
- AuroraJobKey(cluster=self.TEST_CLUSTER, role=self.TEST_ROLE, env=self.TEST_ENV,
- name=self.TEST_JOB), None, config=mock_config)
- self.assert_scheduler_called(mock_api, self.get_expected_task_query(), 3)
-
- def test_happy_hook(self):
- """Test that hooks that return 0 don't block command execution"""
-
- class HappyHook(CoreCommandHook):
- @property
- def name(self):
- return "I'm so happy"
-
- def execute(self, cmd, options, *args, **kwargs):
- return 0
-
- CoreCommandHook.register_hook(HappyHook())
-
- mock_options = self.setup_mock_options()
- mock_config = Mock()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_api.kill_job.return_value = self.get_kill_job_response()
- mock_scheduler_proxy.killTasks.return_value = self.get_kill_job_response()
- mock_query_results = [
- self.create_mock_status_query_result(ScheduleStatus.RUNNING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLED),
- ]
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = mock_query_results
- with contextlib.nested(
- patch('threading._Event.wait'),
- patch('apache.aurora.client.commands.core.make_client',
- return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- killall(['west/mchucarroll/test/hello', fp.name], mock_options)
-
- self.assert_kill_job_called(mock_api)
- mock_api.kill_job.assert_called_with(
- AuroraJobKey(cluster=self.TEST_CLUSTER, role=self.TEST_ROLE, env=self.TEST_ENV,
- name=self.TEST_JOB), None, config=mock_config)
- self.assert_scheduler_called(mock_api, self.get_expected_task_query(), 3)
- CoreCommandHook.clear_hooks()
-
- def test_hook_aborts_kill(self):
- """Test that a command hook that returns non-zero does block command execution."""
- class FailingKillHook(CoreCommandHook):
- @property
- def name(self):
- return "failure"
-
- def execute(self, cmd, options, *args, **kwargs):
- if cmd == "killall":
- assert args[0] == 'west/mchucarroll/test/hello'
- return 1
- else:
- return 0
-
- CoreCommandHook.register_hook(FailingKillHook())
-
- mock_options = self.setup_mock_options()
- mock_config = Mock()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- with contextlib.nested(
- patch('time.sleep'),
- patch('apache.aurora.client.commands.core.make_client',
- return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- self.assertRaises(
- SystemExit, killall, ['west/mchucarroll/test/hello', fp.name], mock_options)
-
- CoreCommandHook.clear_hooks()
- assert mock_api.kill_job.call_count == 0
-
- def create_status_call_result(cls):
- """Set up the mock status call that will be used to get a task list for
- a batched kill command.
- """
- tasks = []
- for i in range(20):
- tasks.append(ScheduledTask(
- assignedTask=AssignedTask(
- instanceId=i,
- taskId='Task%s' % i,
- slaveId='Slave%s' % i,
- slaveHost='SlaveHost%s' % i,
- task=TaskConfig()
- )
- ))
- return Response(
- responseCode=ResponseCode.OK,
- details=[ResponseDetail(message='Ok')],
- result=Result(scheduleStatusResult=ScheduleStatusResult(tasks=tasks))
- )
-
- def test_successful_batched_killall_job(self):
- """Run a test of the "kill" command against a mocked-out API:
- Verifies that the kill command sends the right API RPCs, and performs the correct
- tests on the result."""
-
- mock_options = self.setup_mock_options()
- mock_options.batch_size = 5
- mock_config = Mock()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_api.kill_job.return_value = self.get_kill_job_response()
- mock_api.check_status.return_value = self.create_status_call_result()
- with contextlib.nested(
- patch('apache.aurora.client.commands.core.make_client',
- return_value=mock_api),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config),
- patch('apache.aurora.client.commands.core.JobMonitor')):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- killall(['west/mchucarroll/test/hello', fp.name], mock_options)
-
- # Now check that the right API calls got made.
- assert mock_api.kill_job.call_count == 4
- mock_api.kill_job.assert_called_with(
- AuroraJobKey(cluster=self.TEST_CLUSTER, role=self.TEST_ROLE, env=self.TEST_ENV,
- name=self.TEST_JOB), [15, 16, 17, 18, 19])
-
- @classmethod
- def get_expected_task_query(cls, shards=None):
- """Helper to create the query that will be a parameter to job kill."""
- instance_ids = frozenset(shards) if shards is not None else None
- return TaskQuery(taskIds=None,
- instanceIds=instance_ids,
- jobKeys=[JobKey(role=cls.TEST_ROLE,
- environment=cls.TEST_ENV,
- name=cls.TEST_JOB)])
-
- def test_kill_job_api_level(self):
- """Test kill client-side API logic."""
- mock_options = self.setup_mock_options()
- mock_config = Mock()
- mock_config.hooks = []
- mock_config.raw.return_value.enable_hooks.return_value.get.return_value = False
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_scheduler_proxy.killTasks.return_value = self.get_kill_job_response()
- mock_query_results = [
- self.create_mock_status_query_result(ScheduleStatus.RUNNING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLED),
- ]
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = mock_query_results
- with contextlib.nested(
- patch('threading._Event.wait'),
- patch('apache.aurora.client.factory.make_client', return_value=mock_api),
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- killall(['west/mchucarroll/test/hello', fp.name], mock_options)
-
- # Now check that the right API calls got made.
- assert mock_scheduler_proxy.killTasks.call_count == 1
- query = self.get_expected_task_query()
- mock_scheduler_proxy.killTasks.assert_called_with(query, None)
- self.assert_scheduler_called(mock_api, query, 3)
-
- def test_kill_job_api_level_with_shards(self):
- """Test kill client-side API logic."""
- mock_options = self.setup_mock_options()
- mock_options.shards = [0, 1, 2, 3]
- mock_config = Mock()
- mock_config.hooks = []
- mock_config.raw.return_value.enable_hooks.return_value.get.return_value = False
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_scheduler_proxy.killTasks.return_value = self.get_kill_job_response()
- mock_query_results = [
- self.create_mock_status_query_result(ScheduleStatus.RUNNING),
- self.create_mock_status_query_result(ScheduleStatus.KILLING),
- self.create_mock_status_query_result(ScheduleStatus.KILLED),
- ]
- mock_scheduler_proxy.getTasksWithoutConfigs.side_effect = mock_query_results
- with contextlib.nested(
- patch('threading._Event.wait'),
- patch('apache.aurora.client.factory.make_client', return_value=mock_api),
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- kill(['west/mchucarroll/test/hello', fp.name], mock_options)
-
- # Now check that the right API calls got made.
- assert mock_scheduler_proxy.killTasks.call_count == 1
- query = self.get_expected_task_query([0, 1, 2, 3])
- mock_scheduler_proxy.killTasks.assert_called_with(query, None)
- self.assert_scheduler_called(mock_api, query, 3)
-
- def test_kill_job_api_level_with_shards_batched(self):
- """Test kill client-side API logic."""
- mock_options = self.setup_mock_options()
- mock_options.batch_size = 2
- mock_options.shards = [0, 1, 2, 3]
- mock_config = Mock()
- mock_config.hooks = []
- mock_config.raw.return_value.enable_hooks.return_value.get.return_value = False
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_api.check_status.return_value = self.create_status_call_result()
- mock_scheduler_proxy.getTasksWithoutConfigs.return_value = self.create_status_call_result()
- mock_scheduler_proxy.killTasks.return_value = self.get_kill_job_response()
- with contextlib.nested(
- patch('apache.aurora.client.factory.make_client', return_value=mock_api),
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config),
- patch('apache.aurora.client.commands.core.JobMonitor')):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- kill(['west/mchucarroll/test/hello', fp.name], mock_options)
-
- # Now check that the right API calls got made.
- assert mock_scheduler_proxy.killTasks.call_count == 2
- query = self.get_expected_task_query([2, 3])
- mock_scheduler_proxy.killTasks.assert_called_with(query, None)
-
- def test_kill_job_api_level_with_shards_batched_and_some_errors(self):
- """Test kill client-side API logic."""
- mock_options = self.setup_mock_options()
- mock_options.batch_size = 2
- mock_options.shards = [0, 1, 2, 3]
- mock_options.max_failures_option = 3
- mock_config = Mock()
- mock_config.hooks = []
- mock_config.raw.return_value.enable_hooks.return_value.get.return_value = False
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_api.check_status.return_value = self.create_status_call_result()
- mock_scheduler_proxy.getTasksWithoutConfigs.return_value = self.create_status_call_result()
- mock_api.kill_job.side_effect = [
- self.get_kill_job_error_response(), self.get_kill_job_response()]
- with contextlib.nested(
- patch('apache.aurora.client.factory.make_client', return_value=mock_api),
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options),
- patch('apache.aurora.client.commands.core.get_job_config', return_value=mock_config)):
-
- with temporary_file() as fp:
- fp.write(self.get_valid_config())
- fp.flush()
- # We should get an exception in this case, because the one of the two calls fails.
- self.assertRaises(SystemExit, kill, ['west/mchucarroll/test/hello', fp.name], mock_options)
-
- # killTasks should still have been called twice - the first error shouldn't abort
- # the second batch.
- assert mock_scheduler_proxy.killTasks.call_count == 2
- query = self.get_expected_task_query([2, 3])
- mock_scheduler_proxy.killTasks.assert_called_with(query, None)
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9a817f24/src/test/python/apache/aurora/client/commands/test_listjobs.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_listjobs.py b/src/test/python/apache/aurora/client/commands/test_listjobs.py
deleted file mode 100644
index a7cb98f..0000000
--- a/src/test/python/apache/aurora/client/commands/test_listjobs.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#
-# 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 create_autospec, Mock, patch
-
-from apache.aurora.client.commands.core import list_jobs
-
-from .util import AuroraClientCommandTest
-
-from gen.apache.aurora.api.ttypes import GetJobsResult, JobKey
-
-
-class TestListJobs(AuroraClientCommandTest):
-
- @classmethod
- def setup_mock_options(cls):
- """set up to get a mock options object."""
- mock_options = Mock()
- mock_options.pretty = False
- mock_options.show_cron = False
- mock_options.disable_all_hooks = False
- return mock_options
-
- @classmethod
- def create_mock_jobs(cls):
- jobs = []
- for name in ['foo', 'bar', 'baz']:
- job = Mock()
- job.key = JobKey(role=cls.TEST_ROLE, environment=cls.TEST_ENV, name=name)
- jobs.append(job)
- return jobs
-
- @classmethod
- def create_listjobs_response(cls):
- resp = cls.create_simple_success_response()
- resp.result.getJobsResult = create_autospec(spec=GetJobsResult, instance=True)
- resp.result.getJobsResult.configs = set(cls.create_mock_jobs())
- return resp
-
- def test_successful_listjobs(self):
- """Test the list_jobs command."""
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_scheduler_proxy.getJobs.return_value = self.create_listjobs_response()
- with contextlib.nested(
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)) as (
- mock_scheduler_proxy_class,
- mock_clusters,
- options):
- list_jobs(['west/mchucarroll'])
-
- mock_scheduler_proxy.getJobs.assert_called_with(self.TEST_ROLE)
-
- def test_listjobs_badcluster(self):
- """Test the list_jobs command when the user provides an invalid cluster."""
- mock_options = self.setup_mock_options()
- (mock_api, mock_scheduler_proxy) = self.create_mock_api()
- mock_scheduler_proxy.getJobs.return_value = self.create_listjobs_response()
- with contextlib.nested(
- patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
- patch('apache.aurora.client.factory.CLUSTERS', new=self.TEST_CLUSTERS),
- patch('twitter.common.app.get_options', return_value=mock_options)) as (
- mock_scheduler_proxy_class,
- mock_clusters,
- options):
- self.assertRaises(SystemExit, list_jobs, ['smoof/mchucarroll'])