예제 #1
0
    def test_backup_secrets_cm_failure_configmap(self, Command):
        test_class = None
        with mock.patch('accord.models.Accord.setup_backup_directory'):
            with mock.patch('accord.models.Accord.remove_signal_restore_file'):
                with mock.patch('accord.models.Accord.test_sync_to_backup'):
                    test_class = models.Accord(
                        self.setup_args_backup_default())

        test_class.backup_directory = '.'
        test_class.secret_files = {}
        test_class.config_maps = {'default': ['test-cm']}

        Command().side_effect = sh.ErrorReturnCode_1('kubectl',
                                                     ''.encode('utf-8'),
                                                     ''.encode('utf-8'))
        with mock.patch('accord.models.Accord.get_all_secrets'):
            try:
                process.backup_secrets_config_maps(test_class)
            except exceptions.ConfigMapNotFound:
                pass
            except Exception:
                assert False, 'Exception should have been caught'

        if not os.path.exists('secrets'):
            assert False, 'Did not automatically create the directory'

        if not os.path.exists('secrets/test-cm.yaml'):
            assert False, 'Did not create the secret'
예제 #2
0
    def test_backup_secrets_cm(self, Command):
        test_class = None
        with mock.patch('accord.models.Accord.setup_backup_directory'):
            with mock.patch('accord.models.Accord.remove_signal_restore_file'):
                with mock.patch('accord.models.Accord.test_sync_to_backup'):
                    test_class = models.Accord(
                        self.setup_args_backup_default())

        test_class.backup_directory = '.'
        test_class.secret_files = {'default': ['test-secret']}
        test_class.config_maps = {'default': ['test-cm']}
        with mock.patch('accord.models.Accord.get_all_secrets'):
            process.backup_secrets_config_maps(test_class)

        if not os.path.exists('secrets'):
            assert False, 'Did not automatically create the directory'

        if not os.path.exists('secrets/test-secret.yaml'):
            assert False, 'Did not create the secret'

        if not os.path.exists('secrets/test-cm.yaml'):
            assert False, 'Did not create the secret'