[Fuego] [PATCH 3/3] install-debian: add -x because we dont use docker

Tim.Bird at sony.com Tim.Bird at sony.com
Thu Mar 14 01:40:39 UTC 2019


> -----Original Message-----
> From: Bird, Timothy
> 
> See comments below.
> 
> > -----Original Message-----
> > From: Daniel Sangorrin
> >
> > Signed-off-by: Daniel Sangorrin <daniel.sangorrin at toshiba.co.jp>
> > ---
> >  install-debian.sh | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/install-debian.sh b/install-debian.sh
> > index 1597535..62bf799 100755
> > --- a/install-debian.sh
> > +++ b/install-debian.sh
> > @@ -232,8 +232,8 @@ ln -s /fuego-ro/scripts/fuego-lava-target-teardown
> > /usr/local/bin
> >  #
> >
> ==========================================================
> > ====================
> >  echo "Run 'service netperf start' to start a netperf server"
> >  echo "Run 'iperf3 -V -s -D -f M' to start an iperf3 server"
> > -echo "Run 'ftc list-boards' to see the available boards"
> > -echo "Run 'ftc list-tests' to see the available tests"
> > -echo "Run 'ftc run-test -b local -t Functional.hello_world' to run a hello
> > world"
> > -echo "Run 'ftc run-test -b local -t Benchmark.Dhrystone -s 500M' to run
> > Dhrystone"
> > -echo "Run 'ftc gen-report' to get results"
> > +echo "Run 'ftc -x list-boards' to see the available boards"
> > +echo "Run 'ftc -x list-tests' to see the available tests"
> > +echo "Run 'ftc -x run-test -b local -t Functional.hello_world' to run a hello
> > world"
> > +echo "Run 'ftc -x run-test -b local -t Benchmark.Dhrystone -s 500M' to run
> > Dhrystone"
> > +echo "Run 'ftc -x gen-report' to get results"
> Ugh.  This inconsistency is ugly.  And I don't think these instructions
> will actually work, will they?  I thought 'ftc -x' always required a '-c
> <confpath>'
> to indicate the path to the configuration file.  See the FIXTHIS on line 4950
> of 'ftc'.
> 
> For some of these, it would be better to just run them externally always.
> 'ftc list-boards' , 'ftc list-tests' fall in that category.
> 
> Here's how I'd like 'ftc run-test' to work:
> 'ftc run-test' should be run internally if there is a docker container present,
> and externally if not (allowing the user to override and force it to run
> externally even if there is a container present, using the '-x' argument.)
> 
> Can we reliably detect that a Fuego docker container is running?
> We seem to have some code for this in 'container_command()'.
> 
> I think the logic I'll use here is as follows:
>  - if we're outside the container, and there exists /fuego-ro/conf/fuego.conf,
> then
>     if there is no container running, then execute the command external (don't
> require the '-x' flag)
> 
> I'll put some code in ftc to do this, which should allow us to not require the '-
> x' flag
> for native use of ftc.  Let me know what you think.

Here's what I came up with.  It's in 'next', and pushed to bitbucket.
Can you give it a test?
 -- Tim


Subject: [PATCH] ftc: do better handling for native invocations

If ftc is started outside the container, check if it's likely we're
running ftc natively.  If so, and a container is not running, then
default to running ftc outside the container rather than inside.

This is a bit complicated, but I think it captures the most common
use cases (and hopefully is not too brain-bending in weird situations).

This requires that the native installation have the fuego.conf file
in the directory /fuego-ro/conf, which is what the current debian
install script configures.

Move 'import jenkins' and routines that require it to later in
the command execution sequence, so that routines that don't depend
on it won't fail if python-jenkins is not installed on the host.

Signed-off-by: Tim Bird <tim.bird at sony.com>
---
 scripts/ftc | 150 ++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 86 insertions(+), 64 deletions(-)

diff --git a/scripts/ftc b/scripts/ftc
index e0a0a79..9d35c14 100755
--- a/scripts/ftc
+++ b/scripts/ftc
@@ -4302,6 +4302,25 @@ def inside_docker():
     else:
         return True
 
+# cache the name, if found, to avoid doing 'docker ps' twice
+cached_container_name = None
+
+# return fuego container name, or None if not found
+def get_running_fuego_container_name():
+    global cached_container_name
+
+    if cached_container_name:
+        return cached_container_name
+
+    # return the first container with "fuego" in the image or container name
+    dps_lines = subprocess.check_output("sudo docker ps", shell=True).split('\n')
+    for line in dps_lines:
+        if "fuego" in line:
+            cached_container_name = line.strip().split(" ")[-1]
+            break
+
+    return cached_container_name
+
 # Here's a convenience function to allow running ftc outside the container
 def container_command(cmd_list):
     # get name of docker container
@@ -4310,12 +4329,9 @@ def container_command(cmd_list):
     else:
         # use the first container with "fuego" in the image or container name
         # if none found, use "fuego-container"
-        fuego_container = "fuego-container"
-        dps_lines = subprocess.check_output("sudo docker ps", shell=True).split('\n')
-        for line in dps_lines:
-            if "fuego" in line:
-                fuego_container = line.strip().split(" ")[-1]
-                break
+        fuego_container = get_running_fuego_container_name()
+        if not fuego_container:
+            fuego_container = "fuego-container"
 
     # pass through the FUEGO_BATCH_ID environment variable
     env_arg_list = []
@@ -4894,7 +4910,7 @@ def main():
     global ll_verbose
     global ll_debug
 
-    # most commands must be run inside the docker container
+    # some commands must be run inside the docker container
     run_inside = True
     if "-x" in sys.argv:
         # allow user to force running the command outside the container
@@ -4905,7 +4921,7 @@ def main():
     if "-h" in sys.argv or 'help' in sys.argv:
         run_inside = False
 
-    # unless user requests it, run commands inside the container
+    # check whether to run the command inside the container
     outside_docker = not inside_docker()
     if outside_docker:
         # check for operations that can't be run from outside the container
@@ -4913,6 +4929,11 @@ def main():
             error_out("Can't do rm-jobs outside the container!\n" +
                     "Please re-run the command inside the container.")
 
+        # check if it's likely we're in a native install
+        container_name = get_running_fuego_container_name()
+        if os.path.exists("/fuego-ro/conf/fuego.conf") and not container_name:
+            run_inside = False
+
         if run_inside:
             # run this command inside the container
             cmd_list = ["ftc"] + sys.argv[1:]
@@ -5048,62 +5069,6 @@ def main():
         # shows fuego boards
         do_list_boards(conf)
 
-    if conf.jenkins_enabled:
-        import jenkins
-        server = jenkins.Jenkins(conf.JENKINS_URL)
-
-    if command.startswith("add-job"):
-        # adds Jenkins jobs
-        user_check(conf)
-        try:
-            do_add_jobs(conf, options)
-        except Exception as e:
-            # this assumes the problem is something with the options
-            sys.exit(str(e) + '\n' + command_help['add-jobs'][1])
-
-    if command.startswith("rm-job"):
-        # removes Jenkins jobs
-        user_check(conf)
-        try:
-            do_rm_jobs(conf, options)
-        except Exception as e:
-            sys.exit(str(e) + '\n' + command_help['rm-jobs'][1])
-
-    if command.startswith("add-node"):
-        # adds Jenkins nodes
-        user_check(conf)
-        try:
-            do_add_nodes(conf, options)
-        except Exception as e:
-            sys.exit(str(e) + '\n' + command_help['add-nodes'][1])
-
-    if command.startswith("rm-node"):
-        # removes Jenkins nodes
-        user_check(conf)
-        try:
-            do_rm_nodes(conf, options)
-        except Exception as e:
-            sys.exit(str(e) + '\n' + command_help['rm-nodes'][1])
-
-    if command == "list-nodes":
-        # shows jenkins nodes
-        user_check(conf)
-        do_list_nodes(conf)
-
-    if command == "list-jobs":
-        # shows jenkins jobs
-        user_check(conf)
-        do_list_jobs(conf)
-
-    if command.startswith("build-job"):
-        # build jenkins jobs
-        user_check(conf)
-        do_build_jobs(conf, options)
-
-    if command == "add-view":
-        user_check(conf)
-        do_add_view(conf, options)
-
     if command == "list-plans":
         do_list_plans(conf)
 
@@ -5168,6 +5133,63 @@ def main():
         rcode = do_release_resource(conf, options)
         sys.exit(rcode)
 
+
+    if conf.jenkins_enabled:
+        import jenkins
+        server = jenkins.Jenkins(conf.JENKINS_URL)
+
+    if command.startswith("add-job"):
+        # adds Jenkins jobs
+        user_check(conf)
+        try:
+            do_add_jobs(conf, options)
+        except Exception as e:
+            # this assumes the problem is something with the options
+            sys.exit(str(e) + '\n' + command_help['add-jobs'][1])
+
+    if command.startswith("rm-job"):
+        # removes Jenkins jobs
+        user_check(conf)
+        try:
+            do_rm_jobs(conf, options)
+        except Exception as e:
+            sys.exit(str(e) + '\n' + command_help['rm-jobs'][1])
+
+    if command.startswith("add-node"):
+        # adds Jenkins nodes
+        user_check(conf)
+        try:
+            do_add_nodes(conf, options)
+        except Exception as e:
+            sys.exit(str(e) + '\n' + command_help['add-nodes'][1])
+
+    if command.startswith("rm-node"):
+        # removes Jenkins nodes
+        user_check(conf)
+        try:
+            do_rm_nodes(conf, options)
+        except Exception as e:
+            sys.exit(str(e) + '\n' + command_help['rm-nodes'][1])
+
+    if command == "list-nodes":
+        # shows jenkins nodes
+        user_check(conf)
+        do_list_nodes(conf)
+
+    if command == "list-jobs":
+        # shows jenkins jobs
+        user_check(conf)
+        do_list_jobs(conf)
+
+    if command.startswith("build-job"):
+        # build jenkins jobs
+        user_check(conf)
+        do_build_jobs(conf, options)
+
+    if command == "add-view":
+        user_check(conf)
+        do_add_view(conf, options)
+
     # all non-board commands have been handled
     #if command in board_mod_commands:
     #   check_reservation(bmap, command)
-- 
2.1.4



More information about the Fuego mailing list