示例#1
0
def test_rack():
    message = message_factory.create("RackCreateVMReq")

    # server_stack
    algo_server = Algorithm(HOST, PORT + 2000)
    node_server = Node(HOST, PORT + 1000)
    rack_server = Rack(HOST, PORT)

    # algo setting
    algo_server.node_addr = node_server.addr()

    # rack setting
    rack_server.algorithm_addr = algo_server.addr()

    server_stack = [algo_server, node_server, rack_server]

    for server in server_stack:
        def server_thread():
            server.run()

        t = threading.Thread(target = server_thread)
        t.start()

    # client
    try:
        sleep(3)
        client.sendonly_message((HOST, PORT), message)

    finally:
        for server in reversed(server_stack):
            server.shutdown()

    assert len(rack_server.request_context) == 0
示例#2
0
def test_rack():
    message = message_factory.create("RackCreateVMReq")

    # server_stack
    algo_server = Algorithm(HOST, PORT + 2000)
    node_server = Node(HOST, PORT + 1000)
    rack_server = Rack(HOST, PORT)

    # algo setting
    algo_server.node_addr = node_server.addr()

    # rack setting
    rack_server.algorithm_addr = algo_server.addr()

    server_stack = [algo_server, node_server, rack_server]

    for server in server_stack:

        def server_thread():
            server.run()

        t = threading.Thread(target=server_thread)
        t.start()

    # client
    try:
        sleep(3)
        client.sendonly_message((HOST, PORT), message)

    finally:
        for server in reversed(server_stack):
            server.shutdown()

    assert len(rack_server.request_context) == 0
示例#3
0
def test_cluster():
    message = message_factory.create("ClusterCreateVMReq")

    # server_stack
    algo_server = Algorithm(HOST, PORT + 3000)
    node_server = Node(HOST, PORT + 2000)
    rack_server = Rack(HOST, PORT + 1000)
    cluster_server = Cluster(HOST, PORT)

    # algo setting
    algo_server.node_addr = node_server.addr()
    algo_server.rack_addr = rack_server.addr()

    # cluster setting
    cluster_server.algorithm_addr = algo_server.addr()
    holder = {'createVMResHandler_get_called': False}

    def f(self, message):
        holder['createVMResHandler_get_called'] = True

    cluster_server.createVMResHandler = f

    # rack setting
    rack_server.algorithm_addr = algo_server.addr()

    server_stack = [algo_server, node_server, rack_server, cluster_server]

    for server in server_stack:
        def server_thread():
            server.run()

        t = threading.Thread(target = server_thread)
        t.start()

    # client
    try:
        sleep(3)
        client.sendonly_message((HOST, PORT), message)

        counter = 0
        while counter < 10 and holder['createVMResHandler_get_called'] == False:
            sleep(1)
            counter += 1
    except:
        print 'something wrong'
    finally:
        for server in reversed(server_stack):
            server.shutdown()

    assert holder['createVMResHandler_get_called'] == True
示例#4
0
def test_coordinator():
    # server_stack
    algo_server = Algorithm(HOST, PORT + 4)
    node_server = Node(HOST, PORT + 3)
    rack_server = Rack(HOST, PORT + 2)
    cluster_server = Cluster(HOST, PORT + 1)
    coordinator_server = Coordinator(HOST, PORT)

    # algo setting
    algo_server.node_addr = node_server.addr()
    algo_server.rack_addr = rack_server.addr()
    algo_server.cluster_addr = cluster_server.addr()

    rack_server.algorithm_addr = algo_server.addr()
    cluster_server.algorithm_addr = algo_server.addr()
    coordinator_server.algorithm_addr = algo_server.addr()

    # setup function for assert
    # holder = {'createVMResHandler_get_called': False}
    # def f(self, message):
    #     holder['createVMResHandler_get_called'] = True
    # coordinator_server.createVMResHandler = f

    # start servers
    server_stack = [
        algo_server, node_server, rack_server, cluster_server,
        coordinator_server
    ]
    server_manager.start_server_stack(server_stack)

    try:
        sleep(10)
        # vm = VM("vmid", "groupid", "vmsubid", "vmtype",
        #         "config_cpu", "config_memory", "config_disk", "config_lifetime",
        #         "ownerid")
        # coordinator_server.create_vm(vm)

        counter = 0
        while counter < 10:  # and holder['createVMResHandler_get_called'] == False:
            sleep(1)
            counter += 1
    except Exception as e:
        print e

    finally:
        server_manager.shutdown_server_stack(server_stack)
示例#5
0
def test_coordinator():
    # server_stack
    algo_server = Algorithm(HOST, PORT + 4)
    node_server = Node(HOST, PORT + 3)
    rack_server = Rack(HOST, PORT + 2)
    cluster_server = Cluster(HOST, PORT + 1)
    coordinator_server = Coordinator(HOST, PORT)

    # algo setting
    algo_server.node_addr = node_server.addr()
    algo_server.rack_addr = rack_server.addr()
    algo_server.cluster_addr = cluster_server.addr()

    rack_server.algorithm_addr = algo_server.addr()
    cluster_server.algorithm_addr = algo_server.addr()
    coordinator_server.algorithm_addr = algo_server.addr()

    # setup function for assert
    # holder = {'createVMResHandler_get_called': False}
    # def f(self, message):
    #     holder['createVMResHandler_get_called'] = True
    # coordinator_server.createVMResHandler = f

    # start servers
    server_stack = [algo_server, node_server, rack_server, cluster_server, coordinator_server]
    server_manager.start_server_stack(server_stack)

    try:
        sleep(10)
        # vm = VM("vmid", "groupid", "vmsubid", "vmtype", 
        #         "config_cpu", "config_memory", "config_disk", "config_lifetime", 
        #         "ownerid")
        # coordinator_server.create_vm(vm)

        counter = 0
        while counter < 10: # and holder['createVMResHandler_get_called'] == False:
            sleep(1)
            counter += 1
    except Exception as e:
        print e

    finally:
        server_manager.shutdown_server_stack(server_stack)