Skip to content

Commit 7c21a33

Browse files
authored
Fallback any linux system to use systemd (#6201)
This way we don't have to add every new Linux distro to this list. The majority of the ecosystem is systemd at this point and we can track anything that isn't systemd. Signed-off-by: Tim Smith <tsmith84@gmail.com>
1 parent c8a22b6 commit 7c21a33

File tree

6 files changed

+355
-35
lines changed

6 files changed

+355
-35
lines changed

providers/os/detector/detector_platform_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ func TestEndeavourOSContainerDetector(t *testing.T) {
10111011
assert.Equal(t, []string{"arch", "linux", "unix", "os"}, di.Family)
10121012
}
10131013

1014-
func TestCumulusContainerDetector(t *testing.T) {
1014+
func TestCumulusOSDetector(t *testing.T) {
10151015
di, err := detectPlatformFromMock("./testdata/detect-cumulus.toml")
10161016
assert.Nil(t, err, "was able to create the provider")
10171017

@@ -1020,3 +1020,13 @@ func TestCumulusContainerDetector(t *testing.T) {
10201020
assert.Equal(t, "x86_64", di.Arch, "os arch should be identified")
10211021
assert.Equal(t, []string{"debian", "linux", "unix", "os"}, di.Family)
10221022
}
1023+
1024+
func TestNobaraDetector(t *testing.T) {
1025+
di, err := detectPlatformFromMock("./testdata/detect-nobara.toml")
1026+
assert.Nil(t, err, "was able to create the provider")
1027+
1028+
assert.Equal(t, "nobara", di.Name, "os name should be identified")
1029+
assert.Equal(t, "Nobara Linux 40 (KDE Plasma)", di.Title, "os title should be identified")
1030+
assert.Equal(t, "x86_64", di.Arch, "os arch should be identified")
1031+
assert.Equal(t, []string{"redhat", "linux", "unix", "os"}, di.Family)
1032+
}

providers/os/resources/groups/manager_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func TestManagerDebian(t *testing.T) {
1717
mock, err := mock.New(0, &inventory.Asset{
1818
Platform: &inventory.Platform{
19-
Family: []string{"unix", "linux", "debian"},
19+
Family: []string{"debian", "linux", "unix", "os"},
2020
},
2121
}, mock.WithPath("./testdata/debian.toml"))
2222
require.NoError(t, err)
@@ -38,7 +38,7 @@ func TestManagerDebian(t *testing.T) {
3838
func TestManagerMacos(t *testing.T) {
3939
mock, err := mock.New(0, &inventory.Asset{
4040
Platform: &inventory.Platform{
41-
Family: []string{"darwin"},
41+
Family: []string{"darwin", "bsd", "unix", "os"},
4242
},
4343
}, mock.WithPath("./testdata/osx.toml"))
4444
require.NoError(t, err)
@@ -60,7 +60,7 @@ func TestManagerMacos(t *testing.T) {
6060
func TestManagerFreebsd(t *testing.T) {
6161
mock, err := mock.New(0, &inventory.Asset{
6262
Platform: &inventory.Platform{
63-
Family: []string{"unix", "bsd"},
63+
Family: []string{"bsd", "unix", "os"},
6464
},
6565
}, mock.WithPath("./testdata/freebsd12.toml"))
6666
require.NoError(t, err)
@@ -82,7 +82,7 @@ func TestManagerFreebsd(t *testing.T) {
8282
func TestManagerWindows(t *testing.T) {
8383
mock, err := mock.New(0, &inventory.Asset{
8484
Platform: &inventory.Platform{
85-
Family: []string{"windows"},
85+
Family: []string{"windows", "os"},
8686
},
8787
}, mock.WithPath("./testdata/windows.toml"))
8888
require.NoError(t, err)

providers/os/resources/services/launchd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestParseServiceLaunchD(t *testing.T) {
1818
Name: "macos",
1919
Family: []string{"unix", "darwin"},
2020
},
21-
}, mock.WithPath("./testdata/osx.toml"))
21+
}, mock.WithPath("./testdata/macos.toml"))
2222
if err != nil {
2323
t.Fatal(err)
2424
}

providers/os/resources/services/manager.go

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,12 @@ func ResolveManager(conn shared.Connection) (OSServiceManager, error) {
7373
switch {
7474
case useNoopInit:
7575
osm = &noopOsServiceManager{}
76-
case asset.Platform.IsFamily("arch"): // arch family
77-
osm = ResolveSystemdServiceManager(conn)
7876
case asset.Platform.Name == "amazonlinux":
7977
if amazonlinux1version.MatchString(asset.Platform.Version) {
8078
osm = &UpstartServiceManager{SysVServiceManager{conn: conn}}
8179
} else {
8280
osm = ResolveSystemdServiceManager(conn)
8381
}
84-
case asset.Platform.Name == "photon":
85-
osm = ResolveSystemdServiceManager(conn)
8682
// NOTE: we need to check fedora before rhel family, since its also rhel family
8783
case asset.Platform.Name == "fedora":
8884
rv := detector.ParseOsVersion(asset.Platform.Version)
@@ -132,8 +128,6 @@ func ResolveManager(conn shared.Connection) (OSServiceManager, error) {
132128
} else {
133129
osm = ResolveSystemdServiceManager(conn)
134130
}
135-
case asset.Platform.Name == "raspbian" || asset.Platform.Name == "parrot": // debian based distros that have always been systemd
136-
osm = ResolveSystemdServiceManager(conn)
137131
case asset.Platform.Name == "suse-microos" || asset.Platform.Name == "opensuse-microos": // suse family but uses a different version scheme
138132
osm = ResolveSystemdServiceManager(conn)
139133
case asset.Platform.IsFamily("suse"):
@@ -161,29 +155,9 @@ func ResolveManager(conn shared.Connection) (OSServiceManager, error) {
161155
osm = &OpenrcServiceManager{conn: conn}
162156
case asset.Platform.Name == "gentoo":
163157
osm = &OpenrcServiceManager{conn: conn}
164-
case asset.Platform.Name == "cos":
165-
osm = ResolveSystemdServiceManager(conn)
166158
case asset.Platform.Name == "aix":
167159
osm = &AixServiceManager{conn: conn}
168-
case asset.Platform.IsFamily("euler"):
169-
osm = ResolveSystemdServiceManager(conn)
170-
case asset.Platform.Name == "kali": // debian based with versions from 2015 onwards being systemd based
171-
osm = ResolveSystemdServiceManager(conn)
172-
case asset.Platform.Name == "mageia": // mageia 2 and later are systemd based
173-
osm = ResolveSystemdServiceManager(conn)
174-
case asset.Platform.Name == "cloudlinux": // rhel based
175-
osm = ResolveSystemdServiceManager(conn)
176-
case asset.Platform.Name == "elementary": // ubuntu based
177-
osm = ResolveSystemdServiceManager(conn)
178-
case asset.Platform.Name == "mx": // debian based
179-
osm = ResolveSystemdServiceManager(conn)
180-
case asset.Platform.Name == "zorin": // ubuntu based
181-
osm = ResolveSystemdServiceManager(conn)
182-
case asset.Platform.Name == "cumulus-linux": // debian based
183-
osm = ResolveSystemdServiceManager(conn)
184-
case asset.Platform.Name == "nobara": // fedora based
185-
osm = ResolveSystemdServiceManager(conn)
186-
case asset.Platform.Name == "flatcar":
160+
case asset.Platform.IsFamily("linux"): // fallback for other linux distros which we assume are systemd
187161
osm = ResolveSystemdServiceManager(conn)
188162
}
189163

0 commit comments

Comments
 (0)