Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ini_manage error and change handling #43723

Merged
merged 3 commits into from
Sep 28, 2017

Conversation

nicholasmhughes
Copy link
Collaborator

What does this PR do?

This PR fixes a problem where ini_manage will throw an exception in test mode when a managed file is not present yet. Additionally, the dictionary of changes handles them by sections, which means that scenarios in which changes do not occur still return a dictionary of keys with empty dictionaries as values. The previous method of if changes: would result in changes being detected when there weren't any.

What issues does this PR fix or reference?

None

Previous Behavior

Example of exception during test mode:

----------
          ID: test_config
    Function: ini.options_present
        Name: /etc/test.conf
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/site-packages/salt/state.py", line 1837, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1794, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/site-packages/salt/states/ini_manage.py", line 61, in options_present
                  cur_section = __salt__['ini.get_section'](name, section, separator)
                File "/usr/lib/python2.7/site-packages/salt/modules/ini_manage.py", line 158, in get_section
                  inifile = _Ini.get_ini_file(file_name, separator=separator)
                File "/usr/lib/python2.7/site-packages/salt/modules/ini_manage.py", line 411, in get_ini_file
                  inifile.refresh()
                File "/usr/lib/python2.7/site-packages/salt/modules/ini_manage.py", line 377, in refresh
                  "Exception: {1}".format(self.name, exc)
              CommandExecutionError: Unable to open file '/etc/test.conf'. Exception: [Errno 2] No such file or directory: '/etc/test.conf'
     Started: 13:07:02.077923
    Duration: 3.087 ms
     Changes:   

Also, changes would be detected in files where no changes were made due to ho the dictionary of changes is kept. Enforcing a property within a section such as:

[settings]
property = value

...would return:

{ 'settings': {} }

...in the changes dictionary when there weren't any changes for the settings section.

New Behavior

File access to non-existent files is ignored in test mode.

The state now inspects each key in the changes dictionary for changes by section.

Tests written?

No

Please review Salt's Contributing Guide for best practices.

@ghost
Copy link

ghost commented Sep 25, 2017

@nicholasmhughes, thanks for your PR! By analyzing the history of the files in this pull request, we identified @m03, @s0undt3ch and @alxf to be potential reviewers.

@cachedout cachedout merged commit dd4fc52 into saltstack:2017.7 Sep 28, 2017
@nicholasmhughes nicholasmhughes deleted the ini_manage-error-handling branch September 28, 2017 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants