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

Add Verify Linux Ctl Integration Test #373

Merged
merged 1 commit into from
Feb 22, 2022
Merged
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
14 changes: 14 additions & 0 deletions integration/test/agent_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,17 @@ func ReadAgentOutput(d time.Duration) string {

return string(out)
}

func RunShellScript(path string) {
out, err := exec.Command("bash", "-c", "chmod +x " + path).Output()

if err != nil {
log.Fatal(fmt.Sprint(err) + string(out))
}

out, err = exec.Command("bash", "-c", "sudo ./" + path).Output()

if err != nil {
log.Fatal(fmt.Sprint(err) + string(out))
}
}
128 changes: 128 additions & 0 deletions integration/test/sanity/resources/verifyLinuxCtlScript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/sh
sethAmazon marked this conversation as resolved.
Show resolved Hide resolved

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT

assertStatus() {
keyToCheck="${1:-}"
expectedVal="${2:-}"

grepKey='unknown'
case "${keyToCheck}" in
cwa_running_status)
grepKey="\"status\""
;;
cwa_config_status)
grepKey="\"configstatus\""
;;
cwoc_running_status)
grepKey="\"cwoc_status\""
;;
cwoc_config_status)
grepKey="\"cwoc_configstatus\""
;;
*) echo "Invalid Key To Check: ${keyToCheck}" >&2
exit 1
;;
esac

result=$(/usr/bin/amazon-cloudwatch-agent-ctl -a status | grep "${grepKey}" | awk -F: '{print $2}' | sed 's/ "//; s/",//')

if [ "${result}" = "${expectedVal}" ]; then
echo "In step ${step}, ${keyToCheck} is expected"
else
echo "In step ${step}, ${keyToCheck} is NOT expected. (actual="${result}"; expected="${expectedVal}")"
exit 1
fi
}

# init
step=0
/usr/bin/amazon-cloudwatch-agent-ctl -a remove-config -c all -o all
/usr/bin/amazon-cloudwatch-agent-ctl -a stop

step=1
/usr/bin/amazon-cloudwatch-agent-ctl -a status
assertStatus "cwa_running_status" "stopped"
assertStatus "cwoc_running_status" "stopped"
assertStatus "cwa_config_status" "not configured"
assertStatus "cwoc_config_status" "not configured"

step=2
/usr/bin/amazon-cloudwatch-agent-ctl -a start
assertStatus "cwa_running_status" "running"
assertStatus "cwoc_running_status" "stopped"
assertStatus "cwa_config_status" "configured"
assertStatus "cwoc_config_status" "not configured"

step=3
/usr/bin/amazon-cloudwatch-agent-ctl -a fetch-config -o default -s
/usr/bin/amazon-cloudwatch-agent-ctl -a remove-config -c default -s
assertStatus "cwa_running_status" "stopped"
assertStatus "cwoc_running_status" "running"
assertStatus "cwa_config_status" "not configured"
assertStatus "cwoc_config_status" "configured"

step=4
/usr/bin/amazon-cloudwatch-agent-ctl -a fetch-config -c default -o invalid -s
assertStatus "cwa_running_status" "running"
assertStatus "cwoc_running_status" "running"
assertStatus "cwa_config_status" "configured"
assertStatus "cwoc_config_status" "configured"

step=5
/usr/bin/amazon-cloudwatch-agent-ctl -a prep-restart
/usr/bin/amazon-cloudwatch-agent-ctl -a stop
assertStatus "cwa_running_status" "stopped"
assertStatus "cwoc_running_status" "stopped"
assertStatus "cwa_config_status" "configured"
assertStatus "cwoc_config_status" "configured"

step=6
/usr/bin/amazon-cloudwatch-agent-ctl -a cond-restart
assertStatus "cwa_running_status" "running"
assertStatus "cwoc_running_status" "running"
assertStatus "cwa_config_status" "configured"
assertStatus "cwoc_config_status" "configured"

step=7
/usr/bin/amazon-cloudwatch-agent-ctl -a remove-config -c default -s
assertStatus "cwa_running_status" "stopped"
assertStatus "cwoc_running_status" "running"
assertStatus "cwa_config_status" "not configured"
assertStatus "cwoc_config_status" "configured"

step=8
/usr/bin/amazon-cloudwatch-agent-ctl -a remove-config -o default -s
assertStatus "cwa_running_status" "stopped"
assertStatus "cwoc_running_status" "stopped"
assertStatus "cwa_config_status" "not configured"
assertStatus "cwoc_config_status" "not configured"

step=9
/usr/bin/amazon-cloudwatch-agent-ctl -a append-config -c default -o default -s
assertStatus "cwa_running_status" "running"
assertStatus "cwoc_running_status" "stopped"
assertStatus "cwa_config_status" "configured"
assertStatus "cwoc_config_status" "not configured"

step=10
/usr/bin/amazon-cloudwatch-agent-ctl -a remove-config -c all
assertStatus "cwa_running_status" "running"
assertStatus "cwoc_running_status" "stopped"
assertStatus "cwa_config_status" "not configured"
assertStatus "cwoc_config_status" "not configured"

step=11
/usr/bin/amazon-cloudwatch-agent-ctl -a fetch-config -o default -s
assertStatus "cwa_running_status" "running"
assertStatus "cwoc_running_status" "running"
assertStatus "cwa_config_status" "not configured"
assertStatus "cwoc_config_status" "configured"

step=12
/usr/bin/amazon-cloudwatch-agent-ctl -a stop
SaxyPandaBear marked this conversation as resolved.
Show resolved Hide resolved
assertStatus "cwa_running_status" "stopped"
assertStatus "cwoc_running_status" "stopped"
assertStatus "cwa_config_status" "not configured"
assertStatus "cwoc_config_status" "configured"
16 changes: 16 additions & 0 deletions integration/test/sanity/sanity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice on moving integration test out to Github.

// SPDX-License-Identifier: MIT

// +build linux
// +build integration

package sanity

import (
"github.com/aws/amazon-cloudwatch-agent/integration/test"
"testing"
)

func TestAgentStatus(t *testing.T) {
sethAmazon marked this conversation as resolved.
Show resolved Hide resolved
test.RunShellScript("resources/verifyLinuxCtlScript.sh")
}