Пример #1
0
    def test_main_restore_start_deployments(self, Command):
        self.setup_temp_file('restore')
        with mock.patch(
                'accord.process.argparse.ArgumentParser.parse_args') as args:
            args.return_value = self.setup_args_restore_default(
                start_deployments=True, directory='')
            with mock.patch('accord.process.cleanup_sessions_deployments'):
                with mock.patch('accord.process.scale_postgres_pod'):
                    with mock.patch(
                            'accord.process.cleanup_and_restore_files'):
                        with mock.patch('accord.process.scale_postgres_pod'):
                            with mock.patch(
                                    'accord.process.restore_postgres_database'
                            ):
                                with mock.patch(
                                        'accord.process.cleanup_postgres_database'
                                ):
                                    with mock.patch(
                                            'accord.process.restoring_files'):
                                        with mock.patch(
                                                'accord.process.restart_pods'):
                                            process.main()

        if os.path.isfile('restore'):
            assert False, 'restore file was not cleaned up'
Пример #2
0
    def test_main_backup_repos_only(self, Command, mock_pathlib):
        with mock.patch(
                'accord.process.argparse.ArgumentParser.parse_args') as args:
            args.return_value = self.setup_args_backup_default(repos_only=True,
                                                               directory='')
            with mock.patch('accord.process.backup_repository_db'):
                process.main()

        if not os.path.isfile('restore'):
            assert False, 'restore file was not added'
Пример #3
0
    def test_main_restore_repos(self, Command):
        self.setup_temp_file('restore')
        with mock.patch('accord.process.Accord.setup_backup_directory'):
            with mock.patch('accord.process.argparse.ArgumentParser.parse_args'
                            ) as args:
                args.return_value = self.setup_args_restore_default(
                    repos_only=True, directory='')

                with mock.patch('accord.process.restore_repo_db'):
                    process.main()

        if os.path.isfile('restore'):
            assert False, 'restore file was not cleaned up'
Пример #4
0
 def test_main_restore_use_file_no_restore(self, Command):
     self.setup_temp_file('restore')
     with mock.patch(
             'accord.process.argparse.ArgumentParser.parse_args') as args:
         args.return_value = self.setup_args_restore_default(
             restore_file='test.tar.gz', no_config=True, directory='')
         with mock.patch('accord.models.Accord.extract_tar_archive'):
             with mock.patch(
                     'accord.models.Accord.check_for_restore') as check:
                 check.return_value = False
                 try:
                     process.main()
                     assert False, 'Exception should have been thrown'
                 except exceptions.RestoreSignal:
                     pass
                 except Exception:
                     assert False, 'Did not catch proper exception'
Пример #5
0
    def test_main_backup_sync_files(self, mock_pathlib, Command):
        with mock.patch(
                'accord.process.argparse.ArgumentParser.parse_args') as args:
            args.return_value = self.setup_args_backup_default(
                repos_only=True,
                directory='',
                sync_user='******',
                sync_node='1.2.3.4',
                sync=True)
            with mock.patch('accord.models.Accord.run_su_command'):
                with mock.patch('accord.process.backup_repository_db'):
                    with mock.patch('accord.process.sync_repositories'):
                        with mock.patch('accord.process.sync_files'):
                            process.main()

        if not os.path.isfile('restore'):
            assert False, 'restore file was not added'
Пример #6
0
    def test_main_backup(self, mock_pathlib, Command):
        with mock.patch(
                'accord.process.argparse.ArgumentParser.parse_args') as args:
            args.return_value = self.setup_args_backup_default(directory='',
                                                               archive=True)
            with mock.patch('accord.process.backup_postgres_database'):
                with mock.patch('accord.process.sync_repositories'):
                    with mock.patch('accord.process.file_backup_restore'):
                        with mock.patch(
                                'accord.process.backup_secrets_config_maps'):
                            with mock.patch(
                                    'accord.process.sanitize_secrets_config_maps'
                            ):
                                with mock.patch(
                                        'accord.models.Accord.create_tar_archive'
                                ):
                                    process.main()

        if not os.path.isfile('restore'):
            assert False, 'restore file was not added'
Пример #7
0
    def test_main_restore_use_file(self, Command):
        self.setup_temp_file('restore')
        with mock.patch(
                'accord.process.argparse.ArgumentParser.parse_args') as args:
            args.return_value = self.setup_args_restore_default(
                restore_file='test.tar.gz', no_config=True, directory='')
            with mock.patch('accord.models.Accord.extract_tar_archive'):
                with mock.patch('accord.process.cleanup_sessions_deployments'):
                    with mock.patch('accord.process.scale_postgres_pod'):
                        with mock.patch(
                                'accord.process.cleanup_and_restore_files'):
                            with mock.patch(
                                    'accord.process.scale_postgres_pod'):
                                with mock.patch(
                                        'accord.process.restore_postgres_database'
                                ):
                                    with mock.patch('accord.process.cleanup_'
                                                    'postgres_database'):
                                        with mock.patch(
                                                'accord.process.restart_pods'):
                                            process.main()

        if os.path.isfile('restore'):
            assert False, 'restore file was not cleaned up'
Пример #8
0
 def test_main_restore_exception(self, mock_args):
     raise_exception = mock.Mock()
     raise_exception.side_effect = exceptions.RestoreSignal
     with mock.patch('accord.process.Accord', side_effect=raise_exception):
         with self.assertRaises(SystemExit):
             process.main()