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

Review config file load order, location support #3

Closed
4 of 5 tasks
deoren opened this issue Jul 31, 2018 · 4 comments · Fixed by #12
Closed
4 of 5 tasks

Review config file load order, location support #3

deoren opened this issue Jul 31, 2018 · 4 comments · Fixed by #12
Labels
enhancement New feature or request
Milestone

Comments

@deoren
Copy link
Contributor

deoren commented Jul 31, 2018

I was watching an Ansible training video earlier today and saw this list of supported paths for the Ansible configuration file:

  • Ansible_Config environment variable
  • ansible.cfg file in current directory
  • .ansible.cfg file in user's home directory
  • /etc/ansible/ansible.cfg default settings file

in addition to those, I think we can/should add support for one more:

  • command-line provided path

I've not researched whether the files are merged with settings in one overriding settings in others or if just one file is used. For our purposes, just going with one file is probably sufficient.

Without looking at the code, I think we're already handling points 2 and 4, shouldn't be too hard to add support for the others.

@deoren deoren added the enhancement New feature or request label Jul 31, 2018
@deoren deoren added this to the Future milestone Jul 31, 2018
@deoren
Copy link
Contributor Author

deoren commented Jul 31, 2018

refs WhyAskWhy/automated-tickets#33

@deoren
Copy link
Contributor Author

deoren commented Aug 6, 2018

I think a good intermediate step would be to go ahead and rename the current "live" config files to *.tmpl to deactivate them and force any future user to intentionally copy/paste/modify the files. If no valid config files are found, the script would be very explicit with the error message.

@deoren
Copy link
Contributor Author

deoren commented Aug 6, 2018

ubuntu@ubuntu-1604-virtual-machine:/tmp/mysql2sqlite-dev$ bash bin/create_db.sh

HEAD is now at 8a701fc - Move from using /etc/DOMAIN/PROJECT paths to just /etc/PROJECT
Already on 'deactivate-template-config-files'
Your branch is up-to-date with 'origin/deactivate-template-config-files'.
Already up-to-date.
mkdir: created directory '/var/cache/mysql2sqlite'
changed ownership of '/var/cache/mysql2sqlite' from root:root to ubuntu:ubuntu
Traceback (most recent call last):
  File "/usr/lib/python3.5/configparser.py", line 843, in items
    d.update(self._sections[section])
KeyError: 'flags'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/mysql2sqlite/mysql2sqlite.py", line 164, in <module>
    general_settings = m2slib.GeneralSettings(general_config_file_candidates)
  File "/tmp/mysql2sqlite/mysql2sqlite_lib.py", line 105, in __init__
    self.flags = dict(parser.items('flags'))
  File "/usr/lib/python3.5/configparser.py", line 846, in items
    raise NoSectionError(section)
configparser.NoSectionError: No section: 'flags'
FAILURE to generate SQLite db file!

Current results from quick hacking on the code/files. Posting here as a reminder for where I left off when I pick up and finish the work later. In short, I expected this error, just wanted to remind myself of the specifics before working further.

@deoren
Copy link
Contributor Author

deoren commented Aug 7, 2018

Test output from some work to use template files for testing purposes. On the first run the files are not present, on a follow-up run they are from the prior run.

ubuntu@ubuntu-1604-virtual-machine:/tmp/mysql2sqlite-dev$ git pull; bash bin/create_db.sh

Already up-to-date.
HEAD is now at 7eea346 Fix fall-back filter behavior
Already on 'deactivate-template-config-files'
Your branch is up-to-date with 'origin/deactivate-template-config-files'.
Already up-to-date.
ownership of '/var/cache/mysql2sqlite/mailserver.db' retained as ubuntu:ubuntu
ownership of '/var/cache/mysql2sqlite' retained as ubuntu:ubuntu
Deploying template config files
'/tmp/mysql2sqlite/mysql2sqlite_general.ini.tmpl' -> '/tmp/mysql2sqlite/mysql2sqlite_general.ini'
'/tmp/mysql2sqlite/mysql2sqlite_queries.ini.tmpl' -> '/tmp/mysql2sqlite/mysql2sqlite_queries.ini'
Successfully generated SQLite db file.
Run python3 /tmp/mysql2sqlite-dev/bin/validate_dbs.py next to confirm db was created properly.

ubuntu@ubuntu-1604-virtual-machine:/tmp/mysql2sqlite-dev$ git pull; bash bin/create_db.sh

Already up-to-date.
HEAD is now at 7eea346 Fix fall-back filter behavior
Already on 'deactivate-template-config-files'
Your branch is up-to-date with 'origin/deactivate-template-config-files'.
Already up-to-date.
ownership of '/var/cache/mysql2sqlite/mailserver.db' retained as ubuntu:ubuntu
ownership of '/var/cache/mysql2sqlite' retained as ubuntu:ubuntu
Configuration files found in /tmp/mysql2sqlite. Using those files.
Successfully generated SQLite db file.
Run python3 /tmp/mysql2sqlite-dev/bin/validate_dbs.py next to confirm db was created properly.

deoren added a commit to deoren/mysql2sqlite-dev that referenced this issue Aug 8, 2018
Wrapper script accepts cmdline option in order to
mimic main script functionality and to pass-through
to main script.

cmdline option takes precedence over other locations.

refs WhyAskWhy#2
refs WhyAskWhy/mysql2sqlite#3
deoren added a commit to deoren/mysql2sqlite that referenced this issue Aug 8, 2018
- repo-provided INI files have been renamed to *.tmpl in order
  to prevent them from being used as-is or risk clobbering
  local/custom config files if user opts to install
  directly from Git repo.

- Adjust log formatters to include line number for messages

- Replace explicit exit calls from within our library
  function calls.

- Adjust system-wide config path from /etc/DOMAIN/PROJECT
  to just /etc/PROJECT in order to better match the norm
  for /etc content layout.

- Improve exception handling for config file parsing issues

- Provide support for user-level config files
  - cmdline
  - $HOME/.config/PROJECT

- Fall back to logging warning/error messages to the console
  if settings object is not provided to constructor. Adjust
  filter for handler later once the settings object is properly
  constructed.

refs WhyAskWhy/mysql2sqlite-dev#2
refs WhyAskWhy#3
deoren added a commit to deoren/mysql2sqlite that referenced this issue Aug 8, 2018
- repo-provided INI files have been renamed to *.tmpl in order
  to prevent them from being used as-is or risk clobbering
  local/custom config files if user opts to install
  directly from Git repo.

- Adjust log formatters to include line number for messages

- Replace explicit exit calls from within our library
  function calls.

- Adjust system-wide config path from /etc/DOMAIN/PROJECT
  to just /etc/PROJECT in order to better match the norm
  for /etc content layout.

- Improve exception handling for config file parsing issues

- Provide support for user-level config files
  - cmdline
  - $HOME/.config/PROJECT

- Fall back to logging warning/error messages to the console
  if settings object is not provided to constructor. Adjust
  filter for handler later once the settings object is properly
  constructed.

refs WhyAskWhy/mysql2sqlite-dev#2
refs WhyAskWhy#3
deoren added a commit to deoren/mysql2sqlite-dev that referenced this issue Aug 8, 2018
Look for config files in the paths specified on commandline and
by environment variable. If found, skip deploying template
files prior to attempting generation of SQLite file.

refs WhyAskWhy/mysql2sqlite#3
deoren added a commit to deoren/mysql2sqlite-dev that referenced this issue Aug 8, 2018
Look for config files in the paths specified on command-line and
by environment variable. If found, skip deploying template
files prior to attempting generation of SQLite file.

refs WhyAskWhy/mysql2sqlite#3
@deoren deoren closed this as completed in #12 Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant