Skip to content

Commit

Permalink
Ignore puppetclass attribute conditionally (#906) (#909)
Browse files Browse the repository at this point in the history
* 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 cc34e55)

Co-authored-by: Ondřej Gajdušek <ogajduse@redhat.com>
  • Loading branch information
Satellite-QE and ogajduse authored May 4, 2023
1 parent c2f9ebe commit a99509b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -4242,7 +4242,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'):
Expand Down
8 changes: 6 additions & 2 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,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),
Expand Down Expand Up @@ -1446,6 +1446,7 @@ def test_host_with_interface(self):
return_value={
'interfaces': [{'id': 2}, {'id': 3}],
'parameters': None,
'puppet_proxy': None,
},
):
with mock.patch.object(
Expand Down Expand Up @@ -1733,6 +1734,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()
Expand All @@ -1741,6 +1743,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()
Expand Down Expand Up @@ -3029,6 +3032,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])
Expand Down

0 comments on commit a99509b

Please sign in to comment.