LAVA: Deprecate redundant codes in LAVA helper

LAVA monitor only relies on bl2, regression tests and psa arch tests.
This patch updates the LAVA helper logics to select LAVA monitor in a
much easier way, instead of looping all build params.

Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: Ic00ce2ac308dcf4bd502212bb4e56234576b430f
diff --git a/lava_helper/lava_create_jobs.py b/lava_helper/lava_create_jobs.py
index ce14d24..cfee0ed 100755
--- a/lava_helper/lava_create_jobs.py
+++ b/lava_helper/lava_create_jobs.py
@@ -22,15 +22,6 @@
 from lava_helper_configs import *
 
 
-def get_artifact_url(artifact_store_url, params, filename):
-    platform = params["platform"]
-    if params["device_type"] == "fvp":
-        platform = "fvp"
-
-    url = "{}/artifact/trusted-firmware-m/build/bin/{}".format(artifact_store_url.rstrip("/"), filename)
-    return url
-
-
 def get_recovery_url(recovery_store_url, recovery):
     return "{}/{}".format(recovery_store_url.rstrip('/'), recovery)
 
@@ -46,9 +37,6 @@
         print("No template found for config: %s" % config_key)
         sys.exit(1)
 
-    config["build_no"] = user_args.build_no
-    config["artifact_store_url"] = user_args.jenkins_build_url
-
     # Add the template folder
     config["templ"] = os.path.join(user_args.template_dir, config["templ"])
     return config
@@ -61,74 +49,58 @@
     template_loader = FileSystemLoader(searchpath=work_dir)
     template_env = Environment(loader=template_loader)
     recovery_store_url = config.get('recovery_store_url', '')
-    build_no = user_args.build_no
-    artifact_store_url = config["artifact_store_url"]
     template_file = config.pop("templ")
 
     definitions = {}
 
     for platform, recovery in config["platforms"].items():
-        if platform != user_args.platform:
+        if platform != os.getenv('TFM_PLATFORM'):
             continue
         recovery_image_url = get_recovery_url(recovery_store_url, recovery)
-        for compiler in config["compilers"]:
-            if compiler != user_args.compiler:
-                continue
-            for build_type in config["build_types"]:
-                if build_type != user_args.build_type:
-                    continue
-                for boot_type in config["boot_types"]:
-                    bl2_string = "BL2" if user_args.bl2 else "NOBL2"
-                    if boot_type != bl2_string:
-                        continue
-                    for test_name, test_dict in config["tests"].items():
-                        if "Config{}".format(test_name) != user_args.proj_config:
-                            continue
-                        params = {
-                            "device_type": config["device_type"],
-                            "job_timeout": config["job_timeout"],
-                            "action_timeout": config.get("action_timeout", ''),
-                            "monitor_timeout": config.get("monitor_timeout", ''),
-                            "poweroff_timeout": config.get("poweroff_timeout", ''),
-                            "compiler": compiler,
-                            "build_type": build_type,
-                            "build_no": build_no,
-                            "boot_type": boot_type,
-                            "name": test_name,
-                            "test": test_dict,
-                            "platform": platform,
-                            "recovery_image_url": recovery_image_url,
-                            "data_bin_offset": config.get('data_bin_offset', ''),
-                            "docker_prefix": vars(user_args).get('docker_prefix', ''),
-                            "license_variable": vars(user_args).get('license_variable', ''),
-                            "enable_code_coverage": user_args.enable_code_coverage == "TRUE",
-                            "coverage_trace_plugin": coverage_trace_plugin,
-                            "build_job_url": artifact_store_url,
-                            "cpu0_baseline": config.get("cpu0_baseline", 0),
-                            "cpu0_initvtor_s": config.get("cpu0_initvtor_s", "0x10000000"),
-                            "psa_api_suite": user_args.psa_suite,
-                        }
-                        for binary_type, binary_name in config["binaries"].items():
-                            params.update(
-                                {
-                                    "{}_url".format(binary_type): get_artifact_url(
-                                        artifact_store_url,
-                                        params,
-                                        binary_name
-                                    )
-                                }
-                            )
-                        params.update(
-                            {
-                                "job_name": "{}_{}_{}".format(os.getenv('CONFIG_NAME'), params['build_no'], params["device_type"]),
-                                "build_name": os.getenv('CONFIG_NAME')
-                            }
-                        )
+        if os.getenv("TEST_REGRESSION") == "True":
+            monitor_name = "reg_tests"
+        elif os.getenv("TEST_PSA_API") != "OFF":
+            monitor_name = "arch_tests"
+        else:
+            monitor_name = "no_reg_tests"
+        params = {
+            "job_name": "{}_{}_{}".format(os.getenv('CONFIG_NAME'), os.getenv("BUILD_NUMBER"), config["device_type"]),
+            "build_name": os.getenv('CONFIG_NAME'),
+            "device_type": config["device_type"],
+            "job_timeout": config["job_timeout"],
+            "action_timeout": config.get("action_timeout", ''),
+            "monitor_timeout": config.get("monitor_timeout", ''),
+            "poweroff_timeout": config.get("poweroff_timeout", ''),
+            "build_no": os.getenv("BUILD_NUMBER"),
+            "name": monitor_name,
+            "monitors": config['monitors'].get(monitor_name, []),
+            "platform": platform,
+            "recovery_image_url": recovery_image_url,
+            "data_bin_offset": config.get('data_bin_offset', ''),
+            "docker_prefix": vars(user_args).get('docker_prefix', ''),
+            "license_variable": vars(user_args).get('license_variable', ''),
+            "enable_code_coverage": user_args.enable_code_coverage == "TRUE",
+            "coverage_trace_plugin": coverage_trace_plugin,
+            "build_job_url": os.getenv("BUILD_URL"),
+            "cpu0_baseline": config.get("cpu0_baseline", 0),
+            "cpu0_initvtor_s": config.get("cpu0_initvtor_s", "0x10000000"),
+            "psa_api_suite": os.getenv("TEST_PSA_API") if os.getenv("TEST_PSA_API") == "IPC" else "",
+        }
+        for binary_type, binary_name in config["binaries"].items():
+            params.update(
+                {
+                    "{}_url".format(binary_type): "{}/artifact/trusted-firmware-m/build/bin/{}".format(params["build_job_url"], binary_name)
+                }
+            )
 
-                        definition = template_env.get_template(template_file).render(
-                            params
-                        )
-                        definitions.update({params["job_name"]: definition})
+        if len(params["monitors"]) == 0:
+            break
+
+        definition = template_env.get_template(template_file).render(
+            params
+        )
+        definitions.update({params["job_name"]: definition})
+
     return definitions
 
 
@@ -138,10 +110,10 @@
     # Evaluate current directory
     work_dir = os.path.abspath(os.path.dirname(__file__))
 
-    # If a single platform is requested and it exists in the platform
-    if user_args.platform and user_args.platform in config["platforms"]:
+    # If platform exists in the LAVA platforms
+    if os.getenv("TFM_PLATFORM") in config["platforms"]:
         # Only test this platform
-        platform = user_args.platform
+        platform = os.getenv("TFM_PLATFORM")
         config["platforms"] = {platform: config["platforms"][platform]}
     # Generate the output definition
     definitions = generate_test_definitions(config, work_dir, user_args)
@@ -186,13 +158,6 @@
         help="Select built-in configuration by name",
     )
     cmdargs.add_argument(
-        "--build-number",
-        dest="build_no",
-        action="store",
-        default="lastSuccessfulBuild",
-        help="JENKINS Build number selector. " "Default: lastSuccessfulBuild",
-    )
-    cmdargs.add_argument(
         "--output-dir",
         dest="lava_def_output",
         action="store",
@@ -200,18 +165,6 @@
         help="Set LAVA compatible .yaml output file",
     )
     cmdargs.add_argument(
-        "--platform",
-        dest="platform",
-        action="store",
-        help="Override platform.Only the provided one " "will be tested",
-    )
-    cmdargs.add_argument(
-        "--compiler",
-        dest="compiler",
-        action="store",
-        help="Compiler to build definitions for",
-    )
-    cmdargs.add_argument(
         "--jenkins-build-url",
         dest="jenkins_build_url",
         action="store",
@@ -225,12 +178,6 @@
         help="Set the jenkins job name",
     )
     cmdargs.add_argument(
-        "--proj-config", dest="proj_config", action="store", help="Proj config"
-    )
-    cmdargs.add_argument(
-        "--build-type", dest="build_type", action="store", help="Build type"
-    )
-    cmdargs.add_argument(
         "--docker-prefix", dest="docker_prefix", action="store", help="Prefix string for the FVP docker registry location"
     )
     cmdargs.add_argument(
@@ -239,10 +186,6 @@
     cmdargs.add_argument(
         "--enable-code-coverage", dest="enable_code_coverage", action="store", default="FALSE", help="Enable trace-base code coverage"
     )
-    cmdargs.add_argument("--bl2", dest="bl2", action="store_true", help="BL2")
-    cmdargs.add_argument(
-        "--psa-api-suite", dest="psa_suite", action="store", help="PSA API Suite name"
-    )
 
     device_type.add_argument(
         "--fvp-only",