From 35966c9186d868948a037bae7c58ac6e6279a4f0 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Fri, 20 Mar 2020 17:03:14 +0000 Subject: [PATCH] Fix service_mapped_to_host filter The service_mapped_to_host filter is used to check if a service is mapped to a host, based on the group for the service or its host_in_groups attribute if one exists. We check if the service's group is in the 'groups' list. However, to get the list of groups to which a host belongs, we should use the 'group_names' list. This filter is currently only used in neutron IPv6 module loading, so the effects are minimal. Change-Id: I37409ca8d273b0426df0a648db222dc5432e738a Closes-Bug: #1868285 --- kolla_ansible/filters.py | 2 +- kolla_ansible/tests/unit/test_filters.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kolla_ansible/filters.py b/kolla_ansible/filters.py index 0b238ecc87..bea423347e 100644 --- a/kolla_ansible/filters.py +++ b/kolla_ansible/filters.py @@ -63,7 +63,7 @@ def service_mapped_to_host(context, service): group = service.get("group") if group is not None: - return group in context.get("groups") + return group in context.get("group_names") raise exception.FilterError( "Service definition for '%s' does not have a 'group' or " diff --git a/kolla_ansible/tests/unit/test_filters.py b/kolla_ansible/tests/unit/test_filters.py index c3314ae8cc..8eef4f0e09 100644 --- a/kolla_ansible/tests/unit/test_filters.py +++ b/kolla_ansible/tests/unit/test_filters.py @@ -104,14 +104,14 @@ class TestFilters(unittest.TestCase): service = { 'group': 'foo' } - context = self._make_context({'groups': ['foo', 'bar']}) + context = self._make_context({'group_names': ['foo', 'bar']}) self.assertTrue(filters.service_mapped_to_host(context, service)) def test_service_mapped_to_host_not_in_group(self): service = { 'group': 'foo' } - context = self._make_context({'groups': ['bar']}) + context = self._make_context({'group_names': ['bar']}) self.assertFalse(filters.service_mapped_to_host(context, service)) def test_service_mapped_to_host_no_attr(self):