# -*- coding: utf-8 -*- """Module allowing to set, check and clear a token on a host""" import os import socket import ssh #Path of the token file token_file_path = "/tmp/token.txt" def get(): user = os.getenv("USER") hostname = socket.gethostname() return user + "@" + hostname def set(user, host): print "Setting token on", host, "...{" command = "echo " + get() + " > " + token_file_path ssh.call(user, host, command) print "}" check(user, host) def clear(user, host): print "Clearing token on", host, "...{" command = "rm " + token_file_path ssh.call(user, host, command) print "}" def check(user, host): print "Checking token on", host, "...{" command = "cat " + token_file_path expected = get() actual = ssh.check_output(user, host, command).rstrip("\r\n") info = "The expected token (" + expected + ") is not found on " + \ user + "@" + host + ":" + token_file_path + " (" + actual + ")." assert expected == actual, info print "}"