Add support for handling of forwarded broker requests
Change-Id: I0d4ed457e1d59eabed3340f5dc7d8353d5d66f04
This commit is contained in:
parent
7627eb2e85
commit
61c94148d9
|
@ -1,4 +1,3 @@
|
||||||
- project:
|
- project:
|
||||||
templates:
|
templates:
|
||||||
- python35-charm-jobs
|
- openstack-python3-charm-jobs
|
||||||
- openstack-python3-ussuri-jobs
|
|
||||||
|
|
28
requires.py
28
requires.py
|
@ -13,6 +13,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
import json
|
||||||
import socket
|
import socket
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
@ -151,6 +152,24 @@ class CephRBDMirrorRequires(Endpoint):
|
||||||
ch_ceph.send_request_if_needed(current_request,
|
ch_ceph.send_request_if_needed(current_request,
|
||||||
relation=self.endpoint_name)
|
relation=self.endpoint_name)
|
||||||
|
|
||||||
|
def maybe_send_rq(self, rq):
|
||||||
|
"""Send single broker request with all operations if needed.
|
||||||
|
|
||||||
|
The rbd-mirror charm has two endpoints using this interface connected
|
||||||
|
to the ceph-mon in the local and remote clusters. Subsequently each
|
||||||
|
relation typically only has one other participant, the ceph-mon.
|
||||||
|
|
||||||
|
The charm will recieve a verbatim copy of every broker request the
|
||||||
|
ceph-mon knows about in one end and then extract and filter all the
|
||||||
|
operations and collapse into one new single broker request that is
|
||||||
|
maintained with the ceph-mon in the other end.
|
||||||
|
|
||||||
|
:param rq: Broker Request to evaluate for sending.
|
||||||
|
:type rq: ch_ceph.CephBrokerRq
|
||||||
|
"""
|
||||||
|
for relation in self.relations:
|
||||||
|
ch_ceph.send_request_if_needed(rq, relation=self.endpoint_name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def auth(self):
|
def auth(self):
|
||||||
"""Retrieve ``auth`` from relation data."""
|
"""Retrieve ``auth`` from relation data."""
|
||||||
|
@ -216,3 +235,12 @@ class CephRBDMirrorRequires(Endpoint):
|
||||||
@property
|
@property
|
||||||
def pools(self):
|
def pools(self):
|
||||||
return self.all_joined_units.received['pools']
|
return self.all_joined_units.received['pools']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def broker_requests(self):
|
||||||
|
if ('broker_requests' in self.all_joined_units.received and
|
||||||
|
self.all_joined_units.received['broker_requests'] is not None):
|
||||||
|
for json_rq in self.all_joined_units.received['broker_requests']:
|
||||||
|
yield json.loads(json_rq)
|
||||||
|
# Empty return in generator provides empty iterator and not None PEP479
|
||||||
|
return
|
||||||
|
|
18
tox.ini
18
tox.ini
|
@ -1,6 +1,6 @@
|
||||||
[tox]
|
[tox]
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
envlist = pep8,py37
|
envlist = pep8,py3
|
||||||
# NOTE(beisner): Avoid build/test env pollution by not enabling sitepackages.
|
# NOTE(beisner): Avoid build/test env pollution by not enabling sitepackages.
|
||||||
sitepackages = False
|
sitepackages = False
|
||||||
# NOTE(beisner): Avoid false positives by not skipping missing interpreters.
|
# NOTE(beisner): Avoid false positives by not skipping missing interpreters.
|
||||||
|
@ -69,6 +69,20 @@ commands =
|
||||||
coverage xml -o cover/coverage.xml
|
coverage xml -o cover/coverage.xml
|
||||||
coverage report
|
coverage report
|
||||||
|
|
||||||
|
[testenv:py38]
|
||||||
|
basepython = python3.8
|
||||||
|
deps = -r{toxinidir}/test-requirements.txt
|
||||||
|
setenv =
|
||||||
|
{[testenv]setenv}
|
||||||
|
PYTHON=coverage run
|
||||||
|
commands =
|
||||||
|
coverage erase
|
||||||
|
stestr run {posargs}
|
||||||
|
coverage combine
|
||||||
|
coverage html -d cover
|
||||||
|
coverage xml -o cover/coverage.xml
|
||||||
|
coverage report
|
||||||
|
|
||||||
[testenv:pep8]
|
[testenv:pep8]
|
||||||
basepython = python3
|
basepython = python3
|
||||||
deps = -r{toxinidir}/test-requirements.txt
|
deps = -r{toxinidir}/test-requirements.txt
|
||||||
|
@ -89,4 +103,4 @@ omit =
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# E402 ignore necessary for path append before sys module import in actions
|
# E402 ignore necessary for path append before sys module import in actions
|
||||||
ignore = E402
|
ignore = E402,W504
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import json
|
||||||
import mock
|
import mock
|
||||||
import requires
|
import requires
|
||||||
|
|
||||||
|
@ -209,3 +210,29 @@ class TestCephRBDMirrorRequires(test_utils.PatchHelper):
|
||||||
self._all_joined_units.received.__getitem__.assert_called_once_with(
|
self._all_joined_units.received.__getitem__.assert_called_once_with(
|
||||||
'ceph-cluster-address')
|
'ceph-cluster-address')
|
||||||
self.resolve_network_cidr.assert_called_once_with('192.0.2.1')
|
self.resolve_network_cidr.assert_called_once_with('192.0.2.1')
|
||||||
|
|
||||||
|
def test_maybe_send_rq(self):
|
||||||
|
self.patch_requires_class('_relations')
|
||||||
|
relation = mock.MagicMock()
|
||||||
|
self._relations.__iter__.return_value = [relation]
|
||||||
|
self.patch_object(requires.ch_ceph, 'send_request_if_needed')
|
||||||
|
self.requires_class.maybe_send_rq('aRq')
|
||||||
|
self.send_request_if_needed.assert_called_once_with(
|
||||||
|
'aRq', relation='some-endpoint')
|
||||||
|
|
||||||
|
def test_broker_requests(self):
|
||||||
|
self.patch_requires_class('_all_joined_units')
|
||||||
|
self._all_joined_units.received.__contains__.return_value = True
|
||||||
|
self._all_joined_units.received.__getitem__.return_value = [
|
||||||
|
json.dumps({'fakereq': 0}),
|
||||||
|
json.dumps({'fakereq': 1}),
|
||||||
|
]
|
||||||
|
for rq in self.requires_class.broker_requests:
|
||||||
|
self.assertIn(rq['fakereq'], (0, 1))
|
||||||
|
self._all_joined_units.received.__contains__.return_value = False
|
||||||
|
with self.assertRaises(StopIteration):
|
||||||
|
next(self.requires_class.broker_requests)
|
||||||
|
self._all_joined_units.received.__contains__.return_value = True
|
||||||
|
self._all_joined_units.received.__getitem__.return_value = None
|
||||||
|
with self.assertRaises(StopIteration):
|
||||||
|
next(self.requires_class.broker_requests)
|
||||||
|
|
Loading…
Reference in New Issue