Example #1
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 #2
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)
Example #3
0
    def _create_dcs(self):
        rm0 = UpbSimpleCloudDcRM(max_cu=100, max_mu=2048)
        rm1 = ARORM(max_cu=4, max_mu=512)
        rm2 = ARORM(max_cu=6, max_mu=512)

        self.dc1 = self.addDatacenter("dc1")
        self.dc1.assignResourceModel(rm0)

        self.dc2 = self.addDatacenter("dc2", topo='star', sw_param=3)
        self.dc2.assignResourceModel(rm0)
    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)
    def testInRealTopo(self):
        """
        Start a real container and check if limitations are really passed down to Conteinernet.
        :return:
        """
        # create network
        self.createNet(nswitches=0, ndatacenter=1, nhosts=2, ndockers=0)
        # setup links
        self.net.addLink(self.dc[0], self.h[0])
        self.net.addLink(self.h[1], self.dc[0])
        # add resource model
        r = UpbSimpleCloudDcRM(max_cu=100, max_mu=100)
        self.dc[0].assignResourceModel(r)
        # start Mininet network
        self.startNet()
        # check number of running nodes
        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
        self.assertTrue(self.dc[0]._resource_model is not None)
        self.assertTrue(len(self.net.rm_registrar.resource_models) == 1)

        # check if alloc was called during startCompute
        self.assertTrue(len(r._allocated_compute_instances) == 0)
        tc1 = self.dc[0].startCompute("tc1", flavor_name="tiny")
        time.sleep(1)
        self.assertTrue(len(r._allocated_compute_instances) == 1)

        # 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.resources['cpu_quota']) / tc1.resources['cpu_period'],
            0.005)

        # check if free was called during stopCompute
        self.dc[0].stopCompute("tc1")
        self.assertTrue(len(r._allocated_compute_instances) == 0)
        # check connectivity by using ping
        self.assertTrue(self.net.ping([self.h[0], self.h[1]]) <= 0.0)
        # stop Mininet network
        self.stopNet()
def create_topology1():
    cleanup()
    # create topology
    # use a maximum of 50% cpu time for containers added to data centers
    net = DCNetwork(dc_emulation_max_cpu=0.5, controller=Controller)
    # add some data centers and create a topology
    dc1 = net.addDatacenter("dc1", resource_log_path=RESOURCE_LOG_PATH)
    dc2 = net.addDatacenter("dc2", resource_log_path=RESOURCE_LOG_PATH)
    s1 = net.addSwitch("s1")
    net.addLink(dc1, s1, delay="10ms")
    net.addLink(dc2, s1, delay="20ms")

    # create and assign resource models for each DC
    rm1 = UpbSimpleCloudDcRM(max_cu=4, max_mu=1024)
    rm2 = UpbOverprovisioningCloudDcRM(max_cu=4)
    dc1.assignResourceModel(rm1)
    dc2.assignResourceModel(rm2)

    # add the command line interface endpoint to each DC
    zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242)
    zapi1.connectDatacenter(dc1)
    zapi1.connectDatacenter(dc2)
    # run API endpoint server (in another thread, don't block)
    zapi1.start()

    # start the emulation platform
    net.start()
    print "Wait a moment and allocate some compute start some compute resources..."
    time.sleep(2)
    dc1.startCompute("vnf1")
    dc1.startCompute("vnf2", flavor_name="tiny")
    dc1.startCompute("vnf3", flavor_name="small")
    dc2.startCompute("vnf4", flavor_name="medium")
    dc2.startCompute("vnf5", flavor_name="medium")
    dc2.startCompute("vnf6", flavor_name="medium")
    print "... done."
    time.sleep(5)
    print "Removing instances ..."
    dc1.stopCompute("vnf1")
    dc2.stopCompute("vnf4")
    print "... done"
    net.CLI()
    net.stop()
 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)
Example #9
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
        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.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.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.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.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