def run_setup_marathon_job_no_apps_found(context): update_context_marathon_config(context) with mock.patch.object( SystemPaastaConfig, 'get_zk_hosts', autospec=True, return_value=context.zk_hosts ), mock.patch( 'paasta_tools.setup_marathon_job.parse_args', autospec=True ) as mock_parse_args, mock.patch.object( MarathonServiceConfig, 'format_marathon_app_dict', autospec=True, return_value=context.marathon_complete_config ), mock.patch( 'paasta_tools.setup_marathon_job.monitoring_tools.send_event', autospec=True ), mock.patch( 'paasta_tools.setup_marathon_job.marathon_tools.get_all_marathon_apps', autospec=True, return_value=[]): mock_parse_args.return_value = mock.Mock( verbose=True, soa_dir=context.soa_dir, service_instance_list=[context.job_id], ) setup_marathon_job.main()
def run_setup_marathon_job(context): update_context_marathon_config(context) with mock.patch.object( SystemPaastaConfig, 'get_zk_hosts', autospec=True, return_value=context.zk_hosts, ), mock.patch( 'paasta_tools.setup_marathon_job.parse_args', autospec=True, ) as mock_parse_args, mock.patch.object( MarathonServiceConfig, 'format_marathon_app_dict', autospec=True, return_value=context.marathon_complete_config, ), mock.patch( 'paasta_tools.setup_marathon_job.monitoring_tools.send_event', autospec=True, ): mock_parse_args.return_value = mock.Mock( verbose=True, soa_dir=context.soa_dir, service_instance_list=[context.job_id], ) try: setup_marathon_job.main() except (SystemExit, MarathonHttpError): pass
def create_complete_app(context): with contextlib.nested( mock.patch('paasta_tools.bounce_lib.create_app_lock', autospec=True), mock.patch('paasta_tools.setup_marathon_job.bounce_lib.bounce_lock_zookeeper', autospec=True), mock.patch('paasta_tools.setup_marathon_job.monitoring_tools.send_event', autospec=True), mock.patch('paasta_tools.setup_marathon_job.marathon_tools.create_complete_config', autospec=True), mock.patch('paasta_tools.setup_marathon_job.parse_args', autospec=True), ) as ( _, _, _, mock_create_complete_config, mock_parse_args, ): mock_create_complete_config.return_value = { 'id': context.app_id, 'cmd': '/bin/sleep 1m', 'instances': context.instances, 'mem': 1, 'args': [], 'backoff_factor': 2, 'cpus': 0.01, 'backoff_seconds': 1, 'constraints': None, } mock_parse_args.return_value = mock.Mock( soa_dir=context.soa_dir, service_instance=context.job_id, ) try: setup_marathon_job.main() except SystemExit: pass
def test_main_success(self): fake_client = mock.MagicMock() with contextlib.nested( mock.patch("paasta_tools.setup_marathon_job.parse_args", return_value=self.fake_args, autospec=True), mock.patch( "paasta_tools.setup_marathon_job.get_main_marathon_config", return_value=self.fake_marathon_config, autospec=True, ), mock.patch("paasta_tools.marathon_tools.get_marathon_client", return_value=fake_client, autospec=True), mock.patch( "paasta_tools.marathon_tools.load_marathon_service_config", return_value=self.fake_marathon_service_config, autospec=True, ), mock.patch( "paasta_tools.setup_marathon_job.setup_service", return_value=(0, "it_is_finished"), autospec=True ), mock.patch("paasta_tools.setup_marathon_job.load_system_paasta_config", autospec=True), mock.patch("paasta_tools.setup_marathon_job.send_event", autospec=True), mock.patch("sys.exit", autospec=True), ) as ( parse_args_patch, get_main_conf_patch, get_client_patch, read_service_conf_patch, setup_service_patch, load_system_paasta_config_patch, sensu_patch, sys_exit_patch, ): load_system_paasta_config_patch.return_value.get_cluster = mock.Mock(return_value=self.fake_cluster) setup_marathon_job.main() parse_args_patch.assert_called_once_with() get_main_conf_patch.assert_called_once_with() get_client_patch.assert_called_once_with( self.fake_marathon_config.get_url(), self.fake_marathon_config.get_username(), self.fake_marathon_config.get_password(), ) read_service_conf_patch.assert_called_once_with( decompose_job_id(self.fake_args.service_instance)[0], decompose_job_id(self.fake_args.service_instance)[1], self.fake_cluster, soa_dir=self.fake_args.soa_dir, ) setup_service_patch.assert_called_once_with( decompose_job_id(self.fake_args.service_instance)[0], decompose_job_id(self.fake_args.service_instance)[1], fake_client, self.fake_marathon_config, self.fake_marathon_service_config, "no_more", ) sys_exit_patch.assert_called_once_with(0)
def test_main_sends_event_if_no_deployments(self): fake_client = mock.MagicMock() with contextlib.nested( mock.patch("paasta_tools.setup_marathon_job.parse_args", return_value=self.fake_args, autospec=True), mock.patch( "paasta_tools.setup_marathon_job.get_main_marathon_config", return_value=self.fake_marathon_config, autospec=True, ), mock.patch("paasta_tools.marathon_tools.get_marathon_client", return_value=fake_client, autospec=True), mock.patch( "paasta_tools.marathon_tools.load_marathon_service_config", side_effect=NoDeploymentsAvailable(), autospec=True, ), mock.patch("paasta_tools.setup_marathon_job.setup_service", return_value=(1, "NEVER"), autospec=True), mock.patch("paasta_tools.setup_marathon_job.load_system_paasta_config", autospec=True), mock.patch("paasta_tools.setup_marathon_job.send_event", autospec=True), ) as ( parse_args_patch, get_main_conf_patch, get_client_patch, read_service_conf_patch, setup_service_patch, load_system_paasta_config_patch, sensu_patch, ): load_system_paasta_config_patch.return_value.get_cluster = mock.Mock(return_value=self.fake_cluster) with raises(SystemExit) as exc_info: setup_marathon_job.main() parse_args_patch.assert_called_once_with() get_main_conf_patch.assert_called_once_with() get_client_patch.assert_called_once_with( self.fake_marathon_config.get_url(), self.fake_marathon_config.get_username(), self.fake_marathon_config.get_password(), ) read_service_conf_patch.assert_called_once_with( decompose_job_id(self.fake_args.service_instance)[0], decompose_job_id(self.fake_args.service_instance)[1], self.fake_cluster, soa_dir=self.fake_args.soa_dir, ) expected_string = "No deployments found for %s in cluster %s" % ( self.fake_args.service_instance, self.fake_cluster, ) sensu_patch.assert_called_once_with( decompose_job_id(self.fake_args.service_instance)[0], decompose_job_id(self.fake_args.service_instance)[1], self.fake_args.soa_dir, Status.CRITICAL, expected_string, ) assert exc_info.value.code == 0
def run_setup_marathon_job(context): update_context_marathon_config(context) with contextlib.nested( mock.patch.object(SystemPaastaConfig, "get_zk_hosts", autospec=True, return_value=context.zk_hosts), mock.patch("paasta_tools.setup_marathon_job.parse_args", autospec=True), mock.patch.object( MarathonServiceConfig, "format_marathon_app_dict", autospec=True, return_value=context.marathon_complete_config, ), mock.patch("paasta_tools.setup_marathon_job.monitoring_tools.send_event", autospec=True), ) as (mock_get_zk_hosts, mock_parse_args, _, _): mock_parse_args.return_value = mock.Mock( verbose=True, soa_dir=context.soa_dir, service_instance_list=[context.job_id] ) try: setup_marathon_job.main() except (SystemExit, MarathonHttpError): pass
def run_setup_marathon_job(context): update_context_marathon_config(context) with contextlib.nested( mock.patch.object(SystemPaastaConfig, 'get_zk_hosts', autospec=True, return_value=context.zk_hosts), mock.patch('paasta_tools.setup_marathon_job.marathon_tools.create_complete_config', autospec=True), mock.patch('paasta_tools.setup_marathon_job.parse_args', autospec=True), mock.patch('paasta_tools.setup_marathon_job.monitoring_tools.send_event', autospec=True), ) as ( mock_get_zk_hosts, mock_create_complete_config, mock_parse_args, _, ): mock_create_complete_config.return_value = context.marathon_complete_config mock_parse_args.return_value = mock.Mock( soa_dir=context.soa_dir, service_instance=context.job_id, ) try: setup_marathon_job.main() except SystemExit: pass
def test_main_success(self): fake_client = mock.MagicMock() with contextlib.nested( mock.patch( 'paasta_tools.setup_marathon_job.parse_args', return_value=self.fake_args, autospec=True, ), mock.patch( 'paasta_tools.setup_marathon_job.get_main_marathon_config', return_value=self.fake_marathon_config, autospec=True, ), mock.patch( 'paasta_tools.marathon_tools.get_marathon_client', return_value=fake_client, autospec=True, ), mock.patch( 'paasta_tools.marathon_tools.load_marathon_service_config', return_value=self.fake_marathon_service_config, autospec=True, ), mock.patch( 'paasta_tools.setup_marathon_job.setup_service', return_value=(0, 'it_is_finished'), autospec=True, ), mock.patch('paasta_tools.setup_marathon_job.load_system_paasta_config', autospec=True), mock.patch('paasta_tools.setup_marathon_job.send_event', autospec=True), mock.patch('sys.exit', autospec=True), ) as ( parse_args_patch, get_main_conf_patch, get_client_patch, read_service_conf_patch, setup_service_patch, load_system_paasta_config_patch, sensu_patch, sys_exit_patch, ): load_system_paasta_config_patch.return_value.get_cluster = mock.Mock(return_value=self.fake_cluster) setup_marathon_job.main() parse_args_patch.assert_called_once_with() get_main_conf_patch.assert_called_once_with() get_client_patch.assert_called_once_with( self.fake_marathon_config.get_url(), self.fake_marathon_config.get_username(), self.fake_marathon_config.get_password(), ) read_service_conf_patch.assert_called_once_with( decompose_job_id(self.fake_args.service_instance)[0], decompose_job_id(self.fake_args.service_instance)[1], self.fake_cluster, soa_dir=self.fake_args.soa_dir, ) setup_service_patch.assert_called_once_with( decompose_job_id(self.fake_args.service_instance)[0], decompose_job_id(self.fake_args.service_instance)[1], fake_client, self.fake_marathon_config, self.fake_marathon_service_config, 'no_more', ) sys_exit_patch.assert_called_once_with(0)
def test_main_sends_event_if_no_deployments(self): fake_client = mock.MagicMock() with contextlib.nested( mock.patch( 'paasta_tools.setup_marathon_job.parse_args', return_value=self.fake_args, autospec=True, ), mock.patch( 'paasta_tools.setup_marathon_job.get_main_marathon_config', return_value=self.fake_marathon_config, autospec=True, ), mock.patch( 'paasta_tools.marathon_tools.get_marathon_client', return_value=fake_client, autospec=True, ), mock.patch( 'paasta_tools.marathon_tools.load_marathon_service_config', side_effect=NoDeploymentsAvailable(), autospec=True, ), mock.patch( 'paasta_tools.setup_marathon_job.setup_service', return_value=(1, 'NEVER'), autospec=True, ), mock.patch('paasta_tools.setup_marathon_job.load_system_paasta_config', autospec=True), mock.patch('paasta_tools.setup_marathon_job.send_event', autospec=True), ) as ( parse_args_patch, get_main_conf_patch, get_client_patch, read_service_conf_patch, setup_service_patch, load_system_paasta_config_patch, sensu_patch, ): load_system_paasta_config_patch.return_value.get_cluster = mock.Mock(return_value=self.fake_cluster) with raises(SystemExit) as exc_info: setup_marathon_job.main() parse_args_patch.assert_called_once_with() get_main_conf_patch.assert_called_once_with() get_client_patch.assert_called_once_with( self.fake_marathon_config.get_url(), self.fake_marathon_config.get_username(), self.fake_marathon_config.get_password()) read_service_conf_patch.assert_called_once_with( decompose_job_id(self.fake_args.service_instance)[0], decompose_job_id(self.fake_args.service_instance)[1], self.fake_cluster, soa_dir=self.fake_args.soa_dir) expected_string = 'No deployments found for %s in cluster %s' % ( self.fake_args.service_instance, self.fake_cluster) sensu_patch.assert_called_once_with( decompose_job_id(self.fake_args.service_instance)[0], decompose_job_id(self.fake_args.service_instance)[1], self.fake_args.soa_dir, Status.CRITICAL, expected_string ) assert exc_info.value.code == 0