def test_restore_data(self):
        # Test for unsupported storage backend.
        flexmock(backup_recovery_constants.StorageTypes()).should_receive("get_storage_types").and_return([])
        self.assertEquals(False, cassandra_backup.restore_data("blah", ""))

        # Test with failure to download backup from GCS.
        flexmock(gcs_helper).should_receive("download_from_bucket").and_return(False)
        self.assertEquals(False, cassandra_backup.restore_data(backup_recovery_constants.StorageTypes.GCS, ""))

        # Test with successful download from GCS and failure to shut down Cassandra.
        flexmock(gcs_helper).should_receive("download_from_bucket").and_return(True)
        flexmock(shut_down_cassandra).should_receive("run").and_return(False)
        flexmock(backup_recovery_helper).should_receive("delete_local_backup_file").and_return()
        self.assertEquals(False, cassandra_backup.restore_data(backup_recovery_constants.StorageTypes.GCS, ""))

        # Test with successful Cassandra shutdown and failure to untar.
        flexmock(gcs_helper).should_receive("download_from_bucket").and_return(True)
        flexmock(shut_down_cassandra).should_receive("run").and_return(True)
        flexmock(cassandra_backup).should_receive("remove_old_data").and_return()
        flexmock(backup_recovery_helper).should_receive("untar_backup_files").and_raise(backup_exceptions.BRException)
        flexmock(start_cassandra).should_receive("run").and_return()
        flexmock(backup_recovery_helper).should_receive("delete_local_backup_file").and_return()
        self.assertEquals(False, cassandra_backup.restore_data(backup_recovery_constants.StorageTypes.GCS, ""))

        # Test normal case for GCS.
        flexmock(gcs_helper).should_receive("download_from_bucket").and_return(True)
        flexmock(shut_down_cassandra).should_receive("run").and_return(True)
        flexmock(cassandra_backup).should_receive("remove_old_data").and_return()
        flexmock(backup_recovery_helper).should_receive("untar_backup_files").and_return()
        flexmock(cassandra_backup).should_receive("restore_snapshots").and_return()
        flexmock(start_cassandra).should_receive("run").and_return()
        flexmock(cassandra_backup).should_receive("refresh_data").and_return()
        flexmock(cassandra_backup).should_receive("clear_old_snapshots").and_return()
        flexmock(backup_recovery_helper).should_receive("delete_local_backup_file").and_return()
        self.assertEquals(True, cassandra_backup.restore_data(backup_recovery_constants.StorageTypes.GCS, ""))

        # Test with failure to shut down Cassandra in local mode.
        flexmock(shut_down_cassandra).should_receive("run").and_return(False)
        self.assertEquals(False, cassandra_backup.restore_data("", ""))

        # Test with successful Cassandra shutdown and failure to untar in local
        # mode.
        flexmock(shut_down_cassandra).should_receive("run").and_return(True)
        flexmock(cassandra_backup).should_receive("remove_old_data").and_return()
        flexmock(backup_recovery_helper).should_receive("untar_backup_files").and_raise(backup_exceptions.BRException)
        flexmock(start_cassandra).should_receive("run").and_return()
        self.assertEquals(False, cassandra_backup.restore_data("", ""))

        # Test normal case in local mode.
        flexmock(shut_down_cassandra).should_receive("run").and_return(True)
        flexmock(cassandra_backup).should_receive("remove_old_data").and_return()
        flexmock(backup_recovery_helper).should_receive("untar_backup_files").and_return()
        flexmock(cassandra_backup).should_receive("restore_snapshots").and_return()
        flexmock(start_cassandra).should_receive("run").and_return()
        flexmock(cassandra_backup).should_receive("refresh_data").and_return()
        flexmock(cassandra_backup).should_receive("clear_old_snapshots").and_return()
        self.assertEquals(True, cassandra_backup.restore_data("", ""))
Beispiel #2
0
  def do_cassandra_restore(self, storage, path):
    """ Top level function for doing Cassandra restores.

    Args:
      storage: A str, one of the StorageTypes class members.
      path: A str, the name of the backup file to be created.
    Returns:
      A JSON string to return to the client.
    """
    success = True
    reason = "success"
    try:
      logging.info("Acquiring lock for db restore.")
      self.__cassandra_backup_lock.acquire(True)
      logging.info("Got the lock for db restore.")
      if not cassandra_backup.restore_data(storage, path):
        return self.bad_request("DB restore failed!")
      else:
        logging.info("Successful db restore!")
    except backup_exceptions.BRException, exception:
      logging.error("Unable to complete db restore: {0}".format(exception))
      success = False
      reason = str(exception)
Beispiel #3
0
    def do_cassandra_restore(self, storage, path):
        """ Top level function for doing Cassandra restores.

    Args:
      storage: A str, one of the StorageTypes class members.
      path: A str, the name of the backup file to be created.
    Returns:
      A JSON string to return to the client.
    """
        success = True
        reason = "success"
        try:
            logging.info("Acquiring lock for db restore.")
            self.__cassandra_backup_lock.acquire(True)
            logging.info("Got the lock for db restore.")
            if not cassandra_backup.restore_data(storage, path):
                return self.bad_request("DB restore failed!")
            else:
                logging.info("Successful db restore!")
        except backup_exceptions.BRException, exception:
            logging.error(
                "Unable to complete db restore: {0}".format(exception))
            success = False
            reason = str(exception)
Beispiel #4
0
    def test_restore_data(self):
        # Test for unsupported storage backend.
        flexmock(backup_recovery_constants.StorageTypes()).\
          should_receive("get_storage_types").and_return([])
        self.assertEquals(False, cassandra_backup.restore_data('blah', ''))

        # Test with failure to download backup from GCS.
        flexmock(gcs_helper).should_receive('download_from_bucket').and_return(
            False)
        self.assertEquals(
            False,
            cassandra_backup.restore_data(
                backup_recovery_constants.StorageTypes.GCS, ''))

        # Test with successful download from GCS and failure to shut down Cassandra.
        flexmock(gcs_helper).should_receive('download_from_bucket').and_return(
            True)
        flexmock(shut_down_cassandra).should_receive('run').and_return(False)
        flexmock(cassandra_backup).should_receive('delete_local_backup_file').\
          and_return()
        self.assertEquals(
            False,
            cassandra_backup.restore_data(
                backup_recovery_constants.StorageTypes.GCS, ''))

        # Test with successful Cassandra shutdown and failure to untar.
        flexmock(gcs_helper).should_receive('download_from_bucket').and_return(
            True)
        flexmock(shut_down_cassandra).should_receive('run').and_return(True)
        flexmock(cassandra_backup).should_receive(
            'remove_old_data').and_return()
        flexmock(cassandra_backup).should_receive(
            'untar_backup_files').and_raise(backup_exceptions.BRException)
        flexmock(start_cassandra).should_receive('run').and_return()
        flexmock(cassandra_backup).should_receive('delete_local_backup_file').\
          and_return()
        self.assertEquals(
            False,
            cassandra_backup.restore_data(
                backup_recovery_constants.StorageTypes.GCS, ''))

        # Test normal case for GCS.
        flexmock(gcs_helper).should_receive('download_from_bucket').and_return(
            True)
        flexmock(shut_down_cassandra).should_receive('run').and_return(True)
        flexmock(cassandra_backup).should_receive(
            'remove_old_data').and_return()
        flexmock(cassandra_backup).should_receive(
            'untar_backup_files').and_return()
        flexmock(cassandra_backup).should_receive(
            'restore_snapshots').and_return()
        flexmock(start_cassandra).should_receive('run').and_return()
        flexmock(cassandra_backup).should_receive('refresh_data').and_return()
        flexmock(cassandra_backup).should_receive('clear_old_snapshots').\
          and_return()
        flexmock(cassandra_backup).should_receive('delete_local_backup_file').\
          and_return()
        self.assertEquals(
            True,
            cassandra_backup.restore_data(
                backup_recovery_constants.StorageTypes.GCS, ''))

        # Test with failure to shut down Cassandra in local mode.
        flexmock(shut_down_cassandra).should_receive('run').and_return(False)
        self.assertEquals(False, cassandra_backup.restore_data('', ''))

        # Test with successful Cassandra shutdown and failure to untar in local
        # mode.
        flexmock(shut_down_cassandra).should_receive('run').and_return(True)
        flexmock(cassandra_backup).should_receive(
            'remove_old_data').and_return()
        flexmock(cassandra_backup).should_receive(
            'untar_backup_files').and_raise(backup_exceptions.BRException)
        flexmock(start_cassandra).should_receive('run').and_return()
        self.assertEquals(False, cassandra_backup.restore_data('', ''))

        # Test normal case in local mode.
        flexmock(shut_down_cassandra).should_receive('run').and_return(True)
        flexmock(cassandra_backup).should_receive(
            'remove_old_data').and_return()
        flexmock(cassandra_backup).should_receive(
            'untar_backup_files').and_return()
        flexmock(cassandra_backup).should_receive(
            'restore_snapshots').and_return()
        flexmock(start_cassandra).should_receive('run').and_return()
        flexmock(cassandra_backup).should_receive('refresh_data').and_return()
        flexmock(cassandra_backup).should_receive('clear_old_snapshots').\
          and_return()
        self.assertEquals(True, cassandra_backup.restore_data('', ''))