From b2a29bf80a18064febeb7e8278efe83f15d3b39a Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Tue, 14 Feb 2017 14:27:44 +0100 Subject: [PATCH] fix unittest for resource testing --- .../dcemulator/resourcemodel/upb/simple.py | 4 +- .../test/unittests/test_resourcemodel.py | 62 ++++++++++--------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/emuvim/dcemulator/resourcemodel/upb/simple.py b/src/emuvim/dcemulator/resourcemodel/upb/simple.py index 5f260d6..79db24a 100755 --- a/src/emuvim/dcemulator/resourcemodel/upb/simple.py +++ b/src/emuvim/dcemulator/resourcemodel/upb/simple.py @@ -164,7 +164,7 @@ class UpbSimpleCloudDcRM(BaseResourceModel): # calculate input values for CFS scheduler bandwidth limitation cpu_period, cpu_quota = self._calculate_cpu_cfs_values(cpu_time_percentage) # apply limits to container if changed - if d.cpu_period != cpu_period or d.cpu_quota != cpu_quota: + if d.resources['cpu_period'] != cpu_period or d.resources['cpu_quota'] != cpu_quota: LOG.debug("Setting CPU limit for %r: cpu_quota = cpu_period * limit = %f * %f = %f (op_factor=%f)" % ( d.name, cpu_period, cpu_time_percentage, cpu_quota, self.cpu_op_factor)) d.updateCpuLimit(cpu_period=int(cpu_period), cpu_quota=int(cpu_quota)) @@ -210,7 +210,7 @@ class UpbSimpleCloudDcRM(BaseResourceModel): mem_limit = self.single_mu * number_mu mem_limit = self._calculate_mem_limit_value(mem_limit) # apply to container if changed - if d.mem_limit != mem_limit: + if d.resources['mem_limit'] != mem_limit: LOG.debug("Setting MEM limit for %r: mem_limit = %f MB (op_factor=%f)" % (d.name, mem_limit/1024/1024, self.mem_op_factor)) d.updateMemoryLimit(mem_limit=mem_limit) diff --git a/src/emuvim/test/unittests/test_resourcemodel.py b/src/emuvim/test/unittests/test_resourcemodel.py index 5fbd172..4a21fee 100755 --- a/src/emuvim/test/unittests/test_resourcemodel.py +++ b/src/emuvim/test/unittests/test_resourcemodel.py @@ -97,17 +97,23 @@ def createDummyContainerObject(name, flavor): def __init__(self): # take defaukt values from son-emu - # self.cpu_period = -1 - self.cpu_quota = -1 - # self.mem_limit = -1 - # self.memswap_limit = -1 + self.resources = dict( + cpu_period = -1, + cpu_quota = -1, + mem_limit = -1, + memswap_limit = -1 + ) + #self.cpu_period = self.resources['cpu_period'] + #self.cpu_quota = self.resources['cpu_quota'] + #self.mem_limit = self.resources['mem_limit'] + #self.memswap_limit = self.resources['memswap_limit'] def updateCpuLimit(self, cpu_period, cpu_quota): - self.cpu_period = cpu_period - self.cpu_quota = cpu_quota + self.resources['cpu_period'] = cpu_period + self.resources['cpu_quota'] = cpu_quota def updateMemoryLimit(self, mem_limit): - self.mem_limit = mem_limit + self.resources['mem_limit'] = mem_limit d = DummyContainer() d.name = name @@ -139,28 +145,28 @@ class testUpbSimpleCloudDcRM(SimpleTestTopology): c1 = createDummyContainerObject("c1", flavor="tiny") rm.allocate(c1) # calculate allocation - self.assertEqual(float(c1.cpu_quota) / c1.cpu_period, E_CPU / MAX_CU * 0.5) # validate compute result - self.assertEqual(float(c1.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 32) # validate memory result + self.assertEqual(float(c1.resources['cpu_quota']) / c1.resources['cpu_period'], E_CPU / MAX_CU * 0.5) # validate compute result + self.assertEqual(float(c1.resources['mem_limit']/1024/1024), float(E_MEM) / MAX_MU * 32) # validate memory result c2 = createDummyContainerObject("c2", flavor="small") rm.allocate(c2) # calculate allocation - self.assertEqual(float(c2.cpu_quota) / c2.cpu_period, E_CPU / MAX_CU * 1) # validate compute result - self.assertEqual(float(c2.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 128) # validate memory result + self.assertEqual(float(c2.resources['cpu_quota']) / c2.resources['cpu_period'], E_CPU / MAX_CU * 1) # validate compute result + self.assertEqual(float(c2.resources['mem_limit']/1024/1024), float(E_MEM) / MAX_MU * 128) # validate memory result c3 = createDummyContainerObject("c3", flavor="medium") rm.allocate(c3) # calculate allocation - self.assertEqual(float(c3.cpu_quota) / c3.cpu_period, E_CPU / MAX_CU * 4) # validate compute result - self.assertEqual(float(c3.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 256) # validate memory result + self.assertEqual(float(c3.resources['cpu_quota']) / c3.resources['cpu_period'], E_CPU / MAX_CU * 4) # validate compute result + self.assertEqual(float(c3.resources['mem_limit']/1024/1024), float(E_MEM) / MAX_MU * 256) # validate memory result 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 + self.assertEqual(float(c4.resources['cpu_quota']) / c4.resources['cpu_period'], E_CPU / MAX_CU * 8) # validate compute result + self.assertEqual(float(c4.resources['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 + self.assertEqual(float(c5.resources['cpu_quota']) / c5.resources['cpu_period'], E_CPU / MAX_CU * 16) # validate compute result + self.assertEqual(float(c5.resources['mem_limit']/1024/1024), float(E_MEM) / MAX_MU * 1024) # validate memory result def testAllocationCpuLimit(self): @@ -274,7 +280,7 @@ class testUpbSimpleCloudDcRM(SimpleTestTopology): # check if there is a real limitation set for containers cgroup # deactivated for now, seems not to work in docker-in-docker setup used in CI - self.assertEqual(float(tc1.cpu_quota)/tc1.cpu_period, 0.005) + self.assertEqual(float(tc1.resources['cpu_quota'])/tc1.resources['cpu_period'], 0.005) # check if free was called during stopCompute self.dc[0].stopCompute("tc1") @@ -307,33 +313,33 @@ class testUpbOverprovisioningCloudDcRM(SimpleTestTopology): c1 = createDummyContainerObject("c1", flavor="small") rm.allocate(c1) # calculate allocation - self.assertAlmostEqual(float(c1.cpu_quota) / c1.cpu_period, E_CPU / MAX_CU * 1.0, places=5) - self.assertAlmostEqual(float(c1.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 128) + self.assertAlmostEqual(float(c1.resources['cpu_quota']) / c1.resources['cpu_period'], E_CPU / MAX_CU * 1.0, places=5) + self.assertAlmostEqual(float(c1.resources['mem_limit']/1024/1024), float(E_MEM) / MAX_MU * 128) self.assertAlmostEqual(rm.cpu_op_factor, 1.0) c2 = createDummyContainerObject("c2", flavor="small") rm.allocate(c2) # calculate allocation - self.assertAlmostEqual(float(c2.cpu_quota) / c2.cpu_period, E_CPU / MAX_CU * 1.0, places=5) - self.assertAlmostEqual(float(c2.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 128) + self.assertAlmostEqual(float(c2.resources['cpu_quota']) / c2.resources['cpu_period'], E_CPU / MAX_CU * 1.0, places=5) + self.assertAlmostEqual(float(c2.resources['mem_limit']/1024/1024), float(E_MEM) / MAX_MU * 128) self.assertAlmostEqual(rm.cpu_op_factor, 1.0) c3 = createDummyContainerObject("c3", flavor="small") rm.allocate(c3) # calculate allocation - self.assertAlmostEqual(float(c3.cpu_quota) / c3.cpu_period, E_CPU / MAX_CU * 1.0, places=5) - self.assertAlmostEqual(float(c3.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 128) + self.assertAlmostEqual(float(c3.resources['cpu_quota']) / c3.resources['cpu_period'], E_CPU / MAX_CU * 1.0, places=5) + self.assertAlmostEqual(float(c3.resources['mem_limit']/1024/1024), float(E_MEM) / MAX_MU * 128) self.assertAlmostEqual(rm.cpu_op_factor, 1.0) # from this container onwards, we should go to over provisioning mode: c4 = createDummyContainerObject("c4", flavor="small") rm.allocate(c4) # calculate allocation - self.assertAlmostEqual(float(c4.cpu_quota) / c4.cpu_period, E_CPU / MAX_CU * (float(3) / 4), places=5) - self.assertAlmostEqual(float(c4.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 128, places=5) + self.assertAlmostEqual(float(c4.resources['cpu_quota']) / c4.resources['cpu_period'], E_CPU / MAX_CU * (float(3) / 4), places=5) + self.assertAlmostEqual(float(c4.resources['mem_limit']/1024/1024), float(E_MEM) / MAX_MU * 128, places=5) self.assertAlmostEqual(rm.cpu_op_factor, 0.75) c5 = createDummyContainerObject("c5", flavor="small") rm.allocate(c5) # calculate allocation - self.assertAlmostEqual(float(c5.cpu_quota) / c5.cpu_period, E_CPU / MAX_CU * (float(3) / 5), places=5) - self.assertAlmostEqual(float(c5.mem_limit/1024/1024), float(E_MEM) / MAX_MU * 128) + self.assertAlmostEqual(float(c5.resources['cpu_quota']) / c5.resources['cpu_period'], E_CPU / MAX_CU * (float(3) / 5), places=5) + self.assertAlmostEqual(float(c5.resources['mem_limit']/1024/1024), float(E_MEM) / MAX_MU * 128) self.assertAlmostEqual(rm.cpu_op_factor, 0.6) -- 2.25.1