The are two types of versions - LNST Major Version and git HEAD commit hash. LNST Major Version is used when LNST is installed and run from RPM and git commit hash is used when LNST is run from devel git repo.
LNSTMajorVersion variable in Config.py will have to be manully incremented each time new release is made.
Used version is stored in Config.version attribute.
Getting git HEAD commit hash is done in following steps: 1) Save cwd 2) Change cwd to directory where Config.py file is located 3) Try running git rev-parse HEAD, which returns commit hash 4) If git command execution was successful, use hash as version 5) Else use value of LNSTMajorVersion as version 6) Return to original working directory
If we didn't change cwd, we would have problems with running LNST installed from RPM in any git repo folder.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Common/Config.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py index 31481b2..7b4d17e 100644 --- a/lnst/Common/Config.py +++ b/lnst/Common/Config.py @@ -13,12 +13,15 @@ olichtne@redhat.com (Ondrej Lichtner) import os import sys import re +import subprocess from lnst.Common.Utils import bool_it from lnst.Common.NetUtils import verify_mac_address from lnst.Common.Colours import get_preset_conf
DefaultRPCPort = 9999
+LNSTMajorVersion = '11' + class ConfigError(Exception): pass
@@ -28,6 +31,21 @@ class Config():
def __init__(self): self._options = dict() + self.version = self._get_version() + + def _get_version(self): + # Check if I'm in git + try: + cwd = os.getcwd() + abspath = os.path.abspath(__file__) + dname = os.path.dirname(abspath) + os.chdir(dname) + head = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() + return head + except subprocess.CalledProcessError: + return LNSTMajorVersion + finally: + os.chdir(cwd)
def controller_init(self): self._options['environment'] = dict()
This patch just adds LNST version string to slave description dict which is sent to Controller.
Version comparison will be done on Controller.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Slave/NetTestSlave.py | 1 + 1 file changed, 1 insertion(+)
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py index 9a366f3..8d8fada 100644 --- a/lnst/Slave/NetTestSlave.py +++ b/lnst/Slave/NetTestSlave.py @@ -97,6 +97,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["lnst_version"] = lnst_config.version
return ("hello", slave_desc)
This patch implements version check between Controller and Slaves. Check is done after hello messages are exchanged. Controller extracts Slave version slave_desc dict and compares with its own version.
These situations might happen: 1) Versions match - everything continues as normally 2) Versions mismatch: a) Both Ctl and Slave are run from git repo - warning message is shown, but execution continues b) Ctl/Slave is run from git repo but the second one is run from RPM installation - exception is raised and execution is stopped
changes in v2: * logging warning message is now multiline - decorated with '=' * replaced method compare_versions with is_git_version
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- lnst/Controller/Machine.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py index c5d9191..3e730bd 100644 --- a/lnst/Controller/Machine.py +++ b/lnst/Controller/Machine.py @@ -247,6 +247,22 @@ class Machine(object): "to machine %s, handshake failed!" % hostname raise MachineError(msg)
+ slave_version = slave_desc["lnst_version"] + slave_is_git = self.is_git_version(slave_version) + ctl_version = lnst_config.version + ctl_is_git = self.is_git_version(ctl_version) + if slave_version != ctl_version: + if ctl_is_git and slave_is_git: + msg = "Controller and Slave '%s' git versions are different"\ + % hostname + logging.warning(len(msg)*"=") + logging.warning(msg) + logging.warning(len(msg)*"=") + else: + msg = "Controller and Slave '%s' versions are not compatible!"\ + % hostname + raise MachineError(msg) + self._slave_desc = slave_desc
devices = self._rpc_call("get_devices") @@ -258,6 +274,13 @@ class Machine(object):
self._configured = True
+ def is_git_version(self, version): + try: + int(version) + return False + except ValueError: + return True + def is_configured(self): """ Test if the machine was configured """
Version number is now stored in Common/Config.py file, so it can be imported to setup.py. When releasing new version, only that variable will have to be updated.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/setup.py b/setup.py index 4c7b460..144e25c 100755 --- a/setup.py +++ b/setup.py @@ -23,6 +23,7 @@ import gzip import os from time import gmtime, strftime from distutils.core import setup +from lnst.Common.Config import LNSTMajorVersion
def process_template(template_path, values): template_name_re = ".in$" @@ -181,7 +182,7 @@ DATA_FILES = CONFIG + TEST_MODULES + MULTICAST_TEST_TOOLS + MAN_PAGES + \ SCHEMAS + BASH_COMP + RECIPE_FILES + RESULT_XSLT_DATA
setup(name="lnst", - version="11", + version=LNSTMajorVersion, description="Linux Network Stack Test", author="LNST Team", author_email="lnst-developers@lists.fedorahosted.org",
On Tue, May 31, 2016 at 03:27:03PM +0200, Jiri Prochazka wrote:
Version number is now stored in Common/Config.py file, so it can be imported to setup.py. When releasing new version, only that variable will have to be updated.
Signed-off-by: Jiri Prochazka jprochaz@redhat.com
ack to set
lnst-developers@lists.fedorahosted.org