--- /dev/null
+import sys\r
+import os\r
+import time\r
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', '../libraries/common'))\r
+from datetime import datetime # noqa\r
+from datetime import timedelta # noqa\r
+from robot.libraries.BuiltIn import BuiltIn # noqa\r
+from robot.api import logger # noqa\r
+import common_utils # noqa\r
+from decorators_for_robot_functionalities import * # noqa\r
+from test_constants import * # noqa\r
+\r
+\r
+execute = BuiltIn().get_library_instance('execute_command')\r
+stack_infos = BuiltIn().get_library_instance('stack_infos')\r
+\r
+\r
+def HPA_check():\r
+ steps = ['step1_check_initial_replica_count',\r
+ 'step2_check_scale_out',\r
+ 'step3_check_scale_in']\r
+ BuiltIn().run_keyword("HPA_check.setup")\r
+ common_utils.keyword_runner(steps)\r
+\r
+\r
+def setup():\r
+ common_utils.helm_install(chart_name="default/php-apache", release_name="crf01",\r
+ values="registry_url={reg_url}".format(reg_url=reg))\r
+ common_utils.check_kubernetes_object(kube_object=php_apache_pod,\r
+ tester_function=common_utils.test_kubernetes_object_available,\r
+ additional_filter="Running",\r
+ timeout=90)\r
+ flags = ["--horizontal-pod-autoscaler-downscale-stabilization=10s", "--horizontal-pod-autoscaler-sync-period=10s"]\r
+ common_utils.modify_static_pod_config(common_utils.add_flag_to_command, "cm.yml", flags)\r
+ common_utils.helm_install(chart_name="default/load-generator-for-apache", release_name="load")\r
+ common_utils.check_kubernetes_object(kube_object=load_generator_for_apache,\r
+ tester_function=common_utils.test_kubernetes_object_available,\r
+ additional_filter="Running",\r
+ timeout=60)\r
+\r
+\r
+def step1_check_initial_replica_count():\r
+ time.sleep(5)\r
+ replica_count = int(\r
+ execute.execute_unix_command("kubectl get hpa | grep php-apache-hpa | awk '{print $6}'"))\r
+ if replica_count == 1:\r
+ logger.info("number of php apache pod is 1")\r
+ else:\r
+ raise Exception("Expected initial replica count is not correct: expected: 1, got: " + str(replica_count))\r
+\r
+\r
+def step2_check_scale_out():\r
+ check_scaling(expected_replicas="2", timeout=360)\r
+\r
+\r
+def step3_check_scale_in():\r
+ check_scaling(expected_replicas="1", timeout=480)\r
+\r
+\r
+def check_scaling(expected_replicas, timeout):\r
+ wait_until = datetime.now() + timedelta(seconds=timeout)\r
+ actual_replicas = execute.execute_unix_command("kubectl get hpa | grep php-apache-hpa | awk '{print $6}'")\r
+ while actual_replicas != expected_replicas:\r
+ time.sleep(5)\r
+ actual_replicas = execute.execute_unix_command("kubectl get hpa | grep php-apache-hpa | awk '{print $6}'")\r
+ if actual_replicas == expected_replicas:\r
+ logger.info("number of php apache pod is " + expected_replicas + ", scale out was successful")\r
+ elif wait_until < datetime.now():\r
+ raise Exception("Scaling did not happen in " + str(timeout) + " seconds, expected replica count is " +\r
+ expected_replicas + ", got " + actual_replicas)\r