summaryrefslogtreecommitdiffstats
path: root/patches/opnfv-fuel/0021-common.py-allow-specifying-number-of-attempts-in-exe.patch
diff options
context:
space:
mode:
authorJosep Puigdemont <josep.puigdemont@enea.com>2016-05-08 13:04:07 +0200
committerJosep Puigdemont <josep.puigdemont@gmail.com>2016-05-08 12:18:25 +0000
commitbedeb36ac9ad42fb1ead2449ed8e75f0171808a2 (patch)
treed09bf3d730b109339363c326dc96dfd187b037f9 /patches/opnfv-fuel/0021-common.py-allow-specifying-number-of-attempts-in-exe.patch
parent82b3b366f2c677ea0ad58555d630f4c4091f82a3 (diff)
ARMband patches for the fuel@opnfv deploy scripts
These are a collection of patches that adapt the current Fuel deploy scripts for mainly two purposes: - Make it possible to create a Fuel VM on a remote libvirt server. We use the LIBVIRT_DEFAULT_URI environment variable to detect that. Local deploys are possible by setting this variable to 'quemu:///system', or leaving it empty. See: https://libvirt.org/remote.html for more details. - Make it possible to add additional network interfaces. For this we allow the user to pass the "-b bridge" paramter several times, and creating a new virtual NIC for each of them, in the same order they were given. This required a bit of refactoring of the code. None of the changes above should break backwards compatibility, except when indicated in the commit (search for CHANGE in the log) In addition there are some updates to the code that were deemed necessary, like the ability to retry when executing shell commands instead of directly failing, and a simplification of the DHA IPMI adapter. Change-Id: I8a0cd5b8672383decd861309328137971eaed14b Signed-off-by: Josep Puigdemont <josep.puigdemont@enea.com>
Diffstat (limited to 'patches/opnfv-fuel/0021-common.py-allow-specifying-number-of-attempts-in-exe.patch')
-rw-r--r--patches/opnfv-fuel/0021-common.py-allow-specifying-number-of-attempts-in-exe.patch70
1 files changed, 70 insertions, 0 deletions
diff --git a/patches/opnfv-fuel/0021-common.py-allow-specifying-number-of-attempts-in-exe.patch b/patches/opnfv-fuel/0021-common.py-allow-specifying-number-of-attempts-in-exe.patch
new file mode 100644
index 00000000..d799723e
--- /dev/null
+++ b/patches/opnfv-fuel/0021-common.py-allow-specifying-number-of-attempts-in-exe.patch
@@ -0,0 +1,70 @@
+From: Josep Puigdemont <josep.puigdemont@enea.com>
+Date: Fri, 6 May 2016 03:28:26 +0200
+Subject: [PATCH] common.py: allow specifying number of attempts in exec_cmd
+
+Some commands executed by exec_cmd may fail because of a temporary
+cause, and it may be desirable to retry the same command several times
+until it succeeds. One example of this are the ipmitool commands, which
+may fail temorarily on some targets if they get too many requests
+simultaneously.
+
+In this patch two new optional parameters are introduced to the function
+signature, which do not break backward compatibility:
+ attempts: which indicates how many times the command should be run if
+ it returns a non-zero value*, and defaults to 1 (as today).
+ delay: which indicates the delay in seconds between attempts, and
+ defaults to 5 seconds.
+ verbose: It will print the remaining attempts left for the current
+ command if set to True.
+
+* It may be desirable to add yet another parameter to indicate what
+ return value should be considered an error, but zero for now seems a
+ reasonable default
+
+Signed-off-by: Josep Puigdemont <josep.puigdemont@enea.com>
+---
+ deploy/common.py | 24 +++++++++++++++++-------
+ 1 file changed, 17 insertions(+), 7 deletions(-)
+
+diff --git a/deploy/common.py b/deploy/common.py
+index 41b4e27..3cd3e0e 100644
+--- a/deploy/common.py
++++ b/deploy/common.py
+@@ -16,6 +16,7 @@ import argparse
+ import shutil
+ import stat
+ import errno
++import time
+
+ N = {'id': 0, 'status': 1, 'name': 2, 'cluster': 3, 'ip': 4, 'mac': 5,
+ 'roles': 6, 'pending_roles': 7, 'online': 8, 'group_id': 9}
+@@ -37,13 +38,22 @@ out_handler.setFormatter(formatter)
+ LOG.addHandler(out_handler)
+ os.chmod(LOGFILE, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
+
+-def exec_cmd(cmd, check=True):
+- process = subprocess.Popen(cmd,
+- stdout=subprocess.PIPE,
+- stderr=subprocess.PIPE,
+- shell=True)
+- (response, stderr) = process.communicate()
+- return_code = process.returncode
++def exec_cmd(cmd, check=True, attempts=1, delay=5, verbose=False):
++ # a negative value means forever
++ while attempts != 0:
++ attempts = attempts - 1
++ process = subprocess.Popen(cmd,
++ stdout=subprocess.PIPE,
++ stderr=subprocess.PIPE,
++ shell=True)
++ (response, stderr) = process.communicate()
++ return_code = process.returncode
++ if return_code == 0 or attempts == 0:
++ break
++ time.sleep(delay)
++ if verbose:
++ log('%d attempts left: %s' % (attempts, cmd))
++
+ response = response.strip()
+ if check:
+ if return_code > 0: