Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
release,cmd,dirs: Redo the distro checks to take into account distribution families #3984
Conversation
| @@ -66,8 +66,17 @@ func distroSupportsReExec() bool { | ||
| if !release.OnClassic { | ||
| return false | ||
| } | ||
| - switch release.ReleaseInfo.ID { | ||
| - case "fedora", "centos", "rhel", "opensuse", "suse", "poky", "arch", "manjaro", "lirios": | ||
| + var contains = func(haystack []string, needle string) bool { |
Conan-Kudo
Sep 28, 2017
Contributor
Hmm, apparently this already exist as strutil.ListContains, I'll just reuse that.
| + return false | ||
| + | ||
| + } | ||
| + switch { |
zyga
Sep 28, 2017
Contributor
The switch makes little sense here, can you make that into a normal if statement now please?
Conan-Kudo
Sep 28, 2017
Contributor
This is still checking more than one conditional, so the switch makes sense still, I think.
| @@ -165,8 +165,17 @@ func SetRootDir(rootdir string) { | ||
| } | ||
| GlobalRootDir = rootdir | ||
| - switch release.ReleaseInfo.ID { | ||
| - case "fedora", "centos", "rhel", "arch", "manjaro", "lirios": | ||
| + var contains = func(haystack []string, needle string) bool { |
| @@ -93,6 +93,35 @@ BUG_REPORT_URL="https://bugs.launchpad.net/elementary/+filebug"` | ||
| c.Check(os.VersionID, Equals, "0.4") | ||
| } | ||
| +func (s *ReleaseTestSuite) TestFamilyOSRelease(c *C) { | ||
| + mockOSRelease := filepath.Join(c.MkDir(), "mock-os-release") |
| +func (s *ReleaseTestSuite) TestFamilyOSRelease(c *C) { | ||
| + mockOSRelease := filepath.Join(c.MkDir(), "mock-os-release") | ||
| + dump := `NAME="CentOS Linux" | ||
| + VERSION="7 (Core)" |
zyga
Sep 28, 2017
Contributor
I think you have to unindent this. Alternatively just move the variable dump out of the function (and make it a const)
|
@zyga This should address all your feedback now. |
|
I've rebased it against current master to resolve conflicts. |
zyga
requested changes
Sep 29, 2017
•
I think it is close, let me know if you want to help with tests. Feel free to take stuff from https://github.com/zyga/os-release-zoo
| - switch release.ReleaseInfo.ID { | ||
| - case "fedora", "centos", "rhel", "opensuse", "suse", "poky", "arch", "manjaro", "lirios", "solus": | ||
| + switch { | ||
| + case release.ReleaseInfo.ID != "debian", !strutil.ListContains(release.ReleaseInfo.IDLike, "debian"): |
zyga
Sep 29, 2017
Contributor
Can you please add a similar check for ID_LIKE=ubuntu, the code as it stands today would regress on Elementary OS
NAME="elementary OS"
VERSION="0.4 Loki"
ID="elementary OS"
ID_LIKE=ubuntu
PRETTY_NAME="elementary OS Loki"
VERSION_ID="0.4"
HOME_URL="http://elementary.io/"
SUPPORT_URL="http://elementary.io/support/"
BUG_REPORT_URL="https://bugs.launchpad.net/elementary/+filebug"
| + c.Check(os.VersionID, Equals, "7") | ||
| + c.Check(os.IDLike, DeepEquals, []string{"rhel", "fedora"}) | ||
| +} | ||
| + |
zyga
Sep 29, 2017
Contributor
I'd like to see a few more test cases for distributions:
- fedora
- centos (thanks)
- rhel
- ubuntu
- ubuntu core
- elementary
- mint
- arch
etc.
What we save by having nice generic code here I'd like to check by having very comprehensive test suite that measures behaviour.
mvo5
Sep 29, 2017
Collaborator
AIUI @zyga has a hole bunch of examples of those maybe we can import them here?
Conan-Kudo
Sep 29, 2017
Contributor
I don't want to import all of them, as that isn't quite necessary. We just need to prove that the negative cases work.
mvo5
reviewed
Sep 29, 2017
Looks good, some ideas inline, thanks a bunch for working on this.
| - switch release.ReleaseInfo.ID { | ||
| - case "fedora", "centos", "rhel", "opensuse", "suse", "poky", "arch", "manjaro", "lirios", "solus": | ||
| + switch { | ||
| + case release.ReleaseInfo.ID != "debian", !strutil.ListContains(release.ReleaseInfo.IDLike, "debian"): |
mvo5
Sep 29, 2017
Collaborator
It seems like an "if" statement here should be fine, a switch {} with just a single case looks a bit out of place.
| + c.Check(os.VersionID, Equals, "7") | ||
| + c.Check(os.IDLike, DeepEquals, []string{"rhel", "fedora"}) | ||
| +} | ||
| + |
zyga
Sep 29, 2017
Contributor
I'd like to see a few more test cases for distributions:
- fedora
- centos (thanks)
- rhel
- ubuntu
- ubuntu core
- elementary
- mint
- arch
etc.
What we save by having nice generic code here I'd like to check by having very comprehensive test suite that measures behaviour.
mvo5
Sep 29, 2017
Collaborator
AIUI @zyga has a hole bunch of examples of those maybe we can import them here?
Conan-Kudo
Sep 29, 2017
Contributor
I don't want to import all of them, as that isn't quite necessary. We just need to prove that the negative cases work.
Conan-Kudo
added some commits
Sep 28, 2017
zyga
reviewed
Sep 29, 2017
One more comment, I need to check various arch derivatives first.
| @@ -66,8 +66,8 @@ func distroSupportsReExec() bool { | ||
| if !release.OnClassic { | ||
| return false | ||
| } | ||
| - switch release.ReleaseInfo.ID { | ||
| - case "fedora", "centos", "rhel", "opensuse", "suse", "poky", "arch", "manjaro", "lirios", "solus": | ||
| + if release.ReleaseInfo.ID != "debian" || !strutil.ListContains(release.ReleaseInfo.IDLike, "debian") || |
| - switch release.ReleaseInfo.ID { | ||
| - case "fedora", "centos", "rhel", "arch", "manjaro", "lirios": | ||
| + switch { | ||
| + case release.ReleaseInfo.ID == "fedora", strutil.ListContains(release.ReleaseInfo.IDLike, "fedora"), release.ReleaseInfo.ID == "arch", strutil.ListContains(release.ReleaseInfo.IDLike, "arch"): |
zyga
Sep 29, 2017
Contributor
I'm not sure if Manjaro uses /var/lib/snapd/snap anymore, I think it was reverted back to /snap there
codecov-io
commented
Sep 30, 2017
•
Codecov Report
@@ Coverage Diff @@
## master #3984 +/- ##
==========================================
- Coverage 75.94% 75.93% -0.01%
==========================================
Files 423 423
Lines 36571 36580 +9
==========================================
+ Hits 27773 27778 +5
- Misses 6850 6853 +3
- Partials 1948 1949 +1
Continue to review full report at Codecov.
|
chipaca
approved these changes
Oct 4, 2017
I think this is fine. FINE.
I'd really like it more if the check were by ability rather than name, but that is Hard.
Conan-Kudo commentedSep 28, 2017
This PR changes the distribution checks in snapd to account for distribution families, so that snapd behaves as expected across not only the main distributions we support, but their derivatives, too.