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

improve config search and add default freebsd config location #835

Merged
merged 4 commits into from
Aug 16, 2021

Conversation

hannaeko
Copy link
Member

@hannaeko hannaeko commented Jul 29, 2021

Purpose

Improve the config search mechanism

Context

Following the comment #833 (comment)

Changes

  • iterate through a default config location list to find an existing file
  • add default freebsd location to the search list (/usr/local/etc/zonemaster/backend_config.ini)
  • update travis file to correctly install the share directory

How to test this PR

  • Create the file /etc/zonemaster/backend_config.ini, run the backend, check that this is the config file loaded, then delete it
  • Create the file /usr/local/etc/zonemaster/backend_config.ini, run the backend, check that this is the config file loaded, then delete it
  • Create the file /tmp/my_config.ini, set the environment variable ZONEMASTER_BACKEND_CONFIG_FILE to /tmp/my_config.ini, run the backend, check that this is the config file loaded, then delete it

@matsduf
Copy link
Contributor

matsduf commented Jul 29, 2021

Is it really good to add the number of places that Config.pm "magically" looks for the configuration file? Isn't it better to let e.g. the start script point out by environment variable where to find it?

@hannaeko
Copy link
Member Author

The environment variable can still be used, I am just adding one more common place to search to the already existing list Config.pm is using. I think that searching for a configuration in standard places is a common pattern but I might be wrong.

Also those are pretty common places to have the configuration file, I think I prefer to have it specified once here than having to deal with edge cases in multiple location because the ones listed here don't work for an OS that we say we are supporting.

@matsduf
Copy link
Contributor

matsduf commented Jul 29, 2021

Also those are pretty common places to have the configuration file, I think I prefer to have it specified once here than having to deal with edge cases in multiple location because the ones listed here don't work for an OS that we say we are supporting.

I understand what you mean and I see the benefit of it too. There were some issues before when unit tests used the configuration files under /etc which made them fail when the updates were not backward compatible. I guess that @mattias-p has fixed that issue.

I agree that is simplifies.

@@ -107,6 +107,10 @@ before_install:
- git clone --depth=1 --branch=$TRAVIS_BRANCH https://github.com/zonemaster/zonemaster-engine.git
- ( cd zonemaster-engine && cpanm --verbose --notest . ) && rm -rf zonemaster-engine

# Install share files
- mkdir -p ./lib/auto/share/dist/
- ln -s ../../../../share ./lib/auto/share/dist/Zonemaster-Backend
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this change relate to this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise the tests fail as dist_file cannot find the dist directory for Zonemaster-Backend

Copy link
Contributor

Choose a reason for hiding this comment

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

This PR adds a second path to look for backend_config.ini, else Config.pm still falls back to what dist_file gives. What has changed that requires a change for Travis? Or is it a bug that you fix at the same time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Before, dist_file was not executed as we are using the environment variable, now it is always executed, that is the difference.

Copy link

Choose a reason for hiding this comment

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

If I may, instead of having to install the share files I'd rather avoid executing dist_file if the ZONEMASTER_BACKEND_CONFIG_FILE variable is set. This would prevent failure such as the Travis one. Would it be possible to execute dist_file only if the environment variable is unset?

Copy link

Choose a reason for hiding this comment

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

Nice, thanks. Then the Travis patch could be removed I guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

Then the Travis patch could be removed I guess.

I would prefer to keep it so that the share directory is correctly installed.

Copy link

Choose a reason for hiding this comment

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

All right.

Copy link
Contributor

Choose a reason for hiding this comment

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

Before, dist_file was not executed as we are using the environment variable, now it is always executed, that is the difference.

That change is not included in the description. Please add that.

Copy link
Member Author

Choose a reason for hiding this comment

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

This has been reverted, dist_file is now executed only if the variable is not set, as it was before.

@@ -107,6 +107,10 @@ before_install:
- git clone --depth=1 --branch=$TRAVIS_BRANCH https://github.com/zonemaster/zonemaster-engine.git
- ( cd zonemaster-engine && cpanm --verbose --notest . ) && rm -rf zonemaster-engine

# Install share files
- mkdir -p ./lib/auto/share/dist/
- ln -s ../../../../share ./lib/auto/share/dist/Zonemaster-Backend
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR adds a second path to look for backend_config.ini, else Config.pm still falls back to what dist_file gives. What has changed that requires a change for Travis? Or is it a bug that you fix at the same time?

if ( -e $default_path ) {
$path = $default_path;
last;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In the current code, $path is always defined. In the new code it will be undefined if the environment variable is undefinded and backend_config.ini does not exist in any of the three paths. That will probably give a different error message. It should probably be defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

The error will be the same actually. If dist_file('Zonemaster-Backend', "backend_config.ini") fails to find the file, then the backend fails to start with error Failed to find shared file 'backend_config.ini' for dist 'Zonemaster-Backend' in both cases, otherwise $path will be defined as the file exists.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does the Change Request still holds? It is blocking the merge process so I would like to know if something needs to be addressed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the description of this PR to include the change for Travis, and I am fine with the changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the description.

@hannaeko hannaeko requested a review from matsduf August 4, 2021 11:51
@hannaeko hannaeko merged commit e9f4f0e into zonemaster:develop Aug 16, 2021
@matsduf matsduf added this to the v2021.2 milestone Sep 1, 2021
@matsduf
Copy link
Contributor

matsduf commented Dec 3, 2021

Testing v2021.2

LGTM.

As far as I can see it works as it should.

@matsduf matsduf added the S-ReleaseTested Status: The PR has been successfully tested in release testing label Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-ReleaseTested Status: The PR has been successfully tested in release testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants