def create_complete_job(context):
    return_tuple = setup_chronos_job.setup_job(
        fake_service_name,
        fake_instance_name,
        fake_service_job_config,
        fake_service_config,
        context.chronos_client,
        "fake_cluster",
    )
    assert return_tuple[0] == 0
def setup_the_chronos_job(context):
    exit_code, output = setup_chronos_job.setup_job(
        service=fake_service_name,
        instance=fake_instance_name,
        chronos_job_config=context.chronos_job_config_obj,
        complete_job_config=context.chronos_job_config,
        client=context.chronos_client,
        cluster=context.cluster)
    print 'setup_chronos_job returned exitcode %s with output:\n%s\n' % (
        exit_code, output)
 def test_setup_job_with_previously_enabled_job(self):
     fake_existing_job = {
         'name': 'fake_job',
         'disabled': False,
     }
     with mock.patch(
             'paasta_tools.setup_chronos_job.bounce_chronos_job',
             autospec=True,
             return_value=(0, 'ok'),
     ) as mock_bounce_chronos_job, mock.patch(
             'paasta_tools.chronos_tools.lookup_chronos_jobs',
             autospec=True,
     ) as mock_lookup_chronos_jobs, mock.patch(
             'paasta_tools.chronos_tools.sort_jobs',
             autospec=True,
             return_value=[fake_existing_job],
     ), mock.patch(
             'paasta_tools.utils.load_system_paasta_config',
             autospec=True,
     ), mock.patch(
             'paasta_tools.chronos_tools.load_system_paasta_config',
             autospec=True,
     ) as load_system_paasta_config_patch, mock.patch(
             'paasta_tools.chronos_tools.load_chronos_job_config',
             autospec=True,
             return_value=self.fake_chronos_job_config,
     ):
         load_system_paasta_config_patch.return_value.get_cluster.return_value = self.fake_cluster
         load_system_paasta_config_patch.return_value.get_volumes.return_value = []
         load_system_paasta_config_patch.return_value.get_deploy_whitelist.return_value = None
         load_system_paasta_config_patch.return_value.get_dockercfg_location.return_value = \
             "file:///root/.dockercfg"
         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,
             job_to_update=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('paasta_tools.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
         load_system_paasta_config_patch.return_value.get_volumes.return_value = []
         load_system_paasta_config_patch.return_value.get_dockerfile_location.return_value = \
             'file:///root/.dockercfg'
         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,
             job_to_update=complete_config,
             client=self.fake_client,
         )
         assert actual == mock_bounce_chronos_job.return_value
Beispiel #5
0
 def test_setup_job_new_app_with_no_previous_jobs(self):
     fake_existing_jobs = []
     with mock.patch(
             "paasta_tools.setup_chronos_job.bounce_chronos_job",
             autospec=True,
             return_value=(0, "ok"),
     ) as mock_bounce_chronos_job, 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.utils.load_system_paasta_config",
                 autospec=True), mock.patch(
                     "paasta_tools.chronos_tools.load_system_paasta_config",
                     autospec=True
                 ) as load_system_paasta_config_patch, mock.patch(
                     "paasta_tools.chronos_tools.load_chronos_job_config",
                     autospec=True,
                     return_value=self.fake_chronos_job_config,
                 ):
         load_system_paasta_config_patch.return_value.get_cluster.return_value = (
             self.fake_cluster)
         load_system_paasta_config_patch.return_value.get_volumes.return_value = []
         load_system_paasta_config_patch.return_value.get_deploy_whitelist.return_value = (
             None)
         load_system_paasta_config_patch.return_value.get_dockercfg_location.return_value = (
             "file:///root/.dockercfg")
         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,
             job_to_update=complete_config,
             client=self.fake_client,
         )
         assert actual == mock_bounce_chronos_job.return_value
Beispiel #6
0
 def test_setup_job_with_previously_enabled_job(self):
     fake_existing_job = {
         'name': 'fake_job',
         'disabled': False,
     }
     with contextlib.nested(
             mock.patch('paasta_tools.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,
             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,
             job_to_update=complete_config,
             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('paasta_tools.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
         load_system_paasta_config_patch.return_value.get_volumes.return_value = []
         load_system_paasta_config_patch.return_value.get_dockercfg_location.return_value = \
             "file:///root/.dockercfg"
         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,
             job_to_update=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('paasta_tools.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
         load_system_paasta_config_patch.return_value.get_volumes.return_value = []
         load_system_paasta_config_patch.return_value.get_dockerfile_location.return_value = \
             'file:///root/.dockercfg'
         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,
             job_to_update=complete_config,
             client=self.fake_client,
         )
         assert actual == mock_bounce_chronos_job.return_value
 def test_setup_job_does_nothing_with_only_existing_app(self):
     fake_existing_job = copy.deepcopy(self.fake_config_dict)
     with contextlib.nested(
             mock.patch('paasta_tools.setup_chronos_job.bounce_chronos_job',
                        autospec=True,
                        return_value=(0, 'ok')),
             mock.patch('paasta_tools.chronos_tools.lookup_chronos_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,
             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 = copy.deepcopy(self.fake_config_dict)
         # 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,
             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,
             job_to_update=None,
             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 = copy.deepcopy(self.fake_config_dict)
     with contextlib.nested(
         mock.patch('paasta_tools.setup_chronos_job.bounce_chronos_job', autospec=True, return_value=(0, 'ok')),
         mock.patch('paasta_tools.chronos_tools.lookup_chronos_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,
         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 = copy.deepcopy(self.fake_config_dict)
         # 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,
             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,
             job_to_update=None,
             client=self.fake_client,
         )
         assert mock_lookup_chronos_jobs.called
         assert actual == mock_bounce_chronos_job.return_value