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

Fetching grains['os'] from /etc/os-release on SUSE systems if it is possible #33903

Merged

Conversation

meaksh
Copy link
Contributor

@meaksh meaksh commented Jun 9, 2016

What does this PR do?

This PR fixes a bug solved for one of our customers which uses SUSE SLES SAP systems. It also defines a new rule to get the grains['os'] in SUSE family systems.

Currently, Salt uses the _OS_FAMILY_MAP to get the grains['os_family'] based on grains['os'] grain, but it implies that we have to keep the map updated for all the possible osname for SUSE products.

So we propose to try to use the CPE_NAME information contained in /etc/os-release in order to know if it's a SUSE product and also to set the grains['os'] == "SUSE"

Tests written?

Yes

/cc @isbm

@isbm
Copy link
Contributor

isbm commented Jun 9, 2016

Lint wants less lines.

@meaksh
Copy link
Contributor Author

meaksh commented Jun 9, 2016

The new test is failing in some environments. I have to fix it.

@cachedout
Copy link
Contributor

Still doesn't look like we're quite there with this failing test. Please let me know when this is ready, @meaksh and thanks!

@meaksh
Copy link
Contributor Author

meaksh commented Jun 13, 2016

Hi @cachedout , the test is now fixed and working. Sorry for the delay :)
Thanks!

@@ -1390,7 +1396,8 @@ def os_data():
shortname = distroname.replace(' ', '').lower()[:10]
# this maps the long names from the /etc/DISTRO-release files to the
# traditional short names that Salt has used.
grains['os'] = _OS_NAME_MAP.get(shortname, distroname)
if 'os' not in grains:
Copy link
Contributor

Choose a reason for hiding this comment

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

The SUSE-specific stuff doesn't concern me but this bit affects all distros. Could you clarify your reasoning here? I tend to be very cautious about modifying anything that touches global grains detection logic. We have been bitten by this many times.

Copy link
Contributor

@isbm isbm Jun 14, 2016

Choose a reason for hiding this comment

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

@cachedout I don't see a problem here. The 'os' key was always set from the keymap, but in our systems it is not always same. Hence @meaksh first trying to modify grain before picking standard key. In case not found anything, one from _OS_NAME_MAP is taken. I would say 👍 here, actually.

However, I see another trouble 💥 here: the whole code of this particular function soon to be a better "winner" than a Toyota design. I mean, let's look at this monster function... It is horrid and needs to be splitted, refactored and cleaned up. IMHO. Yes, only in develop, no worries. 😉

Just my few cents.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cachedout I understand your concern, but currently I think there is no problem here. Before this PR, grains['os'] in linux systems is always picked from _OS_NAME_MAP and there isn't custom assignments for this grain in this scope.

Now, with the PR, the only case where grains['os'] is set manually is our SUSE cases and we don't want to overwrite it later with the default value of _OS_NAME_MAP. So the default behavior for the os grain assignment will be the same that currently is except for SUSE systems.

What do you think?

Thanks @isbm for the comment

@cachedout cachedout added the Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged label Jun 14, 2016
if ":suse:" in os_release['CPE_NAME']:
grains['os'] = "SUSE"
elif ":opensuse:" in os_release['CPE_NAME']:
grains['os'] = "SUSE"
Copy link
Contributor

Choose a reason for hiding this comment

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

It is too much noise for setting the os key. I would put that into one clause:

if ":suse:" in os_release['CPE_NAME'] or ":opensuse:" in os_release['CPE_NAME']:
    grains['os'] = "SUSE"

@isbm
Copy link
Contributor

isbm commented Jun 16, 2016

@cachedout from my side here is 👍 There are some more fixes coming this regard (Leap/Tumbleweed), but this PR should be closed first.

@thatch45 thatch45 merged commit c761237 into saltstack:develop Jun 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants