Commit 871d35cd authored by Leigh Stoller's avatar Leigh Stoller

Test scripts for links and tunnels using new wildcard stuff. Makes

writing test scripts a lot easier.
parent 7ad17706
#! /usr/bin/env python
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004, 2008 University of Utah and the Flux Group.
# All rights reserved.
#
# Permission to use, copy, modify and distribute this software is hereby
# granted provided that (1) source code retains these copyright, permission,
# and disclaimer notices, and (2) redistributions including binaries
# reproduce the notices in supporting documentation.
#
# THE UNIVERSITY OF UTAH ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
# CONDITION. THE UNIVERSITY OF UTAH DISCLAIMS ANY LIABILITY OF ANY KIND
# FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#
#
#
import sys
import pwd
import getopt
import os
import time
import re
import xmlrpclib
# Default server
XMLRPC_SERVER = "boss"
SERVER_PATH = ":443/protogeni/xmlrpc/"
HOME = os.environ["HOME"]
# Path to my certificate
CERTIFICATE = HOME + "/.ssl/encrypted.pem"
# Got tired of typing this over and over so I stuck it in a file.
PASSPHRASEFILE = HOME + "/.ssl/password"
passphrase = ""
# Debugging output.
debug = 0
impotent = 0
def Fatal(message):
print message
sys.exit(1)
return
def PassPhraseCB(v, prompt1='Enter passphrase:', prompt2='Verify passphrase:'):
passphrase = open(PASSPHRASEFILE).readline()
passphrase = passphrase.strip()
return passphrase
#
# Call the rpc server.
#
def do_method(module, method, params, URI=None):
if debug:
print module + " " + method + " " + str(params);
pass
if not os.path.exists(CERTIFICATE):
return Fatal("error: missing emulab certificate: %s\n" % CERTIFICATE)
from M2Crypto.m2xmlrpclib import SSL_Transport
from M2Crypto import SSL
if URI == None:
URI = "https://" + XMLRPC_SERVER + SERVER_PATH + module
else:
URI = URI + "/" + module
pass
ctx = SSL.Context("sslv23")
ctx.load_cert(CERTIFICATE, CERTIFICATE, PassPhraseCB)
ctx.set_verify(SSL.verify_none, 16)
ctx.set_allow_unknown_ca(0)
# Get a handle on the server,
server = xmlrpclib.ServerProxy(URI, SSL_Transport(ctx), verbose=0)
# Get a pointer to the function we want to invoke.
meth = getattr(server, method)
meth_args = [ params ]
#
# Make the call.
#
try:
response = apply(meth, meth_args)
pass
except xmlrpclib.Fault, e:
print e.faultString
return (-1, None)
#
# Parse the Response, which is a Dictionary. See EmulabResponse in the
# emulabclient.py module. The XML standard converts classes to a plain
# Dictionary, hence the code below.
#
if len(response["output"]):
print response["output"],
print ": ",
pass
rval = response["code"]
#
# If the code indicates failure, look for a "value". Use that as the
# return value instead of the code.
#
if rval:
if response["value"]:
rval = response["value"]
pass
pass
return (rval, response)
#
# Get a credential for myself, that allows me to do things at the SA.
#
params = {}
rval,response = do_method("sa", "GetCredential", params)
if rval:
Fatal("Could not get my credential")
pass
mycredential = response["value"]
print "Got my SA credential"
#print str(mycredential);
#
# Lookup my ssh keys.
#
params = {}
params["credential"] = mycredential
rval,response = do_method("sa", "GetKeys", params)
if rval:
Fatal("Could not get my keys")
pass
mykeys = response["value"]
#print str(mykeys);
#
# Lookup slice.
#
params = {}
params["credential"] = mycredential
params["type"] = "Slice"
params["hrn"] = "mytestslice"
rval,response = do_method("sa", "Resolve", params)
if rval:
#
# Create a slice.
#
print "Creating new slice called mytestslice";
params = {}
params["credential"] = mycredential
params["type"] = "Slice"
params["hrn"] = "mytestslice"
rval,response = do_method("sa", "Register", params)
if rval:
Fatal("Could not create new slice")
pass
myslice = response["value"]
print "New slice created"
pass
else:
#
# Get the slice credential.
#
print "Asking for slice credential for mytestslice";
myslice = response["value"]
myuuid = myslice["uuid"]
params = {}
params["credential"] = mycredential
params["type"] = "Slice"
params["uuid"] = myuuid
rval,response = do_method("sa", "GetCredential", params)
if rval:
Fatal("Could not get Slice credential")
pass
myslice = response["value"]
print "Got the slice credential"
pass
#
# Get a ticket. We do not have a real resource discovery tool yet, so
# as a debugging aid, you can wildcard the uuid, and the CM will find
# a free node and fill it in.
#
print "Asking for a ticket from the local CM"
rspec = "<rspec xmlns=\"http://protogeni.net/resources/rspec/0.1\"> " +\
" <node uuid=\"*\" " +\
" nickname=\"geni1\" "+\
" virtualization_type=\"emulab-vnode\"> " +\
" </node>" +\
" <node uuid=\"*\" " +\
" nickname=\"geni2\" "+\
" virtualization_type=\"emulab-vnode\"> " +\
" </node>" +\
" <link name=\"link0\" nickname=\"link0\"> " +\
" <linkendpoints nickname=\"destination_interface\" " +\
" iface_name=\"*\" " +\
" node_nickname=\"geni1\" " +\
" node_uuid=\"*\" /> " +\
" <linkendpoints nickname=\"source_interface\" " +\
" iface_name=\"*\" " +\
" node_nickname=\"geni2\" " +\
" node_uuid=\"*\" /> " +\
" </link> " +\
"</rspec>"
params = {}
params["credential"] = myslice
params["rspec"] = rspec
rval,response = do_method("cm", "GetTicket", params)
if rval:
Fatal("Could not get ticket")
pass
ticket = response["value"]
print "Got a ticket from the CM. Redeeming the ticket ..."
print str(response["output"])
#
# Create the sliver.
#
params = {}
params["ticket"] = ticket
params["keys"] = mykeys
params["impotent"] = impotent
rval,response = do_method("cm", "RedeemTicket", params)
if rval:
Fatal("Could not redeem ticket")
pass
sliver = response["value"]
print "Created the sliver. Starting the sliver ..."
#
# Start the sliver.
#
params = {}
params["credential"] = sliver
params["impotent"] = impotent
rval,response = do_method("cm", "StartSliver", params)
if rval:
Fatal("Could not start sliver")
pass
print "Sliver has been started."
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment