+
+ c4 = createDummyContainerObject("c4", flavor="large")
+ rm.allocate(c4) # calculate allocation
+ self.assertEqual(float(c4.cpu_quota) / c4.cpu_period, E_CPU / MAX_CU * 8) # validate compute result
+ self.assertEqual(float(c4.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 512) # validate memory result
+
+
+ c5 = createDummyContainerObject("c5", flavor="xlarge")
+ rm.allocate(c5) # calculate allocation
+ self.assertEqual(float(c5.cpu_quota) / c5.cpu_period, E_CPU / MAX_CU * 16) # validate compute result
+ self.assertEqual(float(c5.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 1024) # validate memory result
+
+
+ def testAllocationCpuLimit(self):
+ """
+ Test CPU allocation limit
+ :return:
+ """
+ # config
+ E_CPU = 1.0
+ MAX_CU = 40
+ E_MEM = 512
+ MAX_MU = 4096
+ # create dummy resource model environment
+ reg = ResourceModelRegistrar(dc_emulation_max_cpu=E_CPU, dc_emulation_max_mem=E_MEM)
+ rm = UpbSimpleCloudDcRM(max_cu=MAX_CU, max_mu=MAX_MU)
+ reg.register("test_dc", rm)
+
+ # test over provisioning exeption
+ exception = False
+ try:
+ c6 = createDummyContainerObject("c6", flavor="xlarge")
+ c7 = createDummyContainerObject("c7", flavor="xlarge")
+ c8 = createDummyContainerObject("c8", flavor="xlarge")
+ c9 = createDummyContainerObject("c9", flavor="xlarge")
+ rm.allocate(c6) # calculate allocation
+ rm.allocate(c7) # calculate allocation
+ rm.allocate(c8) # calculate allocation
+ rm.allocate(c9) # calculate allocation
+ except Exception as e:
+ self.assertIn("Not enough compute", e.message)
+ exception = True
+ self.assertTrue(exception)
+
+ def testAllocationMemLimit(self):
+ """
+ Test MEM allocation limit
+ :return:
+ """
+ # config
+ E_CPU = 1.0
+ MAX_CU = 500
+ 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 = UpbSimpleCloudDcRM(max_cu=MAX_CU, max_mu=MAX_MU)
+ reg.register("test_dc", rm)