22
33set -e
44
5- # Get the absolute path of the steve directory (this repo)
65STEVE_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /.." && pwd) "
76
8- # Initialize variables from environment or defaults
97RANCHER_IMAGE=" ${RANCHER_IMAGE:- } "
108RANCHER_AGENT_IMAGE=" ${RANCHER_AGENT_IMAGE:- } "
119CONTAINER_NAME=" rancher-server-test"
1210BOOTSTRAP_PASSWORD=" ${CATTLE_BOOTSTRAP_PASSWORD:- admin} "
1311SKIP_SETUP=false
1412
15- # Function to detect Rancher images if not provided
1613detect_rancher_images () {
1714 local rancher_image=$1
1815 local agent_image=$2
@@ -37,12 +34,10 @@ detect_rancher_images() {
3734 fi
3835 fi
3936
40- # Return values via global variables (bash limitation)
4137 RANCHER_IMAGE=" ${rancher_image} "
4238 RANCHER_AGENT_IMAGE=" ${agent_image} "
4339}
4440
45- # Function to cleanup on exit
4641cleanup () {
4742 echo " "
4843 echo " Cleaning up..."
@@ -55,19 +50,16 @@ cleanup() {
5550
5651trap cleanup EXIT
5752
58- # Function to detect the machine's primary IP address
5953detect_rancher_ip () {
6054 local ip=$( hostname -I | awk ' {print $1}' )
6155 if [ -z " $ip " ]; then
6256 echo " Error: Could not determine IP address" >&2
6357 return 1
6458 fi
65- # Set global variable
6659 RANCHER_IP=" $ip "
6760 echo " Using IP address: $RANCHER_IP "
6861}
6962
70- # Function to remove existing container if it exists
7163remove_existing_container () {
7264 local container_name=$1
7365 if docker ps -a --format ' {{.Names}}' | grep -q " ^${container_name} $" ; then
@@ -77,7 +69,6 @@ remove_existing_container() {
7769 fi
7870}
7971
80- # Function to start Rancher server container
8172start_rancher_server () {
8273 local container_name=$1
8374 local rancher_image=$2
@@ -111,7 +102,6 @@ start_rancher_server() {
111102 trap cleanup_logs EXIT
112103}
113104
114- # Function to wait for Rancher to be ready
115105wait_for_rancher () {
116106 local rancher_ip=$1
117107 local max_wait=${2:- 300} # Default 5 minutes
@@ -157,7 +147,6 @@ wait_for_rancher() {
157147 return 1
158148}
159149
160- # Function to run the integration test setup
161150run_setup () {
162151 local steve_dir=$1
163152 local bootstrap_password=$2
@@ -173,20 +162,17 @@ run_setup() {
173162 echo " Running integration test setup..."
174163 cd " ${steve_dir} /tests/integration/setup"
175164
176- # Build setup binary if it doesn't exist
177165 if [ ! -f " ./setup" ] || [ " ./setup" -ot " ./main.go" ]; then
178166 echo " Building setup binary..."
179167 go build -o setup .
180168 fi
181169
182- # Run setup with required environment variables
183170 export CATTLE_BOOTSTRAP_PASSWORD=" ${bootstrap_password} "
184171 export CATTLE_AGENT_IMAGE=" ${agent_image} "
185172 export CATTLE_TEST_CONFIG=" ${steve_dir} /tests/integration/steveapi/steveapi.yaml"
186173 ./setup
187174}
188175
189- # Function to run integration tests
190176run_integration_tests () {
191177 local steve_dir=$1
192178 local bootstrap_password=$2
@@ -208,9 +194,7 @@ run_integration_tests() {
208194 echo " Integration tests completed!"
209195}
210196
211- # Main function
212197main () {
213- # Parse command line arguments
214198 while [[ $# -gt 0 ]]; do
215199 case $1 in
216200 --rancher-image)
@@ -268,5 +252,4 @@ main() {
268252 run_integration_tests " ${STEVE_DIR} " " ${BOOTSTRAP_PASSWORD} " " ${RANCHER_AGENT_IMAGE} "
269253}
270254
271- # Call main function with all arguments
272255main " $@ "
0 commit comments