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) (#4630)

* consul: fixed bug in ConsulService when storing checks

* added changelog fragment

* typo

(cherry picked from commit 5a8422c8cb)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2022-05-05 08:34:22 +02:00 committed by GitHub
parent d1877e1915
commit 45d461c0ec
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.port = port
self.tags = tags
self.checks = []
self._checks = []
if loaded:
self.id = loaded['ID']
self.name = loaded['Service']
@ -424,8 +424,8 @@ class ConsulService(object):
if self.port:
optional['port'] = self.port
if len(self.checks) > 0:
optional['check'] = self.checks[0].check
if len(self._checks) > 0:
optional['check'] = self._checks[0].check
consul_api.agent.service.register(
self.name,
@ -435,13 +435,13 @@ class ConsulService(object):
**optional)
def add_check(self, check):
self.checks.append(check)
self._checks.append(check)
def checks(self):
return self.checks
return self._checks
def has_checks(self):
return len(self.checks) > 0
return len(self._checks) > 0
def __eq__(self, other):
return (isinstance(other, self.__class__) and
@ -459,8 +459,8 @@ class ConsulService(object):
data['port'] = self.port
if self.tags and len(self.tags) > 0:
data['tags'] = self.tags
if len(self.checks) > 0:
data['check'] = self.checks[0].to_dict()
if len(self._checks) > 0:
data['check'] = self._checks[0].to_dict()
return data