Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

executable file 83 lines (71 sloc) 2.214 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
#!/usr/bin/env python

import pexpect
import sys
import os
import uuid

tst_image_name = os.environ['NIMBUS_TEST_IMAGE']
tst_image_src = os.environ['NIMBUS_SOURCE_TEST_IMAGE']
to=int(os.environ["NIMBUS_TEST_TIMEOUT"])
cc_home=os.environ['CLOUD_CLIENT_HOME']
nh=os.environ['NIMBUS_HOME']
logfile = sys.stdout
common_image = str(uuid.uuid1()).replace("-", "")

src_file = tst_image_src
sfa = src_file.split("/")
image_name = sfa[len(sfa) - 1]
size=os.path.getsize(src_file)

cmd = "%s/bin/nimbus-public-image %s %s" % (nh, src_file, common_image)
(x, rc)=pexpect.run(cmd, withexitstatus=1, logfile=logfile)
if rc != 0:
    print "failed create the public image"
    sys.exit(1)

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

cmd = "%s/bin/cloud-client.sh --save --handle %s" % (cc_home, handle)
print cmd
(x, rc)=pexpect.run(cmd, withexitstatus=1, logfile=logfile, timeout=to)
print x
if rc != 0:
    print "failed to terminate"
    sys.exit(1)

# check the various params
cmd = "%s/bin/cloud-client.sh --list" % (cc_home)
child = pexpect.spawn (cmd, timeout=to, maxread=20000, logfile=logfile)
rc = child.expect (common_image)
if rc != 0:
    print "%s not found in the list" % (common_image)
    sys.exit(1)

line = child.readline()
print line
line = child.readline()
print line
token = "Size: "
ndx = line.find(token)
if ndx < 0:
    print "%s not found in line %s" % (token, line)
    sys.exit(1)
line = line[ndx + len(token):]
ndx = line.find(" ")
if ndx < 0:
    print "%s ndx space not found %s" % (token, line)
    sys.exit(1)
line = line[0:ndx].strip()

show_size = int(line)

if show_size != size:
    print "%d != %d" % (show_size, size)
    sys.exit(1)


cmd = "%s/bin/nimbus-public-image --delete %s" % (nh, common_image)
(x, rc)=pexpect.run(cmd, withexitstatus=1, logfile=logfile)
if rc != 0:
    print "failed create the public image"
    sys.exit(1)
sys.exit(0)
Something went wrong with that request. Please try again.