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)

        # test over provisioning exeption
        exception = False
        try:
            c6 = createDummyContainerObject("c6", flavor="xlarge")
            c7 = createDummyContainerObject("c7", flavor="xlarge")
            c8 = createDummyContainerObject("c8", flavor="xlarge")
            rm.allocate(c6)  # calculate allocation
            rm.allocate(c7)  # calculate allocation
            rm.allocate(c8)  # calculate allocation
        except NotEnoughResourcesAvailable as e:
            self.assertIn("Not enough memory", str(e))
            exception = True
        self.assertTrue(exception)
Example #2
0
    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)

        # test over provisioning exeption
        exception = False
        try:
            c6 = createDummyContainerObject("c6", flavor="xlarge")
            c7 = createDummyContainerObject("c7", flavor="xlarge")
            c8 = createDummyContainerObject("c8", flavor="xlarge")
            rm.allocate(c6)  # calculate allocation
            rm.allocate(c7)  # calculate allocation
            rm.allocate(c8)  # calculate allocation
        except NotEnoughResourcesAvailable as e:
            self.assertIn("Not enough memory", e.message)
            exception = True
        self.assertTrue(exception)
Example #3
0
    def testAllocationComputations(self):
        """
        Test the allocation procedures and correct calculations.
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 100
        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)

        c1 = createDummyContainerObject("c1", flavor="tiny")
        rm.allocate(c1)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c1.resources['cpu_quota']) / c1.resources['cpu_period'], E_CPU / MAX_CU * 0.5)
        # validate memory result
        self.assertEqual(
            float(c1.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 32)

        c2 = createDummyContainerObject("c2", flavor="small")
        rm.allocate(c2)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c2.resources['cpu_quota']) / c2.resources['cpu_period'], E_CPU / MAX_CU * 1)
        # validate memory result
        self.assertEqual(
            float(c2.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 128)

        c3 = createDummyContainerObject("c3", flavor="medium")
        rm.allocate(c3)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c3.resources['cpu_quota']) / c3.resources['cpu_period'], E_CPU / MAX_CU * 4)
        # validate memory result
        self.assertEqual(
            float(c3.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 256)

        c4 = createDummyContainerObject("c4", flavor="large")
        rm.allocate(c4)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c4.resources['cpu_quota']) / c4.resources['cpu_period'], E_CPU / MAX_CU * 8)
        # validate memory result
        self.assertEqual(
            float(c4.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 512)

        c5 = createDummyContainerObject("c5", flavor="xlarge")
        rm.allocate(c5)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c5.resources['cpu_quota']) / c5.resources['cpu_period'], E_CPU / MAX_CU * 16)
        # validate memory result
        self.assertEqual(
            float(c5.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 1024)
 def testFree(self):
     """
     Test the free procedure.
     :return:
     """
     # create dummy resource model environment
     reg = ResourceModelRegistrar(dc_emulation_max_cpu=1.0,
                                  dc_emulation_max_mem=512)
     rm = UpbSimpleCloudDcRM(max_cu=100, max_mu=100)
     reg.register("test_dc", rm)
     c1 = createDummyContainerObject("c6", flavor="tiny")
     rm.allocate(c1)  # calculate allocation
     self.assertTrue(rm.dc_alloc_cu == 0.5)
     rm.free(c1)
     self.assertTrue(rm.dc_alloc_cu == 0)
Example #5
0
 def testFree(self):
     """
     Test the free procedure.
     :return:
     """
     # create dummy resource model environment
     reg = ResourceModelRegistrar(
         dc_emulation_max_cpu=1.0, dc_emulation_max_mem=512)
     rm = UpbSimpleCloudDcRM(max_cu=100, max_mu=100)
     reg.register("test_dc", rm)
     c1 = createDummyContainerObject("c6", flavor="tiny")
     rm.allocate(c1)  # calculate allocation
     self.assertTrue(rm.dc_alloc_cu == 0.5)
     rm.free(c1)
     self.assertTrue(rm.dc_alloc_cu == 0)
    def testAllocationComputations(self):
        """
        Test the allocation procedures and correct calculations.
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 100
        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)

        c1 = createDummyContainerObject("c1", flavor="tiny")
        rm.allocate(c1)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c1.resources['cpu_quota']) / c1.resources['cpu_period'],
            E_CPU / MAX_CU * 0.5)
        # validate memory result
        self.assertEqual(float(c1.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 32)

        c2 = createDummyContainerObject("c2", flavor="small")
        rm.allocate(c2)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c2.resources['cpu_quota']) / c2.resources['cpu_period'],
            E_CPU / MAX_CU * 1)
        # validate memory result
        self.assertEqual(float(c2.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 128)

        c3 = createDummyContainerObject("c3", flavor="medium")
        rm.allocate(c3)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c3.resources['cpu_quota']) / c3.resources['cpu_period'],
            E_CPU / MAX_CU * 4)
        # validate memory result
        self.assertEqual(float(c3.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 256)

        c4 = createDummyContainerObject("c4", flavor="large")
        rm.allocate(c4)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c4.resources['cpu_quota']) / c4.resources['cpu_period'],
            E_CPU / MAX_CU * 8)
        # validate memory result
        self.assertEqual(float(c4.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 512)

        c5 = createDummyContainerObject("c5", flavor="xlarge")
        rm.allocate(c5)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c5.resources['cpu_quota']) / c5.resources['cpu_period'],
            E_CPU / MAX_CU * 16)
        # validate memory result
        self.assertEqual(float(c5.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 1024)