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

Create file if doesnt exist in ini.options_present state #58339

Merged
merged 2 commits into from
Sep 25, 2020

Conversation

Ch3LL
Copy link
Contributor

@Ch3LL Ch3LL commented Aug 31, 2020

What does this PR do?

Makes sure the ini file is created if it does not already exist.

What issues does this PR fix or reference?

Fixes: #34236

Previous Behavior

local:
----------
          ID: ini
    Function: ini.options_present
        Name: /etc/some_config.ini
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/home/ch3ll/git/salt/salt/modules/ini_manage.py", line 418, in refresh
                  with salt.utils.files.fopen(self.name) as rfh:
                File "/home/ch3ll/git/salt/salt/utils/files.py", line 396, in fopen
                  f_handle = open(*args, **kwargs)  # pylint: disable=resource-leakage
              FileNotFoundError: [Errno 2] No such file or directory: '/etc/some_config.ini'
              
              During handling of the above exception, another exception occurred:
              
              Traceback (most recent call last):
                File "/home/ch3ll/git/salt/salt/state.py", line 2154, in call
                  *cdata["args"], **cdata["kwargs"]
                File "/home/ch3ll/git/salt/salt/loader.py", line 2087, in wrapper
                  return f(*args, **kwargs)
                File "/home/ch3ll/git/salt/salt/states/ini_manage.py", line 67, in options_present
                  cur_ini = __salt__["ini.get_ini"](name, separator)
                File "/home/ch3ll/git/salt/salt/modules/ini_manage.py", line 244, in get_ini
                  inifile = _Ini.get_ini_file(file_name, separator=separator)
                File "/home/ch3ll/git/salt/salt/modules/ini_manage.py", line 462, in get_ini_file
                  inifile.refresh()
                File "/home/ch3ll/git/salt/salt/modules/ini_manage.py", line 424, in refresh
                  "Exception: {1}".format(self.name, exc)
              salt.exceptions.CommandExecutionError: Unable to open file '/etc/some_config.ini'. Exception: [Errno 2] No such file or directory: '/etc/some_config.ini'
     Started: 14:58:47.981725
    Duration: 2.823 ms
     Changes:   

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   2.823 ms

New Behavior

local:
----------
          ID: ini
    Function: ini.options_present
        Name: /etc/some_config.ini
      Result: True
     Comment: Changes take effect
     Started: 14:59:58.411840
    Duration: 1.145 ms
     Changes:   
              ----------
              general:
                  ----------
                  after:
                      ----------
                      server_hostname:
                          my.server.com
                      server_port:
                          1234
                  before:
                      None

Summary for local
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:   1.145 ms

Merge requirements satisfied?

Commits signed with GPG?

Yes

@Ch3LL Ch3LL requested a review from a team as a code owner August 31, 2020 19:19
@ghost ghost requested review from DmitryKuzmenko and removed request for a team August 31, 2020 19:20
@Ch3LL Ch3LL force-pushed the ini_fix branch 2 times, most recently from d8a8fd5 to f57834a Compare September 2, 2020 11:20
DmitryKuzmenko
DmitryKuzmenko previously approved these changes Sep 14, 2020
DmitryKuzmenko
DmitryKuzmenko previously approved these changes Sep 15, 2020
@sagetherage sagetherage added the Regression The issue is a bug that breaks functionality known to work in previous releases. label Sep 16, 2020
@dwoz dwoz added the Needs-Testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases label Sep 22, 2020
@dwoz dwoz merged commit 7ab82da into saltstack:master Sep 25, 2020
Copy link
Collaborator

@s0undt3ch s0undt3ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟 🌟 🌟 🌟🌟 for the PyTest tests!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Magnesium Mg release after Na prior to Al Needs-Testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases Regression The issue is a bug that breaks functionality known to work in previous releases.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2016.3 regression: ini.options_present crash if ini file does not exist
5 participants