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): update install.sh to use packages on macOS #1127

Merged
merged 14 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions pkg/scripts_test/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ func checkTags(c check) {
require.NoError(c.test, err, "error while reading configuration")

for k, v := range c.installOptions.tags {
require.Equal(c.test, v, conf.Extensions.Sumologic.Tags[k], "installation token is different than expected")
require.Equal(c.test, v, conf.Extensions.Sumologic.Tags[k], "tag is different than expected")
}
}

func checkDifferentTags(c check) {
conf, err := getConfig(userConfigPath)
require.NoError(c.test, err, "error while reading configuration")

require.Equal(c.test, "tag", conf.Extensions.Sumologic.Tags["some"], "installation token is different than expected")
require.Equal(c.test, "tag", conf.Extensions.Sumologic.Tags["some"], "tag is different than expected")
}

func checkAbortedDueToDifferentToken(c check) {
Expand Down Expand Up @@ -165,7 +165,7 @@ func preActionMockUserConfig(c check) {
f, err := os.Create(userConfigPath)
require.NoError(c.test, err)

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

Expand Down
33 changes: 32 additions & 1 deletion pkg/scripts_test/check_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ func checkConfigFilesOwnershipAndPermissions(ownerName string, ownerGroup string
permissions = configPathDirPermissions
}
} else {
if filepath.Dir(path) != confDPath || path == userConfigPath {
if path == configPath {
// /etc/otelcol-sumo/sumologic.yaml
permissions = configPathFilePermissions
} else if path == userConfigPath {
// /etc/otelcol-sumo/conf.d/common.yaml
permissions = commonConfigPathFilePermissions
} else {
// /etc/otelcol-sumo/conf.d/*
permissions = confDPathFilePermissions
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we may use switch here

}
}
Expand Down Expand Up @@ -112,6 +117,32 @@ 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)
}

func preActionInstallPackageWithDifferentTags(c check) {
c.installOptions.tags = map[string]string{
"some": "tag",
}
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionInstallPackageWithNoAPIBaseURL(c check) {
c.installOptions.apiBaseURL = ""
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionInstallPackageWithNoTags(c check) {
c.installOptions.tags = nil
c.code, c.output, c.errorOutput, c.err = runScript(c)
}

func preActionMockLaunchdConfig(c check) {
f, err := os.Create(launchdPath)
require.NoError(c.test, err)
Expand Down
10 changes: 6 additions & 4 deletions pkg/scripts_test/consts_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ const (
uninstallScriptPath string = appSupportDirPath + "/uninstall.sh"

// TODO: fix mismatch between darwin permissions & linux binary install permissions
configPathDirPermissions uint32 = 0770
configPathFilePermissions uint32 = 0440
confDPathFilePermissions uint32 = 0644
etcPathPermissions uint32 = 0755
// common.yaml must be writable as the install scripts mutate it
commonConfigPathFilePermissions uint32 = 0660
configPathDirPermissions uint32 = 0770
configPathFilePermissions uint32 = 0440
confDPathFilePermissions uint32 = 0644
etcPathPermissions uint32 = 0755

rootGroup string = "wheel"
rootUser string = "root"
Expand Down
9 changes: 5 additions & 4 deletions pkg/scripts_test/consts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const (
tokenEnvFilePath string = envDirectoryPath + "/token.env"

// TODO: fix mismatch between package permissions & expected permissions
configPathDirPermissions uint32 = 0550
configPathFilePermissions uint32 = 0440
confDPathFilePermissions uint32 = 0644
etcPathPermissions uint32 = 0551
commonConfigPathFilePermissions uint32 = 0550
configPathDirPermissions uint32 = 0550
configPathFilePermissions uint32 = 0440
confDPathFilePermissions uint32 = 0644
etcPathPermissions uint32 = 0551

rootGroup string = "root"
rootUser string = "root"
Expand Down
74 changes: 34 additions & 40 deletions pkg/scripts_test/install_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,13 @@ func TestInstallScriptDarwin(t *testing.T) {
skipInstallToken: true,
},
preActions: []checkFunc{
preActionMockUserConfig,
preActionWriteAPIBaseURLToUserConfig,
preActionInstallPackage,
},
preChecks: []checkFunc{
checkBinaryNotCreated,
checkConfigNotCreated,
checkBinaryCreated,
checkConfigCreated,
checkUserConfigCreated,
checkUserNotExists,
checkUserExists,
},
postChecks: []checkFunc{
checkBinaryCreated,
Expand All @@ -252,20 +251,19 @@ func TestInstallScriptDarwin(t *testing.T) {
skipInstallToken: true,
},
preActions: []checkFunc{
preActionMockUserConfig,
preActionWriteDifferentAPIBaseURLToUserConfig,
preActionInstallPackageWithDifferentAPIBaseURL,
},
preChecks: []checkFunc{
checkBinaryNotCreated,
checkConfigNotCreated,
checkBinaryCreated,
checkConfigCreated,
checkUserConfigCreated,
checkUserNotExists,
checkUserExists,
},
postChecks: []checkFunc{
checkBinaryNotCreated,
checkConfigNotCreated,
checkBinaryCreated,
checkConfigCreated,
checkUserConfigCreated,
checkLaunchdConfigNotCreated,
checkLaunchdConfigCreated,
checkAbortedDueToDifferentAPIBaseURL,
},
installCode: 1,
Expand All @@ -276,12 +274,12 @@ func TestInstallScriptDarwin(t *testing.T) {
apiBaseURL: apiBaseURL,
skipInstallToken: true,
},
preActions: []checkFunc{preActionMockUserConfig},
preActions: []checkFunc{preActionInstallPackageWithNoAPIBaseURL},
preChecks: []checkFunc{
checkBinaryNotCreated,
checkConfigNotCreated,
checkBinaryCreated,
checkConfigCreated,
checkUserConfigCreated,
checkUserNotExists,
checkUserExists,
},
postChecks: []checkFunc{
checkBinaryCreated,
Expand All @@ -297,14 +295,13 @@ func TestInstallScriptDarwin(t *testing.T) {
skipInstallToken: true,
},
preActions: []checkFunc{
preActionMockUserConfig,
preActionWriteEmptyUserConfig,
preActionInstallPackageWithNoAPIBaseURL,
},
preChecks: []checkFunc{
checkBinaryNotCreated,
checkConfigNotCreated,
checkBinaryCreated,
checkConfigCreated,
checkUserConfigCreated,
checkUserNotExists,
checkUserExists,
},
postChecks: []checkFunc{
checkBinaryCreated,
Expand Down Expand Up @@ -342,14 +339,13 @@ func TestInstallScriptDarwin(t *testing.T) {
},
},
preActions: []checkFunc{
preActionMockUserConfig,
preActionWriteTagsToUserConfig,
preActionInstallPackage,
},
preChecks: []checkFunc{
checkBinaryNotCreated,
checkConfigNotCreated,
checkBinaryCreated,
checkConfigCreated,
checkUserConfigCreated,
checkUserNotExists,
checkUserExists,
},
postChecks: []checkFunc{
checkBinaryCreated,
Expand All @@ -370,21 +366,20 @@ func TestInstallScriptDarwin(t *testing.T) {
},
},
preActions: []checkFunc{
preActionMockUserConfig,
preActionWriteDifferentTagsToUserConfig,
preActionInstallPackageWithDifferentTags,
},
preChecks: []checkFunc{
checkBinaryNotCreated,
checkConfigNotCreated,
checkBinaryCreated,
checkConfigCreated,
checkUserConfigCreated,
checkUserNotExists,
checkUserExists,
},
postChecks: []checkFunc{
checkBinaryNotCreated,
checkConfigNotCreated,
checkBinaryCreated,
checkConfigCreated,
checkUserConfigCreated,
checkDifferentTags,
checkLaunchdConfigNotCreated,
checkLaunchdConfigCreated,
checkAbortedDueToDifferentTags,
},
installCode: 1,
Expand All @@ -399,14 +394,13 @@ func TestInstallScriptDarwin(t *testing.T) {
},
},
preActions: []checkFunc{
preActionMockUserConfig,
preActionWriteEmptyUserConfig,
preActionInstallPackageWithNoTags,
},
preChecks: []checkFunc{
checkBinaryNotCreated,
checkConfigNotCreated,
checkBinaryCreated,
checkConfigCreated,
checkUserConfigCreated,
checkUserNotExists,
checkUserExists,
},
postChecks: []checkFunc{
checkBinaryCreated,
Expand Down
4 changes: 2 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,11 @@ function setup_config_darwin() {
write_sumologic_extension "${COMMON_CONFIG_PATH}" "${INDENTATION}"

# fill in api base url
if [[ -n "${API_BASE_URL}" && -z "${USER_API_URL}" ]]; then
if [[ -n "${API_BASE_URL}" ]]; then
Copy link
Contributor

@sumo-drosiek sumo-drosiek Jul 5, 2023

Choose a reason for hiding this comment

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

Do we need this change? If yes, can add to linux as well?

Copy link
Contributor Author

@amdprophet amdprophet Jul 5, 2023

Choose a reason for hiding this comment

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

This is only necessary on macOS as common.yaml is replaced on upgrades. I haven't been able to find a way around this.

write_api_url "${API_BASE_URL}" "${COMMON_CONFIG_PATH}" "${EXT_INDENTATION}"
fi

if [[ -n "${FIELDS}" && -z "${USER_FIELDS}" ]]; then
if [[ -n "${FIELDS}" ]]; then
write_tags "${FIELDS}" "${COMMON_CONFIG_PATH}" "${INDENTATION}" "${EXT_INDENTATION}"
fi

Expand Down