blob: 7174331e83ec8fa5e1adfe2ca3fe0b10921d3e1b [file] [log] [blame]
Scott Bakerab23fa92013-08-25 16:53:49 -07001import os
2import json
3import sys
4import time
5
Scott Bakereaeabad2015-02-09 11:18:46 -08006sys.path.append("/opt/xos")
Scott Bakerab23fa92013-08-25 16:53:49 -07007
8os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
9from openstack.manager import OpenStackManager
10from core.models import Slice, Sliver, ServiceClass, Reservation, Tag, Network, User, Node, Image, Deployment, Site, NetworkTemplate, NetworkSlice
11
12TEST_SITE_NAME = "Princeton University"
13TEST_USER_EMAIL = "sbaker@planetstack.org"
14TEST_IMAGE_NAME = "Fedora 16 LXC rev 1.3"
15TEST_NODE_NAME = "viccidev3.cs.princeton.edu"
16TEST_DEPLOYMENT_NAME = "VICCI"
17
18def fail(msg):
19 print msg
20 sys.exit(-1)
21
22def fail_unless(condition, msg):
23 if not condition:
24 fail(msg)
25
26class PlanetStackTest:
27 def __init__(self):
28 self.objs_saved = []
29 self.counter = 0
30
31 def setup(self):
32 self.manager = OpenStackManager()
33
34 print "getting test site"
35 self.testSite = Site.objects.get(name=TEST_SITE_NAME)
36
37 print "getting test user"
38 self.testUser = User.objects.get(email=TEST_USER_EMAIL)
39
40 print "getting test image"
41 self.testImage = Image.objects.get(name=TEST_IMAGE_NAME)
42
43 print "getting test node"
44 self.testNode = Node.objects.get(name=TEST_NODE_NAME)
45
46 print "getting test deployment"
47 self.testDeployment = Deployment.objects.get(name=TEST_DEPLOYMENT_NAME)
48
49 def save_and_wait_for_enacted(self, x, nonempty_fields=[]):
50 print "saving", x.__class__.__name__, str(x)
51 x.save()
52 self.objs_saved.append(x)
53 print " waiting for", str(x), "to be enacted"
54 tStart = time.time()
55 while True:
56 new_x = x.__class__.objects.get(id=x.id)
57 if (new_x.enacted != None) and (new_x.enacted >= new_x.updated):
58 print " ", str(x), "has been enacted"
59 break
60 time.sleep(5)
61
62 if nonempty_fields:
63 print " waiting for", ", ".join(nonempty_fields), "to be nonempty"
64 while True:
65 new_x = x.__class__.objects.get(id=x.id)
66 keep_waiting=False
67 for field in nonempty_fields:
68 if not getattr(new_x, field, None):
69 keep_waiting=True
70 if not keep_waiting:
71 break
72
73 print " saved and enacted in %d seconds" % int(time.time() - tStart)
74
75 return new_x
76
77 def make_slice_name(self):
78 self.counter = self.counter +1
79 return "test-" + str(time.time()) + "." + str(self.counter)
80
81 def get_network_template(self,name):
82 template = NetworkTemplate.objects.get(name=name)
83 return template
84
85 def cleanup(self):
86 print "cleaning up"
87 print "press return"
88 sys.stdin.readline()
89 for obj in self.objs_saved:
90 try:
91 print " deleting", str(obj)
92 obj.delete()
93 except:
94 print "failed to delete", str(obj)