This function computes hash from all .py files in "lnst/" directory and from files "lnst-ctl" and "lnst-slave".
This function will be used for computing version of LNST
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Common/Utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
diff --git a/lnst/Common/Utils.py b/lnst/Common/Utils.py index 22d2925..ce67c92 100644 --- a/lnst/Common/Utils.py +++ b/lnst/Common/Utils.py @@ -290,3 +290,33 @@ def is_installed(program): return True except subprocess.CalledProcessError: return False + +def get_version_hash(): + """ + Returns MD5 hash computed from all .py files in lnst/ directory + and files lnst-ctl and lnst-slave + """ + file_list = [] + file_sum = "" + + for root, _, files in os.walk("./lnst/"): + for f in files: + if f.endswith(".py"): + file_list.append(os.path.join(root, f)) + + file_list.sort() + + for f in file_list: + with open(f, 'r') as fin: + file_sum += fin.read() + fin.close() + + for f in ["./lnst-ctl", "./lnst-slave"]: + with open(f, 'r') as fin: + file_sum += fin.read() + fin.close() + + md5 = hashlib.md5() + md5.update(file_sum) + + return md5.hexdigest()
This patch adds version hash to slave_desc variable which is returned in hello message in connection estabilishing between slave and controller.
We can check and compare the versions on controller, thus forbidding using different version of slave and controller, which may result in undefined behaviour
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Slave/NetTestSlave.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py index 9104e31..73cdeb1 100644 --- a/lnst/Slave/NetTestSlave.py +++ b/lnst/Slave/NetTestSlave.py @@ -24,7 +24,7 @@ from xmlrpclib import Binary from tempfile import NamedTemporaryFile from lnst.Common.Logs import log_exc_traceback from lnst.Common.PacketCapture import PacketCapture -from lnst.Common.Utils import die_when_parent_die +from lnst.Common.Utils import die_when_parent_die, get_version_hash from lnst.Common.ExecCmd import exec_cmd, ExecCmdFail from lnst.Common.ResourceCache import ResourceCache from lnst.Common.NetTestCommand import NetTestCommandContext @@ -95,6 +95,7 @@ class SlaveMethods: r_release, _ = exec_cmd("cat /etc/redhat-release", False, False, False) slave_desc["kernel_release"] = k_release.strip() slave_desc["redhat_release"] = r_release.strip() + slave_desc["version"] = get_version_hash()
return ("hello", slave_desc)
This patch adds check between version of Controller and each Slave used for the actual recipe. If the hashes are different, test ends with an error and informs user on which machine versions differ
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Controller/Machine.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py index 14a8061..73f1494 100644 --- a/lnst/Controller/Machine.py +++ b/lnst/Controller/Machine.py @@ -21,7 +21,7 @@ from xmlrpclib import Binary from lnst.Common.Config import lnst_config from lnst.Common.NetUtils import normalize_hwaddr from lnst.Common.Utils import wait_for, create_tar_archive -from lnst.Common.Utils import check_process_running +from lnst.Common.Utils import check_process_running, get_version_hash from lnst.Common.NetTestCommand import DEFAULT_TIMEOUT
# conditional support for libvirt @@ -193,6 +193,10 @@ class Machine(object): "to machine %s, handshake failed!" % hostname raise MachineError(msg)
+ if slave_desc["version"] != get_version_hash(): + raise MachineError("Version hash mismatch between this machine "\ + "and machine %s (%s)!" % (m_id, hostname)) + self._slave_desc = slave_desc
for iface in self._interfaces:
scratch this patchset, I accidentally run regression-tests on wrong branch, all tests fail due to bad path
sorry for the inconvenience
Best regards,
Jiri Prochazka LNST Developer | www.lnst-project.org
+420 532 294 633 | jprochaz@redhat.com Red Hat Czech | Purkyňova 71/99, 612 00 Brno
2015-08-27 18:42 GMT+02:00 Jiri Prochazka jprochaz@redhat.com:
This function computes hash from all .py files in "lnst/" directory and from files "lnst-ctl" and "lnst-slave".
This function will be used for computing version of LNST
Signed-off-by: Jiri Prochazka jprochaz@redhat.com
lnst/Common/Utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
diff --git a/lnst/Common/Utils.py b/lnst/Common/Utils.py index 22d2925..ce67c92 100644 --- a/lnst/Common/Utils.py +++ b/lnst/Common/Utils.py @@ -290,3 +290,33 @@ def is_installed(program): return True except subprocess.CalledProcessError: return False
+def get_version_hash():
- """
- Returns MD5 hash computed from all .py files in lnst/ directory
- and files lnst-ctl and lnst-slave
- """
- file_list = []
- file_sum = ""
- for root, _, files in os.walk("./lnst/"):
for f in files:
if f.endswith(".py"):
file_list.append(os.path.join(root, f))
- file_list.sort()
- for f in file_list:
with open(f, 'r') as fin:
file_sum += fin.read()
fin.close()
- for f in ["./lnst-ctl", "./lnst-slave"]:
with open(f, 'r') as fin:
file_sum += fin.read()
fin.close()
- md5 = hashlib.md5()
- md5.update(file_sum)
- return md5.hexdigest()
-- 2.4.3
lnst-developers@lists.fedorahosted.org