Skip to content

Commit

Permalink
Add Verify Linux Ctl Integration Test
Browse files Browse the repository at this point in the history
  • Loading branch information
sethAmazon committed Feb 22, 2022
1 parent 0c6d2dd commit 1fe9a1b
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
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

# 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
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.
// 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) {
test.RunShellScript("resources/verifyLinuxCtlScript.sh")
}

0 comments on commit 1fe9a1b

Please sign in to comment.