Added test that automatically deploys son-demo.son through the dummy GK. Closes #58
[osm/vim-emu.git] / src / emuvim / test / test_resourcemodel_api.py
index 35b4dd5..3412ec4 100644 (file)
@@ -1,6 +1,8 @@
 import time
 from emuvim.test.base import SimpleTestTopology
 from emuvim.dcemulator.resourcemodel import BaseResourceModel, ResourceFlavor
+from emuvim.dcemulator.resourcemodel.upb.simple import UpbSimpleCloudDcRM
+from emuvim.dcemulator.resourcemodel import ResourceModelRegistrar
 
 
 class testResourceModel(SimpleTestTopology):
@@ -49,3 +51,70 @@ class testResourceModel(SimpleTestTopology):
         assert(self.net.ping([self.h[0], self.h[1]]) <= 0.0)
         # stop Mininet network
         self.stopNet()
+
+
+class testUpbSimpleCloudDcRM(SimpleTestTopology):
+    """
+    Test the UpbSimpleCloudDc resource model.
+    """
+    def testAllocation(self):
+        # config
+        E_CPU = 1.0
+        MAX_CU = 100
+        # create dummy resource model environment
+        reg = ResourceModelRegistrar(dc_emulation_max_cpu=1.0)
+        rm = UpbSimpleCloudDcRM(max_cu=100, max_mu=100)
+        reg.register("test_dc", rm)
+
+        res = rm.allocate("c1", "tiny")  # calculate allocation
+        assert(res[0] == E_CPU / MAX_CU * 1)   # validate compute result
+        assert(res[1] < 0)   # validate memory result
+        assert(res[2] < 0)   # validate disk result
+
+        res = rm.allocate("c2", "small")  # calculate allocation
+        assert(res[0] == E_CPU / MAX_CU * 4)   # validate compute result
+        assert(res[1] < 0)   # validate memory result
+        assert(res[2] < 0)   # validate disk result
+
+        res = rm.allocate("c3", "medium")  # calculate allocation
+        assert(res[0] == E_CPU / MAX_CU * 8)   # validate compute result
+        assert(res[1] < 0)   # validate memory result
+        assert(res[2] < 0)   # validate disk result
+
+        res = rm.allocate("c4", "large")  # calculate allocation
+        assert(res[0] == E_CPU / MAX_CU * 16)   # validate compute result
+        assert(res[1] < 0)   # validate memory result
+        assert(res[2] < 0)   # validate disk result
+
+        res = rm.allocate("c5", "xlarge")  # calculate allocation
+        assert(res[0] == E_CPU / MAX_CU * 32)   # validate compute result
+        assert(res[1] < 0)   # validate memory result
+        assert(res[2] < 0)   # validate disk result
+
+        # test over provisioning exeption
+        exception = False
+        try:
+            rm.allocate("c6", "xlarge")  # calculate allocation
+            rm.allocate("c7", "xlarge")  # calculate allocation
+            rm.allocate("c8", "xlarge")  # calculate allocation
+            rm.allocate("c9", "xlarge")  # calculate allocation
+        except Exception as e:
+            assert("Not enough compute" in e.message)
+            exception = True
+        assert(exception)
+
+    def testFree(self):
+        # config
+        E_CPU = 1.0
+        MAX_CU = 100
+        # create dummy resource model environment
+        reg = ResourceModelRegistrar(dc_emulation_max_cpu=1.0)
+        rm = UpbSimpleCloudDcRM(max_cu=100, max_mu=100)
+        reg.register("test_dc", rm)
+        rm.allocate("c1", "tiny")  # calculate allocation
+        assert(rm.dc_alloc_cu == 1)
+        rm.free("c1")
+        assert(rm.dc_alloc_cu == 0)
+
+
+