Пример #1
0
 def test_main_no_deployments(self):
     with mock.patch(
             'paasta_tools.setup_chronos_job.parse_args',
             return_value=self.fake_args,
             autospec=True,
     ), mock.patch(
             'paasta_tools.chronos_tools.load_chronos_config',
             autospec=True,
     ), mock.patch(
             'paasta_tools.chronos_tools.get_chronos_client',
             return_value=self.fake_client,
             autospec=True,
     ), mock.patch(
             'paasta_tools.chronos_tools.create_complete_config',
             return_value={},
             autospec=True,
             side_effect=NoDeploymentsAvailable,
     ), mock.patch(
             'paasta_tools.setup_chronos_job.setup_job',
             return_value=(0, 'it_is_finished'),
             autospec=True,
     ), mock.patch(
             'paasta_tools.setup_chronos_job.load_system_paasta_config',
             autospec=True,
     ) as load_system_paasta_config_patch, mock.patch(
             'paasta_tools.setup_chronos_job.send_event',
             autospec=True,
     ):
         load_system_paasta_config_patch.return_value.get_cluster = mock.MagicMock(
             return_value=self.fake_cluster)
         with raises(SystemExit) as excinfo:
             setup_chronos_job.main()
         assert excinfo.value.code == 0
Пример #2
0
 def test_main_no_deployments(self):
     with contextlib.nested(
         mock.patch('paasta_tools.setup_chronos_job.parse_args',
                    return_value=self.fake_args,
                    autospec=True),
         mock.patch('paasta_tools.chronos_tools.load_chronos_config', autospec=True),
         mock.patch('paasta_tools.chronos_tools.get_chronos_client',
                    return_value=self.fake_client,
                    autospec=True),
         mock.patch('paasta_tools.chronos_tools.create_complete_config',
                    return_value={},
                    autospec=True,
                    side_effect=NoDeploymentsAvailable),
         mock.patch('paasta_tools.setup_chronos_job.setup_job',
                    return_value=(0, 'it_is_finished'),
                    autospec=True),
         mock.patch('paasta_tools.setup_chronos_job.load_system_paasta_config', autospec=True),
         mock.patch('paasta_tools.setup_chronos_job.send_event', autospec=True),
     ) as (
         parse_args_patch,
         load_chronos_config_patch,
         get_client_patch,
         load_chronos_job_config_patch,
         setup_job_patch,
         load_system_paasta_config_patch,
         send_event_patch,
     ):
         load_system_paasta_config_patch.return_value.get_cluster = mock.MagicMock(return_value=self.fake_cluster)
         with raises(SystemExit) as excinfo:
             setup_chronos_job.main()
         assert excinfo.value.code == 0
Пример #3
0
    def test_main_success(self):
        expected_status = 0
        expected_output = 'it_is_finished'
        fake_complete_job_config = {'foo': 'bar'}
        with contextlib.nested(
                mock.patch('paasta_tools.setup_chronos_job.parse_args',
                           return_value=self.fake_args,
                           autospec=True),
                mock.patch('paasta_tools.chronos_tools.load_chronos_config',
                           autospec=True),
                mock.patch('paasta_tools.chronos_tools.get_chronos_client',
                           return_value=self.fake_client,
                           autospec=True),
                mock.patch('paasta_tools.chronos_tools.create_complete_config',
                           return_value=fake_complete_job_config,
                           autospec=True),
                mock.patch('paasta_tools.setup_chronos_job.setup_job',
                           return_value=(expected_status, expected_output),
                           autospec=True),
                mock.patch('paasta_tools.setup_chronos_job.send_event',
                           autospec=True),
                mock.patch(
                    'paasta_tools.setup_chronos_job.load_system_paasta_config',
                    autospec=True),
                mock.patch('sys.exit', autospec=True),
        ) as (
                parse_args_patch,
                load_chronos_config_patch,
                get_client_patch,
                create_complete_config_patch,
                setup_job_patch,
                send_event_patch,
                load_system_paasta_config_patch,
                sys_exit_patch,
        ):
            load_system_paasta_config_patch.return_value.get_cluster = mock.MagicMock(
                return_value=self.fake_cluster)
            setup_chronos_job.main()

            parse_args_patch.assert_called_once_with()
            get_client_patch.assert_called_once_with(
                load_chronos_config_patch.return_value)
            setup_job_patch.assert_called_once_with(
                service=self.fake_service,
                instance=self.fake_instance,
                complete_job_config=fake_complete_job_config,
                client=self.fake_client,
                cluster=self.fake_cluster,
            )
            send_event_patch.assert_called_once_with(
                service=self.fake_service,
                instance=self.fake_instance,
                soa_dir=self.fake_args.soa_dir,
                status=expected_status,
                output=expected_output,
            )
            sys_exit_patch.assert_called_once_with(0)
Пример #4
0
    def test_main_success(self):
        expected_status = 0
        expected_output = 'it_is_finished'
        fake_complete_job_config = {'foo': 'bar'}
        with contextlib.nested(
            mock.patch('paasta_tools.setup_chronos_job.parse_args',
                       return_value=self.fake_args,
                       autospec=True),
            mock.patch('paasta_tools.chronos_tools.load_chronos_config', autospec=True),
            mock.patch('paasta_tools.chronos_tools.get_chronos_client',
                       return_value=self.fake_client,
                       autospec=True),
            mock.patch('paasta_tools.chronos_tools.create_complete_config',
                       return_value=fake_complete_job_config,
                       autospec=True),
            mock.patch('paasta_tools.setup_chronos_job.setup_job',
                       return_value=(expected_status, expected_output),
                       autospec=True),
            mock.patch('paasta_tools.setup_chronos_job.send_event', autospec=True),
            mock.patch('paasta_tools.setup_chronos_job.load_system_paasta_config', autospec=True),
            mock.patch('sys.exit', autospec=True),
        ) as (
            parse_args_patch,
            load_chronos_config_patch,
            get_client_patch,
            create_complete_config_patch,
            setup_job_patch,
            send_event_patch,
            load_system_paasta_config_patch,
            sys_exit_patch,
        ):
            load_system_paasta_config_patch.return_value.get_cluster = mock.MagicMock(return_value=self.fake_cluster)
            setup_chronos_job.main()

            parse_args_patch.assert_called_once_with()
            get_client_patch.assert_called_once_with(load_chronos_config_patch.return_value)
            setup_job_patch.assert_called_once_with(
                service=self.fake_service,
                instance=self.fake_instance,
                complete_job_config=fake_complete_job_config,
                client=self.fake_client,
                cluster=self.fake_cluster,
            )
            send_event_patch.assert_called_once_with(
                service=self.fake_service,
                instance=self.fake_instance,
                soa_dir=self.fake_args.soa_dir,
                status=expected_status,
                output=expected_output,
            )
            sys_exit_patch.assert_called_once_with(0)
Пример #5
0
    def test_main_success(self):
        expected_status = 0
        expected_output = "it_is_finished"
        fake_complete_job_config = {"foo": "bar"}
        with mock.patch(
                "paasta_tools.setup_chronos_job.parse_args",
                return_value=self.fake_args,
                autospec=True,
        ) as parse_args_patch, mock.patch(
                "paasta_tools.chronos_tools.load_chronos_config", autospec=True
        ) as load_chronos_config_patch, mock.patch(
                "paasta_tools.chronos_tools.get_chronos_client",
                return_value=self.fake_client,
                autospec=True,
        ) as get_client_patch, mock.patch(
                "paasta_tools.chronos_tools.create_complete_config",
                return_value=fake_complete_job_config,
                autospec=True,
        ), mock.patch(
                "paasta_tools.setup_chronos_job.setup_job",
                return_value=(expected_status, expected_output),
                autospec=True,
        ) as setup_job_patch, mock.patch(
                "paasta_tools.setup_chronos_job.send_event", autospec=True
        ) as send_event_patch, mock.patch(
                "paasta_tools.setup_chronos_job.load_system_paasta_config",
                autospec=True) as load_system_paasta_config_patch, mock.patch(
                    "sys.exit", autospec=True) as sys_exit_patch:
            load_system_paasta_config_patch.return_value.get_cluster = mock.MagicMock(
                return_value=self.fake_cluster)
            setup_chronos_job.main()

            parse_args_patch.assert_called_once_with()
            get_client_patch.assert_called_once_with(
                load_chronos_config_patch.return_value)
            setup_job_patch.assert_called_once_with(
                service=self.fake_service,
                instance=self.fake_instance,
                complete_job_config=fake_complete_job_config,
                client=self.fake_client,
                cluster=self.fake_cluster,
            )
            send_event_patch.assert_called_once_with(
                service=self.fake_service,
                instance=self.fake_instance,
                soa_dir=self.fake_args.soa_dir,
                status=expected_status,
                output=expected_output,
            )
            sys_exit_patch.assert_called_once_with(0)
Пример #6
0
 def test_main_bad_chronos_job_config_notifies_user(self):
     with contextlib.nested(
             mock.patch('paasta_tools.setup_chronos_job.parse_args',
                        return_value=self.fake_args,
                        autospec=True),
             mock.patch('paasta_tools.chronos_tools.load_chronos_config',
                        autospec=True),
             mock.patch('paasta_tools.chronos_tools.get_chronos_client',
                        return_value=self.fake_client,
                        autospec=True),
             mock.patch('paasta_tools.chronos_tools.create_complete_config',
                        autospec=True,
                        side_effect=chronos_tools.UnknownChronosJobError(
                            'test bad configuration')),
             mock.patch('paasta_tools.setup_chronos_job.setup_job',
                        return_value=(0, 'it_is_finished'),
                        autospec=True),
             mock.patch(
                 'paasta_tools.setup_chronos_job.load_system_paasta_config',
                 autospec=True),
             mock.patch('paasta_tools.setup_chronos_job.send_event',
                        autospec=True),
     ) as (
             parse_args_patch,
             load_chronos_config_patch,
             get_client_patch,
             load_chronos_job_config_patch,
             setup_job_patch,
             load_system_paasta_config_patch,
             send_event_patch,
     ):
         load_system_paasta_config_patch.return_value.get_cluster = mock.MagicMock(
             return_value=self.fake_cluster)
         with raises(SystemExit) as excinfo:
             setup_chronos_job.main()
         assert excinfo.value.code == 0
         expected_error_msg = (
             "Could not read chronos configuration file for %s in cluster %s\nError was: test bad configuration"
             % (compose_job_id(self.fake_service,
                               self.fake_instance), self.fake_cluster))
         send_event_patch.assert_called_once_with(
             service=self.fake_service,
             instance=self.fake_instance,
             soa_dir=self.fake_args.soa_dir,
             status=Status.CRITICAL,
             output=expected_error_msg)
Пример #7
0
 def test_main_bad_chronos_job_config_notifies_user(self):
     with mock.patch(
             "paasta_tools.setup_chronos_job.parse_args",
             return_value=self.fake_args,
             autospec=True,
     ), mock.patch(
             "paasta_tools.chronos_tools.load_chronos_config", autospec=True
     ), mock.patch(
             "paasta_tools.chronos_tools.get_chronos_client",
             return_value=self.fake_client,
             autospec=True,
     ), mock.patch(
             "paasta_tools.chronos_tools.create_complete_config",
             autospec=True,
             side_effect=NoConfigurationForServiceError(
                 "test bad configuration"),
     ), mock.patch(
             "paasta_tools.setup_chronos_job.setup_job",
             return_value=(0, "it_is_finished"),
             autospec=True,
     ), mock.patch(
             "paasta_tools.setup_chronos_job.load_system_paasta_config",
             autospec=True) as load_system_paasta_config_patch, mock.patch(
                 "paasta_tools.setup_chronos_job.send_event",
                 autospec=True) as send_event_patch:
         load_system_paasta_config_patch.return_value.get_cluster = mock.MagicMock(
             return_value=self.fake_cluster)
         with raises(SystemExit) as excinfo:
             setup_chronos_job.main()
         assert excinfo.value.code == 0
         expected_error_msg = (
             "Could not read chronos configuration file for %s in cluster %s\nError was: test bad configuration"
             % (
                 compose_job_id(self.fake_service, self.fake_instance),
                 self.fake_cluster,
             ))
         send_event_patch.assert_called_once_with(
             service=self.fake_service,
             instance=self.fake_instance,
             soa_dir=self.fake_args.soa_dir,
             status=Status.CRITICAL,
             output=expected_error_msg,
         )
Пример #8
0
 def test_main_bad_chronos_job_config_notifies_user(self):
     with contextlib.nested(
         mock.patch('paasta_tools.setup_chronos_job.parse_args',
                    return_value=self.fake_args,
                    autospec=True),
         mock.patch('paasta_tools.chronos_tools.load_chronos_config', autospec=True),
         mock.patch('paasta_tools.chronos_tools.get_chronos_client',
                    return_value=self.fake_client,
                    autospec=True),
         mock.patch('paasta_tools.chronos_tools.create_complete_config',
                    autospec=True,
                    side_effect=chronos_tools.UnknownChronosJobError('test bad configuration')),
         mock.patch('paasta_tools.setup_chronos_job.setup_job',
                    return_value=(0, 'it_is_finished'),
                    autospec=True),
         mock.patch('paasta_tools.setup_chronos_job.load_system_paasta_config', autospec=True),
         mock.patch('paasta_tools.setup_chronos_job.send_event', autospec=True),
     ) as (
         parse_args_patch,
         load_chronos_config_patch,
         get_client_patch,
         load_chronos_job_config_patch,
         setup_job_patch,
         load_system_paasta_config_patch,
         send_event_patch,
     ):
         load_system_paasta_config_patch.return_value.get_cluster = mock.MagicMock(return_value=self.fake_cluster)
         with raises(SystemExit) as excinfo:
             setup_chronos_job.main()
         assert excinfo.value.code == 0
         expected_error_msg = (
             "Could not read chronos configuration file for %s in cluster %s\nError was: test bad configuration"
             % (compose_job_id(self.fake_service, self.fake_instance), self.fake_cluster)
         )
         send_event_patch.assert_called_once_with(
             service=self.fake_service,
             instance=self.fake_instance,
             soa_dir=self.fake_args.soa_dir,
             status=Status.CRITICAL,
             output=expected_error_msg
         )