Last active
May 13, 2021 08:50
-
-
Save Jonsy13/8c5ca3a1376c43df2158b49d828cc8fb to your computer and use it in GitHub Desktop.
Script for automating the External Agent Registration Tests Using LitmusCTL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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