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]
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.AuroraClientAPI', new=Mock(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_domain_uptime_with_override(self): self.mock_get_tasks([ self.create_task(100, 1, 'h1', self._name), self.create_task(200, 2, 'h2', self._name), self.create_task(100, 1, 'h2', 'j2') ]) job_override = { self._job_key: JobUpTimeLimit(job=self._job_key, percentage=50, duration_secs=100) } self.assert_safe_domain_result('h1', 50, 400, in_limit=job_override)
def parse_jobs_file(filename): result = {} with open(filename, 'r') as overrides: for line in overrides: if not line.strip(): continue tokens = line.split() if len(tokens) != 3: die('Invalid line in %s:%s' % (filename, line)) job_key = AuroraJobKey.from_path(tokens[0]) result[job_key] = JobUpTimeLimit( job=job_key, percentage=parse_sla_percentage(tokens[1]), duration_secs=parse_time(tokens[2]).as_(Time.SECONDS)) return result