Skip to content

Commit

Permalink
Redsigned test script tests/test_domainmgr.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
sadov committed Feb 24, 2020
1 parent 4a2c940 commit 8274270
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 45 deletions.
2 changes: 1 addition & 1 deletion tests/run_local_eve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ echo "and Serial Number"
echo "$sn"
echo "in zedcloud.zededa.net"
echo "You can connect to node via ssh"
echo "sudo ssh -p $ssh_port 127.0.0.1"
echo "sudo ssh -p $ssh_port localhost"
echo "Or via telnet:"
echo "telnet localhost $telnet_port"
while true; do
Expand Down
128 changes: 84 additions & 44 deletions tests/test_domainmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,96 @@
from pexpect import *
import json

if len(sys.argv) < 2:
print("Usage: %s port [app-name]" % sys.argv[0])
sys.exit()

eve=spawn('ssh -o StrictHostKeyChecking=no -p %s localhost' % sys.argv[1], timeout=None)
eve.sendline('')
eve.expect('\(ns: pillar\) (.*):/#')

eve.sendline("cat /var/run/domainmgr.pid")
res = eve.expect(['([0-9]+)\(ns: pillar\) (.*):/#','cat: /var/run/domainmgr.pid: No such file or directory'])
if res == 0:
pid = eve.match.groups()[0].decode('utf-8')
print("domainmgr PID: ", pid)
eve.sendline("kill " + pid)
if res == 1:
print(eve.after.decode('utf-8'))
eve.close()
sys.exit(-1)

eve.expect('\(ns: pillar\) (.*):/#')
eve.sendline('/opt/zededa/bin/domainmgr -c IMGA -d >/tmp/domainmgr.log 2>&1 &')
eve.expect('\(ns: pillar\) (.*):/#')
eve.sendline('tail -f /tmp/domainmgr.log')
eve.expect('tail -f /tmp/domainmgr.log')

while 1:
s = eve.readline().decode('utf-8')

def xl_list(eve):
vms = []
eve.sendline('')
eve.expect('\(ns: pillar\) (.*):/#')
eve.sendline("xl list")
eve.expect("xl list\r\r\n")
eve.expect("Name\s+ID\s+Mem\s+VCPUs\s+State\s+Time\(s\)\r\r\n")
while 1:
res = eve.expect(["(\S+)\s+\S*\s+\S*\s+\S*\s+(\S*)\s+(\S*)\r\r\n",'\(ns: pillar\) (.*):/#'])
if res == 0:
name = eve.match.groups()[0].decode('utf-8')
if name != "Domain-0":
state = eve.match.groups()[1].decode('utf-8')
time = eve.match.groups()[2].decode('utf-8')
vms.append({"name":name, "state":state, "time":time})
else:
return vms


def connect(port):
eve=spawn('ssh -o StrictHostKeyChecking=no -p %s localhost' % port, timeout=None)
eve.sendline('')
eve.expect('\(ns: pillar\) (.*):/#')

return eve

def setup_log(eve):
eve.sendline("cat /var/run/domainmgr.pid")
res = eve.expect(['([0-9]+)\(ns: pillar\) (.*):/#','cat: /var/run/domainmgr.pid: No such file or directory'])
if res == 0:
pid = eve.match.groups()[0].decode('utf-8')
print("domainmgr PID: ", pid)
eve.sendline("kill " + pid)
if res == 1:
print(eve.after.decode('utf-8'))
eve.close()
sys.exit(-1)

eve.expect('\(ns: pillar\) (.*):/#')
eve.sendline('/opt/zededa/bin/domainmgr -c IMGA -d >/tmp/domainmgr.log 2>&1 &')
eve.expect('\(ns: pillar\) (.*):/#')
eve.sendline('tail -f /tmp/domainmgr.log')
eve.expect('tail -f /tmp/domainmgr.log')

def log_json(data):
try:
#print(s)
j=json.loads(s)
if j["file"] == "/pillar/pubsub/publish.go:288":
t=j['time']
j=json.loads("{" + j['msg'].split(" val {")[1])
#print(j.keys())
if 'DisplayName' in j.keys():
if len(j['LastErr']):
out = "(%-30s) %s Activated: %s Error: '%s' (%s)" % (t, j['DisplayName'], j['Activated'], j['LastErr'], j['LastErrTime'])
else:
out = "(%-30s) %s Activated: %s" % (t, j['DisplayName'], j['Activated'])
if len(sys.argv) >=3:
if j["DisplayName"] == sys.argv[2]:
print(out)
else:
print(out)
j=json.loads(data)
func = j["func"].split('/')[-1]
if j["file"].find("/pillar/cmd/domainmgr/domainmgr.go") == 0 and func in funcs.keys():
msg = j["msg"]
time = j['time']
out = funcs[func](func, msg, time)
return(out)
except json.JSONDecodeError:
pass
#print("JSONDecodeError:", sys.exc_info())
#s = eve.readline().decode('utf-8')
#print(s)
return(None)
except:
print("ERR: '%s'" % s)
print(sys.exc_info())
sys.exit()

def info(name, msg, time):
return("(%-30s) %s: %s" % (time, name, msg))

funcs = {
"domainmgr.handleCreate": info,
"domainmgr.doActivate": info,
"domainmgr.doActivateTail": info,
"domainmgr.doInactivate": info,
"domainmgr.DomainDestroy": info,
"domainmgr.handleDelete": info,
"domainmgr.handleModify": info,
"domainmgr.xlDomid": info
}

if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: %s port [app-name]" % sys.argv[0])
sys.exit()

eve = connect(sys.argv[1])
setup_log(eve)
evesh = connect(sys.argv[1])

while 1:
s = log_json(eve.readline().decode('utf-8'))
if s:
print(s)
vms = xl_list(evesh)
print("xl list: %s" % vms)

0 comments on commit 8274270

Please sign in to comment.