Пример #1
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
Пример #2
0
def prepare_test_single_node_dies_2pod_killed_deployment_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

    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])
    return k, globalVar
Пример #3
0
def test_cyclic_create():
    k, globalVar, n = prepare_test_single_node_dies_2pod_killed_service_outage()
    yamlStateBeforeCreate = convert_space_to_yaml(k.state_objects, wrap_items=True)

    pod_pending_1 = build_pending_pod(3,2,2,n)

    dnew = Deployment()
    dnew.amountOfActivePods = 0
    dnew.spec_replicas = 1
    dnew.podList.add(pod_pending_1) # important to add as we extract status, priority spec from pod

    snew = Service()
    snew.metadata_name = "test-service-new"
    snew.amountOfActivePods = 0
    pod_pending_1.targetService = snew

    create_objects = [dnew, snew]
    yamlCreate = convert_space_to_yaml(create_objects, wrap_items=False, load_logic_support=False)

    # snew.status = STATUS_SERV["Started"]
    k.state_objects.extend([pod_pending_1, dnew, snew])
    yamlState = convert_space_to_yaml(k.state_objects, wrap_items=True)

    k2 = KubernetesCluster()
    for y in yamlStateBeforeCreate: 
        # print(y)
        k2.load(y)
    for y in yamlCreate:
        k2.load(y, mode=KubernetesCluster.CREATE_MODE)
    k2._build_state()
    globalVar = k2.state_objects[1]
    # print("--- RUN 2 ---")
    
    yamlState2 = convert_space_to_yaml(k2.state_objects, wrap_items=True)
    # for y in yamlState2:
        # print(y)

    assert prepare_yamllist_for_diff(yamlState, ignore_names=True) == \
                    prepare_yamllist_for_diff(yamlState2, ignore_names=True)