integ/python/zerorpc-python/debian/deb_folder/patches/0005-Fix-kwargs-when-internal-opts-are-present.patch
Alyson Deives Pereira 838ae8f47c Create Debian zerorpc-python package
The zerorpc package is a light-weight, reliable and language-agnostic
library for distributed communication between server-side processes.
It builds on top of ZeroMQ and MessagePack.

This package is required for sysinv ZeroMQ-based RPC backend [1].

TEST PLAN:
PASS: Verify STX Debian builds properly
PASS: Verify STX Debian deploys properly
PASS: Verify zerorpc-python package was properly installed
PASS: Verify syinv processes runs properly

[1] https://review.opendev.org/c/starlingx/config/+/859571

Story: 2010087
Task: 46794

Signed-off-by: Alyson Deives Pereira <alyson.deivespereira@windriver.com>
Change-Id: I62565e2ce39c0bed63506bfcabf909d5cf186ec1
2022-11-14 15:43:13 -03:00

120 lines
3.9 KiB
Diff

From 219a731eed49141430890bd87495a29903b11fd4 Mon Sep 17 00:00:00 2001
From: Isac Souza <IsacSacchi.Souza@windriver.com>
Date: Wed, 10 Aug 2022 09:10:56 -0300
Subject: [PATCH] Fix kwargs when internal opts are present
---
tests/test_kwargs.py | 8 ++++----
tox.ini | 2 +-
zerorpc/core.py | 31 +++++++++++++++++++++++--------
3 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/tests/test_kwargs.py b/tests/test_kwargs.py
index e3d7009..4aa56b3 100644
--- a/tests/test_kwargs.py
+++ b/tests/test_kwargs.py
@@ -19,12 +19,12 @@ def test_client_connect():
client = zerorpc.Client()
client.connect(endpoint)
- args = 1, 2, 3
+ args = [1, 2, 3]
kwargs = {'a': 7, 'b': 8}
res = client.echo(*args, **kwargs)
assert len(res) == 2
assert res[0] == args
- assert len(res[1]) == 3
+ assert len(res[1]) == 2
assert 'a' in res[1] and 'b' in res[1]
def test_client_quick_connect():
@@ -41,10 +41,10 @@ def test_client_quick_connect():
client = zerorpc.Client(endpoint)
- args = 1, 2, 3
+ args = [1, 2, 3]
kwargs = {'a': 7, 'b': 8}
res = client.echo(*args, **kwargs)
assert len(res) == 2
assert res[0] == args
- assert len(res[1]) == 3
+ assert len(res[1]) == 2
assert 'a' in res[1] and 'b' in res[1]
diff --git a/tox.ini b/tox.ini
index f2727d8..2f1a989 100644
--- a/tox.ini
+++ b/tox.ini
@@ -7,7 +7,7 @@ deps =
pytest
commands =
#flake8 zerorpc bin
- pytest -v
+ pytest -v {posargs}
passenv = ZPC_TEST_TIME_FACTOR
[flake8]
diff --git a/zerorpc/core.py b/zerorpc/core.py
index 3bee937..f9f0b38 100644
--- a/zerorpc/core.py
+++ b/zerorpc/core.py
@@ -45,6 +45,23 @@ from logging import getLogger
logger = getLogger(__name__)
+class MessageOptions:
+ def __init__(self, timeout, slots, async_response):
+ self.timeout = timeout
+ self.slots = slots
+ self.async_response = async_response
+
+ @staticmethod
+ def from_kwargs(kwargs_dict, default_timeout):
+ timeout = kwargs_dict.pop('timeout_', default_timeout)
+ slots = kwargs_dict.pop('slots_', 100)
+ # In python 3.7, "async" is a reserved keyword, clients should now use
+ # "async_": support both for the time being
+ async_ = kwargs_dict.pop('async_', False)
+
+ return MessageOptions(timeout, slots, async_)
+
+
class ServerBase(object):
def __init__(self, channel, methods=None, name=None, context=None,
@@ -255,25 +272,23 @@ class ClientBase(object):
if isinstance(method, bytes):
method = method.decode('utf-8')
- timeout = kwargs.pop('timeout_', self._timeout)
+ opts = MessageOptions.from_kwargs(kwargs, self._timeout)
+
channel = self._multiplexer.channel()
hbchan = HeartBeatOnChannel(channel, freq=self._heartbeat_freq,
passive=self._passive_heartbeat)
- bufchan = BufferedChannel(hbchan, inqueue_size=kwargs.pop('slots_', 100))
+ bufchan = BufferedChannel(hbchan, inqueue_size=opts.slots)
xheader = self._context.hook_get_task_context()
request_event = bufchan.new_event(method, args, kwargs, xheader)
self._context.hook_client_before_request(request_event)
bufchan.emit_event(request_event)
- # In python 3.7, "async" is a reserved keyword, clients should now use
- # "async_": support both for the time being
- async_ = kwargs.pop('async_', False)
- if not async_:
- return self._process_response(request_event, bufchan, timeout)
+ if not opts.async_response:
+ return self._process_response(request_event, bufchan, opts.timeout)
return eventlet.spawn(self._process_response, request_event, bufchan,
- timeout)
+ opts.timeout)
def __getattr__(self, method):
return lambda *args, **kwargs: self(method, *args, **kwargs)
--
2.25.1