X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Femuvim%2Ftest%2Ftest_resourcemodel_api.py;h=3412ec47c6ef22e8a46ef215b99dbb93258f8dda;hb=279565d5f8749ac9ac5927a718b7e8e6e63b8450;hp=35b4dd5f45163dfe93b7180252ceb091f22f44b2;hpb=0caea49645adff9a83f3ae300c4ac785d8a1f32f;p=osm%2Fvim-emu.git diff --git a/src/emuvim/test/test_resourcemodel_api.py b/src/emuvim/test/test_resourcemodel_api.py index 35b4dd5..3412ec4 100644 --- a/src/emuvim/test/test_resourcemodel_api.py +++ b/src/emuvim/test/test_resourcemodel_api.py @@ -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) + + +