X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Femuvim%2Ftest%2Ftest_resourcemodel.py;h=a1d273c08a459de141999b0228292517f95cf0c7;hb=7408542a62711664395fcc15582d277d186daa86;hp=01cc792b04544218c905aaf5045054956d8046d0;hpb=eedba63896751d1669e2bb6b1fa329d3344621b3;p=osm%2Fvim-emu.git diff --git a/src/emuvim/test/test_resourcemodel.py b/src/emuvim/test/test_resourcemodel.py index 01cc792..a1d273c 100644 --- a/src/emuvim/test/test_resourcemodel.py +++ b/src/emuvim/test/test_resourcemodel.py @@ -1,9 +1,9 @@ import time import os from emuvim.test.base import SimpleTestTopology -from emuvim.dcemulator.resourcemodel import BaseResourceModel, ResourceFlavor -from emuvim.dcemulator.resourcemodel.upb.simple import UpbSimpleCloudDcRM, UpbOverprovisioningCloudDcRM -from emuvim.dcemulator.resourcemodel import ResourceModelRegistrar +from emuvim.dcemulator.resourcemodel import BaseResourceModel, ResourceFlavor, NotEnoughResourcesAvailable, ResourceModelRegistrar +from emuvim.dcemulator.resourcemodel.upb.simple import UpbSimpleCloudDcRM, UpbOverprovisioningCloudDcRM, UpbDummyRM + class testResourceModel(SimpleTestTopology): @@ -41,7 +41,7 @@ class testResourceModel(SimpleTestTopology): # start Mininet network self.startNet() # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 0) + self.assertTrue(len(self.getContainernetContainers()) == 0) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 1) # check resource model and resource model registrar @@ -159,7 +159,7 @@ class testUpbSimpleCloudDcRM(SimpleTestTopology): rm.allocate(c7) # calculate allocation rm.allocate(c8) # calculate allocation rm.allocate(c9) # calculate allocation - except Exception as e: + except NotEnoughResourcesAvailable as e: self.assertIn("Not enough compute", e.message) exception = True self.assertTrue(exception) @@ -188,7 +188,7 @@ class testUpbSimpleCloudDcRM(SimpleTestTopology): rm.allocate(c6) # calculate allocation rm.allocate(c7) # calculate allocation rm.allocate(c8) # calculate allocation - except Exception as e: + except NotEnoughResourcesAvailable as e: self.assertIn("Not enough memory", e.message) exception = True self.assertTrue(exception) @@ -213,7 +213,7 @@ class testUpbSimpleCloudDcRM(SimpleTestTopology): def testInRealTopo(self): """ - Start a real container and check if limitations are really passed down to Dockernet. + Start a real container and check if limitations are really passed down to Conteinernet. :return: """ # ATTENTION: This test should only be executed if emu runs not inside a Docker container, @@ -231,7 +231,7 @@ class testUpbSimpleCloudDcRM(SimpleTestTopology): # start Mininet network self.startNet() # check number of running nodes - self.assertTrue(len(self.getDockernetContainers()) == 0) + self.assertTrue(len(self.getContainernetContainers()) == 0) self.assertTrue(len(self.net.hosts) == 2) self.assertTrue(len(self.net.switches) == 1) # check resource model and resource model registrar @@ -309,4 +309,31 @@ class testUpbOverprovisioningCloudDcRM(SimpleTestTopology): self.assertAlmostEqual(rm.cpu_op_factor, 0.6) +class testUpbDummyRM(SimpleTestTopology): + """ + Test the UpbDummyRM resource model. + """ + + def testAllocationComputations(self): + """ + Test the allocation procedures and correct calculations. + :return: + """ + # config + E_CPU = 1.0 + MAX_CU = 3 + E_MEM = 512 + MAX_MU = 2048 + # create dummy resource model environment + reg = ResourceModelRegistrar(dc_emulation_max_cpu=E_CPU, dc_emulation_max_mem=E_MEM) + rm = UpbDummyRM(max_cu=MAX_CU, max_mu=MAX_MU) + reg.register("test_dc", rm) + + c1 = createDummyContainerObject("c1", flavor="small") + rm.allocate(c1) # calculate allocation + self.assertEqual(len(rm._allocated_compute_instances), 1) + + c2 = createDummyContainerObject("c2", flavor="small") + rm.allocate(c2) # calculate allocation + self.assertEqual(len(rm._allocated_compute_instances), 2)