Skip to content

W/A hardcoding of debian alternatives priority #177

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

Merged
merged 2 commits into from
Mar 6, 2018
Merged

W/A hardcoding of debian alternatives priority #177

merged 2 commits into from
Mar 6, 2018

Conversation

noelmcloughlin
Copy link
Contributor

@noelmcloughlin noelmcloughlin commented Jan 14, 2018

The current hardcoding of 'postgres.alternatives.install.priority=30', breaks formula reruns.

- - priority: 30

This PR is a workaround solution, by exposing the value as a configurable pillar.

+ - priority: {{ postgres.linux.altpriority|int }}

Implementation decisions

  1. To mimic existing behaviour the alternatives.priority value of '30' is retained by defaults.yaml.
  2. Users can disable Debian Alternatives - new feature - by setting '0' as pillar value (that would be better formula default IMHO but lets go one step at a time).

@noelmcloughlin
Copy link
Contributor Author

Would anyone be able to review?

@EvaSDK
Copy link
Contributor

EvaSDK commented Jan 30, 2018

I don't think debian alternatives makes sense on os_family other than Debian so I'm not sure the conditional is right.

@noelmcloughlin
Copy link
Contributor Author

I think debian alternatives is a historical name. Its called 'alternatives' on RedHat for example-

alternatives is a tool for managing different software packages that provide the same functionality. Red Hat Enterprise Linux uses alternatives to ensure that only one Java Development Kit (JDK) is set as the system default at one time.

@noelmcloughlin
Copy link
Contributor Author

BTW, this PR does not add alternatives feature, just removes a hardcoding of 30 priority.

There is a pre-existing check for os_family which do not support 'debian alternatives'.

{% if grains.os_family not in ('Arch',) %}

@EvaSDK
Copy link
Contributor

EvaSDK commented Jan 30, 2018

Gentoo has eselect which is somewhat similar but has its own module https://docs.saltstack.com/en/latest/ref/states/all/salt.states.eselect.html. Not sure alternatives would work there.

@noelmcloughlin
Copy link
Contributor Author

Good point @EvaSDK Could you raise issue? BTW, such problems exist as legacy technical debt.

@noelmcloughlin
Copy link
Contributor Author

noelmcloughlin commented Feb 16, 2018

Hey @EvaSDK I updated commit for your comments. Was thinking this PR assists future eselect support because pillar is reusable for that feature. Probaby eselect has priorities too?

Copy link
Contributor

@vutny vutny left a comment

Choose a reason for hiding this comment

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

I like the idea of this PR. Having configurable priority for alternatives is a neat feature.

Let's make an implementation more robust. I have few concerns, let's address them one by one as usual.

{%- if 'bin_dir' in postgres %}
{% if postgres.linux.altpriority|int > 0 %}
{% if grains.os_family not in ('Arch', 'Gentoo', 'MacOS', 'Windows',) %}
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to hard-code the list of distros in the state.
The top-level if statement checks if bin_dir parameter has been defined. And it is explicitly defined only for RedHat in osmap.yaml for now. It does not exist for any other system.

Same applies to the server state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats correct. The Jinja is unnecessary here. done.

@noelmcloughlin noelmcloughlin removed the request for review from gtmanfred February 19, 2018 12:26
{%- if 'bin_dir' in postgres %}
{% if postgres.linux.altpriority|int > 0 %}
Copy link
Contributor

Choose a reason for hiding this comment

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

At first, you don't need to introduce lower level if statement, it's better to collapse two statements into one simply using and operator. It reduces amount of changes, unnecessary indentations and makes it more readable overall.

At second, no need to use int filter here. You could just test with implicit Boolean comparison:

  {%- if 'bin_dir' in postgres and
          postgres.linux.altpriority %}

This would negate the check if postgres.linux.altpriority would be 0, '',false or none. And that looks better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion. This is all done.


{{ bin }}:
alternatives.install:
- link: {{ salt['file.join']('/usr/bin', bin) }}
- path: {{ path }}
- priority: 30
- priority: {{ postgres.linux.altpriority|int }}
Copy link
Contributor

Choose a reason for hiding this comment

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

As well, the int filter is unnecessary. YAML renderer does not care about Jinja internal data type.


linux:
#Alternatives system are disabled by a 'altpriority=0' pillar.
altpriority: 30
Copy link
Contributor

Choose a reason for hiding this comment

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

Since for now the formula is able to provision the alternatives only for RedHat systems when PG comes from upstream repo, I think the default value across all supported distros must be empty:

linux:
  # Alternatives are applicable only for some OS
  altpriority:

Please set actual value in osmap.yaml file near bin_dir and *_bins parameters.

Copy link
Contributor

@vutny vutny left a comment

Choose a reason for hiding this comment

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

Awesome. I tested this on CentOS and Ubuntu and it works like a charm.

Thanks for you contribution @noelmcloughlin

@noelmcloughlin noelmcloughlin merged commit 36fb8f4 into saltstack-formulas:master Mar 6, 2018
@noelmcloughlin noelmcloughlin deleted the alternatives branch March 6, 2018 16:26
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.

3 participants