Merge pull request #55595 from cvedel/wrong-isinstance-in-ini-options_absent

Wrong isinstance in ini options absent
This commit is contained in:
Daniel Wozniak 2020-04-23 23:32:15 -07:00 committed by GitHub
commit 6ba77aa282
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -211,7 +211,7 @@ def options_absent(name, sections=None, separator="="):
return ret
except AttributeError:
cur_section = section
if isinstance(sections[section], (dict, OrderedDict)):
if isinstance(sections[section], list):
for key in sections[section]:
cur_value = cur_section.get(key)
if not cur_value:
@ -248,7 +248,7 @@ def options_absent(name, sections=None, separator="="):
if section not in ret["changes"]:
ret["changes"].update({section: {}})
ret["changes"][section].update({key: current_value})
if not isinstance(sections[section], (dict, OrderedDict)):
if not isinstance(sections[section], list):
ret["changes"].update({section: current_value})
# break
ret["comment"] = "Changes take effect"

View file

@ -111,6 +111,17 @@ class IniManageTestCase(TestCase, LoaderModuleMockMixin):
comt = "No anomaly detected"
ret.update({"comment": comt, "result": True})
self.assertDictEqual(ini_manage.options_absent(name), ret)
original = {"Tables": {"key1": "1", "key2": "2", "key3": "3", "key4": "4"}}
sections = {"Tables": ["key2", "key3"]}
changes = {"Tables": {"key2": "2", "key3": "3"}}
with patch.dict(
ini_manage.__salt__,
{"ini.remove_option": MagicMock(side_effect=["2", "3"])},
):
with patch.dict(ini_manage.__opts__, {"test": False}):
comt = "Changes take effect"
ret.update({"comment": comt, "result": True, "changes": changes})
self.assertDictEqual(ini_manage.options_absent(name, sections), ret)
# 'sections_present' function tests: 1