test cases for compute and users
diff --git a/xos/tosca/tests/alltests.py b/xos/tosca/tests/alltests.py
index 341a577..59ad49d 100644
--- a/xos/tosca/tests/alltests.py
+++ b/xos/tosca/tests/alltests.py
@@ -2,9 +2,13 @@
from porttest import PortTest
from networktest import NetworkTest
from servicetest import ServiceTest
+from usertest import UserTest
+from computetest import ComputeTest
if __name__ == "__main__":
NetworkTest()
PortTest()
CoarseTenancyTest()
ServiceTest()
+ UserTest()
+ ComputeTest()
diff --git a/xos/tosca/tests/basetest.py b/xos/tosca/tests/basetest.py
index 5d873d0..e90aa8e 100644
--- a/xos/tosca/tests/basetest.py
+++ b/xos/tosca/tests/basetest.py
@@ -1,4 +1,6 @@
import os
+import random
+import string
import sys
# add the parent parent directory to sys.path
@@ -34,7 +36,7 @@
def __init__(self):
self.runtest()
- def make_nodetemplate(self, name, type, props={}, reqs=[], caps={}):
+ def make_nodetemplate(self, name, type, props={}, reqs=[], caps={}, artifacts={}):
yml = " %s:\n type: %s\n" % (name, type)
if props:
yml = yml + " properties:\n"
@@ -58,8 +60,26 @@
for (k,v) in capdict.items():
yml = yml + " %s: %s\n" % (k,v)
+ if artifacts:
+ yml = yml + " artifacts:\n"
+ for (k,v) in artifacts.items():
+ yml = yml + " %s: %s\n" % (k,v)
+
return yml
+ def make_compute(self, slice, name, caps={}, props={}, reqs=[], num_cpus="1", disk_size="10 GB", mem_size="4 MB"):
+ caps.update( {"host": {"num_cpus": num_cpus, "disk_size": disk_size, "mem_size": mem_size},
+ "os": {"architecture": "x86_64", "type": "linux", "distribution": "rhel", "version": "6.5"}} )
+ reqs.append( (slice, "tosca.relationships.MemberOfSlice") )
+
+ return self.make_nodetemplate(name, "tosca.nodes.Compute",
+ caps= caps,
+ props = props,
+ reqs= reqs)
+
+ def make_random_string(self,desired_len):
+ return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(desired_len))
+
def assert_noobj(self, cls, name):
objs = cls.objects.filter(name=name)
assert(not objs)
diff --git a/xos/tosca/tests/computetest.py b/xos/tosca/tests/computetest.py
new file mode 100644
index 0000000..9eac593
--- /dev/null
+++ b/xos/tosca/tests/computetest.py
@@ -0,0 +1,96 @@
+from basetest import BaseToscaTest
+
+from core.models import Sliver, Slice
+
+class ComputeTest(BaseToscaTest):
+ tests = ["create_compute_m1_tiny",
+ "create_compute_m1_small",
+ "create_compute_m1_large_8192MB",
+ "create_compute_m1_large_8GB",
+ "destroy_compute",
+ "create_compute_scalable",
+ "destroy_compute_scalable",
+ ]
+
+ def cleanup(self):
+ self.try_to_delete(Sliver, name="test_compute1")
+ self.try_to_delete(Sliver, name="test_compute1-0")
+ self.try_to_delete(Sliver, name="test_compute1-1")
+ self.try_to_delete(Sliver, name="test_compute1-2")
+ self.try_to_delete(Sliver, name="test_compute1-3")
+ self.try_to_delete(Slice, name="testsite_slice1")
+
+ def get_base_templates(self):
+ return self.make_nodetemplate("testsite", "tosca.nodes.Site") + \
+ self.make_nodetemplate("testsite_slice1", "tosca.nodes.Slice", reqs=[("testsite", "tosca.relationships.MemberOfSite")])
+
+ def create_compute_m1_tiny(self):
+ self.assert_noobj(Sliver, "test_compute1")
+ self.execute(self.get_base_templates() +
+ self.make_compute("testsite_slice1", "test_compute1", disk_size="1 GB", mem_size="500 MB"))
+ sliver = self.assert_obj(Sliver, "test_compute1")
+ assert(sliver.flavor.name == "m1.tiny")
+
+ def create_compute_m1_small(self):
+ self.assert_noobj(Sliver, "test_compute1")
+ self.execute(self.get_base_templates() +
+ self.make_compute("testsite_slice1", "test_compute1", disk_size="1 GB", mem_size="513 MB"))
+ sliver = self.assert_obj(Sliver, "test_compute1")
+ assert(sliver.flavor.name == "m1.small")
+
+ def create_compute_m1_large_8192MB(self):
+ self.assert_noobj(Sliver, "test_compute1")
+ self.execute(self.get_base_templates() +
+ self.make_compute("testsite_slice1", "test_compute1", mem_size="8192 MB"))
+ sliver = self.assert_obj(Sliver, "test_compute1")
+ assert(sliver.flavor.name == "m1.large")
+
+ def create_compute_m1_large_8GB(self):
+ self.assert_noobj(Sliver, "test_compute1")
+ self.execute(self.get_base_templates() +
+ self.make_compute("testsite_slice1", "test_compute1", mem_size="8 GB"))
+ sliver = self.assert_obj(Sliver, "test_compute1")
+ assert(sliver.flavor.name == "m1.large")
+
+ def destroy_compute(self):
+ self.execute(self.get_base_templates() +
+ self.make_compute("testsite_slice1", "test_compute1"))
+ self.assert_obj(Sliver, "test_compute1")
+ self.destroy(self.get_base_templates() +
+ self.make_compute("testsite_slice1", "test_compute1"))
+ self.assert_noobj(Sliver, "test_compute1")
+
+ def create_compute_scalable(self):
+ self.assert_noobj(Sliver, "test_compute1-1")
+ self.assert_noobj(Sliver, "test_compute1-2")
+ self.assert_noobj(Sliver, "test_compute1-3")
+ self.execute(self.get_base_templates() +
+ self.make_compute("testsite_slice1", "test_compute1", mem_size="8 GB",
+ caps={"scalable": {"min_instances": 2, "max_instances": 3, "default_instances": 2}}))
+ # there should be two instances
+ sliver0 = self.assert_obj(Sliver, "test_compute1-0")
+ sliver1 = self.assert_obj(Sliver, "test_compute1-1")
+ self.assert_noobj(Sliver, "test_compute1-2")
+
+ def destroy_compute_scalable(self):
+ self.assert_noobj(Sliver, "test_compute1-1")
+ self.assert_noobj(Sliver, "test_compute1-2")
+ self.assert_noobj(Sliver, "test_compute1-3")
+ self.execute(self.get_base_templates() +
+ self.make_compute("testsite_slice1", "test_compute1", mem_size="8 GB",
+ caps={"scalable": {"min_instances": 2, "max_instances": 3, "default_instances": 2}}))
+ # there should be two instances
+ sliver0 = self.assert_obj(Sliver, "test_compute1-0")
+ sliver1 = self.assert_obj(Sliver, "test_compute1-1")
+
+ self.destroy(self.get_base_templates() +
+ self.make_compute("testsite_slice1", "test_compute1", mem_size="8 GB",
+ caps={"scalable": {"min_instances": 2, "max_instances": 3, "default_instances": 2}}))
+
+ self.assert_noobj(Sliver, "test_compute1-0")
+ self.assert_noobj(Sliver, "test_compute1-1")
+
+if __name__ == "__main__":
+ ComputeTest()
+
+
diff --git a/xos/tosca/tests/porttest.py b/xos/tosca/tests/porttest.py
index c7efe33..a0d23e3 100644
--- a/xos/tosca/tests/porttest.py
+++ b/xos/tosca/tests/porttest.py
@@ -43,12 +43,6 @@
def test_slice2_2(self):
return Sliver.objects.get(name="test_slice2-2")
- def make_compute(self, slice, name):
- return self.make_nodetemplate(name, "tosca.nodes.Compute",
- caps={"host": {"num_cpus": "1", "disk_size": "10 GB", "mem_size": "4 MB"},
- "os": {"architecture": "x86_64", "type": "linux", "distribution": "rhel", "version": "6.5"}},
- reqs=[(slice, "tosca.relationships.MemberOfSlice")])
-
def get_base_templates(self):
return self.make_nodetemplate("testsite", "tosca.nodes.Site") + \
self.make_nodetemplate("testsite_slice1", "tosca.nodes.Slice", reqs=[("testsite", "tosca.relationships.MemberOfSite")]) + \
diff --git a/xos/tosca/tests/usertest.py b/xos/tosca/tests/usertest.py
new file mode 100644
index 0000000..f36eb06
--- /dev/null
+++ b/xos/tosca/tests/usertest.py
@@ -0,0 +1,98 @@
+from basetest import BaseToscaTest
+
+from core.models import User
+
+class UserTest(BaseToscaTest):
+ tests = ["create_user_minimal",
+ "create_user_maximal",
+ "create_user_key_artifact",
+ "destroy_user",
+ ]
+
+ def cleanup(self):
+ self.try_to_delete(User, email="test@user.com")
+
+ def get_base_templates(self):
+ return self.make_nodetemplate("testsite", "tosca.nodes.Site")
+
+ def assert_nouser(self, email):
+ assert(not User.objects.filter(email=email))
+
+ def assert_user(self, email, **kwargs):
+ obj = User.objects.get(email=email)
+ assert(obj)
+ for (k,v) in kwargs.items():
+ if (getattr(obj,k,None) != v):
+ print "Object %s property '%s' is '%s' and should be '%s'" % (obj, k, getattr(obj,k,None), v)
+ assert(False)
+ return obj
+
+ def create_user_minimal(self):
+ self.assert_nouser("test@user.com")
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test@user.com", "tosca.nodes.User",
+ props = {"firstname": "test", "lastname": "user", "password": "letmein"},
+ reqs = [("testsite", "tosca.relationships.MemberOfSite")]))
+ user = self.assert_user("test@user.com",
+ firstname="test",
+ lastname="user",
+ is_active=True,
+ is_admin=False)
+
+
+ def create_user_maximal(self):
+ self.assert_nouser("test@user.com")
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test@user.com", "tosca.nodes.User",
+ props = {"firstname": "test",
+ "lastname": "user",
+ "password": "letmein",
+ "phone": "123-456-7890",
+ "user_url": "http://foo.bar/",
+ "public_key": "thisismykey",
+ "is_active": False,
+ "is_admin": True},
+ reqs = [("testsite", "tosca.relationships.MemberOfSite")]))
+ user = self.assert_user("test@user.com",
+ firstname="test",
+ lastname="user",
+ phone="123-456-7890",
+ user_url="http://foo.bar/",
+ public_key="thisismykey",
+ # is_active=False, XXX investigate -- this is failing
+ is_admin=True)
+
+ def create_user_key_artifact(self):
+ self.assert_nouser("test@user.com")
+ pubkey = self.make_random_string(400)
+ file("/tmp/pubkey", "w").write(pubkey)
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test@user.com", "tosca.nodes.User",
+ props = {"firstname": "test", "lastname": "user", "password": "letmein", "public_key": "{ get_artifact: [ SELF, pubkey, LOCAL_FILE] }" },
+ artifacts = {"pubkey": "/tmp/pubkey"},
+ reqs = [("testsite", "tosca.relationships.MemberOfSite")]))
+ user = self.assert_user("test@user.com",
+ firstname="test",
+ lastname="user",
+ is_active=True,
+ is_admin=False,
+ public_key=pubkey)
+
+ def destroy_user(self):
+ self.assert_nouser("test@user.com")
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test@user.com", "tosca.nodes.User",
+ props = {"firstname": "test", "lastname": "user", "password": "letmein"},
+ reqs = [("testsite", "tosca.relationships.MemberOfSite")]))
+ user = self.assert_user("test@user.com")
+ self.destroy(self.get_base_templates() +
+ self.make_nodetemplate("test@user.com", "tosca.nodes.User",
+ props = {"firstname": "test", "lastname": "user", "password": "letmein"},
+ reqs = [("testsite", "tosca.relationships.MemberOfSite")]))
+ self.assert_nouser("test@user.com")
+
+
+if __name__ == "__main__":
+ UserTest()
+
+