コード例 #1
0
ファイル: test_cyclic_load.py プロジェクト: KellyGriffin/kalc
def prepare_test_single_node_dies_2pod_killed_service_outage():
    # Initialize scheduler, globalvar
    k = KubernetesCluster()
    scheduler = next(filter(lambda x: isinstance(x, Scheduler), k.state_objects))
    globalVar = next(filter(lambda x: isinstance(x, GlobalVar), k.state_objects))
    # initial node state
    n = Node()
    n.cpuCapacity = 5
    n.memCapacity = 5
    # Create running pods
    pod_running_1 = build_running_pod(1,2,2,n)
    pod_running_2 = build_running_pod(2,2,2,n)

    ## Set consumptoin as expected
    n.currentFormalCpuConsumption = 4
    n.currentFormalMemConsumption = 4
    n.amountOfActivePods = 2

    # Service to detecte eviction
    s = Service()
    s.metadata_name = "test-service"
    s.amountOfActivePods = 2
    s.status = STATUS_SERV["Started"]

    # our service has multiple pods but we are detecting pods pending issue
    # remove service as we are detecting service outage by a bug above
    pod_running_1.targetService = s
    pod_running_2.targetService = s
    pod_running_1.hasService = True
    pod_running_2.hasService = True

    k.state_objects.extend([n, pod_running_1, pod_running_2, s])
    # print_objects(k.state_objects)
    return k, globalVar, n
コード例 #2
0
def test_convert_node_problem():
    # Initialize scheduler, globalvar
    k = KubernetesCluster()
    scheduler = next(
        filter(lambda x: isinstance(x, Scheduler), k.state_objects))
    globalVar = next(
        filter(lambda x: isinstance(x, GlobalVar), k.state_objects))
    # initial node state
    n = Node()
    n.cpuCapacity = 5
    n.memCapacity = 5
    # Create running pods
    pod_running_1 = build_running_pod(1, 2, 2, n)
    pod_running_2 = build_running_pod(2, 2, 2, n)

    ## Set consumptoin as expected
    n.currentFormalCpuConsumption = 4
    n.currentFormalMemConsumption = 4
    n.amountOfActivePods = 2

    pc = PriorityClass()
    pc.priority = 10
    pc.metadata_name = "high-prio-test"

    # Service to detecte eviction
    s = Service()
    s.metadata_name = "test-service"
    s.amountOfActivePods = 2
    s.status = STATUS_SERV["Started"]

    # our service has multiple pods but we are detecting pods pending issue
    # remove service as we are detecting service outage by a bug above
    pod_running_1.targetService = s
    pod_running_2.targetService = s
    pod_running_1.hasService = True
    pod_running_2.hasService = True
    pod_running_1.priorityClass = pc
    pod_running_2.priorityClass = pc

    d = Deployment()
    d.spec_replicas = 2
    d.amountOfActivePods = 2
    pod_running_1.hasDeployment = True
    pod_running_2.hasDeployment = True
    d.podList.add(pod_running_1)
    d.podList.add(pod_running_2)

    k.state_objects.extend([n, pod_running_1, pod_running_2, s, d, pc])
    k2 = KubernetesCluster()
    for y in convert_space_to_yaml(k.state_objects, wrap_items=True):
        # print(y)
        k2.load(y)
    k2._build_state()


# TODO: test node outage exclusion
コード例 #3
0
def test_get_fullscript():
    k = KubernetesCluster()
    p = Pod()
    p.status = STATUS_POD["Running"]
    p.metadata_name = "test-pod-1"
    p.cpuRequest = 2
    p.memRequest = 2
    n_orig = Node("orgi")
    n = Node()
    p.nodeSelectorList.add(n)
    n_orig.metadata_name = "ORIG"
    n_orig.currentFormalMemConsumption = 5
    n_orig.currentFormalCpuConsumption = 5
    n.status = STATUS_NODE["Active"]
    n.cpuCapacity = 10
    n.memCapacity = 10
    l1 = Label("a:b")
    l1.key = "a"
    l1.value = "b"
    l2 = Label("c:d")
    l2.key = "c"
    l2.value = "b"
    n.metadata_labels.add(l1)
    n.metadata_labels.add(l2)

    d = Deployment()
    d.metadata_name = "dep-test1"
    d.podList.add(p)
    p.hasDeployment = True
    p.atNode = n_orig

    rs = ReplicaSet()
    rs.metadata_name = "rs-test1"
    rs.metadata_ownerReferences__name = "dep-test1"
    # typically, you can find correct replicaSet by ownerReferences
    # TODO: create utililty function to do that 

    k.state_objects.extend([d, n, p, rs])

    prob = Balance_pods_and_drain_node(k.state_objects)
    s = k.scheduler
    g = k.globalvar
    prob.MoveRunningPodToAnotherNode(p, n_orig, n, s, g)

    assert len(prob.script)