Ejemplo n.º 1
0
def test_eviction_fromfiles_strictgoal():
    k = KubernetesCluster()
    k.load_dir(TEST_CLUSTER_FOLDER)
    k.create_resource(open(TEST_DAEMONET).read())
    k._build_state()
    p = SingleGoalEvictionDetect(k.state_objects)
    p.select_target_service()
    p.run(timeout=6600, sessionName="test_eviction_fromfiles_strictgoal")
    if not p.plan:
        raise Exception("Could not solve %s" % p.__class__.__name__)
    print(Scenario(p.plan).asyaml())
    if p.plan:
        i = 0
        for a in p.plan:
            i = i + 1
            print(
                i, ":", a.__class__.__name__, "\n",
                yaml.dump(
                    {
                        str(k):
                        repr(v._get_value()) if v else f"NONE_VALUE:{v}"
                        for (k, v) in a.kwargs.items()
                    },
                    default_flow_style=False))
    assert "StartPod" in p.plan.__str__()
Ejemplo n.º 2
0
def test_killpod():
    k = KubernetesCluster()
    k.load(open(NODE1).read())  # trim resource, run only one Node
    k.load(open(PODS).read())
    k.load(open(SERVICES).read())
    k.load(open(REPLICASETS).read())
    k.load(open(PRIORITYCLASSES).read())
    k.load(open(DEPLOYMENT).read())

    k.create_resource(open(DEPLOYMENT_NEW).read())

    k._build_state()
    p = OptimisticRun(
        k.state_objects
    )  # TODO check me, i'd like to run exiction test with killpod execution
    # print_objects(k.state_objects)
    p.run(timeout=6600, sessionName="test_start_pods")
    if not p.plan:
        raise Exception("Could not solve %s" % p.__class__.__name__)
    print(Scenario(p.plan).asyaml())
    assert "StartPod" in p.plan.__str__(
    )  # test for transition from Pending to Running
    #get pods only in Running state to check atNode value
    runningPods = filter(
        lambda z: z.status != STATUS_POD["Running"],
        (filter(lambda x: isinstance(x, mpod.Pod), k.state_objects)))
    nodes = filter(lambda x: isinstance(x, Node), k.state_objects)
    for pod in runningPods:
        assert pod.atNode in nodes._get_value(
        )  # check each pod than each have atNode
    killingPods = filter(
        lambda z: z.status != STATUS_POD["Killing"],
        (filter(lambda x: isinstance(x, mpod.Pod), k.state_objects)))
    assert len(killingPods) > 0  # test that some pod Killed
def test_anyservice_interrupted_fromfiles():
    k = KubernetesCluster()
    k.load_dir(TEST_CLUSTER_FOLDER)
    k.create_resource(open(TEST_DAEMONET).read())
    k._build_state()
    mark_excluded_service(k.state_objects)
    p = AnyServiceInterrupted(k.state_objects)
    print_objects(k.state_objects)
    p.run(timeout=6600, sessionName="test_anyservice_interrupted_fromfiles")
    if not p.plan:
        raise Exception("Could not solve %s" % p.__class__.__name__)
    print(Scenario(p.plan).asyaml())
Ejemplo n.º 4
0
def test_anydeployment_interrupted_fromfiles():
    k = KubernetesCluster()
    k.load_dir(TEST_CLUSTER_FOLDER)
    k.create_resource(open(TEST_DEPLOYMENT).read())
    k._build_state()
    mark_excluded_service(k.state_objects)
    print("------Objects before solver processing------")
    print_objects(k.state_objects)
    p = NodeInterupted(k.state_objects)
    p.run(timeout=6600, sessionName="test_anydeployment_interrupted_fromfiles")
    if not p.plan:
        raise Exception("Could not solve %s" % p.__class__.__name__)
    print("------Objects after solver processing------")
    print(Scenario(p.plan).asyaml())
    print_objects(k.state_objects)
Ejemplo n.º 5
0
def test_OptimisticRun():
    k = KubernetesCluster()
    k.load(open(NODE1).read())
    k.load(open(NODE2).read())
    k.load(open(PODS).read())
    # k.load(open(PODS_PENDING).read())
    k.load(open(SERVICES).read())
    k.load(open(REPLICASETS).read())
    k.load(open(PRIORITYCLASSES).read())
    k.load(open(DEPLOYMENT).read())
    k.create_resource(open(DEPLOYMENT_NEW).read())
    k._build_state()
    p = OptimisticRun(
        k.state_objects)  # self.scheduler.status == STATUS_SCHED["Clean"]
    # print_objects(k.state_objects)
    p.run(timeout=6600, sessionName="test_OptimisticRun")
    if not p.plan:
        raise Exception("Could not solve %s" % p.__class__.__name__)
    print(Scenario(p.plan).asyaml())
Ejemplo n.º 6
0
def test_pod_cant_start():
    k = KubernetesCluster()
    k.load(open(NODE1).read())  # trim resource, run only one Node
    k.load(open(PODS).read())
    k.load(open(SERVICES).read())
    k.load(open(REPLICASETS).read())
    k.load(open(PRIORITYCLASSES).read())
    k.load(open(DEPLOYMENT).read())

    k.create_resource(open(DEPLOYMENT_NEW_WO_PRIO).read())

    k._build_state()
    p = OptimisticRun(
        k.state_objects
    )  # TODO check me, i'd like to run exiction test with killpod execution
    # print_objects(k.state_objects)
    p.run(timeout=6600, sessionName="test_pod_cant_start")
    if not p.plan:
        raise Exception("Could not solve %s" % p.__class__.__name__)
    print(Scenario(p.plan).asyaml())
Ejemplo n.º 7
0
def test_start_pod_from_dump():
    k = KubernetesCluster()
    k.load(open(NODE1).read())
    k.load(open(NODE2).read())
    k.load(open(PODS_PENDING).read())
    k.load(open(SERVICES).read())
    k.load(open(REPLICASETS).read())
    k.load(open(PRIORITYCLASSES).read())
    k.load(open(DEPLOYMENT).read())
    k._build_state()
    p = QueueLoadCheck(
        k.state_objects)  # self.scheduler.status == STATUS_SCHED["Clean"]
    # print_objects(k.state_objects)
    p.run(timeout=6600, sessionName="test_start_pod_from_dump")
    if not p.plan:
        raise Exception("Could not solve %s" % p.__class__.__name__)
    print(Scenario(p.plan).asyaml())
    assert "StartPod" in p.plan.__str__(
    )  # test for transition from Pending to Running
    pods = filter(lambda x: isinstance(x, mpod.Pod), k.state_objects)
    nodes = filter(lambda x: isinstance(x, Node), k.state_objects)
    for pod in pods:
        assert pod.atNode in nodes._get_value(
        )  # check each pod than each have atNode
Ejemplo n.º 8
0
def test_start_pod():
    k = KubernetesCluster()
    k.load(open(NODE1).read())
    k.load(open(NODE2).read())
    k.load(open(PODS).read())
    # k.load(open(PODS_PENDING).read())
    k.load(open(SERVICES).read())
    k.load(open(REPLICASETS).read())
    k.load(open(PRIORITYCLASSES).read())
    k.load(open(DEPLOYMENT).read())
    k.create_resource(open(DEPLOYMENT_NEW).read())
    k._build_state()

    class PodStart(K8ServiceInterruptSearch):
        goal = lambda self: self.goalFoo()

        def goalFoo(self):
            for pod in filter(lambda x: isinstance(x, mpod.Pod),
                              k.state_objects):
                if pod.status != STATUS_POD["Running"]:
                    return False
            return True

    p = PodStart(
        k.state_objects)  # self.scheduler.status == STATUS_SCHED["Clean"]
    # print_objects(k.state_objects)
    p.run(timeout=6600, sessionName="test_start_pods")
    if not p.plan:
        raise Exception("Could not solve %s" % p.__class__.__name__)
    print(Scenario(p.plan).asyaml())
    assert "StartPod" in p.plan.__str__(
    )  # test for transition from Pending to Running
    pods = filter(lambda x: isinstance(x, mpod.Pod), k.state_objects)
    nodes = filter(lambda x: isinstance(x, Node), k.state_objects)
    for pod in pods:
        assert pod.atNode in nodes._get_value()