test cases for coarsetenancy and network
diff --git a/xos/tosca/tests/coarsetenancytest.py b/xos/tosca/tests/coarsetenancytest.py
new file mode 100644
index 0000000..3da288f
--- /dev/null
+++ b/xos/tosca/tests/coarsetenancytest.py
@@ -0,0 +1,49 @@
+from basetest import BaseToscaTest
+
+from core.models import Service, CoarseTenant
+
+class CoarseTenancyTest(BaseToscaTest):
+ tests = ["create_coarsetenant",
+ "update_coarsetenant"]
+
+ def cleanup(self):
+ self.try_to_delete(Service, name="test_svc1")
+ self.try_to_delete(Service, name="test_svc2")
+
+ def create_coarsetenant(self):
+ self.assert_noobj(Service, "test_svc1")
+ self.assert_noobj(Service, "test_svc2")
+ self.execute(self.make_nodetemplate("test_svc1", "tosca.nodes.Service", reqs=[("test_svc2", "tosca.relationships.TenantOfService")]) +
+ self.make_nodetemplate("test_svc2", "tosca.nodes.Service"))
+ svc1 = self.assert_obj(Service, "test_svc1", kind="generic", published=True, enabled=True)
+ svc2 = self.assert_obj(Service, "test_svc2", kind="generic", published=True, enabled=True)
+
+ ct = CoarseTenant.objects.filter(provider_service=svc2, subscriber_service=svc1)
+ assert(ct)
+
+ def update_coarsetenant(self):
+ # first make the services without the coarse tenancy relationship
+ self.assert_noobj(Service, "test_svc1")
+ self.assert_noobj(Service, "test_svc2")
+ self.execute(self.make_nodetemplate("test_svc1", "tosca.nodes.Service") +
+ self.make_nodetemplate("test_svc2", "tosca.nodes.Service"))
+ svc1 = self.assert_obj(Service, "test_svc1", kind="generic", published=True, enabled=True)
+ svc2 = self.assert_obj(Service, "test_svc2", kind="generic", published=True, enabled=True)
+ ct = CoarseTenant.objects.filter(provider_service=svc2, subscriber_service=svc1)
+ assert(not ct)
+
+ # now add the relationship
+ self.execute(self.make_nodetemplate("test_svc1", "tosca.nodes.Service", reqs=[("test_svc2", "tosca.relationships.TenantOfService")])+
+ self.make_nodetemplate("test_svc2", "tosca.nodes.Service"))
+ updated_svc1 = self.assert_obj(Service, "test_svc1", kind="generic", published=True, enabled=True)
+
+ assert(svc1.id == updated_svc1.id)
+
+ ct = CoarseTenant.objects.filter(provider_service=svc2, subscriber_service=svc1)
+ assert(ct)
+
+
+if __name__ == "__main__":
+ CoarseTenancyTest()
+
+
diff --git a/xos/tosca/tests/networktest.py b/xos/tosca/tests/networktest.py
new file mode 100644
index 0000000..98f3490
--- /dev/null
+++ b/xos/tosca/tests/networktest.py
@@ -0,0 +1,136 @@
+from basetest import BaseToscaTest
+
+from core.models import Network, Slice, NetworkTemplate, NetworkSlice
+
+class NetworkTest(BaseToscaTest):
+ tests = ["create_network_minimal",
+ "create_network_maximal",
+ "create_network_connected",
+ "create_network_connected_two_slices",
+ "update_network_labels"]
+
+ def cleanup(self):
+ self.try_to_delete(Network, name="test_net")
+ self.try_to_delete(Slice, name="testsite_slice1")
+ self.try_to_delete(Slice, name="testsite_slice2")
+
+ @property
+ def slice1(self):
+ return Slice.objects.get(name="testsite_slice1")
+
+ @property
+ def slice2(self):
+ return Slice.objects.get(name="testsite_slice2")
+
+ @property
+ def private(Self):
+ return NetworkTemplate.objects.get(name="Private")
+
+
+ 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")]) + \
+ self.make_nodetemplate("testsite_slice2", "tosca.nodes.Slice", reqs=[("testsite", "tosca.relationships.MemberOfSite")]) + \
+ self.make_nodetemplate("Private", "tosca.nodes.NetworkTemplate")
+
+ def create_network_minimal(self):
+ self.assert_noobj(Network, "test_net")
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test_net", "tosca.nodes.network.Network",
+ reqs=[("testsite_slice1", "tosca.relationships.MemberOfSlice"),
+ ("Private", "tosca.relationships.UsesNetworkTemplate")]))
+ net=self.assert_obj(Network, "test_net", owner=self.slice1, template=self.private)
+
+ ns = NetworkSlice.objects.filter(slice=self.slice1, network=net)
+ assert(not ns)
+
+ def create_network_maximal(self):
+ self.assert_noobj(Network, "test_net")
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test_net", "tosca.nodes.network.Network.XOS",
+ props={"ports": "tcp/1234, udp/5678",
+ "labels": "foo,bar",
+ "permit_all_slices": False},
+ reqs=[("testsite_slice1", "tosca.relationships.MemberOfSlice"),
+ ("Private", "tosca.relationships.UsesNetworkTemplate")]))
+ net=self.assert_obj(Network, "test_net",
+ owner=self.slice1,
+ template=self.private,
+ ports="tcp/1234, udp/5678",
+ labels="foo,bar",
+ permit_all_slices=False)
+
+ ns = NetworkSlice.objects.filter(slice=self.slice1, network=net)
+ assert(not ns)
+
+ def create_network_connected(self):
+ self.assert_noobj(Network, "test_net")
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test_net", "tosca.nodes.network.Network",
+ reqs=[("testsite_slice1", "tosca.relationships.MemberOfSlice"),
+ ("Private", "tosca.relationships.UsesNetworkTemplate"),
+ ("testsite_slice1", "tosca.relationships.ConnectsToSlice")]))
+
+ net=self.assert_obj(Network, "test_net", owner=self.slice1, template=self.private)
+
+ ns = NetworkSlice.objects.filter(slice=self.slice1, network=net)
+ assert(ns)
+
+ def create_network_connected_two_slices(self):
+ self.assert_noobj(Network, "test_net")
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test_net", "tosca.nodes.network.Network",
+ reqs=[("testsite_slice1", "tosca.relationships.MemberOfSlice"),
+ ("Private", "tosca.relationships.UsesNetworkTemplate"),
+ ("testsite_slice1", "tosca.relationships.ConnectsToSlice"),
+ ("testsite_slice2", "tosca.relationships.ConnectsToSlice")]))
+
+ net=self.assert_obj(Network, "test_net", owner=self.slice1, template=self.private)
+
+ ns = NetworkSlice.objects.filter(slice=self.slice1, network=net)
+ assert(ns)
+
+ ns = NetworkSlice.objects.filter(slice=self.slice1, network=net)
+ assert(ns)
+
+ def update_network_labels(self):
+ self.assert_noobj(Network, "test_net")
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test_net", "tosca.nodes.network.Network.XOS",
+ reqs=[("testsite_slice1", "tosca.relationships.MemberOfSlice"),
+ ("Private", "tosca.relationships.UsesNetworkTemplate")]))
+ net=self.assert_obj(Network, "test_net", owner=self.slice1, template=self.private, labels=None)
+
+ self.execute(self.get_base_templates() +
+ self.make_nodetemplate("test_net", "tosca.nodes.network.Network.XOS",
+ props={"labels": "testlabel"},
+ reqs=[("testsite_slice1", "tosca.relationships.MemberOfSlice"),
+ ("Private", "tosca.relationships.UsesNetworkTemplate")]))
+
+ updated_net = self.assert_obj(Network, "test_net", owner=self.slice1, template=self.private, labels="testlabel")
+
+ assert(net.id == updated_net.id)
+
+"""
+ name = models.CharField(max_length=32)
+ template = models.ForeignKey(NetworkTemplate)
+ subnet = models.CharField(max_length=32, blank=True)
+ ports = models.CharField(max_length=1024, blank=True, null=True, validators=[ValidateNatList])
+ labels = models.CharField(max_length=1024, blank=True, null=True)
+ owner = models.ForeignKey(Slice, related_name="ownedNetworks", help_text="Slice that owns control of this Network")
+
+ guaranteed_bandwidth = models.IntegerField(default=0)
+ permit_all_slices = models.BooleanField(default=False)
+ permitted_slices = models.ManyToManyField(Slice, blank=True, related_name="availableNetworks")
+ slices = models.ManyToManyField(Slice, blank=True, related_name="networks", through="NetworkSlice")
+ slivers = models.ManyToManyField(Sliver, blank=True, related_name="networks", through="NetworkSliver")
+
+ topology_parameters = models.TextField(null=True, blank=True)
+ controller_url = models.CharField(null=True, blank=True, max_length=1024)
+ controller_parameters = models.TextField(null=True, blank=True)
+"""
+
+if __name__ == "__main__":
+ NetworkTest()
+
+