tuntest.py 8.79 KB
Newer Older
1 2 3
#! /usr/bin/env python
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2008-2009 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# 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 re
import xmlrpclib
import urllib
from xml.sax.handler import ContentHandler
import xml.sax
import string
29
from M2Crypto import X509
30

31
execfile( "test-common.py" )
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

class findElement(ContentHandler):
    name       = None
    value      = None
    string     = None
    attributes = None
    data       = None
    
    def __init__(self, name, stuff):
        self.name = name
        xml.sax.parseString(stuff, self)
        pass
    def startElement(self, name, attrs):
        if self.name == name:
            self.data = []
            self.attributes = attrs
        elif self.data != None:
            self.data.append("<" + name + ">")
            pass
        pass
    def characters(self, content):
        if self.data != None:
            self.data.append(content)
            pass
        pass
    def endElement(self, name):
        if self.name == name:
            self.value  = string.join(self.data, "");
            self.string = "<" + name + ">" + self.value + "</" + name + ">"
            self.data   = None;
        elif self.data != None:
            self.data.append("</" + name + ">")
            pass
        pass
    pass

#
# Get a credential for myself, that allows me to do things at the SA.
#
params = {}
params["uuid"] = "0b2eb97e-ed30-11db-96cb-001143e453fe"
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 slice.
#
params = {}
params["credential"] = mycredential
params["type"]       = "Slice"
87
params["hrn"]        = SLICENAME
88 89 90 91 92
rval,response = do_method("sa", "Resolve", params)
if rval:
    #
    # Create a slice. 
    #
93
    print "Creating new slice called " + SLICENAME
94 95 96
    params = {}
    params["credential"] = mycredential
    params["type"]       = "Slice"
97
    params["hrn"]        = SLICENAME
98 99 100 101 102 103 104 105 106 107 108
    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.
    #
109
    print "Asking for slice credential for " + SLICENAME
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    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

#
# Ask the clearinghouse for a list of component managers. 
#
params = {}
params["credential"] = mycredential
129
rval,response = do_method("ch", "ListComponents", params)
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
if rval:
    Fatal("Could not get a list of components from the ClearingHouse")
    pass
components = response["value"];
url1 = components[0]["url"]
url2 = components[1]["url"]

#
# Get a ticket for a node on a CM.
#
rspec1 = "<rspec xmlns=\"http://protogeni.net/resources/rspec/0.1\"> " +\
        " <node uuid=\"*\" " +\
        "       nickname=\"geni1\" "+\
        "       virtualization_type=\"emulab-vnode\"> " +\
        " </node>" +\
        "</rspec>"

params = {}
params["credential"] = myslice
params["rspec"]      = rspec1
rval,response = do_method(None, "GetTicket", params, URI=url1)
if rval:
    Fatal("Could not get ticket")
    pass
ticket1 = response["value"]
print "Got a ticket from CM1"

#
# Get the uuid of the node assigned so we can specify it in the tunnel.
#
ticket_element = findElement("ticket", ticket1)
node_element   = findElement("node", str(ticket_element.string))
uuid_element   = findElement("uuid", str(node_element.string))
node1_uuid     = uuid_element.value

#
# Get a ticket for a node on another CM.
#
rspec2 = "<rspec xmlns=\"http://protogeni.net/resources/rspec/0.1\"> " +\
        " <node uuid=\"*\" " +\
        "       nickname=\"geni1\" "+\
        "       virtualization_type=\"emulab-vnode\"> " +\
        " </node>" +\
        "</rspec>"

params = {}
params["credential"] = myslice
params["rspec"]      = rspec2
rval,response = do_method(None, "GetTicket", params, URI=url2)
if rval:
    Fatal("Could not get ticket")
    pass
ticket2 = response["value"]
print "Got a ticket from CM2"

#
# Get the uuid of the node assigned so we can specify it in the tunnel.
#
ticket_element = findElement("ticket", ticket2)
node_element   = findElement("node", str(ticket_element.string))
uuid_element   = findElement("uuid", str(node_element.string))
node2_uuid     = uuid_element.value

#
# Create the slivers.
#
params = {}
params["ticket"]   = ticket1
rval,response = do_method(None, "RedeemTicket", params, url1)
if rval:
    Fatal("Could not redeem ticket on CM1")
    pass
sliver1 = response["value"]
print "Created a sliver CM1"

params = {}
params["ticket"]   = ticket2
rval,response = do_method(None, "RedeemTicket", params, url2)
if rval:
    Fatal("Could not redeem ticket on CM2")
    pass
sliver2 = response["value"]
print "Created a sliver on CM2"

#
# Now add the tunnel part since we have the uuids for the two nodes.
#
rspec1 = "<rspec xmlns=\"http://protogeni.net/resources/rspec/0.1\"> " +\
        " <node uuid=\"" + node1_uuid + "\" " +\
        "       nickname=\"geni1\" "+\
        "       virtualization_type=\"emulab-vnode\"> " +\
        " </node>" +\
        " <link name=\"link0\" nickname=\"link0\" link_type=\"tunnel\"> " +\
        "  <linkendpoints nickname=\"destination_interface\" " +\
        "            tunnel_ip=\"192.168.1.1\" " +\
        "            node_nickname=\"geni1\" " +\
        "            node_uuid=\"" + node1_uuid + "\" /> " +\
        "  <linkendpoints nickname=\"source_interface\" " +\
        "            tunnel_ip=\"192.168.1.2\" " +\
        "            node_nickname=\"geni2\" " +\
        "            node_uuid=\"" + node2_uuid + "\" /> " +\
        " </link> " +\
        "</rspec>"

params = {}
params["credential"] = sliver1
params["rspec"]      = rspec1
rval,response = do_method(None, "UpdateSliver", params, url1)
if rval:
    Fatal("Could not update sliver on CM1")
    pass
print "Updated sliver on CM1 with tunnel stuff"

#
# And again for the second sliver.
#
rspec2 = "<rspec xmlns=\"http://protogeni.net/resources/rspec/0.1\"> " +\
        " <node uuid=\"" + node2_uuid + "\" " +\
        "       nickname=\"geni2\" "+\
        "       virtualization_type=\"emulab-vnode\"> " +\
        " </node>" +\
        " <link name=\"link0\" nickname=\"link0\" link_type=\"tunnel\"> " +\
        "  <linkendpoints nickname=\"destination_interface\" " +\
        "            tunnel_ip=\"192.168.1.1\" " +\
        "            node_nickname=\"geni1\" " +\
        "            node_uuid=\"" + node1_uuid + "\" /> " +\
        "  <linkendpoints nickname=\"source_interface\" " +\
        "            tunnel_ip=\"192.168.1.2\" " +\
        "            node_nickname=\"geni2\" " +\
        "            node_uuid=\"" + node2_uuid + "\" /> " +\
        " </link> " +\
        "</rspec>"

params = {}
params["credential"] = sliver2
params["rspec"]      = rspec2
rval,response = do_method(None, "UpdateSliver", params, url2)
if rval:
    Fatal("Could not update sliver on CM2")
    pass
print "Updated sliver on CM2 with tunnel stuff"

#
# Start the slivers.
#
params = {}
params["credential"] = sliver1
rval,response = do_method(None, "StartSliver", params, url1)
if rval:
    Fatal("Could not start sliver on CM1")
    pass

params = {}
params["credential"] = sliver2
rval,response = do_method(None, "StartSliver", params, url2)
if rval:
    Fatal("Could not start sliver on CM2")
    pass

print "Slivers have been started, waiting for input to delete it"
print "You should be able to log into the sliver after a little bit"
sys.stdin.readline();

#
# Delete the slivers.
#
print "Deleting sliver1 now"
params = {}
params["credential"] = sliver1
rval,response = do_method(None, "DeleteSliver", params, url1)
if rval:
    Fatal("Could not delete sliver on CM1")
    pass
print "Sliver1 has been deleted"

print "Deleting sliver2 now"
params = {}
params["credential"] = sliver2
rval,response = do_method(None, "DeleteSliver", params, url2)
if rval:
    Fatal("Could not delete sliver on CM2")
    pass
print "Sliver2 has been deleted"