[elbe-devel] [PATCH 1/9] elbepack: remove global configuration soaptimeout
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Thu Aug 1 12:40:22 CEST 2024
Instead of having a global variable, pass around the value explicitly
from the entrypoints to the usage site.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/commands/control.py | 5 ++++-
elbepack/commands/prjrepo.py | 5 ++++-
elbepack/commands/updated.py | 4 ++++
elbepack/config.py | 12 ++++++++----
elbepack/soapclient.py | 5 ++---
elbepack/updated.py | 6 +++---
6 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/elbepack/commands/control.py b/elbepack/commands/control.py
index 101c4bdcc0fd..c642b27a19b8 100644
--- a/elbepack/commands/control.py
+++ b/elbepack/commands/control.py
@@ -15,7 +15,7 @@ from urllib.error import URLError
from suds import WebFault
from elbepack.cli import add_argument, add_arguments_from_decorated_function
-from elbepack.config import cfg
+from elbepack.config import add_argument_soaptimeout, cfg
from elbepack.elbexml import ElbeXML, ValidationMode
from elbepack.soapclient import ElbeSoapClient
@@ -381,6 +381,8 @@ def run_command(argv):
aparser.add_argument('--user', dest='user', default=cfg['elbeuser'],
help='Username (default is root).')
+ add_argument_soaptimeout(aparser)
+
aparser.add_argument(
'--retries',
dest='retries',
@@ -416,6 +418,7 @@ def run_command(argv):
args.port,
args.user,
args.passwd,
+ args.soaptimeout,
debug=args.debug,
retries=args.retries)
except URLError:
diff --git a/elbepack/commands/prjrepo.py b/elbepack/commands/prjrepo.py
index 769eb4420904..a10592db1a2e 100644
--- a/elbepack/commands/prjrepo.py
+++ b/elbepack/commands/prjrepo.py
@@ -16,7 +16,7 @@ import debian.deb822
from suds import WebFault
from elbepack.cli import add_argument, add_arguments_from_decorated_function
-from elbepack.config import cfg
+from elbepack.config import add_argument_soaptimeout, cfg
from elbepack.soapclient import ElbeSoapClient
@@ -141,6 +141,8 @@ def run_command(argv):
aparser.add_argument('--user', dest='user', default=cfg['elbeuser'],
help='Username (default is root).')
+ add_argument_soaptimeout(aparser)
+
aparser.add_argument(
'--retries',
dest='retries',
@@ -171,6 +173,7 @@ def run_command(argv):
args.port,
args.user,
args.passwd,
+ args.soaptimeout,
debug=args.debug,
retries=args.retries,
)
diff --git a/elbepack/commands/updated.py b/elbepack/commands/updated.py
index 0ae7f244ebd0..1fe453e1a9ea 100644
--- a/elbepack/commands/updated.py
+++ b/elbepack/commands/updated.py
@@ -12,6 +12,7 @@ from wsgiref.simple_server import make_server
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
+from elbepack.config import add_argument_soaptimeout
from elbepack.updated import UpdateApplication, UpdateService, UpdateStatus
from elbepack.updated_monitors import FileMonitor
@@ -60,6 +61,8 @@ def run_command(argv):
default=False,
help='monitor USB devices')
+ add_argument_soaptimeout(aparser)
+
args = aparser.parse_args(argv)
status.nosign = args.nosign
@@ -98,6 +101,7 @@ def run_command(argv):
mon.start()
application = UpdateApplication([UpdateService], 'update',
+ monitor_timeout=args.soaptimeout,
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11())
application.status = status
diff --git a/elbepack/config.py b/elbepack/config.py
index f0f3e4c80237..c9a0edff2a9a 100644
--- a/elbepack/config.py
+++ b/elbepack/config.py
@@ -10,7 +10,6 @@ class Config(dict):
dict.__init__(self)
self['soaphost'] = 'localhost'
self['soapport'] = '7587'
- self['soaptimeout'] = 90
self['sshport'] = '5022'
self['elbeuser'] = 'root'
self['elbepass'] = 'foo'
@@ -25,9 +24,6 @@ class Config(dict):
if 'ELBE_SOAPHOST' in os.environ:
self['soaphost'] = os.environ['ELBE_SOAPHOST']
- if 'ELBE_SOAPTIMEOUT_SECS' in os.environ:
- self['soaptimeout'] = int(os.environ['ELBE_SOAPTIMEOUT_SECS'])
-
if 'ELBE_USER' in os.environ:
self['elbeuser'] = os.environ['ELBE_USER']
@@ -39,3 +35,11 @@ class Config(dict):
cfg = Config()
+
+
+def add_argument_soaptimeout(parser):
+ parser.add_argument(
+ '--soaptimeout',
+ type=int,
+ default=os.environ.get('ELBE_SOAPTIMEOUT_SECS', '90'),
+ )
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index 3957cfa2469d..21e2fd980e20 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -13,7 +13,6 @@ from urllib.error import URLError
from suds.client import Client
-from elbepack.config import cfg
from elbepack.version import elbe_version
@@ -45,7 +44,7 @@ def set_suds_debug(debug):
class ElbeSoapClient:
- def __init__(self, host, port, user, passwd, retries=10, debug=False):
+ def __init__(self, host, port, user, passwd, timeout, retries=10, debug=False):
# Mess with suds logging, for debug, or squelch warnings
set_suds_debug(debug)
@@ -59,7 +58,7 @@ class ElbeSoapClient:
while control is None:
current_retries += 1
try:
- control = Client(self.wsdl, timeout=cfg['soaptimeout'])
+ control = Client(self.wsdl, timeout=timeout)
except URLError as e:
if current_retries > retries:
raise e
diff --git a/elbepack/updated.py b/elbepack/updated.py
index 214cb379ec2d..a413e55975f0 100644
--- a/elbepack/updated.py
+++ b/elbepack/updated.py
@@ -31,7 +31,6 @@ from elbepack.aptprogress import (
ElbeInstallProgress,
ElbeOpProgress,
)
-from elbepack.config import cfg
from elbepack.egpg import unsign_file
from elbepack.treeutils import etree
@@ -93,9 +92,10 @@ class UpdateStatus:
class UpdateApplication (Application):
- def __init__(self, *args, **kargs):
+ def __init__(self, *args, monitor_timeout, **kargs):
Application.__init__(self, *args, **kargs)
self.status = UpdateStatus()
+ self.monitor_timeout = monitor_timeout
class UpdateService (ServiceBase):
@@ -139,7 +139,7 @@ class UpdateService (ServiceBase):
@rpc(String)
def register_monitor(self, wsdl_url):
- self.app.status.monitor = Client(wsdl_url, timeout=cfg['soaptimeout'])
+ self.app.status.monitor = Client(wsdl_url, timeout=self.app.monitor_timeout)
self.app.status.log('connection established')
--
2.45.2
More information about the elbe-devel
mailing list