improved peer svc stop request logic
This commit is contained in:
@@ -302,6 +302,14 @@ def all_peers_stopped(responses):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_first_available_value(responses, key):
|
||||||
|
for r in responses:
|
||||||
|
if key in r:
|
||||||
|
return r['key']
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def cluster_leader_actions():
|
def cluster_leader_actions():
|
||||||
"""Cluster relation hook actions to be performed by leader units.
|
"""Cluster relation hook actions to be performed by leader units.
|
||||||
|
|
||||||
@@ -322,8 +330,8 @@ def cluster_leader_actions():
|
|||||||
raise SwiftProxyCharmException(msg)
|
raise SwiftProxyCharmException(msg)
|
||||||
|
|
||||||
log("Syncing rings and builders", level=DEBUG)
|
log("Syncing rings and builders", level=DEBUG)
|
||||||
peers = not responses[0].get(key, False)
|
peers_only = not get_first_available_value(responses, key)
|
||||||
broadcast_rings_available(peers=peers)
|
broadcast_rings_available(storage=not peers_only)
|
||||||
else:
|
else:
|
||||||
log("Not all peer apis stopped - skipping sync until all peers ready "
|
log("Not all peer apis stopped - skipping sync until all peers ready "
|
||||||
"(got %s)" % (responses), level=INFO)
|
"(got %s)" % (responses), level=INFO)
|
||||||
@@ -339,12 +347,14 @@ def cluster_non_leader_actions():
|
|||||||
settings = relation_get()
|
settings = relation_get()
|
||||||
|
|
||||||
# Check whether we have been requested to stop proxy service
|
# Check whether we have been requested to stop proxy service
|
||||||
rq_token = settings.get('stop-proxy-service')
|
token = settings.get('stop-proxy-service', None)
|
||||||
if rq_token:
|
if token:
|
||||||
log("Peer request to stop proxy service received (%s)" % (rq_token),
|
log("Peer request to stop proxy service received (%s)" % (token),
|
||||||
level=INFO)
|
level=INFO)
|
||||||
service_stop('swift-proxy')
|
service_stop('swift-proxy')
|
||||||
rq = SwiftProxyClusterRPC().stop_proxy_ack(rq_token)
|
peers_only = settings.get('peers-only', None)
|
||||||
|
rq = SwiftProxyClusterRPC().stop_proxy_ack(echo_token=token,
|
||||||
|
echo_peers_only=peers_only)
|
||||||
relation_set(relation_settings=rq)
|
relation_set(relation_settings=rq)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -181,14 +181,16 @@ class SwiftProxyClusterRPC(object):
|
|||||||
rq['peers-only'] = peers_only
|
rq['peers-only'] = peers_only
|
||||||
return rq
|
return rq
|
||||||
|
|
||||||
def stop_proxy_ack(self, token):
|
def stop_proxy_ack(self, echo_token, echo_peers_only):
|
||||||
"""Ack that peer proxy service is stopped.
|
"""Ack that peer proxy service is stopped.
|
||||||
|
|
||||||
NOTE: non-leader action
|
NOTE: non-leader action
|
||||||
"""
|
"""
|
||||||
rq = self.template()
|
rq = self.template()
|
||||||
rq['trigger'] = str(uuid.uuid4())
|
rq['trigger'] = str(uuid.uuid4())
|
||||||
rq['stop-proxy-service-ack'] = token
|
# These echo values should match those received in the request
|
||||||
|
rq['stop-proxy-service-ack'] = echo_token
|
||||||
|
rq['peers-only'] = echo_peers_only
|
||||||
return rq
|
return rq
|
||||||
|
|
||||||
def sync_rings_request(self, broker_host):
|
def sync_rings_request(self, broker_host):
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ class SwiftUtilsTestCase(unittest.TestCase):
|
|||||||
def test_cluster_rpc_stop_proxy_ack(self, mock_uuid):
|
def test_cluster_rpc_stop_proxy_ack(self, mock_uuid):
|
||||||
mock_uuid.uuid4.return_value = 'token2'
|
mock_uuid.uuid4.return_value = 'token2'
|
||||||
rpc = swift_utils.SwiftProxyClusterRPC()
|
rpc = swift_utils.SwiftProxyClusterRPC()
|
||||||
rq = rpc.stop_proxy_ack('token1')
|
rq = rpc.stop_proxy_ack(echo_token='token1', echo_peers_only='1')
|
||||||
self.assertEqual({'trigger': 'token2',
|
self.assertEqual({'trigger': 'token2',
|
||||||
'builder-broker': None,
|
'builder-broker': None,
|
||||||
'peers-only': None,
|
'peers-only': '1',
|
||||||
'stop-proxy-service': None,
|
'stop-proxy-service': None,
|
||||||
'stop-proxy-service-ack': 'token1'}, rq)
|
'stop-proxy-service-ack': 'token1'}, rq)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user