示例#1
0
def delete_all_shares():
  '''Clean the slate by deleting all of the shares'''
  share = ''
  path = ''

  shares = []

  share_re = re.compile(r'^ (share) ([0-9]+):(.*)')
  path_re = re.compile(r'^\t(path)=(.*)$')

  ssh = paramiko.SSHClient()
  ssh.load_system_host_keys()
  ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

  host = 'dd'
  command = env.pdshare_ctl + ' list';
  print 'The host is ' + host
  print 'Trying to connect to ' + env.env[host]['address']

  # First find the set of shares to delete
  try:
    ssh.connect(env.env[host]['address'], username=env.env[host]['username'], password=env.env[host]['password'], timeout=300)
  except paramiko.AuthenticationException:
    print 'Authentication failed when connecting to %s' % env.env[host]['address']
    sys.exit(1)
  except:
    print 'Random error connecting to %s' % env.env[host]['address']
    sys.exit(1)

  try:
    stdin, stdout, stderr = ssh.exec_command(command,timeout=300)
  except paramiko.SSHException:
    print 'Cannot execute ' + command + ' on %s' % env.env[host]['address']
    sys.exit(1)

  retval = stdout.channel.recv_exit_status()

  for line in stdout:
    if ' share ' in line:
      m = re.match(share_re, line)
      share = m.group(2)
      print 'found SHARE ' + share,
    elif 'path=' in line:
      m = re.match(path_re, line)
      path = m.group(2)
      print 'with PATH ' + path,
      shares.append({'share':share, 'path':path})

  ssh.close()

  for share in sorted(shares, key=lambda share: share['path'], reverse=True):
    # shares are supposed to be empty before being deleted
    retval = pd.mount('client', env.env['paths']['mount'], 'dd', share['path'])
    if retval == 0:
      retval = pd.run_cmd('client', '/usr/bin/rm -rf ' + env.env['paths']['mount'])
      retval = pd.umount('client', env.env['paths']['mount'])

    command = env.pdshare_ctl + ' remove ' + share['share']
    print command
    retval = pd.run_cmd('dd', command)
    if retval != 0:
      print 'Could not remove share: ' + share['share'] + '\n'
      sys.exit(retval)

  return retval
示例#2
0
def test_mount_root():
  '''Test wrapper on mounting the dd's root on the client'''
  return pd.mount('client', env.env['paths']['mount'], 'dd', '/')