def test_setup_job_does_nothing_with_only_existing_app(self): fake_existing_job = self.fake_config_dict with contextlib.nested( mock.patch('setup_chronos_job.bounce_chronos_job', autospec=True, return_value=(0, 'ok')), mock.patch('paasta_tools.chronos_tools.lookup_chronos_jobs', autospec=True), mock.patch('paasta_tools.chronos_tools.sort_jobs', autospec=True, return_value=[fake_existing_job]), mock.patch( 'paasta_tools.chronos_tools.load_system_paasta_config', autospec=True), mock.patch( 'paasta_tools.chronos_tools.load_chronos_job_config', autospec=True, return_value=self.fake_chronos_job_config), ) as ( mock_bounce_chronos_job, mock_lookup_chronos_jobs, mock_sort_jobs, load_system_paasta_config_patch, load_chronos_job_config_patch, ): load_system_paasta_config_patch.return_value.get_cluster.return_value = self.fake_cluster complete_config = chronos_tools.create_complete_config( service=self.fake_service, job_name=self.fake_instance, soa_dir=self.fake_args.soa_dir) # Force the complete_config's name to match the return value of # lookup_chronos_jobs to simulate that they have the same name complete_config["name"] = fake_existing_job["name"] actual = setup_chronos_job.setup_job( service=self.fake_service, instance=self.fake_instance, chronos_job_config=self.fake_chronos_job_config, complete_job_config=complete_config, client=self.fake_client, cluster=self.fake_cluster, ) mock_bounce_chronos_job.assert_called_once_with( service=self.fake_service, instance=self.fake_instance, cluster=self.fake_cluster, jobs_to_delete=[], jobs_to_disable=[], job_to_create=None, client=self.fake_client, ) assert mock_lookup_chronos_jobs.called assert actual == mock_bounce_chronos_job.return_value
def test_setup_job_with_previously_enabled_job(self): fake_existing_job = { 'name': 'fake_job', 'disabled': False, } with contextlib.nested( mock.patch('setup_chronos_job.bounce_chronos_job', autospec=True, return_value=(0, 'ok')), mock.patch('paasta_tools.chronos_tools.lookup_chronos_jobs', autospec=True), mock.patch('paasta_tools.chronos_tools.sort_jobs', autospec=True, return_value=[fake_existing_job]), mock.patch( 'paasta_tools.chronos_tools.load_system_paasta_config', autospec=True), mock.patch( 'paasta_tools.chronos_tools.load_chronos_job_config', autospec=True, return_value=self.fake_chronos_job_config), ) as ( mock_bounce_chronos_job, mock_lookup_chronos_jobs, mock_sort_jobs, load_system_paasta_config_patch, load_chronos_job_config_patch, ): load_system_paasta_config_patch.return_value.get_cluster.return_value = self.fake_cluster complete_config = chronos_tools.create_complete_config( service=self.fake_service, job_name=self.fake_instance, soa_dir=self.fake_args.soa_dir) actual = setup_chronos_job.setup_job( service=self.fake_service, instance=self.fake_instance, chronos_job_config=self.fake_chronos_job_config, complete_job_config=complete_config, client=self.fake_client, cluster=self.fake_cluster, ) mock_bounce_chronos_job.assert_called_once_with( service=self.fake_service, instance=self.fake_instance, cluster=self.fake_cluster, jobs_to_delete=[], jobs_to_disable=[fake_existing_job], job_to_create=complete_config, client=self.fake_client, ) assert mock_lookup_chronos_jobs.called assert actual == mock_bounce_chronos_job.return_value
def test_setup_job_does_nothing_with_only_existing_app(self): fake_existing_job = self.fake_config_dict with contextlib.nested( mock.patch('setup_chronos_job.bounce_chronos_job', autospec=True, return_value=(0, 'ok')), mock.patch('paasta_tools.chronos_tools.lookup_chronos_jobs', autospec=True), mock.patch('paasta_tools.chronos_tools.sort_jobs', autospec=True, return_value=[fake_existing_job]), mock.patch('paasta_tools.chronos_tools.load_system_paasta_config', autospec=True), mock.patch('paasta_tools.chronos_tools.load_chronos_job_config', autospec=True, return_value=self.fake_chronos_job_config), ) as ( mock_bounce_chronos_job, mock_lookup_chronos_jobs, mock_sort_jobs, load_system_paasta_config_patch, load_chronos_job_config_patch, ): load_system_paasta_config_patch.return_value.get_cluster.return_value = self.fake_cluster complete_config = chronos_tools.create_complete_config( service=self.fake_service, job_name=self.fake_instance, soa_dir=self.fake_args.soa_dir ) # Force the complete_config's name to match the return value of # lookup_chronos_jobs to simulate that they have the same name complete_config["name"] = fake_existing_job["name"] actual = setup_chronos_job.setup_job( service=self.fake_service, instance=self.fake_instance, chronos_job_config=self.fake_chronos_job_config, complete_job_config=complete_config, client=self.fake_client, cluster=self.fake_cluster, ) mock_bounce_chronos_job.assert_called_once_with( service=self.fake_service, instance=self.fake_instance, cluster=self.fake_cluster, jobs_to_delete=[], jobs_to_disable=[], job_to_create=None, client=self.fake_client, ) assert mock_lookup_chronos_jobs.called assert actual == mock_bounce_chronos_job.return_value
def test_setup_job_with_previously_enabled_job(self): fake_existing_job = { 'name': 'fake_job', 'disabled': False, } with contextlib.nested( mock.patch('setup_chronos_job.bounce_chronos_job', autospec=True, return_value=(0, 'ok')), mock.patch('paasta_tools.chronos_tools.lookup_chronos_jobs', autospec=True), mock.patch('paasta_tools.chronos_tools.sort_jobs', autospec=True, return_value=[fake_existing_job]), mock.patch('paasta_tools.chronos_tools.load_system_paasta_config', autospec=True), mock.patch('paasta_tools.chronos_tools.load_chronos_job_config', autospec=True, return_value=self.fake_chronos_job_config), ) as ( mock_bounce_chronos_job, mock_lookup_chronos_jobs, mock_sort_jobs, load_system_paasta_config_patch, load_chronos_job_config_patch, ): load_system_paasta_config_patch.return_value.get_cluster.return_value = self.fake_cluster complete_config = chronos_tools.create_complete_config( service=self.fake_service, job_name=self.fake_instance, soa_dir=self.fake_args.soa_dir ) actual = setup_chronos_job.setup_job( service=self.fake_service, instance=self.fake_instance, chronos_job_config=self.fake_chronos_job_config, complete_job_config=complete_config, client=self.fake_client, cluster=self.fake_cluster, ) mock_bounce_chronos_job.assert_called_once_with( service=self.fake_service, instance=self.fake_instance, cluster=self.fake_cluster, jobs_to_delete=[], jobs_to_disable=[fake_existing_job], job_to_create=complete_config, client=self.fake_client, ) assert mock_lookup_chronos_jobs.called assert actual == mock_bounce_chronos_job.return_value
def test_setup_job_new_app_with_no_previous_jobs(self): fake_existing_jobs = [] with contextlib.nested( mock.patch("setup_chronos_job.bounce_chronos_job", autospec=True, return_value=(0, "ok")), mock.patch("paasta_tools.chronos_tools.lookup_chronos_jobs", autospec=True), mock.patch("paasta_tools.chronos_tools.sort_jobs", autospec=True, return_value=fake_existing_jobs), mock.patch("paasta_tools.chronos_tools.load_system_paasta_config", autospec=True), mock.patch( "paasta_tools.chronos_tools.load_chronos_job_config", autospec=True, return_value=self.fake_chronos_job_config, ), ) as ( mock_bounce_chronos_job, lookup_chronos_jobs_patch, sort_jobs_patch, load_system_paasta_config_patch, load_chronos_job_config_patch, ): load_system_paasta_config_patch.return_value.get_cluster.return_value = self.fake_cluster complete_config = chronos_tools.create_complete_config( service=self.fake_service, job_name=self.fake_instance, soa_dir=self.fake_args.soa_dir ) actual = setup_chronos_job.setup_job( service=self.fake_service, instance=self.fake_instance, complete_job_config=complete_config, client=self.fake_client, cluster=self.fake_cluster, ) mock_bounce_chronos_job.assert_called_once_with( service=self.fake_service, instance=self.fake_instance, cluster=self.fake_cluster, jobs_to_delete=[], jobs_to_disable=[], job_to_create=complete_config, client=self.fake_client, ) assert actual == mock_bounce_chronos_job.return_value