lava_rpc_connector: If enabled, submit FVP jobs to TuxSuite

Controlled by USE_TUXSUITE_FVP job param (default is 0 as of now).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: I3fa35ca6077e4fa41d55bd062c9fd2db5d954d07
diff --git a/tfm_ci_pylib/lava_rpc_connector.py b/tfm_ci_pylib/lava_rpc_connector.py
index 6baa90a..37e602e 100644
--- a/tfm_ci_pylib/lava_rpc_connector.py
+++ b/tfm_ci_pylib/lava_rpc_connector.py
@@ -21,10 +21,12 @@
 __version__ = "1.4.0"
 
 import xmlrpc.client
+import os
 import time
 import yaml
 import requests
 import shutil
+import subprocess
 import logging
 
 
@@ -194,6 +196,23 @@
                   job_definition)
             print(e)
             return None, None
+
+        device_type = self.device_type_from_def(job_data)
+
+        if device_type == "fvp" and os.environ.get("USE_TUXSUITE_FVP", "0") == "1":
+            output = subprocess.check_output(
+                "python3 -u -m tuxsuite test submit --no-wait --device fvp-lava --job-definition %s" % job_definition,
+                shell=True,
+            )
+
+            job_id = job_url = None
+            for l in output.decode().split("\n"):
+                _log.debug(l)
+                if l.startswith("uid:"):
+                    job_id = l.split(None, 1)[1].strip()
+                    job_url = "https://tuxapi.tuxsuite.com/v1/groups/tfc/projects/ci/tests/" + job_id
+            return (job_id, job_url)
+
         try:
             if self.has_device_type(job_data):
                 job_id = self.scheduler.submit_job(job_data)