Skip to content

Commit

Permalink
Fixed issue: Incorrect number of hosts down reported
Browse files Browse the repository at this point in the history
bugzilla: 1687333
tendrl-bug-id: Tendrl#1076

Signed-off-by: GowthamShanmugasundaram <gshanmug@redhat.com>
  • Loading branch information
GowthamShanmugam committed Jun 7, 2019
1 parent e6f20cd commit ebb77b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 14 additions & 1 deletion tendrl/commons/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def thread_safe_method(self, *args, **kws):
class BaseObject(object):
def __init__(self, *args, **kwargs):
self._ttl = None
self._ttl_attr = []
self._lock = threading.RLock()
self.hash = None
self._rendered = None
Expand Down Expand Up @@ -112,7 +113,19 @@ def save(self, update=True, ttl=None):
NS.publisher_id,
{"message": _msg}
)
etcd_utils.write(item['key'], item['value'], quorum=True)
if self._ttl and item['name'] in self._ttl_attr:
etcd_utils.write(
item['key'],
item['value'],
quorum=True,
ttl=self._ttl
)
else:
etcd_utils.write(
item['key'],
item['value'],
quorum=True
)
if hash_key_changed:
data_key = self.value + '/data'
etcd_utils.write(data_key, self.json)
Expand Down
8 changes: 2 additions & 6 deletions tendrl/commons/objects/node_context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,15 @@ def render(self):
return super(NodeContext, self).render()

def save(self, update=True, ttl=None):
super(NodeContext, self).save(update)
status = self.value + "/status"
if self.status == "UP" and ttl is None:
# Set ttl always when node status in up
ttl = int(
NS.config.data.get("sync_interval", 60)
)
if ttl:
self._ttl = ttl
try:
etcd_utils.refresh(status, ttl)
except etcd.EtcdKeyNotFound:
pass
self._ttl_attr = ['status']
super(NodeContext, self).save(update)

def on_change(self, attr, prev_value, current_value):
if attr == "status" and "tendrl/monitor" in NS.node_context.tags:
Expand Down

0 comments on commit ebb77b3

Please sign in to comment.