def test_restore_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, 'ls {}'.format(path), method=subprocess.call).and_return(0)

    flexmock(utils).should_receive('ssh').with_args(re.compile('^192.*'),
      keyname, 'monit summary', method=subprocess.check_output).\
      and_return('summary output')
    flexmock(utils).should_receive('monit_status').and_return('Not monitored')

    flexmock(utils).should_receive('ssh').with_args(re.compile('^192.*'),
      keyname, re.compile('^find.* -exec rm .*'))
    flexmock(utils).should_receive('ssh').with_args(re.compile('^192.*'),
      keyname, re.compile('^tar xf .*'))
    flexmock(utils).should_receive('ssh').with_args(re.compile('^192.*'),
      keyname, re.compile('^monit start .*'))
    flexmock(utils).should_receive('ssh').with_args(
      re.compile('^192.*'), keyname, re.compile('^chown -R cassandra /opt/.*'))

    cassandra_backup.restore_data(path, keyname)
Example #2
0
    def test_restore_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,
            'ls {}'.format(path),
            method=subprocess.call).and_return(0)

        flexmock(utils).should_receive('ssh').with_args(re.compile('^192.*'),
          keyname, 'monit summary', method=subprocess.check_output).\
          and_return('summary output')
        status_outputs = (['Not monitored'] * len(db_ips)) +\
                         (['Running'] * len(db_ips))
        flexmock(utils).should_receive('monit_status').and_return(*status_outputs)\
          .one_by_one()

        flexmock(utils).should_receive('ssh').with_args(
            re.compile('^192.*'), keyname, re.compile('^find.* -exec rm .*'))
        flexmock(utils).should_receive('ssh').with_args(
            re.compile('^192.*'), keyname, re.compile('^tar xf .*'))
        flexmock(utils).should_receive('ssh').with_args(
            re.compile('^192.*'), keyname, re.compile('^monit start .*'))
        flexmock(utils).should_receive('ssh').with_args(
            re.compile('^192.*'), keyname,
            re.compile('^chown -R cassandra /opt/.*'))

        cassandra_backup.restore_data(path, keyname)
  def test_restore_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(appscale_utils).should_receive('ssh').with_args(
      re.compile('^192.*'), keyname, 'ls {}'.format(path),
      method=subprocess.call).and_return(0)

    flexmock(appscale_utils).should_receive('ssh').with_args(
      re.compile('^192.*'), keyname, 'monit summary',
      method=subprocess.check_output).and_return('summary output')
    status_outputs = (['Not monitored'] * len(db_ips)) +\
                     (['Running'] * len(db_ips))
    flexmock(utils).should_receive('monit_status').\
      and_return(*status_outputs).one_by_one()

    flexmock(appscale_utils).should_receive('ssh').with_args(
      re.compile('^192.*'), keyname, re.compile('^find.* -exec rm .*'))
    flexmock(appscale_utils).should_receive('ssh').with_args(
      re.compile('^192.*'), keyname, re.compile('^tar xf .*'))
    flexmock(appscale_utils).should_receive('ssh').with_args(
      re.compile('^192.*'), keyname, re.compile('^monit start .*'),
      subprocess.call)
    flexmock(appscale_utils).should_receive('ssh').with_args(
      re.compile('^192.*'), keyname, re.compile('^monit start .*'))
    flexmock(appscale_utils).should_receive('ssh').with_args(
      re.compile('^192.*'), keyname, re.compile('^chown -R cassandra /opt/.*'))
    flexmock(rebalance).should_receive('get_status').and_return(
      [{'state': 'UN'} for _ in db_ips])

    flexmock(time).should_receive('sleep')

    flexmock(appscale_utils).should_receive('ssh').with_args(
      re.compile('^192.*'), keyname, re.compile('.*nodetool status'),
      method=subprocess.check_output).\
      and_return('UN 192.168.33.10\nUN 192.168.33.11')

    cassandra_backup.restore_data(path, keyname)
Example #4
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)