1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

consul: fixed bug in ConsulService when storing checks (#4590)

* consul: fixed bug in ConsulService when storing checks

* added changelog fragment

* typo
This commit is contained in:
Alexei Znamensky 2022-05-05 18:23:00 +12:00 committed by GitHub
parent 841b46ff6a
commit 5a8422c8cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- consul - fixed bug where class ``ConsulService`` was overwriting the field ``checks``, preventing the addition of checks to a service (https://github.com/ansible-collections/community.general/pull/4590).

View file

@ -411,7 +411,7 @@ class ConsulService(object):
self.address = address self.address = address
self.port = port self.port = port
self.tags = tags self.tags = tags
self.checks = [] self._checks = []
if loaded: if loaded:
self.id = loaded['ID'] self.id = loaded['ID']
self.name = loaded['Service'] self.name = loaded['Service']
@ -424,8 +424,8 @@ class ConsulService(object):
if self.port: if self.port:
optional['port'] = self.port optional['port'] = self.port
if len(self.checks) > 0: if len(self._checks) > 0:
optional['check'] = self.checks[0].check optional['check'] = self._checks[0].check
consul_api.agent.service.register( consul_api.agent.service.register(
self.name, self.name,
@ -435,13 +435,13 @@ class ConsulService(object):
**optional) **optional)
def add_check(self, check): def add_check(self, check):
self.checks.append(check) self._checks.append(check)
def checks(self): def checks(self):
return self.checks return self._checks
def has_checks(self): def has_checks(self):
return len(self.checks) > 0 return len(self._checks) > 0
def __eq__(self, other): def __eq__(self, other):
return (isinstance(other, self.__class__) and return (isinstance(other, self.__class__) and
@ -459,8 +459,8 @@ class ConsulService(object):
data['port'] = self.port data['port'] = self.port
if self.tags and len(self.tags) > 0: if self.tags and len(self.tags) > 0:
data['tags'] = self.tags data['tags'] = self.tags
if len(self.checks) > 0: if len(self._checks) > 0:
data['check'] = self.checks[0].to_dict() data['check'] = self._checks[0].to_dict()
return data return data