From a5a2031eef7341c762b903c568ae6dcceacb6e9c Mon Sep 17 00:00:00 2001 From: Satellite QE <115476073+Satellite-QE@users.noreply.github.com> Date: Thu, 4 May 2023 04:11:45 -0400 Subject: [PATCH] Ignore puppetclass attribute conditionally (#906) (#907) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Ignore puppetclass also if Puppet is enabled, but host does not have Puppet proxy assigned. * Fix tests, change puppet_proxy_id to puppet_proxy (cherry picked from commit cc34e55068deaa47c6c93f33573489a398ec6d03) Co-authored-by: Ondřej Gajdušek --- nailgun/entities.py | 9 ++++++++- tests/test_entities.py | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/nailgun/entities.py b/nailgun/entities.py index 6dcf5848..f2437c2a 100644 --- a/nailgun/entities.py +++ b/nailgun/entities.py @@ -4251,7 +4251,14 @@ def read(self, entity=None, attrs=None, ignore=None, params=None): # host id is required for interface initialization ignore.add('interface') ignore.add('build_status_label') - if 'Puppet' not in _feature_list(self._server_config): + # Ignore puppetclass attribute if we are running against Puppet disabled + # instance. Ignore it also if the API does not return puppetclasses for + # the given host, but only if it does not have Puppet proxy assigned. + if ( + 'Puppet' not in _feature_list(self._server_config) + or 'puppetclasses' not in attrs + and not attrs['puppet_proxy'] + ): ignore.add('puppetclass') result = super().read(entity, attrs, ignore, params) if attrs.get('image_id'): diff --git a/tests/test_entities.py b/tests/test_entities.py index b61702a8..12c8bf93 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -1246,8 +1246,8 @@ def test_entity_ids(self): ), ( entities.Host(self.cfg), - {'parameters': None}, - {'host_parameters_attributes': None}, + {'parameters': None, 'puppet_proxy': None}, + {'host_parameters_attributes': None, 'puppet_proxy': None}, ), ( entities.Filter(self.cfg), @@ -1455,6 +1455,7 @@ def test_host_with_interface(self): return_value={ 'interfaces': [{'id': 2}, {'id': 3}], 'parameters': None, + 'puppet_proxy': None, }, ): with mock.patch.object( @@ -1742,6 +1743,7 @@ def test_host_with_image(self): 'image_id': 1, 'compute_resource_id': 1, 'parameters': {}, + 'puppet_proxy': None, } read.return_value = host host = host.read() @@ -1750,6 +1752,7 @@ def test_host_with_image(self): # Image wasn't set read_json.return_value = { 'parameters': {}, + 'puppet_proxy': None, } read.return_value = host host = host.read() @@ -3038,6 +3041,7 @@ def test_no_facet_attributes(self): attrs={ 'parameters': None, 'puppetclasses': None, + 'puppet_proxy': None, } ) self.assertNotIn('content_facet_attributes', read.call_args[0][1])