Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 143 lines (120 sloc) 3.946 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
#!/usr/bin/env python

import pexpect
import sys
import os
import re

try:
    node_host = os.environ['NIMBUS_TEST_NODE_HOST']
except:
    node_host = "localhost"

tst_ca = os.environ['NIMBUS_TEST_CA']

to=int(os.environ["NIMBUS_TEST_TIMEOUT"])
tst_image_name = os.environ['NIMBUS_TEST_IMAGE']
tst_image_src = os.environ['NIMBUS_SOURCE_TEST_IMAGE']

cc_home=os.environ['CLOUD_CLIENT_HOME']
nimbus_home=os.environ['NIMBUS_HOME']
nimbus_user=os.environ['NIMBUS_TEST_USER']
logfile = sys.stdout

try:
os.mkdir("%s/history/vm-999" % (cc_home))
except:
print "The directory already exists"
pass

cmd = "%s/bin/nimbus-admin --shutdown --all" % (nimbus_home)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, logfile=logfile, timeout=to)


cmd = "%s/bin/nimbus-list-users %%" % (nimbus_home)
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
print x

cmd = "%s/bin/cloud-client.sh --transfer --sourcefile %s" % (cc_home, tst_image_src)
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)

cmd = "%s/bin/cloud-client.sh --run --name %s --hours .5" % (cc_home, tst_image_name)
child = pexpect.spawn (cmd, timeout=to, maxread=20000, logfile=logfile)
rc = child.expect ('Running:')
if rc != 0:
    print "%s not found in the list" % (tst_image_name)
    sys.exit(1)
handle = child.readline().strip().replace("'", "")
rc = child.expect(pexpect.EOF)
if rc != 0:
    print "run"
    sys.exit(1)

cmd = "%s/bin/nimbus-admin --list --user %s" % (nimbus_home, nimbus_user)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
print x
if rc != 0 or not re.match(".*id\s*?:\s*?\d.*", x):
    print "error"
    sys.exit(1)

cmd = "%s/bin/nimbus-admin --list --dn %s/CN=%s" % (nimbus_home, tst_ca, nimbus_user)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
print x
if rc != 0 or not re.match(".*id\s*?:\s*?\d.*", x):
print "error"
sys.exit(1)

cmd = "%s/bin/nimbus-admin --list --host %s" % (nimbus_home, node_host)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
print x
if rc != 0 or not re.match(".*id\s*?:\s*?\d.*", x):
    print "error"
    sys.exit(1)

cmd = "%s/bin/nimbus-admin --list --gid 1" % (nimbus_home)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
print x
if rc != 0 or not re.match(".*id\s*?:\s*?\d.*", x):
    print "error"
    sys.exit(1)

cmd = "%s/bin/nimbus-admin --list --gname UNLIMITED" % (nimbus_home)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
print x
if rc != 0 or not re.match(".*id\s*?:\s*?\d.*", x):
    print "error"
    sys.exit(1)

cmd = "%s/bin/nimbus-admin --list" % (nimbus_home)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
print x
if rc != 0 or not re.match(".*id\s*?:\s*?\d.*", x):
    print "error"
    sys.exit(1)

cmd = "%s/bin/cloud-client.sh --run --name %s --hours .5" % (cc_home, tst_image_name)
child = pexpect.spawn (cmd, timeout=to, maxread=20000, logfile=logfile)
rc = child.expect ('Running:')
if rc != 0:
    print "%s not found in the list" % (tst_image_name)
    sys.exit(1)
handle = child.readline().strip().replace("'", "")
rc = child.expect(pexpect.EOF)
if rc != 0:
    print "run"
    sys.exit(1)

cmd = "%s/bin/nimbus-admin --nodes" % (nimbus_home)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
print x
if rc != 0:
    print "error"
    sys.exit(1)
if not re.search("node\s*:\s*%s" % (node_host), x):
    print "not showing %s node?" % (node_host)
    sys.exit(1)
if not re.search("id\s*:\s*\d*,\s\d*", x):
    print "not showing two vms on %s node?" % (node_host)
    sys.exit(1)

cmd = "%s/bin/nimbus-admin --batch --shutdown --all" % (nimbus_home)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
print x
if rc != 0:
    print "error"
    sys.exit(1)

cmd = "%s/bin/cloud-client.sh --delete --name %s" % (cc_home, tst_image_name)
(x, rc)=pexpect.run(cmd, withexitstatus=1, timeout=to)
if rc != 0:
    print "error"
    sys.exit(1)

sys.exit(0)
Something went wrong with that request. Please try again.