ch sync
This commit is contained in:
parent
bb3a8850aa
commit
0a879252b9
@ -41,7 +41,6 @@ from charmhelpers.core.hookenv import (
|
|||||||
relation_ids,
|
relation_ids,
|
||||||
relation_set,
|
relation_set,
|
||||||
related_units,
|
related_units,
|
||||||
remote_unit,
|
|
||||||
log,
|
log,
|
||||||
DEBUG,
|
DEBUG,
|
||||||
INFO,
|
INFO,
|
||||||
@ -437,9 +436,6 @@ class CephBrokerRsp(object):
|
|||||||
|
|
||||||
The API is versioned and defaults to version 1.
|
The API is versioned and defaults to version 1.
|
||||||
"""
|
"""
|
||||||
VALID = 0
|
|
||||||
ABSENT = 1
|
|
||||||
INVALID = 2
|
|
||||||
|
|
||||||
def __init__(self, encoded_rsp):
|
def __init__(self, encoded_rsp):
|
||||||
self.api_version = None
|
self.api_version = None
|
||||||
@ -457,30 +453,10 @@ class CephBrokerRsp(object):
|
|||||||
def exit_msg(self):
|
def exit_msg(self):
|
||||||
return self.rsp.get('stderr')
|
return self.rsp.get('stderr')
|
||||||
|
|
||||||
def validate_request_id(self):
|
|
||||||
pending_request_id = None
|
|
||||||
pending_request_raw = relation_get(attribute='broker_req',
|
|
||||||
unit=local_unit())
|
|
||||||
if pending_request_raw:
|
|
||||||
pending_request = json.loads(pending_request_raw)
|
|
||||||
pending_request_id = pending_request.get('request-id')
|
|
||||||
if not self.request_id:
|
|
||||||
log('Request has no request-id'.format(svc), level=DEBUG)
|
|
||||||
# back compat
|
|
||||||
return self.ABSENT
|
|
||||||
|
|
||||||
if pending_request_id and self.request_id != pending_request_id:
|
|
||||||
log('request-id {} does not match expected request-id '
|
|
||||||
'{}'.format(self.request_id, pending_request_id), level=DEBUG)
|
|
||||||
return self.INVALID
|
|
||||||
|
|
||||||
log('request-id {} is expected'.format(self.request_id))
|
|
||||||
return self.VALID
|
|
||||||
|
|
||||||
def request_states(request_needed):
|
def request_states(request_needed):
|
||||||
"""Return dict showing if a request has been sent and completed per rid"""
|
"""Return dict showing if a request has been sent and completed per rid"""
|
||||||
complete = []
|
complete = []
|
||||||
issued = {}
|
|
||||||
requests = {}
|
requests = {}
|
||||||
for rid in relation_ids('ceph'):
|
for rid in relation_ids('ceph'):
|
||||||
complete = False
|
complete = False
|
||||||
@ -496,6 +472,7 @@ def request_states(request_needed):
|
|||||||
}
|
}
|
||||||
return requests
|
return requests
|
||||||
|
|
||||||
|
|
||||||
def request_sent(request_needed):
|
def request_sent(request_needed):
|
||||||
"""Check to see if a matching request has been sent"""
|
"""Check to see if a matching request has been sent"""
|
||||||
states = request_states(request_needed)
|
states = request_states(request_needed)
|
||||||
@ -504,6 +481,7 @@ def request_sent(request_needed):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def request_complete(request_needed):
|
def request_complete(request_needed):
|
||||||
"""Check to see if a matching request has been completed"""
|
"""Check to see if a matching request has been completed"""
|
||||||
states = request_states(request_needed)
|
states = request_states(request_needed)
|
||||||
@ -512,6 +490,7 @@ def request_complete(request_needed):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def equivalent_broker_requests(encoded_req1, encoded_req2):
|
def equivalent_broker_requests(encoded_req1, encoded_req2):
|
||||||
"""Check to see if two requests are equivalent (ignore request id)"""
|
"""Check to see if two requests are equivalent (ignore request id)"""
|
||||||
if not encoded_req1 or not encoded_req2:
|
if not encoded_req1 or not encoded_req2:
|
||||||
@ -526,6 +505,7 @@ def equivalent_broker_requests(encoded_req1, encoded_req2):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def broker_request_completed(encoded_req, rid):
|
def broker_request_completed(encoded_req, rid):
|
||||||
"""Check if a given request has been completed on the given relation"""
|
"""Check if a given request has been completed on the given relation"""
|
||||||
req = json.loads(encoded_req)
|
req = json.loads(encoded_req)
|
||||||
@ -553,10 +533,12 @@ def broker_request_completed(encoded_req, rid):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_broker_rsp_key():
|
def get_broker_rsp_key():
|
||||||
"""Return broker request key for this unit"""
|
"""Return broker request key for this unit"""
|
||||||
return 'broker-rsp-' + local_unit().replace('/', '-')
|
return 'broker-rsp-' + local_unit().replace('/', '-')
|
||||||
|
|
||||||
|
|
||||||
def send_request_if_needed(rq):
|
def send_request_if_needed(rq):
|
||||||
"""Send broker request if one has not already been sent"""
|
"""Send broker request if one has not already been sent"""
|
||||||
if request_sent(rq):
|
if request_sent(rq):
|
||||||
|
Loading…
Reference in New Issue
Block a user