[elbe-devel] [PATCH] elbepack: soapclient: always validate server version
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Mon Jun 24 11:29:54 CEST 2024
Only matching versions between the elbe soap server and client are
supported. Always validate this.
Previously it was possible to use "elbe control/prjrepo --ignore-version-diff"
to manually skip this check. But as these lowlevel commands are always
executed without those arguments through the highlevel wrappers, they
are unused.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/commands/control.py | 25 -------------------------
elbepack/commands/prjrepo.py | 26 --------------------------
elbepack/soapclient.py | 15 +++++++++++++++
3 files changed, 15 insertions(+), 51 deletions(-)
diff --git a/elbepack/commands/control.py b/elbepack/commands/control.py
index f729388e1cbc..feed0c71b3cd 100644
--- a/elbepack/commands/control.py
+++ b/elbepack/commands/control.py
@@ -13,7 +13,6 @@ from suds import WebFault
from elbepack.config import cfg
from elbepack.elbexml import ValidationMode
from elbepack.soapclient import ClientAction, ElbeSoapClient
-from elbepack.version import elbe_version
def run_command(argv):
@@ -103,11 +102,6 @@ def run_command(argv):
dest='debug', default=False,
help='Enable debug mode.')
- devel.add_option('--ignore-version-diff', action='store_true',
- dest='ignore_version', default=False,
- help='allow different elbe version on host and initvm')
- oparser.add_option_group(devel)
-
(opt, args) = oparser.parse_args(argv)
if not args:
@@ -151,25 +145,6 @@ def run_command(argv):
print("try 'elbe initvm start'", file=sys.stderr)
sys.exit(15)
- try:
- v_server = control.service.get_version()
- if v_server != elbe_version:
- print(
- f'elbe v{v_server} is used in initvm, this is not compatible '
- f'with elbe v{elbe_version} that is used on this machine. '
- 'Please install same versions of elbe in initvm and on your '
- 'machine.',
- file=sys.stderr)
-
- if not opt.ignore_version:
- sys.exit(16)
- except AttributeError:
- print("the elbe installation inside the initvm doesn't provide a "
- 'get_version interface. Please create a new initvm or upgrade '
- 'elbe inside the existing initvm.', file=sys.stderr)
- if not opt.ignore_version:
- sys.exit(24)
-
try:
action = ClientAction(args[0])
except KeyError:
diff --git a/elbepack/commands/prjrepo.py b/elbepack/commands/prjrepo.py
index 220d956bba7a..5d4b4acef52a 100644
--- a/elbepack/commands/prjrepo.py
+++ b/elbepack/commands/prjrepo.py
@@ -12,7 +12,6 @@ from suds import WebFault
from elbepack.config import cfg
from elbepack.soapclient import ElbeSoapClient, RepoAction
-from elbepack.version import elbe_version
def run_command(argv):
@@ -46,11 +45,6 @@ def run_command(argv):
dest='debug', default=False,
help='Enable debug mode.')
- devel.add_option('--ignore-version-diff', action='store_true',
- dest='ignore_version', default=False,
- help='allow different elbe version on host and initvm')
- oparser.add_option_group(devel)
-
(opt, args) = oparser.parse_args(argv)
if not args:
@@ -97,26 +91,6 @@ def run_command(argv):
file=sys.stderr)
sys.exit(12)
- # Check Elbe version
- try:
- v_server = control.service.get_version()
- if v_server != elbe_version:
- print(
- f'elbe v{v_server} is used in initvm, this is not compatible '
- f'with elbe v{elbe_version} that is used on this machine. '
- 'Please install same versions of elbe in initvm and on your '
- 'machine.',
- file=sys.stderr)
-
- if not opt.ignore_version:
- sys.exit(20)
- except AttributeError:
- print("the elbe installation inside the initvm doesn't provide a \
-get_version interface. Please create a new initvm or upgrade \
-elbe inside the existing initvm.", file=sys.stderr)
- if not opt.ignore_version:
- sys.exit(21)
-
# Check whether subcommand exists
try:
action = RepoAction(args[0])
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index 475bc23ad7e3..71365bbcb78e 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -21,6 +21,19 @@ from suds.client import Client
from elbepack.config import cfg
from elbepack.elbexml import ElbeXML, ValidationMode
+from elbepack.version import elbe_version
+
+
+class ElbeVersionMismatch(RuntimeError):
+ def __init__(self, client_version, server_version):
+ self.client_version = client_version
+ self.server_version = server_version
+ super().__init__(f'Client: {client_version} Server: {server_version}')
+
+ @classmethod
+ def check(cls, client_version, server_version):
+ if client_version != server_version:
+ raise cls(client_version, server_version)
def set_suds_debug(debug):
@@ -71,6 +84,8 @@ class ElbeSoapClient:
# to the service object.
self.service = self.control.service
+ ElbeVersionMismatch.check(elbe_version, self.service.get_version())
+
# We have a Connection, now login
self.service.login(user, passwd)
---
base-commit: d81932de2d2a72bb6bebe0f5ac67b3a59326a574
change-id: 20240624-version-check-a48b1f8c07d2
Best regards,
--
Thomas Weißschuh <thomas.weissschuh at linutronix.de>
More information about the elbe-devel
mailing list