def akimpersonate(user): """Acquire an AFS token for authenticated access without Kerberos.""" if not user: raise AssertionError("User name is required") aklog = get_var('AKLOG') cell = get_var('AFS_CELL') realm = get_var('KRB_REALM') keytab = get_var('KRB_AFS_KEYTAB') principal = get_principal(user, realm) cmd = "%s -d -c %s -k %s -keytab %s -principal %s" % (aklog, cell, realm, keytab, principal) rc, out, err = run_program(cmd) if rc: raise AssertionError("aklog failed: '%s'; exit code = %d" % (cmd, rc))
def login_with_password(user, password): """Acquire a Kerberos ticket and AFS token with a password.""" if not user: raise AssertionError("user is required") if not password: raise AssertionError("password is required") klog_krb5 = get_var('KLOG_KRB5') cell = get_var('AFS_CELL') realm = get_var('KRB_REALM') cmd = "%s -principal %s -password %s -cell %s -k %s" % ( klog_krb5, user, password, cell, realm) rc, out, err = run_program(cmd) if rc: raise AssertionError("klog.krb5 failed: '%s'; exit code = %d" % (cmd, rc))
def logout(self): """Release the AFS token.""" if not get_bool('AFS_AKIMPERSONATE'): kdestroy = get_var('KDESTROY') krb5cc = "/tmp/afsrobot.krb5cc" cmd = "KRB5CCNAME=%s %s" % (krb5cc, kdestroy) rc, out, err = run_program(cmd) if rc: raise AssertionError("kdestroy failed: '%s'; exit code = %d" % (cmd, rc)) unlog = get_var('UNLOG') rc, out, err = run_program(unlog) if rc: raise AssertionError("unlog failed: '%s'; exit code = %d" % (unlog, rc))
def pag_shell(self, script): """Run a command in the pagsh and returns the output.""" PAGSH = get_var('PAGSH') logger.info("running %s" % (PAGSH, )) logger.debug("script=%s" % (script, )) if not PY2: script = script.encode('ascii') pagsh = subprocess.Popen(PAGSH, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (output, error) = pagsh.communicate(input=script) code = pagsh.wait() if code == 0: logger.debug("stdin=%s" % (script, )) logger.debug("code=%d" % (code, )) logger.debug("stdout=%s" % (output, )) logger.debug("stderr=%s" % (error, )) else: logger.info("stdin=%s" % (script, )) logger.info("code=%d" % (code, )) logger.info("stdout=%s" % (output, )) logger.info("stderr=%s" % (error, )) raise AssertionError("Failed to run pagsh!") if not PY2: output = output.decode('ascii') return output
def vos(*args): rc,out,err = run_program([get_var('VOS')] + list(args)) if rc != 0: lines = err.splitlines() if len(lines) > 0 and lines[0] == "VLDB: no such entry": raise NoSuchEntryError() else: raise CommandFailed('vos', err) return out
def vos(*args): rc, out, err = run_program([get_var('VOS')] + list(args)) if rc != 0: for line in err.splitlines(): if "VLDB: no such entry" in line: raise NoSuchEntryError(args) if "does not exist" in line: raise NoSuchEntryError(args) raise CommandFailed('vos', args, err) return out
def get_crash_count(): count = 0 last = "" filename = "%s/BosLog" % get_var('AFS_LOGS_DIR') log = open(filename, "r") for line in log.readlines(): if 'core dumped' in line: last = line count += 1 log.close() return (count, last)
def login_with_keytab(user, keytab): """Acquire an AFS token for authenticated access with Kerberos.""" if not user: raise ValueError("User name is required.") if not keytab: raise ValueError("keytab is required.") kinit = get_var('KINIT') aklog = get_var('AKLOG') cell = get_var('AFS_CELL') realm = get_var('KRB_REALM') principal = get_principal(user, realm) logger.info("keytab: " + keytab) if not os.path.exists(keytab): raise AssertionError("Keytab file '%s' is missing." % keytab) krb5cc = "/tmp/afsrobot.krb5cc" cmd = "KRB5CCNAME=%s %s -5 -k -t %s %s" % (krb5cc, kinit, keytab, principal) rc, out, err = run_program(cmd) if rc: raise AssertionError("kinit failed: '%s'; exit code = %d" % (cmd, rc)) cmd = "KRB5CCNAME=%s %s -d -c %s -k %s" % (krb5cc, aklog, cell, realm) rc, out, err = run_program(cmd) if rc: raise AssertionError("kinit failed: '%s'; exit code = %d" % (cmd, rc))
def fs(*args): rc,out,err = run_program([get_var('FS')] + list(args)) if rc != 0: raise CommandFailed('fs', err) return out
def rxdebug(*args): rc,out,err = run_program([get_var('RXDEBUG')] + list(args)) if rc != 0: raise CommandFailed('rxdebug', err) return out
def fs(*args): rc, out, err = run_program([get_var('FS')] + list(args)) if rc != 0: raise CommandFailed('fs', args, err) return out
def rxdebug(*args): rc, out, err = run_program([get_var('RXDEBUG')] + list(args)) if rc != 0: raise CommandFailed('rxdebug', args, err) return out
def crash_check(self): """Fails if a server process crash was detected.""" before = get_var('CRASH_COUNT') (after, last) = get_crash_count() if after != before: raise AssertionError("Server crash detected! %s" % last)