Skip to content

Instantly share code, notes, and snippets.

@Jonsy13
Last active May 13, 2021 08:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jonsy13/8c5ca3a1376c43df2158b49d828cc8fb to your computer and use it in GitHub Desktop.
Save Jonsy13/8c5ca3a1376c43df2158b49d828cc8fb to your computer and use it in GitHub Desktop.
Script for automating the External Agent Registration Tests Using LitmusCTL
#!/usr/bin/expect -f
## [STILL IN DEVELOPMENT]
## Prerequisites
# litmusctl should have the permissions to create role/rolebindings
# expect should be installed on user's system
## expect is used for expecting an interactive prompts.
## send is used for sending inputs to the prompts.
## PROJECT is Project Number, Can be taken from dropdown in Portal UI
## INSTALLATION_MODE, 1 for Cluster Mode and 2 for Namespaced Mode
array set MODES {
1 "cluster"
2 "namespace"
}
## PLATFORM, 1. AWS, 2. GKE, 3. Openshift, 4. Rancher, 5. Others
array set Platforms {
1 "AWS"
2 "GKE"
3 "Openshift"
4 "Rancher"
5 "Others"
}
##Setting Inputs before Executing the Script
set HOST_URL [lindex $argv 0];
set USERNAME admin
set PASSWORD litmus
set PROJECT 1
set INSTALLATION_MODE [lindex $argv 1];
set AGENT_NAME "External Agent"
set AGENT_DESCRIPTION "My External Agent"
set PLATFORM 5
set NAMESPACE litmus
set SERVICE_ACCOUNT litmus
set timeout 600
## Connecting new agent
spawn litmusctl agent connect
## https://wiki.tcl-lang.org/page/match_max
match_max 100000
## Input Host URL
expect -exact "πŸ”₯ Connecting LitmusChaos agent\r
\r
πŸ“Ά Please enter LitmusChaos details --\r
πŸ‘‰ Host URL where litmus is installed: "
send -- "$HOST_URL\r"
## Input Admin Credentials
expect -exact "πŸ€” Username \[admin\]: "
send -- "$USERNAME\r"
expect -exact "πŸ™ˆ Password: "
send -- "$PASSWORD\r"
expect -exact "βœ… Login Successful!\r"
# Select the project
expect -exact "\r
✨ Projects List:\r
1. admin's project\r
\r
πŸ”Ž Select Project: "
send -- "$PROJECT\r"
## Select the installation Mode
expect -exact "\r
πŸ”Œ Installation Modes:\r
1. Cluster\r
2. Namespace\r
\r
πŸ‘‰ Select Mode \[cluster\]: "
send -- "$INSTALLATION_MODE\r"
## Prerequisites check
if {$INSTALLATION_MODE == 1} {
expect -exact "\r
πŸƒ Running prerequisites check....\r
πŸ”‘ clusterrole - βœ…\r
πŸ”‘ clusterrolebinding - βœ…\r
\r
🌟 Sufficient permissions. Connecting Agent\r
\r"
} else {
expect -exact "\r
πŸƒ Running prerequisites check....\r
πŸ”‘ role - βœ…\r
πŸ”‘ rolebinding - βœ…\r
\r
🌟 Sufficient permissions. Connecting Agent\r
\r"
}
## Enter Agent Details (Name & Description)
expect -exact "πŸ”— Enter the details of the agent ----\r
🀷 Agent Name: "
send -- "$AGENT_NAME\r"
expect -exact "πŸ“˜ Agent Description: "
send -- "$AGENT_DESCRIPTION\r"
## Select the Agent's Platform
expect -exact "πŸ“¦ Platform List\r
1. AWS\r
2. GKE\r
3. Openshift\r
4. Rancher\r
5. Others\r
πŸ”Ž Select Platform \[Others\]: "
send -- "$PLATFORM\r"
## Enter Namespace
expect -exact "πŸ“ Enter the namespace (new or existing) \[litmus\]: "
send -- "$NAMESPACE\r"
## Enter Service Account for Agent
expect -exact "πŸ”‘ Enter service account \[litmus\]: "
send -- "$SERVICE_ACCOUNT\r"
## Check Summary and Select Y for registering agent.
expect -exact "\r
πŸ“Œ Summary --------------------------\r
\r
Agent Name: $AGENT_NAME\r
Agent Description: $AGENT_DESCRIPTION\r
Platform Name: $Platforms($PLATFORM)\r
Namespace: $NAMESPACE (new)\r
Service Account: $SERVICE_ACCOUNT (new)\r
Installation Mode: $MODES($INSTALLATION_MODE)\r
\r
-------------------------------------\r
\r"
expect -exact "🀷 Do you want to continue with the above details? \[Y/N\]: "
## Change this to N, if you don't want to connect agent.
send -- "Y\r"
expect eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment