示例#1
0
 def setUp(self):
     env = {}
     env['WAL_S3_BUCKET'] = 'batman'
     env['WALE_BACKUP_THRESHOLD_PERCENTAGE'] = 100
     env['WALE_BACKUP_THRESHOLD_MEGABYTES'] = 100
     self.wale_restore = WALERestore("batman",
                                     "master",
                                     "/data",
                                     "host=batman port=5432 user=batman",
                                     env=env)
示例#2
0
 def setUp(self):
     env = {}
     env['WAL_S3_BUCKET'] = 'batman'
     env['WALE_BACKUP_THRESHOLD_PERCENTAGE'] = 100
     env['WALE_BACKUP_THRESHOLD_MEGABYTES'] = 100
     self.wale_restore = WALERestore("batman", "master", "/data", "host=batman port=5432 user=batman", env=env)
示例#3
0
class TestWALERestore(unittest.TestCase):

    def setUp(self):
        env = {}
        env['WAL_S3_BUCKET'] = 'batman'
        env['WALE_BACKUP_THRESHOLD_PERCENTAGE'] = 100
        env['WALE_BACKUP_THRESHOLD_MEGABYTES'] = 100
        self.wale_restore = WALERestore("batman", "master", "/data", "host=batman port=5432 user=batman", env=env)

    def tearDown(self):
        pass

    def test_setup(self):
        self.wale_restore.setup()
        self.assertFalse(self.wale_restore.init_error)

    # have to redefine the class-level os.access mock inside the function
    # since the class-level mock will be applied after the function level one.
    @patch('os.access', return_value=False)
    def test_setup_fail(self, mock_no_access):
        os.access = mock_no_access
        self.wale_restore.setup()
        self.assertTrue(self.wale_restore.init_error)

    # The 3 tests above only differ with the mock function instead of a subprocess call
    # in the first one, subprocess call should return success only for wal-e command,
    # checking the primary use-case of restoring from WAL-E backup.
    # In the second one, we test fallbacks by failing at WAL-E, but succeeding at
    # pg_basebackup.
    # Finally, the last use case is when all subprocess.call fails. resulting in a
    # failure to restore from replica
    @patch('subprocess.call',
           MagicMock(side_effect=lambda *args, **kwargs: 0 if 'wal-e' in args[0] else 1))
    def test_run(self):
        self.wale_restore.setup()
        ret = self.wale_restore.run()
        self.assertEqual(ret, 0)

    @patch('subprocess.call',
           MagicMock(side_effect=lambda *args, **kwargs: 0 if 'pg_basebackup' in args[0] else 1))
    def test_run_fallback(self):
        self.wale_restore.setup()
        ret = self.wale_restore.run()
        self.assertEqual(ret, 0)

    @patch('subprocess.call', MagicMock(return_value=1))
    def test_run_all_fail(self):
        self.wale_restore.setup()
        ret = self.wale_restore.run()
        self.assertEqual(ret, 1)
示例#4
0
class TestWALERestore(unittest.TestCase):
    def setUp(self):
        env = {}
        env['WAL_S3_BUCKET'] = 'batman'
        env['WALE_BACKUP_THRESHOLD_PERCENTAGE'] = 100
        env['WALE_BACKUP_THRESHOLD_MEGABYTES'] = 100
        self.wale_restore = WALERestore("batman",
                                        "master",
                                        "/data",
                                        "host=batman port=5432 user=batman",
                                        env=env)

    def tearDown(self):
        pass

    def test_setup(self):
        self.wale_restore.setup()
        self.assertFalse(self.wale_restore.init_error)

    # have to redefine the class-level os.access mock inside the function
    # since the class-level mock will be applied after the function level one.
    @patch('os.access', return_value=False)
    def test_setup_fail(self, mock_no_access):
        os.access = mock_no_access
        self.wale_restore.setup()
        self.assertTrue(self.wale_restore.init_error)

    # The 3 tests above only differ with the mock function instead of a subprocess call
    # in the first one, subprocess call should return success only for wal-e command,
    # checking the primary use-case of restoring from WAL-E backup.
    # In the second one, we test fallbacks by failing at WAL-E, but succeeding at
    # pg_basebackup.
    # Finally, the last use case is when all subprocess.call fails. resulting in a
    # failure to restore from replica
    @patch(
        'subprocess.call',
        MagicMock(
            side_effect=lambda *args, **kwargs: 0 if 'wal-e' in args[0] else 1)
    )
    def test_run(self):
        self.wale_restore.setup()
        ret = self.wale_restore.run()
        self.assertEqual(ret, 0)

    @patch('subprocess.call',
           MagicMock(side_effect=lambda *args, **kwargs: 0
                     if 'pg_basebackup' in args[0] else 1))
    def test_run_fallback(self):
        self.wale_restore.setup()
        ret = self.wale_restore.run()
        self.assertEqual(ret, 0)

    @patch('subprocess.call', MagicMock(return_value=1))
    def test_run_all_fail(self):
        self.wale_restore.setup()
        ret = self.wale_restore.run()
        self.assertEqual(ret, 1)