Esempio n. 1
0
    def test_backup_data(self):
        db_ips = ['192.168.33.10', '192.168.33.11']
        keyname = 'key1'
        path = '~/cassandra_backup.tar'

        flexmock(appscale_info).should_receive('get_db_ips').and_return(db_ips)

        flexmock(utils).should_receive('ssh').with_args(
            re.compile('^192.*'), keyname, re.compile('.*snapshot$'))

        flexmock(utils).should_receive('ssh').with_args(db_ips[0], keyname,
          re.compile('.*du -s.*'), method=subprocess.check_output).\
          and_return('200 file1\n500 file2\n')
        flexmock(utils).should_receive('ssh').with_args(db_ips[1], keyname,
          re.compile('.*du -s.*'), method=subprocess.check_output).\
          and_return('900 file1\n100 file2\n')

        # Assume first DB machine does not have enough space.
        flexmock(utils).should_receive('ssh').with_args(db_ips[0], keyname,
          re.compile('^df .*'), method=subprocess.check_output).\
          and_return('headers\ndisk blocks used 100 etc')
        self.assertRaises(backup_exceptions.BRException,
                          cassandra_backup.backup_data, path, keyname)

        flexmock(utils).should_receive('ssh').with_args(db_ips[0], keyname,
          re.compile('^df .*'), method=subprocess.check_output).\
          and_return('headers\ndisk blocks used 2000 etc')
        flexmock(utils).should_receive('ssh').with_args(db_ips[1], keyname,
          re.compile('^df .*'), method=subprocess.check_output).\
          and_return('headers\ndisk blocks used 3000 etc')

        flexmock(utils).should_receive('ssh').with_args(
            re.compile('^192.*'), keyname, re.compile('.*tar --transform.*'))
        cassandra_backup.backup_data(path, keyname)
  def test_backup_data(self):
    db_ips = ['192.168.33.10', '192.168.33.11']
    keyname = 'key1'
    path = '~/cassandra_backup.tar'

    flexmock(appscale_info).should_receive('get_db_ips').and_return(db_ips)

    flexmock(utils).should_receive('ssh').with_args(re.compile('^192.*'),
      keyname, re.compile('.*snapshot$'))

    flexmock(utils).should_receive('ssh').with_args(db_ips[0], keyname,
      re.compile('.*du -s.*'), method=subprocess.check_output).\
      and_return('200 file1\n500 file2\n')
    flexmock(utils).should_receive('ssh').with_args(db_ips[1], keyname,
      re.compile('.*du -s.*'), method=subprocess.check_output).\
      and_return('900 file1\n100 file2\n')

    # Assume first DB machine does not have enough space.
    flexmock(utils).should_receive('ssh').with_args(db_ips[0], keyname,
      re.compile('^df .*'), method=subprocess.check_output).\
      and_return('headers\ndisk blocks used 100 etc')
    self.assertRaises(backup_exceptions.BRException,
      cassandra_backup.backup_data, path, keyname)

    flexmock(utils).should_receive('ssh').with_args(db_ips[0], keyname,
      re.compile('^df .*'), method=subprocess.check_output).\
      and_return('headers\ndisk blocks used 2000 etc')
    flexmock(utils).should_receive('ssh').with_args(db_ips[1], keyname,
      re.compile('^df .*'), method=subprocess.check_output).\
      and_return('headers\ndisk blocks used 3000 etc')

    flexmock(utils).should_receive('ssh').with_args(re.compile('^192.*'),
      keyname, re.compile('.*tar --transform.*'))
    cassandra_backup.backup_data(path, keyname)
Esempio n. 3
0
  def do_cassandra_backup(self, storage, path):
    """ Top level function for doing Cassandra backups.

    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 backup.")
      self.__cassandra_backup_lock.acquire(True)
      logging.info("Got the lock for db backup.")
      if not cassandra_backup.backup_data(storage, path):
        return self.bad_request("DB backup failed!")
      else:
        logging.info("Successful db backup!")
    except backup_exceptions.BRException, exception:
      logging.error("Unable to complete db backup: {0}".format(exception))
      success = False
      reason = str(exception)