예제 #1
0
    def test_me(self):
        """ test function """
        # create an incorrect CHPA spec as in TestIncorrectSpec test
        # and then fix it and check that the deployment is scaled
        name = self.resource_name()
        chpa_obj = chpa.CHPA(name, 8, name, {"metricSourceType": "Pods"})
        cmd = ["kubectl", "apply", "-f", chpa_obj.save_to_tmp_file()]
        test_helper.check_output(cmd)

        # fix chpa specs
        chpa_obj = chpa.CHPA(name, 8, name)
        cmd = ["kubectl", "apply", "-f", chpa_obj.save_to_tmp_file()]
        test_helper.check_output(cmd)

        self.add_cpu_load(0.5)
        # first scale up will be 1 -> 4
        res = test_helper.run_until(self.LONG_TEST_TIMEOUT,
                                    check_replicas(name, 4))
        self.assertTrue(res)

        self.remove_cpu_load()
        # then it will go down 4 -> 1
        res = test_helper.run_until(self.LONG_TEST_TIMEOUT,
                                    check_replicas(name, 1))
        self.assertTrue(res)
예제 #2
0
def tearDownModule():
    """ tear down module-level stuff """
    global MANAGER_PIPE
    out, err = test_helper.stop_manager(MANAGER_PIPE)
    sys.stdout.write("stdout: " + out.decode("utf-8"))
    sys.stdout.write("stderr: " + err.decode("utf-8"))
    cmd = [
        "kubectl", "delete", "service,deploy,chpas.autoscalers.postmates.com",
        "-l", "app=chpa-test"
    ]
    test_helper.check_output(cmd)
예제 #3
0
 def add_cpu_load(self, sleep):
     """ Add load to our chpa-managed deployment"""
     service_name = "{}-{}".format(self.DEPLOY_NAME_PREFIX,
                                   self.__class__.__name__).lower()
     name = "{}-load".format(service_name)
     cmd_str = "while true; do echo 'next'; wget -q -O- {}; sleep {}; done;"
     command = cmd_str.format(service_name, sleep)
     labels = "--labels={}={}".format(self.DEPLOY_LABEL_KEY,
                                      self.DEPLOY_LABEL_VALUE)
     cmd = [
         "kubectl", "run", name, "--image=busybox", labels, "--", "/bin/sh",
         "-c", command
     ]
     test_helper.check_output(cmd)
예제 #4
0
    def test_me(self):
        """ test something """
        name = self.resource_name()
        chpa_obj = chpa.CHPA(
            name,
            3,
            name,
            {"minReplicas": 2},
        )
        cmd = ["kubectl", "apply", "-f", chpa_obj.save_to_tmp_file()]
        test_helper.check_output(cmd)

        res = test_helper.run_until(self.DEFAULT_TEST_TIMEOUT,
                                    check_replicas(name, 2))
        self.assertTrue(res)
예제 #5
0
    def test_me(self):
        """ test function """
        # create an incorrect CHPA spec and make a usual 'raise to max' test
        # we specify metricSourceType = Pods, while specify resource usage:
        #  "metrics": [{
        #    "type": "Pods",
        #    "resource": {
        #      "name": "cpu",
        #      "targetAverageUtilization": 80
        #    }}]
        # it should be either:
        #  "metrics": [{
        #    "type": "Resource",
        #    "resource": {
        #      "name": "cpu",
        #      "targetAverageUtilization": 80
        #    }}]
        # or
        #  "metrics": [{
        #    "type": "Pods",
        #    "pods": {
        #      "name": "cpu",
        #      "targetAverageValue": 80
        #    }}]
        name = self.resource_name()
        incorrect_chpa = chpa.CHPA("incorrect", 8, name,
                                   {"metricSourceType": "Pods"})
        cmd = ["kubectl", "apply", "-f", incorrect_chpa.save_to_tmp_file()]
        test_helper.check_output(cmd)

        # add correct chpa
        correct_chpa = chpa.CHPA(name, 8, name)
        cmd = ["kubectl", "apply", "-f", correct_chpa.save_to_tmp_file()]
        test_helper.check_output(cmd)

        self.add_cpu_load(0.5)
        # first scale up will be 1 -> 4
        res = test_helper.run_until(self.LONG_TEST_TIMEOUT,
                                    check_replicas(name, 4))
        self.assertTrue(res)

        self.remove_cpu_load()
        # then it will go down 4 -> 1
        res = test_helper.run_until(self.LONG_TEST_TIMEOUT,
                                    check_replicas(name, 1))
        self.assertTrue(res)
예제 #6
0
    def test_me(self):
        """ test something """
        name = self.resource_name()
        chpa_obj = chpa.CHPA(name, 8, name, {"scaleUpLimitFactor": 10.0})
        cmd = ["kubectl", "apply", "-f", chpa_obj.save_to_tmp_file()]
        test_helper.check_output(cmd)

        self.add_cpu_load(0.5)
        # scaling will be very fast: 1 -> 8
        self.assertTrue(
            test_helper.run_until(self.LONG_TEST_TIMEOUT,
                                  check_replicas(name, 8)))

        self.remove_cpu_load()
        # then it will go down instantly 8 -> 1
        res = test_helper.run_until(self.LONG_TEST_TIMEOUT,
                                    check_replicas(name, 1))
        self.assertTrue(res)
예제 #7
0
    def test_me(self):
        """ test something """
        name = self.resource_name()
        chpa_obj = chpa.CHPA(name, 8, name)
        cmd = ["kubectl", "apply", "-f", chpa_obj.save_to_tmp_file()]
        test_helper.check_output(cmd)

        self.add_cpu_load(0.5)
        # first scale up will be 1 -> 4
        res = test_helper.run_until(self.LONG_TEST_TIMEOUT,
                                    check_replicas(name, 4))
        self.assertTrue(res)
        # next will be 4 -> 8
        res = test_helper.run_until(self.LONG_TEST_TIMEOUT,
                                    check_replicas(name, 8))
        self.assertTrue(res)

        self.remove_cpu_load()
        # then it will go down instantly 8 -> 1
        res = test_helper.run_until(self.LONG_TEST_TIMEOUT,
                                    check_replicas(name, 1))
        self.assertTrue(res)
예제 #8
0
 def remove_cpu_load(self):
     """ Remove deployment that adds load to our chpa-managed deployment"""
     name = "{}-{}-load".format(self.DEPLOY_NAME_PREFIX,
                                self.__class__.__name__).lower()
     cmd = ["kubectl", "delete", "deploy", name]
     test_helper.check_output(cmd)