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

feat(scripts): add linux deb & rpm package support to install script #1219

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ jobs:
name: Test Install Script
runs-on: ${{ matrix.runs_on }}
strategy:
fail-fast: false
matrix:
include:
- arch_os: linux_amd64
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Released TBD

- feat(install.sh): prevent permission error when collecting host metrics [#1228]
- feat(install.sh): add linux deb & rpm package support [#1219]

[#1228]: https://github.com/SumoLogic/sumologic-otel-collector/pull/1228
[Unreleased]: https://github.com/SumoLogic/sumologic-otel-collector/compare/v0.83.0-sumo-0...main
Expand Down
154 changes: 96 additions & 58 deletions pkg/scripts_test/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type check struct {
test *testing.T
installOptions installOptions
installType installType
code int
err error
expectedInstallCode int
Expand Down Expand Up @@ -55,6 +56,44 @@ func checkRun(c check) {
require.Equal(c.test, c.expectedInstallCode, c.code, "unexpected installation script error code")
}

func checkConfigFilesOwnershipAndPermissions(c check) {
ownerName := getConfigFilesOwner(c)
groupName := getConfigFilesGroup(c)
etcPathGlob := filepath.Join(etcPath, "*")
etcPathNestedGlob := filepath.Join(etcPath, "*", "*")

for _, glob := range []string{etcPathGlob, etcPathNestedGlob} {
paths, err := filepath.Glob(glob)
require.NoError(c.test, err)
for _, path := range paths {
var permissions uint32
info, err := os.Stat(path)
require.NoError(c.test, err)
if info.IsDir() {
permissions = configPathDirPermissions
} else {
switch path {
case configPath:
// /etc/otelcol-sumo/sumologic.yaml
permissions = configPathFilePermissions
case userConfigPath:
// /etc/otelcol-sumo/conf.d/common.yaml
permissions = commonConfigPathFilePermissions
case tokenEnvFilePath:
// /etc/otelcol-sumo/env/token.env
permissions = commonConfigPathFilePermissions
default:
// /etc/otelcol-sumo/conf.d/**/
permissions = confDPathFilePermissions
}
}
PathHasPermissions(c.test, path, permissions)
PathHasOwner(c.test, configPath, ownerName, groupName)
}
}
PathHasPermissions(c.test, configPath, configPathFilePermissions)
}

func checkConfigCreated(c check) {
require.FileExists(c.test, configPath, "configuration has not been created properly")
}
Expand All @@ -77,6 +116,13 @@ func checkConfigOverrided(c check) {
}, "invalid value for installation token")
}

func checkHostmetricsOwnershipAndPermissions(c check) {
ownerName := getConfigFilesOwner(c)
groupName := getConfigFilesGroup(c)
PathHasOwner(c.test, hostmetricsConfigPath, ownerName, groupName)
PathHasPermissions(c.test, hostmetricsConfigPath, confDPathFilePermissions)
}

func checkUserConfigCreated(c check) {
require.FileExists(c.test, userConfigPath, "user configuration has not been created properly")
}
Expand Down Expand Up @@ -138,75 +184,67 @@ func checkAbortedDueToNoToken(c check) {
require.Contains(c.test, c.output[len(c.output)-1], "You can ignore this requirement by adding '--skip-installation-token argument.")
}

func preActionMockConfig(c check) {
err := os.MkdirAll(etcPath, fs.FileMode(etcPathPermissions))
require.NoError(c.test, err)

f, err := os.Create(configPath)
require.NoError(c.test, err)

err = f.Chmod(fs.FileMode(configPathFilePermissions))
require.NoError(c.test, err)
}

func preActionMockUserConfig(c check) {
err := os.MkdirAll(etcPath, fs.FileMode(etcPathPermissions))
require.NoError(c.test, err)

err = os.MkdirAll(confDPath, fs.FileMode(configPathDirPermissions))
require.NoError(c.test, err)

f, err := os.Create(userConfigPath)
require.NoError(c.test, err)

err = f.Chmod(fs.FileMode(commonConfigPathFilePermissions))
require.NoError(c.test, err)
func getConfigFilesOwner(c check) string {
if c.installOptions.uninstall {
if c.installType&PACKAGE_INSTALL != 0 {
return systemUser
}
return rootUser
}
if c.installOptions.skipSystemd || c.installOptions.skipInstallToken {
return rootUser
}
return systemUser
}

func preActionWriteAPIBaseURLToUserConfig(c check) {
conf, err := getConfig(userConfigPath)
require.NoError(c.test, err)

conf.Extensions.Sumologic.APIBaseURL = c.installOptions.apiBaseURL
err = saveConfig(userConfigPath, conf)
require.NoError(c.test, err)
func getConfigFilesGroup(c check) string {
if c.installOptions.uninstall {
if c.installType&PACKAGE_INSTALL != 0 {
return systemGroup
}
return rootGroup
}
if c.installOptions.skipSystemd || c.installOptions.skipInstallToken {
return rootGroup
}
return systemGroup
}

func preActionWriteDifferentAPIBaseURLToUserConfig(c check) {
conf, err := getConfig(userConfigPath)
require.NoError(c.test, err)

conf.Extensions.Sumologic.APIBaseURL = "different" + c.installOptions.apiBaseURL
err = saveConfig(userConfigPath, conf)
require.NoError(c.test, err)
func preActionInstallPackage(c check) {
c.installOptions.installToken = installToken
c.installOptions.uninstall = false
c.installOptions.purge = false
c.installOptions.apiBaseURL = mockAPIBaseURL
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionWriteDifferentTagsToUserConfig(c check) {
conf, err := getConfig(userConfigPath)
require.NoError(c.test, err)

conf.Extensions.Sumologic.Tags = map[string]string{
"some": "tag",
func preActionInstallPackageVersion(version string) checkFunc {
return func(c check) {
c.installOptions.installToken = installToken
c.installOptions.uninstall = false
c.installOptions.purge = false
c.installOptions.version = version
c.installOptions.apiBaseURL = mockAPIBaseURL
c.code, c.output, c.errorOutput, c.err = runScript(c)
}
err = saveConfig(userConfigPath, conf)
require.NoError(c.test, err)
}

func preActionWriteEmptyUserConfig(c check) {
conf, err := getConfig(userConfigPath)
require.NoError(c.test, err)

err = saveConfig(userConfigPath, conf)
require.NoError(c.test, err)
func preActionInstallPreviousVersion(c check) {
if c.installType&PACKAGE_INSTALL != 0 {
preActionInstallPackageVersion(previousPackageVersion)(c)
}
preActionInstallVersion(previousBinaryVersion)(c)
}

func preActionWriteTagsToUserConfig(c check) {
conf, err := getConfig(userConfigPath)
require.NoError(c.test, err)

conf.Extensions.Sumologic.Tags = c.installOptions.tags
err = saveConfig(userConfigPath, conf)
require.NoError(c.test, err)
func preActionInstallVersion(version string) checkFunc {
return func(c check) {
c.installOptions.installToken = installToken
c.installOptions.uninstall = false
c.installOptions.purge = false
c.installOptions.version = version
c.installOptions.apiBaseURL = mockAPIBaseURL
c.code, c.output, c.errorOutput, c.err = runScript(c)
}
}

func checkAbortedDueToDifferentAPIBaseURL(c check) {
Expand Down
56 changes: 1 addition & 55 deletions pkg/scripts_test/check_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,12 @@ package sumologic_scripts_tests
import (
"io/fs"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/stretchr/testify/require"
)

func checkConfigFilesOwnershipAndPermissions(ownerName string, ownerGroup string) func(c check) {
return func(c check) {
PathHasPermissions(c.test, etcPath, etcPathPermissions)
PathHasOwner(c.test, etcPath, ownerName, ownerGroup)

etcPathGlob := filepath.Join(etcPath, "*")
etcPathNestedGlob := filepath.Join(etcPath, "*", "*")

for _, glob := range []string{etcPathGlob, etcPathNestedGlob} {
paths, err := filepath.Glob(glob)
require.NoError(c.test, err)
for _, path := range paths {
var permissions uint32
info, err := os.Stat(path)
require.NoError(c.test, err)
if info.IsDir() {
if path == etcPath {
permissions = etcPathPermissions
} else {
permissions = configPathDirPermissions
}
} else {
switch path {
case configPath:
// /etc/otelcol-sumo/sumologic.yaml
permissions = configPathFilePermissions
case userConfigPath:
// /etc/otelcol-sumo/conf.d/common.yaml
permissions = commonConfigPathFilePermissions
default:
// /etc/otelcol-sumo/conf.d/*
permissions = confDPathFilePermissions
}
}
PathHasPermissions(c.test, path, permissions)
PathHasOwner(c.test, configPath, ownerName, ownerGroup)
}
}
PathHasPermissions(c.test, configPath, configPathFilePermissions)
}
}

func checkDifferentTokenInLaunchdConfig(c check) {
require.NotEmpty(c.test, c.installOptions.installToken, "installation token has not been provided")

Expand All @@ -71,13 +28,6 @@ func checkGroupNotExists(c check) {
require.False(c.test, exists, "group has been created")
}

func checkHostmetricsOwnershipAndPermissions(ownerName string, ownerGroup string) func(c check) {
return func(c check) {
PathHasOwner(c.test, hostmetricsConfigPath, ownerName, ownerGroup)
PathHasPermissions(c.test, hostmetricsConfigPath, confDPathFilePermissions)
}
}

func checkLaunchdConfigCreated(c check) {
require.FileExists(c.test, launchdPath, "launchd configuration has not been created properly")
}
Expand All @@ -87,7 +37,7 @@ func checkLaunchdConfigNotCreated(c check) {
}

func checkPackageCreated(c check) {
re, err := regexp.Compile("Package downloaded to: .*/otelcol-sumo.pkg")
re, err := regexp.Compile(`^Package downloaded to: .*/otelcol-sumo-(apple|intel)\.pkg$`)
require.NoError(c.test, err)

matchedLine := ""
Expand Down Expand Up @@ -121,10 +71,6 @@ func checkUserNotExists(c check) {
require.False(c.test, exists, "user has been created")
}

func preActionInstallPackage(c check) {
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionInstallPackageWithDifferentAPIBaseURL(c check) {
c.installOptions.apiBaseURL = "different" + c.installOptions.apiBaseURL
c.code, c.output, c.errorOutput, c.err = runScript(c)
Expand Down
Loading