From c8c6cd8b7ec331c9b533adcf22de792fa6f6324c Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Mon, 6 Jun 2022 13:36:18 +0200 Subject: [PATCH 01/22] Update integration test --- tests/integration_tests/run_tests.sh | 319 ++++++++++----------------- 1 file changed, 115 insertions(+), 204 deletions(-) diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 7d93541..5c0f792 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -1,32 +1,27 @@ #!/bin/bash # Integration tests for Cyber Sandbox Creator. -# For a set of topologies defined in given configuration file, see if Creator correctly generates sandbox by -# building the virtual environment and then testing the virtual network. +# Set constants +TEST_PATH="$(readlink -e "$(dirname "${BASH_SOURCE[0]}")")" +CSC_PATH="$(readlink -e "${TEST_PATH}/../..")" +CREATOR_PATH="${CSC_PATH}/sandboxcreator/scripts/create.py" +MANAGER_PATH="${CSC_PATH}/sandboxcreator/scripts/manage.py" +TEMP_TOPOLOGY_PATH="$(readlink -f "${PWD}/tmp_topologies")" -# Generate sandbox from topology definition file with given optional arguments using Cyber Sandbox Creator. +# Generate an intermediate definition from a topology definition file with +# given optional arguments using Cyber Sandbox Creator. # param file: path to the topology definition yaml file # param arguments: optional arguments for Cyber Sandbox Creator create_sandbox() { local file=$1 IFS="$oIFS" - local arguments=($2) + local arguments=( "$2" ) IFS=$'\n' - local current_path=$(pwd) - cd $creator_path - local output=$(python3 create.py ${arguments[@]} $file) - if [ "$output" != "Sandbox was successfully created." ]; then - echo "Failed to build virtual machines: error while creating sandbox." - if [ "$output" != "" ]; then - echo "Full error is \"$output\"." - fi - cd $current_path - return 1 - fi - cd $current_path + echo '└── Generating intermediate definition...' + PYTHONPATH=$CSC_PATH python3 "$CREATOR_PATH" "-o=${TEMP_TOPOLOGY_PATH}/sandbox" "$file" > /dev/null || { echo 'Error while creating intermediate definition.'; exit 1; } } @@ -34,55 +29,51 @@ create_sandbox() # Output is redirected to corresponding file in output directory. build_machines() { - local current_path=$(pwd) - cd $creator_path/sandbox - - vagrant up --machine-readable > vagrant_output_build.txt 2>&1 + echo '└── Building the sandbox...' + PYTHONPATH=$CSC_PATH python3 "$MANAGER_PATH" 'build' '-v' "-d=${TEMP_TOPOLOGY_PATH}/sandbox" > vagrant_output_build.txt 2>&1 if [ "$?" -ne 0 ]; then # Parse the output file to find out which part of build failed and display appropriate output. machine=$(grep ",action,up,start" vagrant_output_build.txt | tail -n 1 | sed -r "s/^[0-9]*,(.*),action,up,start$/\1/") - if [[ ! -z "$machine" ]]; then + if [ -n "$machine" ]; then provisioning=$(grep "$machine: Running provisioner:" vagrant_output_build.txt) booting=$(grep "$machine: Booting VM..." vagrant_output_build.txt) importing_box=$(grep "$machine: Importing base box" vagrant_output_build.txt) downloading_box=$(grep "$machine: Downloading:" vagrant_output_build.txt) - - if [[ ! -z "$provisioning" ]]; then + + if [ -n "$provisioning" ]; then echo "Failed to build machine $machine: error while provisioning machine." - elif [[ ! -z "$booting" ]]; then + elif [ -n "$booting" ]; then echo "Failed to build machine $machine: error while booting machine." - elif [[ ! -z "$importing_box" ]]; then + elif [ -n "$importing_box" ]; then echo "Failed to build machine $machine: error while creating machine." - elif [[ ! -z "$downloading_box" ]]; then + elif [ -n "$downloading_box" ]; then echo "Failed to build machine $machine: error while downloading Vagrant box." else echo "Failed to build machine $machine." - fi - else + fi + else echo "Failed to build virtual machines: error while running vagrant up." fi if $print_output; then echo -e "Full Vagrant output is:\n" - - cat vagrant_output_build.txt | tee -a $outputdir/build_output_$filename_$i.txt + cat vagrant_output_build.txt | tee -a "$outputdir/build_output_${filename}_$i.txt" rm vagrant_output_build.txt else echo "Full Vagrant output can be found in file $outputdir/build_output_$filename-$i.txt" - cat vagrant_output_build.txt > $outputdir/build_output_$filename-$i.txt + cat vagrant_output_build.txt > "$outputdir/build_output_$filename-$i.txt" rm vagrant_output_build.txt fi - - cd $current_path + return 1 + fi - cat vagrant_output_build.txt >> $outputdir/build_output_$filename-$i.txt + cat vagrant_output_build.txt >> "${outputdir}/build_output_${filename}-${i}.txt" rm vagrant_output_build.txt - cd $current_path } @@ -90,37 +81,29 @@ build_machines() # can all reach www.muni.cz and each other, and check the routing. test_machines() { - local current_path=$(pwd) - cd $creator_path/sandbox + echo '└── Initializing tests...' + local current_path + current_path=$(pwd) + cd "${TEMP_TOPOLOGY_PATH}/sandbox" || { echo "Could not find the intermediate definition"; cleanup_and_exit 1; } # Get list of host machines. - hosts=($(PYTHONPATH=$path python3 -c "from yaml_topology import get_hosts; get_hosts('$creator_path/$file')")) + mapfile -t hosts < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_hosts; get_hosts('$TEST_PATH/$file')") # Get list of router machines. - routers=($(PYTHONPATH=$path python3 -c "from yaml_topology import get_routers; get_routers('$creator_path/$file')")) + mapfile -t routers < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_routers; get_routers('$TEST_PATH/$file')") # check network settings on host machines. for host in "${hosts[@]}" - do - vagrant ssh $host -c 'cmd /c ver' > /dev/null 2>&1 - if [ $? -ne 0 ]; then + do + + if ! vagrant ssh "$host" -c 'cmd /c ver' > /dev/null 2>&1; then # Check that machine has access to the internet. - vagrant ssh $host -c "ping -c 1 www.muni.cz" > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - echo "Test failed: $host can't reach www.muni.cz." - cd $current_path - return 1 - fi + vagrant ssh "$host" -c "ping -c 1 www.muni.cz" > /dev/null 2>&1 && echo " └── '$host' has Internet access." || { echo "Test failed: $host can't reach www.muni.cz."; cd "$current_path"; return 1; } # Check that machine can reach all other host machines. for target in "${hosts[@]}" do if [ "$host" != "$target" ]; then - vagrant ssh $host -c "ping -c 1 $target" > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - echo "Test failed: $host can't reach $target." - cd $current_path - return 1 - fi + vagrant ssh "$host" -c "ping -c 1 $target" > /dev/null 2>&1 && echo " └── '$host' can access '$target'." || { echo "Test failed: $host can't reach $target."; cd "$current_path"; return 1; } fi done @@ -128,64 +111,39 @@ test_machines() # Check that machine can reach all router machines. for target in "${routers[@]}" do - vagrant ssh $host -c "ping -c 1 $target" > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - echo "Test failed: $host can't reach $target." - cd $current_path - return 1 - fi + vagrant ssh "$host" -c "ping -c 1 $target" > /dev/null 2>&1 && echo " └── '$host' can access '$target'." || { echo "Test failed: $host can't reach $target."; cd "$current_path"; return 1; } done - # Check that route from host goes through the correct router. - network=$(PYTHONPATH=$path python3 -c "from yaml_topology import get_network_for_host; get_network_for_host('$creator_path/$file', '$host')") - router=$(PYTHONPATH=$path python3 -c "from yaml_topology import get_router_for_network; get_router_for_network('$creator_path/$file', '$network')") - - output=$(vagrant ssh $host -c "traceroute $router | head -n 2 | tail -n 1 | grep '$router'" 2> /dev/null | tr -d '\r') - if [ -z "$output" ]; then - echo "Test failed: $host does not route through $router." - cd $current_path - return 1 - fi - - # Check if network contains border router. - if [[ $arguments_string == *"border_router"* ]]; then - # Check that machine can reach border router. - vagrant ssh $host -c "ping -c 1 br" > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - echo "Test failed: $host can't reach border router." - cd $current_path - return 1 - fi + # Check that route from host goes through the correct router. + network=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_network_for_host; get_network_for_host('$TEST_PATH/$file', '$host')") + router=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_router_for_network; get_router_for_network('$TEST_PATH/$file', '$network')") - # Check that route from host goes through the border router. - output=$(vagrant ssh $host -c "traceroute www.muni.com | grep 'br'" 2> /dev/null | tr -d '\r') - if [ -z "$output" ]; then - echo "Test failed: $host does not route through border router." - cd $current_path - return 1 - fi + output=$(vagrant ssh "$host" -c "traceroute $router | head -n 2 | tail -n 1 | grep '$router'" 2> /dev/null | tr -d '\r') + if [ -n "$output" ]; then + echo "'$host routes through $router'" + else + echo "Test failed: $host does not route through $router." + cd "$current_path" + return 1 fi fi else # Check that machine has access to the internet. - output=$(vagrant powershell $host -c "ping -c 1 www.muni.cz" 2>&1 | tr -d '\r' | grep "output code 0") - if [ -z "$output" ]; then - echo "Test failed: $host can't reach www.muni.cz." - cd $current_path - return 1 - fi + output=$(vagrant powershell "$host" -c "ping -c 1 www.muni.cz" 2>&1 | tr -d '\r' | grep "output code 0") + if [ -n "$output" ]; then + echo " └── '$host' has Internet access." + else + echo "Test failed: $host can't reach www.muni.cz." + cd "$current_path" + return 1 + fi # Check that machine can reach all other host machines. for target in "${hosts[@]}" do if [ "$host" != "$target" ]; then - ip=$(PYTHONPATH=$path python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$creator_path/$file', '$target')") - vagrant ssh $host -c "ping -c 1 $ip" > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - echo "Test failed: $host can't reach $target." - cd $current_path - return 1 - fi + ip=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$TEST_PATH/$file', '$target')") + vagrant ssh "$host" -c "ping -c 1 $ip" > /dev/null 2>&1 && echo " └── '$host' can access '$target'." || { echo "Test failed: $host can't reach $target."; cd "$current_path"; return 1; } fi done @@ -193,12 +151,14 @@ test_machines() # Check that machine can reach all router machines. for target in "${routers[@]}" do - ip=$(PYTHONPATH=$path python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$creator_path/$file', '$target')") - output=$(vagrant powershell $host -c "ping -c 1 www.muni.cz" 2>&1 | tr -d '\r' | grep "output code 0") - if [ -z "$output" ]; then - echo "Test failed: $host can't reach $target." - cd $current_path - return 1 + ip=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$TEST_PATH/$file', '$target')") + output=$(vagrant powershell "$host" -c "ping -c 1 www.muni.cz" 2>&1 | tr -d '\r' | grep "output code 0") + if [ -n "$output" ]; then + echo " └── '$host' can access '$target'." + else + echo "Test failed: $host can't reach $target." + cd "$current_path" + return 1 fi done fi @@ -207,61 +167,31 @@ test_machines() # Check network settings on router machines. for router in "${routers[@]}" - do + do # Check that machine can reach all other router machines. for target in "${routers[@]}" do if [ "$router" != "$target" ]; then - vagrant ssh $router -c "ping -c 1 $target" > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - echo "Test failed: $router can't reach $target." - cd $current_path - return 1 - fi + vagrant ssh "$router" -c "ping -c 1 $target" > /dev/null 2>&1 && echo " └── '$router' can access '$target'." || { echo "Test failed: $router can't reach $target."; cd "$current_path"; return 1; } fi done # Check that machine can reach all host machines. for target in "${hosts[@]}" do - vagrant ssh $router -c "ping -c 1 $target" > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - echo "Test failed: $router can't reach $target." - cd $current_path - return 1 - fi + vagrant ssh "$router" -c "ping -c 1 $target" > /dev/null 2>&1 && echo " └── '$router' can access '$target'." || { echo "Test failed: $router can't reach $target."; cd "$current_path"; return 1; } done - - # Check if network contains border router. - if [[ $arguments_string == *"border_router"* ]]; then - # Check that machine can reach border router. - vagrant ssh $router -c "ping -c 1 br" > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - echo "Test failed: $router can't reach border router." - cd $current_path - return 1 - fi - - # Check that route from host goes through the border router. - output=$(vagrant ssh $router -c "traceroute www.muni.com | grep 'br'" 2> /dev/null | tr -d '\r') - if [ -z "$output" ]; then - echo "Test failed: $router does not route through border router." - cd $current_path - return 1 - fi - fi done - cd $current_path + cd "$current_path" || return 1 } # Destroy existing virtual environment using Vagrant. # Output is redirected to corresponding file in output directory. destroy_machines() { - local current_path=$(pwd) - cd $creator_path/sandbox - vagrant destroy -f > vagrant_output_destroy.txt 2>&1 + echo '└── Destroying sandbox...' + PYTHONPATH=$CSC_PATH python3 "$MANAGER_PATH" 'destroy' '-v' "-d=$TEMP_TOPOLOGY_PATH/sandbox" > vagrant_output_destroy.txt 2>&1 if [ "$?" -eq 1 ]; then echo "Failed to destroy machines." @@ -272,17 +202,15 @@ destroy_machines() rm vagrant_output_destroy.txt else echo "Vagrant output can be found in file $outputdir/destroy_output_$filename-$i.txt" - - cat vagrant_output_destroy.txt >> $outputdir/destroy_output_$filename-$i.txt + + cat vagrant_output_destroy.txt >> "${outputdir}/destroy_output_${filename}-${i}.txt" rm vagrant_output_destroy.txt fi - cd $current_path return 1 fi - + rm vagrant_output_destroy.txt - cd $current_path } # Open topology definition file and change all host OS images to given value creating a new definition file. @@ -298,22 +226,26 @@ change_boxes() local box_name=$(PYTHONPATH=$path python3 -c "from yaml_topology import get_box_name; get_box_name('$path/box_names_mapping.yml', '$box')") local box_memory=$(PYTHONPATH=$path python3 -c "from yaml_topology import get_box_memory; get_box_memory('$path/box_memory_mapping.yml', '$box')") - newfile="$creator_path/tmp_topologies/${filename}_$box_name.yml" - + newfile="${TEMP_TOPOLOGY_PATH}/${filename}_${box_name}.yml" + PYTHONPATH=$path python3 -c "from yaml_topology import change_boxes; change_boxes('$file', '$newfile', '$box', '$box_memory')" echo "$newfile" } -# Get absolute path to the script. -path="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" -creator_path=$(dirname $path) +cleanup_and_exit() +{ + local exitcode=$1 + [ -d "$TEMP_TOPOLOGY_PATH" ] && rm -r "$TEMP_TOPOLOGY_PATH" + exit "$exitcode" +} + -config_file="" -print_output=false # Read command-line arguments given while starting the script and save values to variables. -while [ "$1" != "" ]; do +config_file='' +print_output=false +while [ "$1" != '' ]; do case $1 in -c | --config ) shift config_file="$1" @@ -321,7 +253,7 @@ while [ "$1" != "" ]; do -p | --print_output ) print_output=true ;; -h | --help ) echo "Usage: ./run_tests.sh [-c|--config CONFIG_FILE] [-p|--print_output]" - echo " CONFIG_FILE: configuration file [default: $path/config.yml]" + echo " CONFIG_FILE: configuration file [default: ${TEST_PATH}/config.yml]" ;; * ) echo "Failed to parse arguments: unknown argument $1" exit 1 @@ -333,13 +265,13 @@ done # Check if path to configuration file was set by a command-line argument. If not use the default value. # If the path passes as command-line argument was relative, append it to the path to current directory to get absolute path. if [ -z "$config_file" ]; then - config_file="$path/config.yml" + config_file="${TEST_PATH}/config.yml" elif [[ ! "$config_file" = /* && ! "$config_file" = ~* ]]; then config_file=$(pwd)/$config_file -fi +fi # Check if given configuration file exists. -if [ ! -e $config_file ]; then +if [ ! -e "$config_file" ]; then echo "Failed to process configuration file: file $config_file not found." exit 1 fi @@ -354,26 +286,26 @@ oIFS="$IFS" IFS=$'\n' # Get a list of paths to topology definition files from configuration file. -files=($(PYTHONPATH=$path python3 -c "from yaml_config import get_topology_files; get_topology_files('$config_file')")) +files=( "$(PYTHONPATH=$path python3 -c "from yaml_config import get_topology_files; get_topology_files('$config_file')")" ) if [ "${#files[@]}" -eq 0 ]; then echo "Failed to process configuration file: no topologies were found." fi # Get path to output directory from configuration file. -outputdir=$(PYTHONPATH=$path python3 -c "from yaml_config import get_output_dir; get_output_dir('$config_file')") +outputdir="$(PYTHONPATH=$path python3 -c "from yaml_config import get_output_dir; get_output_dir('$config_file')")" if [[ ! "$outputdir" = /* && ! "$outputdir" = ~* ]]; then outputdir=$(pwd)/$outputdir -fi +fi # Create output directory or delete all contents if it already exists. if [ -d "$outputdir" ]; then - rm -rf "$outputdir/"* + rm -rf "${outputdir:?}/"* else mkdir -p "$outputdir" fi # Create directory for temporary topology files. -mkdir -p "./tmp_topologies" +mkdir -p "$TEMP_TOPOLOGY_PATH" # Flag indicating if any of the tested topologies failed to build correctly. failed=false @@ -381,17 +313,17 @@ failed=false for file in ${files[@]} do # Get list of optional arguments for creating sandbox from configuration file. - arguments_strings=($(PYTHONPATH=$path python3 -c "from yaml_config import get_topology_arguments; get_topology_arguments('$config_file', '$file')")) + mapfile -t arguments_strings < <(PYTHONPATH=$path python3 -c "import yaml_config; yaml_config.get_topology_arguments('$config_file', '${file}')") if [ "${#arguments_strings[@]}" -eq 0 ]; then arguments_strings=(" ") fi # Get list of OS images to be tried in current topology's host machines. - boxes=($(PYTHONPATH=$path python3 -c "from yaml_config import get_topology_boxes; get_topology_boxes('$config_file', '$file')")) + mapfile -t boxes < <(PYTHONPATH=$path python3 -c "from yaml_config import get_topology_boxes; get_topology_boxes('$config_file', '$file')") boxes=("${boxes[@]}") - for box in ${boxes[@]} - do + for box in "${boxes[@]}" + do if [ "$box" = "no-box" ]; then newfile=$file else @@ -401,61 +333,40 @@ do filename=$(basename "$newfile" .yml) i=1 - for arguments_string in ${arguments_strings[@]} + for arguments_string in "${arguments_strings[@]}" do - echo "Starting test for topology $filename and execution arguments [$arguments_string]." + echo "Testing topology $filename with arguments [$arguments_string]." # Try to generate sandbox. - if create_sandbox $newfile $arguments_string; then - echo "Sandbox was succesfully created." - else - echo "Stopping tests." - exit 1 - # If generating sandbox failed, exit with error. - fi + create_sandbox "$newfile" "$arguments_string" && echo '└── Intermediate definition was successfully generated.' || { echo 'Stopping tests.'; cleanup_and_exit 1; } # Try to build and test machines from sandbox. # If either fails the output from failed part is also written to terminal. - if build_machines; then - echo "All machines have been built and provisioned." + if build_machines; then + echo '└── All machines have been built and provisioned.' - if test_machines; then - echo "All tests have been succesfull." - else - echo "Stopping tests." - failed=true - fi + test_machines && echo '└── All tests have been successful.' || { echo 'Stopping tests.'; failed=true; } else - echo "Stopping tests." - failed=true - fi + echo 'Stopping tests.' + failed=true + fi # Try to destroy virtual environment. # Should not fail unless something unexpected happens, in that case it might be necessary to destroy remaining machines manually. - if destroy_machines; then - echo "All machines have been destroyed." - else - echo "Stopping tests." - failed=true - fi + destroy_machines && echo "└── All machines of the sandbox have been destroyed." || { echo 'Stopping tests.'; failed=true; } # If building or testing the virtual environment failed, exit with error. if $failed; then - exit 1 + cleanup_and_exit 1 fi - i=$(( $i+1 )) + i=$(( i+1 )) + printf '\n' done # Remove temporary topology file if it exists. - if [ "$newfile" != "$file" ]; then - rm "$newfile" - fi + [ "$newfile" != "$file" ] && rm "$newfile" done - done -# Remove directory for temporary topology files. -if [ -d "./tmp_topologies" ]; then - rm -r "./tmp_topologies" -fi +cleanup_and_exit 0 -- GitLab From 4be3019540a3b18f925a00836d25809a520150a5 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Mon, 6 Jun 2022 13:36:32 +0200 Subject: [PATCH 02/22] Update integration test --- tests/integration_tests/config.yml | 38 +++++++++++++----------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/tests/integration_tests/config.yml b/tests/integration_tests/config.yml index c433827..80965bb 100644 --- a/tests/integration_tests/config.yml +++ b/tests/integration_tests/config.yml @@ -1,33 +1,29 @@ topologies: - - file: ./topologies/0-routers-1-network-1-host.yml + - file: ../../topologies/0-routers-1-network-1-host.yml arguments: - no-arguments - - ansible_local - - file: ./topologies/1-router-1-network-1-host.yml + - ansible-installed + - file: ../../topologies/1-router-1-network-1-host.yml arguments: - no-arguments - - ansible_local - - border_router - - [ansible_local, border_router] - - file: ./topologies/1-router-2-networks-2-hosts.yml + - ansible-installed + - file: ../../topologies/1-router-2-networks-2-hosts.yml arguments: - no-arguments - - ansible_local - - border_router - - [ansible_local, border_router] - - file: ./topologies/2-routers-2-networks-2-hosts.yml + - ansible-installed + - file: ../../topologies/2-routers-2-networks-2-hosts.yml arguments: - - border_router - - [ansible_local, border_router] - - file: ./topologies/2-routers-4-networks-4-hosts.yml + - no-arguments + - ansible-installed + - file: ../../topologies/2-routers-4-networks-4-hosts.yml arguments: - - border_router - - [ansible_local, border_router] - - file: ./topologies/3-routers-5-networks-5-hosts.yml + - no-arguments + - ansible-installed + - file: ../../topologies/3-routers-5-networks-5-hosts.yml arguments: - - border_router - - [ansible_local, border_router] - - file: ./topologies/0-routers-1-network-4-hosts.yml + - no-arguments + - ansible-installed + - file: ../../topologies/0-routers-1-network-4-hosts.yml arguments: - no-arguments - - ansible_local + - ansible-installed -- GitLab From dc2e69f993b652dc9433aa906d03c181700d1a48 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Mon, 6 Jun 2022 15:18:23 +0200 Subject: [PATCH 03/22] Send error messages to stderr --- sandboxcreator/scripts/create.py | 2 +- sandboxcreator/scripts/manage.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sandboxcreator/scripts/create.py b/sandboxcreator/scripts/create.py index af98a0b..331f72f 100644 --- a/sandboxcreator/scripts/create.py +++ b/sandboxcreator/scripts/create.py @@ -50,7 +50,7 @@ def _run_create(parsed_cli_args: argparse.ArgumentParser) -> None: parsed_cli_args.rewrite_provisioning, parsed_cli_args.verbose_ansible, os.getcwd()) except Exception as e: - print(f"Could not create intermediate sandbox definition:\n{e}") + print(f"Could not create intermediate sandbox definition:\n{e}", file=sys.stderr) sys.exit(1) print("Intermediate sandbox definition was successfully created") diff --git a/sandboxcreator/scripts/manage.py b/sandboxcreator/scripts/manage.py index 34b01b9..bee0985 100644 --- a/sandboxcreator/scripts/manage.py +++ b/sandboxcreator/scripts/manage.py @@ -86,19 +86,19 @@ def _print_final_message(command_name: str, print("Sandbox was successfully reloaded") else: if command_name == "build": - print(f"\nSandbox building process has failed:\n{exception}") + print(f"\nSandbox building process has failed:\n{exception}", file=sys.stderr) elif command_name == "destroy": - print(f"\nSandbox destroying process has failed:\n{exception}") + print(f"\nSandbox destroying process has failed:\n{exception}", file=sys.stderr) elif command_name == "access": - print(f"\nCould not access the virtual machine:\n{exception}") + print(f"\nCould not access the virtual machine:\n{exception}", file=sys.stderr) elif command_name == "suspend": - print(f"\nCould not suspend the sandbox:\n{exception}") + print(f"\nCould not suspend the sandbox:\n{exception}", file=sys.stderr) elif command_name == "resume": - print(f"\nCould not resume the sandbox:\n{exception}") + print(f"\nCould not resume the sandbox:\n{exception}", file=sys.stderr) elif command_name == "shutdown": - print(f"\nCould not shut down the sandbox:\n{exception}") + print(f"\nCould not shut down the sandbox:\n{exception}", file=sys.stderr) elif command_name == "reload": - print(f"\nCould not reload the sandbox:\n{exception}") + print(f"\nCould not reload the sandbox:\n{exception}", file=sys.stderr) def _translate_str_output(output_str: str) -> OutputLocation: -- GitLab From 5407897f3612cbdfe18f75774d95434c2daf0f10 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Tue, 7 Jun 2022 09:46:08 +0200 Subject: [PATCH 04/22] Update CI template topology definitions --- tests/integration_tests/ci/config_debian.yml | 22 +++++-------- tests/integration_tests/ci/config_kali.yml | 29 ++++++++++++++++ .../integration_tests/ci/config_kali_2020.yml | 33 ------------------- .../ci/config_windows_server.yml | 22 +++++++------ 4 files changed, 50 insertions(+), 56 deletions(-) create mode 100644 tests/integration_tests/ci/config_kali.yml delete mode 100644 tests/integration_tests/ci/config_kali_2020.yml diff --git a/tests/integration_tests/ci/config_debian.yml b/tests/integration_tests/ci/config_debian.yml index 32c472a..1084e12 100644 --- a/tests/integration_tests/ci/config_debian.yml +++ b/tests/integration_tests/ci/config_debian.yml @@ -1,21 +1,17 @@ topologies: - - file: ./topologies/0-routers-1-network-1-host.yml + - file: ../../topologies/0-routers-1-network-1-host.yml arguments: - no-arguments - - ansible_local - - file: ./topologies/1-router-1-network-1-host.yml + - ansible_installed + - file: ../../topologies/1-router-1-network-1-host.yml arguments: - no-arguments - - ansible_local - - border_router - - [ansible_local, border_router] - - file: ./topologies/1-router-2-networks-2-hosts.yml + - ansible_installed + - file: ../../topologies/1-router-2-networks-2-hosts.yml arguments: - no-arguments - - ansible_local - - border_router - - [ansible_local, border_router] - - file: ./topologies/2-routers-2-networks-2-hosts.yml + - ansible_installed + - file: ../../topologies/2-routers-2-networks-2-hosts.yml arguments: - - border_router - - [ansible_local, border_router] \ No newline at end of file + - no-arguments + - ansible_installed \ No newline at end of file diff --git a/tests/integration_tests/ci/config_kali.yml b/tests/integration_tests/ci/config_kali.yml new file mode 100644 index 0000000..ddac516 --- /dev/null +++ b/tests/integration_tests/ci/config_kali.yml @@ -0,0 +1,29 @@ +topologies: + - file: ../../topologies/0-routers-1-network-1-host.yml + arguments: + - no-arguments + - ansible_installed + boxes: + - munikypo/kali + original_boxes: false + - file: ../../topologies/1-router-1-network-1-host.yml + arguments: + - no-arguments + - ansible_installed + boxes: + - munikypo/kali + original_boxes: false + - file: ../../topologies/1-router-2-networks-2-hosts.yml + arguments: + - no-arguments + - ansible_installed + boxes: + - munikypo/kali + original_boxes: false + - file: ../../topologies/2-routers-2-networks-2-hosts.yml + arguments: + - no-arguments + - ansible_installed + boxes: + - munikypo/kali + original_boxes: false \ No newline at end of file diff --git a/tests/integration_tests/ci/config_kali_2020.yml b/tests/integration_tests/ci/config_kali_2020.yml deleted file mode 100644 index 90aff42..0000000 --- a/tests/integration_tests/ci/config_kali_2020.yml +++ /dev/null @@ -1,33 +0,0 @@ -topologies: - - file: ./topologies/0-routers-1-network-1-host.yml - arguments: - - no-arguments - - ansible_local - boxes: - - munikypo/kali-2020.4 - original_boxes: false - - file: ./topologies/1-router-1-network-1-host.yml - arguments: - - no-arguments - - ansible_local - - border_router - - [ansible_local, border_router] - boxes: - - munikypo/kali-2020.4 - original_boxes: false - - file: ./topologies/1-router-2-networks-2-hosts.yml - arguments: - - no-arguments - - ansible_local - - border_router - - [ansible_local, border_router] - boxes: - - munikypo/kali-2020.4 - original_boxes: false - - file: ./topologies/2-routers-2-networks-2-hosts.yml - arguments: - - border_router - - [ansible_local, border_router] - boxes: - - munikypo/kali-2020.4 - original_boxes: false \ No newline at end of file diff --git a/tests/integration_tests/ci/config_windows_server.yml b/tests/integration_tests/ci/config_windows_server.yml index 4bfdad9..80ca11f 100644 --- a/tests/integration_tests/ci/config_windows_server.yml +++ b/tests/integration_tests/ci/config_windows_server.yml @@ -1,27 +1,29 @@ topologies: - - file: ./topologies/0-routers-1-network-1-host.yml + - file: ../../topologies/0-routers-1-network-1-host.yml arguments: - - ansible_local + - no-arguments + - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false - - file: ./topologies/1-router-1-network-1-host.yml + - file: ../../topologies/1-router-1-network-1-host.yml arguments: - - ansible_local - - [ansible_local, border_router] + - no-arguments + - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false - - file: ./topologies/1-router-2-networks-2-hosts.yml + - file: ../../topologies/1-router-2-networks-2-hosts.yml arguments: - - ansible_local - - [ansible_local, border_router] + - no-arguments + - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false - - file: ./topologies/2-routers-2-networks-2-hosts.yml + - file: ../../topologies/2-routers-2-networks-2-hosts.yml arguments: - - [ansible_local, border_router] + - no-arguments + - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false \ No newline at end of file -- GitLab From 9cf5c3c18643d1463bf05c7e4843118cbe8906d7 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Tue, 7 Jun 2022 10:34:53 +0200 Subject: [PATCH 05/22] Add test definition for all topologies and supported boxes --- .../config_complete_test.yml | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/integration_tests/config_complete_test.yml diff --git a/tests/integration_tests/config_complete_test.yml b/tests/integration_tests/config_complete_test.yml new file mode 100644 index 0000000..cd4bb86 --- /dev/null +++ b/tests/integration_tests/config_complete_test.yml @@ -0,0 +1,92 @@ +topologies: + - file: ../../topologies/0-routers-1-network-1-host.yml + arguments: + - no-arguments + - ansible-installed + boxes: + - munikypo/debian-10 + - munikypo/kali + - munikypo/centos-7.9 + - munikypo/centos-8.4 + - munikypo/ubuntu-18.04 + - munikypo/windows-server-2019 + - munikypo/windows-10 + original_boxes: false + - file: ../../topologies/1-router-1-network-1-host.yml + arguments: + - no-arguments + - ansible-installed + boxes: + - munikypo/debian-10 + - munikypo/kali + - munikypo/centos-7.9 + - munikypo/centos-8.4 + - munikypo/ubuntu-18.04 + - munikypo/windows-server-2019 + - munikypo/windows-10 + original_boxes: false + - file: ../../topologies/1-router-2-networks-2-hosts.yml + arguments: + - no-arguments + - ansible-installed + boxes: + - munikypo/debian-10 + - munikypo/kali + - munikypo/centos-7.9 + - munikypo/centos-8.4 + - munikypo/ubuntu-18.04 + - munikypo/windows-server-2019 + - munikypo/windows-10 + original_boxes: false + - file: ../../topologies/2-routers-2-networks-2-hosts.yml + arguments: + - no-arguments + - ansible-installed + boxes: + - munikypo/debian-10 + - munikypo/kali + - munikypo/centos-7.9 + - munikypo/centos-8.4 + - munikypo/ubuntu-18.04 + - munikypo/windows-server-2019 + - munikypo/windows-10 + original_boxes: false + - file: ../../topologies/2-routers-4-networks-4-hosts.yml + arguments: + - no-arguments + - ansible-installed + boxes: + - munikypo/debian-10 + - munikypo/kali + - munikypo/centos-7.9 + - munikypo/centos-8.4 + - munikypo/ubuntu-18.04 + - munikypo/windows-server-2019 + - munikypo/windows-10 + original_boxes: false + - file: ../../topologies/3-routers-5-networks-5-hosts.yml + arguments: + - no-arguments + - ansible-installed + boxes: + - munikypo/debian-10 + - munikypo/kali + - munikypo/centos-7.9 + - munikypo/centos-8.4 + - munikypo/ubuntu-18.04 + - munikypo/windows-server-2019 + - munikypo/windows-10 + original_boxes: false + - file: ../../topologies/0-routers-1-network-4-hosts.yml + arguments: + - no-arguments + - ansible-installed + boxes: + - munikypo/debian-10 + - munikypo/kali + - munikypo/centos-7.9 + - munikypo/centos-8.4 + - munikypo/ubuntu-18.04 + - munikypo/windows-server-2019 + - munikypo/windows-10 + original_boxes: false \ No newline at end of file -- GitLab From ef3c988a5ba6f701978c5df724cddbc81b032e46 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Tue, 7 Jun 2022 13:04:36 +0200 Subject: [PATCH 06/22] Fix tests for different base boxes --- tests/integration_tests/run_tests.sh | 10 +-- tests/integration_tests/yaml_topology.py | 109 +++++++++++++---------- 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 5c0f792..16561bf 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -21,7 +21,7 @@ create_sandbox() IFS=$'\n' echo '└── Generating intermediate definition...' - PYTHONPATH=$CSC_PATH python3 "$CREATOR_PATH" "-o=${TEMP_TOPOLOGY_PATH}/sandbox" "$file" > /dev/null || { echo 'Error while creating intermediate definition.'; exit 1; } + PYTHONPATH=$CSC_PATH python3 "$CREATOR_PATH" "-o=${TEMP_TOPOLOGY_PATH}/sandbox" "$file" 1> /dev/null || { echo 'Error while creating intermediate definition.'; exit 1; } } @@ -223,12 +223,12 @@ change_boxes() local box=$2 local filename=$(basename "$file" .yml) - local box_name=$(PYTHONPATH=$path python3 -c "from yaml_topology import get_box_name; get_box_name('$path/box_names_mapping.yml', '$box')") - local box_memory=$(PYTHONPATH=$path python3 -c "from yaml_topology import get_box_memory; get_box_memory('$path/box_memory_mapping.yml', '$box')") + local box_name=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_box_name; get_box_name('$TEST_PATH/box_names_mapping.yml', '$box')") + local box_memory=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_box_memory; get_box_memory('$TEST_PATH/box_memory_mapping.yml', '$box')") newfile="${TEMP_TOPOLOGY_PATH}/${filename}_${box_name}.yml" - PYTHONPATH=$path python3 -c "from yaml_topology import change_boxes; change_boxes('$file', '$newfile', '$box', '$box_memory')" + PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import change_boxes; change_boxes('$file', '$newfile', '$box', '$box_memory')" echo "$newfile" } @@ -327,7 +327,7 @@ do if [ "$box" = "no-box" ]; then newfile=$file else - newfile=$(change_boxes "$creator_path/$file" "$box") + newfile=$(change_boxes "$TEST_PATH/$file" "$box") fi filename=$(basename "$newfile" .yml) diff --git a/tests/integration_tests/yaml_topology.py b/tests/integration_tests/yaml_topology.py index 9e317d3..1e0fa13 100644 --- a/tests/integration_tests/yaml_topology.py +++ b/tests/integration_tests/yaml_topology.py @@ -1,17 +1,18 @@ -"""Contains auxiliary functions for integration testing that allow reading information from topology definition file.""" +"""Contains functions for reading information from topology definition files.""" -import yaml import sys +import yaml + def get_hosts(topology_file): """Read and print name values for all hosts.""" stdout = open(sys.__stdout__.fileno(), - mode=sys.__stdout__.mode, - buffering=1, - encoding=sys.__stdout__.encoding, - errors=sys.__stdout__.errors, - newline='\n', - closefd=False) + mode=sys.__stdout__.mode, + buffering=1, + encoding=sys.__stdout__.encoding, + errors=sys.__stdout__.errors, + newline='\n', + closefd=False) with open(topology_file) as f: doc = yaml.safe_load(f) @@ -20,15 +21,16 @@ def get_hosts(topology_file): for value in doc['hosts']: print(value['name'], file=stdout) + def get_network_for_host(topology_file, host): """Read and print network value for host's net_mapping.""" stdout = open(sys.__stdout__.fileno(), - mode=sys.__stdout__.mode, - buffering=1, - encoding=sys.__stdout__.encoding, - errors=sys.__stdout__.errors, - newline='\n', - closefd=False) + mode=sys.__stdout__.mode, + buffering=1, + encoding=sys.__stdout__.encoding, + errors=sys.__stdout__.errors, + newline='\n', + closefd=False) with open(topology_file) as f: doc = yaml.safe_load(f) @@ -37,15 +39,16 @@ def get_network_for_host(topology_file, host): if mapping['host'] == host: print(mapping['network'], file=stdout) + def get_ip_for_host(topology_file, host): """Read and print ip value for host's net_mapping.""" stdout = open(sys.__stdout__.fileno(), - mode=sys.__stdout__.mode, - buffering=1, - encoding=sys.__stdout__.encoding, - errors=sys.__stdout__.errors, - newline='\n', - closefd=False) + mode=sys.__stdout__.mode, + buffering=1, + encoding=sys.__stdout__.encoding, + errors=sys.__stdout__.errors, + newline='\n', + closefd=False) with open(topology_file) as f: doc = yaml.safe_load(f) @@ -54,15 +57,16 @@ def get_ip_for_host(topology_file, host): if mapping['host'] == host: print(mapping['ip'], file=stdout) + def get_router_for_network(topology_file, network): """Read and print router value for network's router_mapping.""" stdout = open(sys.__stdout__.fileno(), - mode=sys.__stdout__.mode, - buffering=1, - encoding=sys.__stdout__.encoding, - errors=sys.__stdout__.errors, - newline='\n', - closefd=False) + mode=sys.__stdout__.mode, + buffering=1, + encoding=sys.__stdout__.encoding, + errors=sys.__stdout__.errors, + newline='\n', + closefd=False) with open(topology_file) as f: doc = yaml.safe_load(f) @@ -71,15 +75,16 @@ def get_router_for_network(topology_file, network): if mapping['network'] == network: print(mapping['router'], file=stdout) + def get_routers(topology_file): """Read and print name values for all routers.""" stdout = open(sys.__stdout__.fileno(), - mode=sys.__stdout__.mode, - buffering=1, - encoding=sys.__stdout__.encoding, - errors=sys.__stdout__.errors, - newline='\n', - closefd=False) + mode=sys.__stdout__.mode, + buffering=1, + encoding=sys.__stdout__.encoding, + errors=sys.__stdout__.errors, + newline='\n', + closefd=False) with open(topology_file) as f: doc = yaml.safe_load(f) @@ -88,15 +93,16 @@ def get_routers(topology_file): for value in doc['routers']: print(value['name'], file=stdout) + def get_box_name(mapping_file, box): """Check if given vagrant box name exists in mapping and print it or print a default value.""" stdout = open(sys.__stdout__.fileno(), - mode=sys.__stdout__.mode, - buffering=1, - encoding=sys.__stdout__.encoding, - errors=sys.__stdout__.errors, - newline='\n', - closefd=False) + mode=sys.__stdout__.mode, + buffering=1, + encoding=sys.__stdout__.encoding, + errors=sys.__stdout__.errors, + newline='\n', + closefd=False) with open(mapping_file) as f: mapping = yaml.safe_load(f) @@ -106,14 +112,15 @@ def get_box_name(mapping_file, box): else: print("tmp", file=stdout) + def get_box_memory(mapping_file, box): stdout = open(sys.__stdout__.fileno(), - mode=sys.__stdout__.mode, - buffering=1, - encoding=sys.__stdout__.encoding, - errors=sys.__stdout__.errors, - newline='\n', - closefd=False) + mode=sys.__stdout__.mode, + buffering=1, + encoding=sys.__stdout__.encoding, + errors=sys.__stdout__.errors, + newline='\n', + closefd=False) with open(mapping_file) as f: mapping = yaml.safe_load(f) @@ -121,14 +128,18 @@ def get_box_memory(mapping_file, box): if box in mapping: print(mapping[box], file=stdout) -def change_boxes(topology_file, new_file, value, memory): - """Create a copy of given topology file with all host's base_box image values changed to given value and save it as a new file.""" + +def change_boxes(topology_file, new_file, box_name, memory): + """Create a copy of a topology file with updated base_box image names.""" with open(topology_file) as f: doc = yaml.safe_load(f) for host in doc['hosts']: - host['base_box']['image'] = value - host['memory'] = memory + host['base_box']['image'] = box_name + if 'windows' in box_name: + host['base_box']['mgmt_protocol'] = 'winrm' + if memory: + host['extra']['memory'] = int(memory) with open(new_file, 'w+') as f: - yaml.dump(doc, f) + yaml.dump(doc, f, sort_keys=False) -- GitLab From 8ec6cdfecd0f82f8f5941d8284df82ba8f7430dc Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Tue, 7 Jun 2022 13:05:03 +0200 Subject: [PATCH 07/22] Update ci configuration file --- .../.gitlab-ci.yml => .gitlab-ci.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) rename tests/integration_tests/.gitlab-ci.yml => .gitlab-ci.yml (72%) diff --git a/tests/integration_tests/.gitlab-ci.yml b/.gitlab-ci.yml similarity index 72% rename from tests/integration_tests/.gitlab-ci.yml rename to .gitlab-ci.yml index 6c6ac7f..f7304f4 100644 --- a/tests/integration_tests/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,20 +6,20 @@ before_script: - apt-get install -y linux-headers-$(uname -r) - lsmod | grep "vbox" || /usr/lib/virtualbox/vboxdrv.sh setup - pip3 install -r requirements.txt - - chmod +x testing/run_tests.sh + - chmod +x tests/integration_tests/run_tests.sh # Separating integration tests into several stages to ensure only one job creating virtual environment will run at one time. # Running several jobs at once will make them fail while testing virtual network. -# Integration tests need to be separated into several jobs to fit under timeout treshold. +# Integration tests need to be separated into several jobs to fit under timeout threshold. stages: - debian - - kali-2020 + - kali - windows-server debian: stage: debian script: - - testing/run_tests.sh -c testing/ci/config_debian.yml -p + - tests/integration_tests/run_tests.sh -c testing/ci/config_debian.yml -p # run even when other stages fail when: always # only run for merge requests @@ -27,17 +27,17 @@ debian: - merge_requests kali-2020: - stage: kali-2020 - # overwritting global before_script to create a virtual display before running test requiring a display + stage: kali + # overwriting global before_script to create a virtual display before running test requiring a display before_script: - apt-get install -y linux-headers-$(uname -r) - lsmod | grep "vbox" || /usr/lib/virtualbox/vboxdrv.sh setup - pip3 install -r requirements.txt - - chmod +x testing/run_tests.sh + - chmod +x tests/integration_tests/run_tests.sh - Xvfb :1 -screen 0 800x600x16 & script: - - DISPLAY=:1 testing/run_tests.sh -c testing/ci/config_kali_2020.yml -p + - DISPLAY=:1 tests/integration_tests/run_tests.sh -c testing/ci/config_kali.yml -p # run even when other stages fail when: always # only run for and merge requests @@ -47,7 +47,7 @@ kali-2020: windows-server: stage: windows-server script: - - testing/run_tests.sh -c testing/ci/config_windows_server.yml -p + - tests/integration_tests/run_tests.sh -c testing/ci/config_windows_server.yml -p # run even when other stages fail when: always # only run for merge requests -- GitLab From 3d44bf0d5c503ae05c87e91ad0f5adeab5eadc33 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Tue, 7 Jun 2022 15:54:19 +0200 Subject: [PATCH 08/22] Fix message format --- tests/integration_tests/run_tests.sh | 2 +- ...ld_output_0-routers-1-network-1-host-1.txt | 106 ++++ ...ld_output_0-routers-1-network-1-host-2.txt | 106 ++++ ...ild_output_1-router-1-network-1-host-1.txt | 301 ++++++++++++ ...ild_output_1-router-1-network-1-host-2.txt | 301 ++++++++++++ ...d_output_1-router-2-networks-2-hosts-1.txt | 463 ++++++++++++++++++ ...d_output_1-router-2-networks-2-hosts-2.txt | 463 ++++++++++++++++++ 7 files changed, 1741 insertions(+), 1 deletion(-) create mode 100644 tests/integration_tests/test_output/build_output_0-routers-1-network-1-host-1.txt create mode 100644 tests/integration_tests/test_output/build_output_0-routers-1-network-1-host-2.txt create mode 100644 tests/integration_tests/test_output/build_output_1-router-1-network-1-host-1.txt create mode 100644 tests/integration_tests/test_output/build_output_1-router-1-network-1-host-2.txt create mode 100644 tests/integration_tests/test_output/build_output_1-router-2-networks-2-hosts-1.txt create mode 100644 tests/integration_tests/test_output/build_output_1-router-2-networks-2-hosts-2.txt diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 16561bf..d684ab6 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -120,7 +120,7 @@ test_machines() output=$(vagrant ssh "$host" -c "traceroute $router | head -n 2 | tail -n 1 | grep '$router'" 2> /dev/null | tr -d '\r') if [ -n "$output" ]; then - echo "'$host routes through $router'" + echo " └── '$host routes through $router'" else echo "Test failed: $host does not route through $router." cd "$current_path" diff --git a/tests/integration_tests/test_output/build_output_0-routers-1-network-1-host-1.txt b/tests/integration_tests/test_output/build_output_0-routers-1-network-1-host-1.txt new file mode 100644 index 0000000..62f52ae --- /dev/null +++ b/tests/integration_tests/test_output/build_output_0-routers-1-network-1-host-1.txt @@ -0,0 +1,106 @@ +Bringing machine 'home' up with 'virtualbox' provider... +==> home: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 40% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> home: Matching MAC address for NAT networking... +==> home: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> home: Setting the name of the VM: sandbox_home_1654606103991_70811 +==> home: Fixed port collision for 22 => 2222. Now on port 2201. +==> home: Clearing any previously set network interfaces... +==> home: Preparing network interfaces based on configuration... + home: Adapter 1: nat + home: Adapter 2: intnet +==> home: Forwarding ports... + home: 22 (guest) => 2201 (host) (adapter 1) +==> home: Running 'pre-boot' VM customizations... +==> home: Booting VM... +==> home: Waiting for machine to boot. This may take a few minutes... + home: SSH address: 127.0.0.1:2201 + home: SSH username: vagrant + home: SSH auth method: private key + home: + home: Vagrant insecure key detected. Vagrant will automatically replace + home: this with a newly generated keypair for better security. + home: + home: Inserting generated public key within guest... + home: Removing insecure key from the guest if it's present... + home: Key inserted! Disconnecting and reconnecting using new SSH key... +==> home: Machine booted and ready! +==> home: Checking for guest additions in VM... +==> home: Setting hostname... +==> home: Configuring and enabling network interfaces... +==> home: Installing rsync to the VM... +==> home: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> home: - Exclude: [".vagrant/", ".git/"] +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** +skipping: no hosts matched + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [home] + +TASK [Install net-tools] ******************************************************* +ok: [home] + +TASK [Add aliases of all devices] ********************************************** +changed: [home] => (item={'key': '10.10.30.5', 'value': 'home'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [home] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +home : ok=10 changed=6 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 + +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [home] +[DEPRECATION WARNING]: Distribution debian 10.10 on host home should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +home : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +Building the sandbox... + +Sandbox was successfully built diff --git a/tests/integration_tests/test_output/build_output_0-routers-1-network-1-host-2.txt b/tests/integration_tests/test_output/build_output_0-routers-1-network-1-host-2.txt new file mode 100644 index 0000000..29319b1 --- /dev/null +++ b/tests/integration_tests/test_output/build_output_0-routers-1-network-1-host-2.txt @@ -0,0 +1,106 @@ +Bringing machine 'home' up with 'virtualbox' provider... +==> home: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> home: Matching MAC address for NAT networking... +==> home: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> home: Setting the name of the VM: sandbox_home_1654606280835_23203 +==> home: Fixed port collision for 22 => 2222. Now on port 2201. +==> home: Clearing any previously set network interfaces... +==> home: Preparing network interfaces based on configuration... + home: Adapter 1: nat + home: Adapter 2: intnet +==> home: Forwarding ports... + home: 22 (guest) => 2201 (host) (adapter 1) +==> home: Running 'pre-boot' VM customizations... +==> home: Booting VM... +==> home: Waiting for machine to boot. This may take a few minutes... + home: SSH address: 127.0.0.1:2201 + home: SSH username: vagrant + home: SSH auth method: private key + home: + home: Vagrant insecure key detected. Vagrant will automatically replace + home: this with a newly generated keypair for better security. + home: + home: Inserting generated public key within guest... + home: Removing insecure key from the guest if it's present... + home: Key inserted! Disconnecting and reconnecting using new SSH key... +==> home: Machine booted and ready! +==> home: Checking for guest additions in VM... +==> home: Setting hostname... +==> home: Configuring and enabling network interfaces... +==> home: Installing rsync to the VM... +==> home: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> home: - Exclude: [".vagrant/", ".git/"] +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** +skipping: no hosts matched + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [home] + +TASK [Install net-tools] ******************************************************* +ok: [home] + +TASK [Add aliases of all devices] ********************************************** +changed: [home] => (item={'key': '10.10.30.5', 'value': 'home'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [home] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +home : ok=10 changed=6 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 + +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [home] +[DEPRECATION WARNING]: Distribution debian 10.10 on host home should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +home : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +Building the sandbox... + +Sandbox was successfully built diff --git a/tests/integration_tests/test_output/build_output_1-router-1-network-1-host-1.txt b/tests/integration_tests/test_output/build_output_1-router-1-network-1-host-1.txt new file mode 100644 index 0000000..a119563 --- /dev/null +++ b/tests/integration_tests/test_output/build_output_1-router-1-network-1-host-1.txt @@ -0,0 +1,301 @@ +Bringing machine 'router' up with 'virtualbox' provider... +Bringing machine 'home' up with 'virtualbox' provider... +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 40% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> router: Matching MAC address for NAT networking... +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> router: Setting the name of the VM: sandbox_router_1654606467163_84789 +==> router: Fixed port collision for 22 => 2222. Now on port 2201. +==> router: Clearing any previously set network interfaces... +==> router: Preparing network interfaces based on configuration... + router: Adapter 1: nat + router: Adapter 2: intnet + router: Adapter 3: intnet +==> router: Forwarding ports... + router: 22 (guest) => 2201 (host) (adapter 1) +==> router: Running 'pre-boot' VM customizations... +==> router: Booting VM... +==> router: Waiting for machine to boot. This may take a few minutes... + router: SSH address: 127.0.0.1:2201 + router: SSH username: vagrant + router: SSH auth method: private key + router: + router: Vagrant insecure key detected. Vagrant will automatically replace + router: this with a newly generated keypair for better security. + router: + router: Inserting generated public key within guest... + router: Removing insecure key from the guest if it's present... + router: Key inserted! Disconnecting and reconnecting using new SSH key... +==> router: Machine booted and ready! +==> router: Checking for guest additions in VM... +==> router: Setting hostname... +==> router: Configuring and enabling network interfaces... +==> router: Installing rsync to the VM... +==> router: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> router: - Exclude: [".vagrant/", ".git/"] +==> router: Running provisioner: ansible_local... + router: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [router] + +TASK [Enable IP forwarding] **************************************************** +changed: [router] + +TASK [Set up postrouting] ****************************************************** +changed: [router] + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [router] + +TASK [Install net-tools] ******************************************************* +ok: [router] + +TASK [Add aliases of all devices] ********************************************** +changed: [router] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [router] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [router] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [router] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [router] + +TASK [interface : set_fact] **************************************************** +ok: [router] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [router] + +TASK [interface : sanity check] ************************************************ +skipping: [router] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [router] + +TASK [interface : set_fact] **************************************************** +ok: [router] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [router] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [router] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +router : ok=19 changed=12 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0 + +==> router: Running provisioner: ansible_local... + router: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [router] +[DEPRECATION WARNING]: Distribution debian 10.10 on host router should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +router : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +==> home: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> home: Matching MAC address for NAT networking... +==> home: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> home: Setting the name of the VM: sandbox_home_1654606669292_94340 +==> home: Fixed port collision for 22 => 2222. Now on port 2202. +==> home: Clearing any previously set network interfaces... +==> home: Preparing network interfaces based on configuration... + home: Adapter 1: nat + home: Adapter 2: intnet +==> home: Forwarding ports... + home: 22 (guest) => 2202 (host) (adapter 1) +==> home: Running 'pre-boot' VM customizations... +==> home: Booting VM... +==> home: Waiting for machine to boot. This may take a few minutes... + home: SSH address: 127.0.0.1:2202 + home: SSH username: vagrant + home: SSH auth method: private key + home: + home: Vagrant insecure key detected. Vagrant will automatically replace + home: this with a newly generated keypair for better security. + home: + home: Inserting generated public key within guest... + home: Removing insecure key from the guest if it's present... + home: Key inserted! Disconnecting and reconnecting using new SSH key... +==> home: Machine booted and ready! +==> home: Checking for guest additions in VM... +==> home: Setting hostname... +==> home: Configuring and enabling network interfaces... +==> home: Installing rsync to the VM... +==> home: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> home: - Exclude: [".vagrant/", ".git/"] +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** +skipping: no hosts matched + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [home] + +TASK [Install net-tools] ******************************************************* +ok: [home] + +TASK [Add aliases of all devices] ********************************************** +changed: [home] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [home] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [home] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [home] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +home : ok=22 changed=14 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 + +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [home] +[DEPRECATION WARNING]: Distribution debian 10.10 on host home should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +home : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +Building the sandbox... + +Sandbox was successfully built diff --git a/tests/integration_tests/test_output/build_output_1-router-1-network-1-host-2.txt b/tests/integration_tests/test_output/build_output_1-router-1-network-1-host-2.txt new file mode 100644 index 0000000..23bf0a5 --- /dev/null +++ b/tests/integration_tests/test_output/build_output_1-router-1-network-1-host-2.txt @@ -0,0 +1,301 @@ +Bringing machine 'router' up with 'virtualbox' provider... +Bringing machine 'home' up with 'virtualbox' provider... +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 40% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> router: Matching MAC address for NAT networking... +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> router: Setting the name of the VM: sandbox_router_1654606851833_20370 +==> router: Fixed port collision for 22 => 2222. Now on port 2201. +==> router: Clearing any previously set network interfaces... +==> router: Preparing network interfaces based on configuration... + router: Adapter 1: nat + router: Adapter 2: intnet + router: Adapter 3: intnet +==> router: Forwarding ports... + router: 22 (guest) => 2201 (host) (adapter 1) +==> router: Running 'pre-boot' VM customizations... +==> router: Booting VM... +==> router: Waiting for machine to boot. This may take a few minutes... + router: SSH address: 127.0.0.1:2201 + router: SSH username: vagrant + router: SSH auth method: private key + router: + router: Vagrant insecure key detected. Vagrant will automatically replace + router: this with a newly generated keypair for better security. + router: + router: Inserting generated public key within guest... + router: Removing insecure key from the guest if it's present... + router: Key inserted! Disconnecting and reconnecting using new SSH key... +==> router: Machine booted and ready! +==> router: Checking for guest additions in VM... +==> router: Setting hostname... +==> router: Configuring and enabling network interfaces... +==> router: Installing rsync to the VM... +==> router: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> router: - Exclude: [".vagrant/", ".git/"] +==> router: Running provisioner: ansible_local... + router: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [router] + +TASK [Enable IP forwarding] **************************************************** +changed: [router] + +TASK [Set up postrouting] ****************************************************** +changed: [router] + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [router] + +TASK [Install net-tools] ******************************************************* +ok: [router] + +TASK [Add aliases of all devices] ********************************************** +changed: [router] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [router] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [router] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [router] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [router] + +TASK [interface : set_fact] **************************************************** +ok: [router] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [router] + +TASK [interface : sanity check] ************************************************ +skipping: [router] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [router] + +TASK [interface : set_fact] **************************************************** +ok: [router] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [router] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [router] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +router : ok=19 changed=12 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0 + +==> router: Running provisioner: ansible_local... + router: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [router] +[DEPRECATION WARNING]: Distribution debian 10.10 on host router should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +router : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +==> home: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> home: Matching MAC address for NAT networking... +==> home: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> home: Setting the name of the VM: sandbox_home_1654607029330_8717 +==> home: Fixed port collision for 22 => 2222. Now on port 2202. +==> home: Clearing any previously set network interfaces... +==> home: Preparing network interfaces based on configuration... + home: Adapter 1: nat + home: Adapter 2: intnet +==> home: Forwarding ports... + home: 22 (guest) => 2202 (host) (adapter 1) +==> home: Running 'pre-boot' VM customizations... +==> home: Booting VM... +==> home: Waiting for machine to boot. This may take a few minutes... + home: SSH address: 127.0.0.1:2202 + home: SSH username: vagrant + home: SSH auth method: private key + home: + home: Vagrant insecure key detected. Vagrant will automatically replace + home: this with a newly generated keypair for better security. + home: + home: Inserting generated public key within guest... + home: Removing insecure key from the guest if it's present... + home: Key inserted! Disconnecting and reconnecting using new SSH key... +==> home: Machine booted and ready! +==> home: Checking for guest additions in VM... +==> home: Setting hostname... +==> home: Configuring and enabling network interfaces... +==> home: Installing rsync to the VM... +==> home: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> home: - Exclude: [".vagrant/", ".git/"] +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** +skipping: no hosts matched + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [home] + +TASK [Install net-tools] ******************************************************* +ok: [home] + +TASK [Add aliases of all devices] ********************************************** +changed: [home] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [home] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [home] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [home] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +home : ok=22 changed=14 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 + +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [home] +[DEPRECATION WARNING]: Distribution debian 10.10 on host home should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +home : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +Building the sandbox... + +Sandbox was successfully built diff --git a/tests/integration_tests/test_output/build_output_1-router-2-networks-2-hosts-1.txt b/tests/integration_tests/test_output/build_output_1-router-2-networks-2-hosts-1.txt new file mode 100644 index 0000000..7d9928a --- /dev/null +++ b/tests/integration_tests/test_output/build_output_1-router-2-networks-2-hosts-1.txt @@ -0,0 +1,463 @@ +Bringing machine 'router' up with 'virtualbox' provider... +Bringing machine 'server' up with 'virtualbox' provider... +Bringing machine 'home' up with 'virtualbox' provider... +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> router: Matching MAC address for NAT networking... +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> router: Setting the name of the VM: sandbox_router_1654607227274_62738 +==> router: Fixed port collision for 22 => 2222. Now on port 2201. +==> router: Clearing any previously set network interfaces... +==> router: Preparing network interfaces based on configuration... + router: Adapter 1: nat + router: Adapter 2: intnet + router: Adapter 3: intnet + router: Adapter 4: intnet +==> router: Forwarding ports... + router: 22 (guest) => 2201 (host) (adapter 1) +==> router: Running 'pre-boot' VM customizations... +==> router: Booting VM... +==> router: Waiting for machine to boot. This may take a few minutes... + router: SSH address: 127.0.0.1:2201 + router: SSH username: vagrant + router: SSH auth method: private key + router: + router: Vagrant insecure key detected. Vagrant will automatically replace + router: this with a newly generated keypair for better security. + router: + router: Inserting generated public key within guest... + router: Removing insecure key from the guest if it's present... + router: Key inserted! Disconnecting and reconnecting using new SSH key... +==> router: Machine booted and ready! +==> router: Checking for guest additions in VM... +==> router: Setting hostname... +==> router: Configuring and enabling network interfaces... +==> router: Installing rsync to the VM... +==> router: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> router: - Exclude: [".vagrant/", ".git/"] +==> router: Running provisioner: ansible_local... + router: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [router] + +TASK [Enable IP forwarding] **************************************************** +changed: [router] + +TASK [Set up postrouting] ****************************************************** +changed: [router] + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [router] + +TASK [Install net-tools] ******************************************************* +ok: [router] + +TASK [Add aliases of all devices] ********************************************** +changed: [router] => (item={'key': '10.10.20.1', 'value': 'router'}) +changed: [router] => (item={'key': '10.10.20.5', 'value': 'server'}) +changed: [router] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [router] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [router] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [router] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [router] + +TASK [interface : set_fact] **************************************************** +ok: [router] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [router] + +TASK [interface : sanity check] ************************************************ +skipping: [router] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [router] + +TASK [interface : set_fact] **************************************************** +ok: [router] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [router] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [router] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +router : ok=19 changed=12 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0 + +==> router: Running provisioner: ansible_local... + router: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [router] +[DEPRECATION WARNING]: Distribution debian 10.10 on host router should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +router : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +==> server: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> server: Matching MAC address for NAT networking... +==> server: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> server: Setting the name of the VM: sandbox_server_1654607410315_36710 +==> server: Fixed port collision for 22 => 2222. Now on port 2202. +==> server: Clearing any previously set network interfaces... +==> server: Preparing network interfaces based on configuration... + server: Adapter 1: nat + server: Adapter 2: intnet +==> server: Forwarding ports... + server: 22 (guest) => 2202 (host) (adapter 1) +==> server: Running 'pre-boot' VM customizations... +==> server: Booting VM... +==> server: Waiting for machine to boot. This may take a few minutes... + server: SSH address: 127.0.0.1:2202 + server: SSH username: vagrant + server: SSH auth method: private key + server: + server: Vagrant insecure key detected. Vagrant will automatically replace + server: this with a newly generated keypair for better security. + server: + server: Inserting generated public key within guest... + server: Removing insecure key from the guest if it's present... + server: Key inserted! Disconnecting and reconnecting using new SSH key... +==> server: Machine booted and ready! +==> server: Checking for guest additions in VM... +==> server: Setting hostname... +==> server: Configuring and enabling network interfaces... +==> server: Installing rsync to the VM... +==> server: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> server: - Exclude: [".vagrant/", ".git/"] +==> server: Running provisioner: ansible_local... + server: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** +skipping: no hosts matched + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [server] + +TASK [Install net-tools] ******************************************************* +ok: [server] + +TASK [Add aliases of all devices] ********************************************** +changed: [server] => (item={'key': '10.10.20.1', 'value': 'router'}) +changed: [server] => (item={'key': '10.10.20.5', 'value': 'server'}) +changed: [server] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [server] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [server] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [server] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [server] + +TASK [interface : set_fact] **************************************************** +ok: [server] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [server] + +TASK [interface : sanity check] ************************************************ +skipping: [server] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [server] + +TASK [interface : set_fact] **************************************************** +ok: [server] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [server] + +TASK [interface : sanity check] ************************************************ +skipping: [server] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [server] + +TASK [interface : set_fact] **************************************************** +ok: [server] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [server] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [server] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +server : ok=22 changed=14 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 + +==> server: Running provisioner: ansible_local... + server: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [server] +[DEPRECATION WARNING]: Distribution debian 10.10 on host server should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +server : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +==> home: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 40% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> home: Matching MAC address for NAT networking... +==> home: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> home: Setting the name of the VM: sandbox_home_1654607578213_75306 +==> home: Fixed port collision for 22 => 2222. Now on port 2203. +==> home: Clearing any previously set network interfaces... +==> home: Preparing network interfaces based on configuration... + home: Adapter 1: nat + home: Adapter 2: intnet +==> home: Forwarding ports... + home: 22 (guest) => 2203 (host) (adapter 1) +==> home: Running 'pre-boot' VM customizations... +==> home: Booting VM... +==> home: Waiting for machine to boot. This may take a few minutes... + home: SSH address: 127.0.0.1:2203 + home: SSH username: vagrant + home: SSH auth method: private key + home: + home: Vagrant insecure key detected. Vagrant will automatically replace + home: this with a newly generated keypair for better security. + home: + home: Inserting generated public key within guest... + home: Removing insecure key from the guest if it's present... + home: Key inserted! Disconnecting and reconnecting using new SSH key... +==> home: Machine booted and ready! +==> home: Checking for guest additions in VM... +==> home: Setting hostname... +==> home: Configuring and enabling network interfaces... +==> home: Installing rsync to the VM... +==> home: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> home: - Exclude: [".vagrant/", ".git/"] +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** +skipping: no hosts matched + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [home] + +TASK [Install net-tools] ******************************************************* +ok: [home] + +TASK [Add aliases of all devices] ********************************************** +changed: [home] => (item={'key': '10.10.20.1', 'value': 'router'}) +changed: [home] => (item={'key': '10.10.20.5', 'value': 'server'}) +changed: [home] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [home] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [home] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [home] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +home : ok=22 changed=14 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 + +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [home] +[DEPRECATION WARNING]: Distribution debian 10.10 on host home should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +home : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +Building the sandbox... + +Sandbox was successfully built diff --git a/tests/integration_tests/test_output/build_output_1-router-2-networks-2-hosts-2.txt b/tests/integration_tests/test_output/build_output_1-router-2-networks-2-hosts-2.txt new file mode 100644 index 0000000..e49a1c6 --- /dev/null +++ b/tests/integration_tests/test_output/build_output_1-router-2-networks-2-hosts-2.txt @@ -0,0 +1,463 @@ +Bringing machine 'router' up with 'virtualbox' provider... +Bringing machine 'server' up with 'virtualbox' provider... +Bringing machine 'home' up with 'virtualbox' provider... +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> router: Matching MAC address for NAT networking... +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: You assigned a static IP ending in ".1" to this machine. +==> router: This is very often used by the router and can cause the +==> router: network to not work properly. If the network doesn't work +==> router: properly, try changing this IP. +==> router: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> router: Setting the name of the VM: sandbox_router_1654607797909_96398 +==> router: Fixed port collision for 22 => 2222. Now on port 2201. +==> router: Clearing any previously set network interfaces... +==> router: Preparing network interfaces based on configuration... + router: Adapter 1: nat + router: Adapter 2: intnet + router: Adapter 3: intnet + router: Adapter 4: intnet +==> router: Forwarding ports... + router: 22 (guest) => 2201 (host) (adapter 1) +==> router: Running 'pre-boot' VM customizations... +==> router: Booting VM... +==> router: Waiting for machine to boot. This may take a few minutes... + router: SSH address: 127.0.0.1:2201 + router: SSH username: vagrant + router: SSH auth method: private key + router: + router: Vagrant insecure key detected. Vagrant will automatically replace + router: this with a newly generated keypair for better security. + router: + router: Inserting generated public key within guest... + router: Removing insecure key from the guest if it's present... + router: Key inserted! Disconnecting and reconnecting using new SSH key... +==> router: Machine booted and ready! +==> router: Checking for guest additions in VM... +==> router: Setting hostname... +==> router: Configuring and enabling network interfaces... +==> router: Installing rsync to the VM... +==> router: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> router: - Exclude: [".vagrant/", ".git/"] +==> router: Running provisioner: ansible_local... + router: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [router] + +TASK [Enable IP forwarding] **************************************************** +changed: [router] + +TASK [Set up postrouting] ****************************************************** +changed: [router] + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [router] + +TASK [Install net-tools] ******************************************************* +ok: [router] + +TASK [Add aliases of all devices] ********************************************** +changed: [router] => (item={'key': '10.10.20.1', 'value': 'router'}) +changed: [router] => (item={'key': '10.10.20.5', 'value': 'server'}) +changed: [router] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [router] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [router] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [router] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [router] + +TASK [interface : set_fact] **************************************************** +ok: [router] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [router] + +TASK [interface : sanity check] ************************************************ +skipping: [router] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [router] + +TASK [interface : set_fact] **************************************************** +ok: [router] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [router] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [router] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [router] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +router : ok=19 changed=12 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0 + +==> router: Running provisioner: ansible_local... + router: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [router] +[DEPRECATION WARNING]: Distribution debian 10.10 on host router should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +router : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +==> server: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 40% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> server: Matching MAC address for NAT networking... +==> server: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> server: Setting the name of the VM: sandbox_server_1654607966109_62091 +==> server: Fixed port collision for 22 => 2222. Now on port 2202. +==> server: Clearing any previously set network interfaces... +==> server: Preparing network interfaces based on configuration... + server: Adapter 1: nat + server: Adapter 2: intnet +==> server: Forwarding ports... + server: 22 (guest) => 2202 (host) (adapter 1) +==> server: Running 'pre-boot' VM customizations... +==> server: Booting VM... +==> server: Waiting for machine to boot. This may take a few minutes... + server: SSH address: 127.0.0.1:2202 + server: SSH username: vagrant + server: SSH auth method: private key + server: + server: Vagrant insecure key detected. Vagrant will automatically replace + server: this with a newly generated keypair for better security. + server: + server: Inserting generated public key within guest... + server: Removing insecure key from the guest if it's present... + server: Key inserted! Disconnecting and reconnecting using new SSH key... +==> server: Machine booted and ready! +==> server: Checking for guest additions in VM... +==> server: Setting hostname... +==> server: Configuring and enabling network interfaces... +==> server: Installing rsync to the VM... +==> server: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> server: - Exclude: [".vagrant/", ".git/"] +==> server: Running provisioner: ansible_local... + server: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** +skipping: no hosts matched + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [server] + +TASK [Install net-tools] ******************************************************* +ok: [server] + +TASK [Add aliases of all devices] ********************************************** +changed: [server] => (item={'key': '10.10.20.1', 'value': 'router'}) +changed: [server] => (item={'key': '10.10.20.5', 'value': 'server'}) +changed: [server] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [server] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [server] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [server] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [server] + +TASK [interface : set_fact] **************************************************** +ok: [server] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [server] + +TASK [interface : sanity check] ************************************************ +skipping: [server] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [server] + +TASK [interface : set_fact] **************************************************** +ok: [server] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [server] + +TASK [interface : sanity check] ************************************************ +skipping: [server] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [server] + +TASK [interface : set_fact] **************************************************** +ok: [server] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [server] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [server] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [server] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +server : ok=22 changed=14 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 + +==> server: Running provisioner: ansible_local... + server: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [server] +[DEPRECATION WARNING]: Distribution debian 10.10 on host server should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +server : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +==> home: Importing base box 'munikypo/debian-10'... + Progress: 10% Progress: 20% Progress: 30% Progress: 50% Progress: 60% Progress: 70% Progress: 80% Progress: 90% ==> home: Matching MAC address for NAT networking... +==> home: Checking if box 'munikypo/debian-10' version '0.4.0' is up to date... +==> home: Setting the name of the VM: sandbox_home_1654608151553_57252 +==> home: Fixed port collision for 22 => 2222. Now on port 2203. +==> home: Clearing any previously set network interfaces... +==> home: Preparing network interfaces based on configuration... + home: Adapter 1: nat + home: Adapter 2: intnet +==> home: Forwarding ports... + home: 22 (guest) => 2203 (host) (adapter 1) +==> home: Running 'pre-boot' VM customizations... +==> home: Booting VM... +==> home: Waiting for machine to boot. This may take a few minutes... + home: SSH address: 127.0.0.1:2203 + home: SSH username: vagrant + home: SSH auth method: private key + home: + home: Vagrant insecure key detected. Vagrant will automatically replace + home: this with a newly generated keypair for better security. + home: + home: Inserting generated public key within guest... + home: Removing insecure key from the guest if it's present... + home: Key inserted! Disconnecting and reconnecting using new SSH key... +==> home: Machine booted and ready! +==> home: Checking for guest additions in VM... +==> home: Setting hostname... +==> home: Configuring and enabling network interfaces... +==> home: Installing rsync to the VM... +==> home: Rsyncing folder: /home/ati/Documents/CS4E/cyber-sandbox-creator/tests/integration_tests/tmp_topologies/sandbox/ => /vagrant +==> home: - Exclude: [".vagrant/", ".git/"] +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [Router configuration] **************************************************** +skipping: no hosts matched + +PLAY [Linux configuration] ***************************************************** + +TASK [Gathering Facts] ********************************************************* +ok: [home] + +TASK [Install net-tools] ******************************************************* +ok: [home] + +TASK [Add aliases of all devices] ********************************************** +changed: [home] => (item={'key': '10.10.20.1', 'value': 'router'}) +changed: [home] => (item={'key': '10.10.20.5', 'value': 'server'}) +changed: [home] => (item={'key': '10.10.30.1', 'value': 'router'}) +changed: [home] => (item={'key': '10.10.30.5', 'value': 'home'}) +changed: [home] => (item={'key': '100.100.100.1', 'value': 'router'}) + +TASK [Configure routes] ******************************************************** + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +TASK [interface : sanity check] ************************************************ +skipping: [home] + +TASK [interface : find all interfaces configuration files] ********************* +ok: [home] + +TASK [interface : set_fact] **************************************************** +ok: [home] + +TASK [interface : remove old iface settings for retrieved interface name] ****** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove the rest of old settings for retrieved interface name] *** +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : remove multiple consecutive new line characters] ************* +changed: [home] => (item=/etc/network/interfaces) + +TASK [interface : configure interface] ***************************************** +changed: [home] + +RUNNING HANDLER [interface : interface_networking_restart] ********************* +changed: [home] + +PLAY [Windows configuration] *************************************************** +skipping: no hosts matched +[WARNING]: Could not match supplied host pattern, ignoring: controller + +PLAY [Controller configuration] ************************************************ +skipping: no hosts matched + +PLAY RECAP ********************************************************************* +home : ok=22 changed=14 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0 + +==> home: Running provisioner: ansible_local... + home: Running ansible-playbook... + +PLAY [all] ********************************************************************* + +TASK [Gathering Facts] ********************************************************* +ok: [home] +[DEPRECATION WARNING]: Distribution debian 10.10 on host home should use +/usr/bin/python3, but is using /usr/bin/python for backward compatibility with +prior Ansible releases. A future Ansible release will default to using the +discovered platform python for this host. See https://docs.ansible.com/ansible/ +2.11/reference_appendices/interpreter_discovery.html for more information. This + feature will be removed in version 2.12. Deprecation warnings can be disabled +by setting deprecation_warnings=False in ansible.cfg. + +PLAY RECAP ********************************************************************* +home : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 + +Building the sandbox... + +Sandbox was successfully built -- GitLab From 1975396ebc72e8f00fc4559f6f8216641f594dc3 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Wed, 29 Jun 2022 15:51:01 +0200 Subject: [PATCH 09/22] Remove unsupported boxes --- .../config_complete_test.yml | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/tests/integration_tests/config_complete_test.yml b/tests/integration_tests/config_complete_test.yml index cd4bb86..3fdedee 100644 --- a/tests/integration_tests/config_complete_test.yml +++ b/tests/integration_tests/config_complete_test.yml @@ -6,9 +6,6 @@ topologies: boxes: - munikypo/debian-10 - munikypo/kali - - munikypo/centos-7.9 - - munikypo/centos-8.4 - - munikypo/ubuntu-18.04 - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false @@ -19,9 +16,6 @@ topologies: boxes: - munikypo/debian-10 - munikypo/kali - - munikypo/centos-7.9 - - munikypo/centos-8.4 - - munikypo/ubuntu-18.04 - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false @@ -32,9 +26,6 @@ topologies: boxes: - munikypo/debian-10 - munikypo/kali - - munikypo/centos-7.9 - - munikypo/centos-8.4 - - munikypo/ubuntu-18.04 - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false @@ -45,9 +36,6 @@ topologies: boxes: - munikypo/debian-10 - munikypo/kali - - munikypo/centos-7.9 - - munikypo/centos-8.4 - - munikypo/ubuntu-18.04 - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false @@ -58,9 +46,6 @@ topologies: boxes: - munikypo/debian-10 - munikypo/kali - - munikypo/centos-7.9 - - munikypo/centos-8.4 - - munikypo/ubuntu-18.04 - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false @@ -71,9 +56,6 @@ topologies: boxes: - munikypo/debian-10 - munikypo/kali - - munikypo/centos-7.9 - - munikypo/centos-8.4 - - munikypo/ubuntu-18.04 - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false @@ -84,9 +66,6 @@ topologies: boxes: - munikypo/debian-10 - munikypo/kali - - munikypo/centos-7.9 - - munikypo/centos-8.4 - - munikypo/ubuntu-18.04 - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false \ No newline at end of file -- GitLab From 123e9be4777bc7a20805602ee6e275df02fb5500 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Wed, 29 Jun 2022 16:16:39 +0200 Subject: [PATCH 10/22] Update package list before tests --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7304f4..436ad7c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,7 @@ image: registry.gitlab.ics.muni.cz:443/muni-kypo-csc/cyber-sandbox-creator/csc-d # Make sure that VirtualBox kernel modules are loaded and install Python dependencies. before_script: + - apt-get update - apt-get install -y linux-headers-$(uname -r) - lsmod | grep "vbox" || /usr/lib/virtualbox/vboxdrv.sh setup - pip3 install -r requirements.txt @@ -30,6 +31,7 @@ kali-2020: stage: kali # overwriting global before_script to create a virtual display before running test requiring a display before_script: + - apt-get update - apt-get install -y linux-headers-$(uname -r) - lsmod | grep "vbox" || /usr/lib/virtualbox/vboxdrv.sh setup - pip3 install -r requirements.txt -- GitLab From 62b87c01c492f15bd3dd39f6dd17d9b8d3cd4eb1 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 13:42:06 +0200 Subject: [PATCH 11/22] Fix test config paths --- .gitlab-ci.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 436ad7c..2f7e86d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,8 +3,6 @@ image: registry.gitlab.ics.muni.cz:443/muni-kypo-csc/cyber-sandbox-creator/csc-d # Make sure that VirtualBox kernel modules are loaded and install Python dependencies. before_script: - - apt-get update - - apt-get install -y linux-headers-$(uname -r) - lsmod | grep "vbox" || /usr/lib/virtualbox/vboxdrv.sh setup - pip3 install -r requirements.txt - chmod +x tests/integration_tests/run_tests.sh @@ -20,7 +18,7 @@ stages: debian: stage: debian script: - - tests/integration_tests/run_tests.sh -c testing/ci/config_debian.yml -p + - tests/integration_tests/run_tests.sh -c tests/integration_tests/ci/config_debian.yml -p # run even when other stages fail when: always # only run for merge requests @@ -31,15 +29,13 @@ kali-2020: stage: kali # overwriting global before_script to create a virtual display before running test requiring a display before_script: - - apt-get update - - apt-get install -y linux-headers-$(uname -r) - lsmod | grep "vbox" || /usr/lib/virtualbox/vboxdrv.sh setup - pip3 install -r requirements.txt - chmod +x tests/integration_tests/run_tests.sh - Xvfb :1 -screen 0 800x600x16 & script: - - DISPLAY=:1 tests/integration_tests/run_tests.sh -c testing/ci/config_kali.yml -p + - DISPLAY=:1 tests/integration_tests/run_tests.sh -c tests/integration_tests/ci/config_kali.yml -p # run even when other stages fail when: always # only run for and merge requests @@ -49,7 +45,7 @@ kali-2020: windows-server: stage: windows-server script: - - tests/integration_tests/run_tests.sh -c testing/ci/config_windows_server.yml -p + - tests/integration_tests/run_tests.sh -c tests/integration_tests/ci/config_windows_server.yml -p # run even when other stages fail when: always # only run for merge requests -- GitLab From fd8ae3854e3ae1250dda20f0cd2dde9e257fca99 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 16:23:52 +0200 Subject: [PATCH 12/22] Update package registry --- .gitlab-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2f7e86d..bac334f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,8 @@ image: registry.gitlab.ics.muni.cz:443/muni-kypo-csc/cyber-sandbox-creator/csc-d # Make sure that VirtualBox kernel modules are loaded and install Python dependencies. before_script: + - apt-get update -y --allow-releaseinfo-change + - apt-get install -y linux-headers-$(uname -r) - lsmod | grep "vbox" || /usr/lib/virtualbox/vboxdrv.sh setup - pip3 install -r requirements.txt - chmod +x tests/integration_tests/run_tests.sh @@ -29,6 +31,8 @@ kali-2020: stage: kali # overwriting global before_script to create a virtual display before running test requiring a display before_script: + - apt-get update -y --allow-releaseinfo-change + - apt-get install -y linux-headers-$(uname -r) - lsmod | grep "vbox" || /usr/lib/virtualbox/vboxdrv.sh setup - pip3 install -r requirements.txt - chmod +x tests/integration_tests/run_tests.sh -- GitLab From b3b94b262c7e4eb4ce99ea7f5ee69ef8f2e747c9 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 16:41:09 +0200 Subject: [PATCH 13/22] Fix python script paths --- tests/integration_tests/run_tests.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index d684ab6..97c2fec 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -286,13 +286,13 @@ oIFS="$IFS" IFS=$'\n' # Get a list of paths to topology definition files from configuration file. -files=( "$(PYTHONPATH=$path python3 -c "from yaml_config import get_topology_files; get_topology_files('$config_file')")" ) +files=( "$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_config import get_topology_files; get_topology_files('$config_file')")" ) if [ "${#files[@]}" -eq 0 ]; then echo "Failed to process configuration file: no topologies were found." fi # Get path to output directory from configuration file. -outputdir="$(PYTHONPATH=$path python3 -c "from yaml_config import get_output_dir; get_output_dir('$config_file')")" +outputdir="$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_config import get_output_dir; get_output_dir('$config_file')")" if [[ ! "$outputdir" = /* && ! "$outputdir" = ~* ]]; then outputdir=$(pwd)/$outputdir fi @@ -313,13 +313,13 @@ failed=false for file in ${files[@]} do # Get list of optional arguments for creating sandbox from configuration file. - mapfile -t arguments_strings < <(PYTHONPATH=$path python3 -c "import yaml_config; yaml_config.get_topology_arguments('$config_file', '${file}')") + mapfile -t arguments_strings < <(PYTHONPATH=$TEST_PATH python3 -c "import yaml_config; yaml_config.get_topology_arguments('$config_file', '${file}')") if [ "${#arguments_strings[@]}" -eq 0 ]; then arguments_strings=(" ") fi # Get list of OS images to be tried in current topology's host machines. - mapfile -t boxes < <(PYTHONPATH=$path python3 -c "from yaml_config import get_topology_boxes; get_topology_boxes('$config_file', '$file')") + mapfile -t boxes < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_config import get_topology_boxes; get_topology_boxes('$config_file', '$file')") boxes=("${boxes[@]}") for box in "${boxes[@]}" -- GitLab From 25b34bf50c2d2c85a7726f88553a9abaf6f405f3 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 17:02:01 +0200 Subject: [PATCH 14/22] Fix topology definition paths --- tests/integration_tests/run_tests.sh | 4 ++-- tests/integration_tests/yaml_config.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 97c2fec..a766c33 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -286,13 +286,13 @@ oIFS="$IFS" IFS=$'\n' # Get a list of paths to topology definition files from configuration file. -files=( "$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_config import get_topology_files; get_topology_files('$config_file')")" ) +files=( "$TEST_PATH/$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_config import get_topology_files; get_topology_files('$config_file')")" ) if [ "${#files[@]}" -eq 0 ]; then echo "Failed to process configuration file: no topologies were found." fi # Get path to output directory from configuration file. -outputdir="$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_config import get_output_dir; get_output_dir('$config_file')")" +outputdir="$TEST_PATH/$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_config import get_output_dir; get_output_dir('$config_file')")" if [[ ! "$outputdir" = /* && ! "$outputdir" = ~* ]]; then outputdir=$(pwd)/$outputdir fi diff --git a/tests/integration_tests/yaml_config.py b/tests/integration_tests/yaml_config.py index ce4a388..7934c20 100644 --- a/tests/integration_tests/yaml_config.py +++ b/tests/integration_tests/yaml_config.py @@ -19,7 +19,7 @@ def get_output_dir(config_file): if 'output_directory' in doc: print(doc['output_directory'], file=stdout) else: - print("./test_output", file=stdout) + print("test_output", file=stdout) def get_topology_files(config_file): """Read and print values for file for all topologies.""" -- GitLab From 392b63efbf58cf9fa8064fd7353ff4513dd15473 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 18:07:51 +0200 Subject: [PATCH 15/22] Fix topology definition paths --- tests/integration_tests/ci/config_debian.yml | 8 ++++---- tests/integration_tests/ci/config_kali.yml | 8 ++++---- .../integration_tests/ci/config_windows_server.yml | 8 ++++---- tests/integration_tests/config.yml | 14 +++++++------- tests/integration_tests/config_complete_test.yml | 14 +++++++------- tests/integration_tests/run_tests.sh | 4 ++-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/integration_tests/ci/config_debian.yml b/tests/integration_tests/ci/config_debian.yml index 1084e12..4e0be8c 100644 --- a/tests/integration_tests/ci/config_debian.yml +++ b/tests/integration_tests/ci/config_debian.yml @@ -1,17 +1,17 @@ topologies: - - file: ../../topologies/0-routers-1-network-1-host.yml + - file: topologies/0-routers-1-network-1-host.yml arguments: - no-arguments - ansible_installed - - file: ../../topologies/1-router-1-network-1-host.yml + - file: topologies/1-router-1-network-1-host.yml arguments: - no-arguments - ansible_installed - - file: ../../topologies/1-router-2-networks-2-hosts.yml + - file: topologies/1-router-2-networks-2-hosts.yml arguments: - no-arguments - ansible_installed - - file: ../../topologies/2-routers-2-networks-2-hosts.yml + - file: topologies/2-routers-2-networks-2-hosts.yml arguments: - no-arguments - ansible_installed \ No newline at end of file diff --git a/tests/integration_tests/ci/config_kali.yml b/tests/integration_tests/ci/config_kali.yml index ddac516..463d0f1 100644 --- a/tests/integration_tests/ci/config_kali.yml +++ b/tests/integration_tests/ci/config_kali.yml @@ -1,26 +1,26 @@ topologies: - - file: ../../topologies/0-routers-1-network-1-host.yml + - file: topologies/0-routers-1-network-1-host.yml arguments: - no-arguments - ansible_installed boxes: - munikypo/kali original_boxes: false - - file: ../../topologies/1-router-1-network-1-host.yml + - file: topologies/1-router-1-network-1-host.yml arguments: - no-arguments - ansible_installed boxes: - munikypo/kali original_boxes: false - - file: ../../topologies/1-router-2-networks-2-hosts.yml + - file: topologies/1-router-2-networks-2-hosts.yml arguments: - no-arguments - ansible_installed boxes: - munikypo/kali original_boxes: false - - file: ../../topologies/2-routers-2-networks-2-hosts.yml + - file: topologies/2-routers-2-networks-2-hosts.yml arguments: - no-arguments - ansible_installed diff --git a/tests/integration_tests/ci/config_windows_server.yml b/tests/integration_tests/ci/config_windows_server.yml index 80ca11f..dcb9358 100644 --- a/tests/integration_tests/ci/config_windows_server.yml +++ b/tests/integration_tests/ci/config_windows_server.yml @@ -1,26 +1,26 @@ topologies: - - file: ../../topologies/0-routers-1-network-1-host.yml + - file: topologies/0-routers-1-network-1-host.yml arguments: - no-arguments - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false - - file: ../../topologies/1-router-1-network-1-host.yml + - file: topologies/1-router-1-network-1-host.yml arguments: - no-arguments - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false - - file: ../../topologies/1-router-2-networks-2-hosts.yml + - file: topologies/1-router-2-networks-2-hosts.yml arguments: - no-arguments - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false - - file: ../../topologies/2-routers-2-networks-2-hosts.yml + - file: topologies/2-routers-2-networks-2-hosts.yml arguments: - no-arguments - ansible_installed diff --git a/tests/integration_tests/config.yml b/tests/integration_tests/config.yml index 80965bb..d84aae1 100644 --- a/tests/integration_tests/config.yml +++ b/tests/integration_tests/config.yml @@ -1,29 +1,29 @@ topologies: - - file: ../../topologies/0-routers-1-network-1-host.yml + - file: topologies/0-routers-1-network-1-host.yml arguments: - no-arguments - ansible-installed - - file: ../../topologies/1-router-1-network-1-host.yml + - file: topologies/1-router-1-network-1-host.yml arguments: - no-arguments - ansible-installed - - file: ../../topologies/1-router-2-networks-2-hosts.yml + - file: topologies/1-router-2-networks-2-hosts.yml arguments: - no-arguments - ansible-installed - - file: ../../topologies/2-routers-2-networks-2-hosts.yml + - file: topologies/2-routers-2-networks-2-hosts.yml arguments: - no-arguments - ansible-installed - - file: ../../topologies/2-routers-4-networks-4-hosts.yml + - file: topologies/2-routers-4-networks-4-hosts.yml arguments: - no-arguments - ansible-installed - - file: ../../topologies/3-routers-5-networks-5-hosts.yml + - file: topologies/3-routers-5-networks-5-hosts.yml arguments: - no-arguments - ansible-installed - - file: ../../topologies/0-routers-1-network-4-hosts.yml + - file: topologies/0-routers-1-network-4-hosts.yml arguments: - no-arguments - ansible-installed diff --git a/tests/integration_tests/config_complete_test.yml b/tests/integration_tests/config_complete_test.yml index 3fdedee..e297f46 100644 --- a/tests/integration_tests/config_complete_test.yml +++ b/tests/integration_tests/config_complete_test.yml @@ -1,5 +1,5 @@ topologies: - - file: ../../topologies/0-routers-1-network-1-host.yml + - file: topologies/0-routers-1-network-1-host.yml arguments: - no-arguments - ansible-installed @@ -9,7 +9,7 @@ topologies: - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false - - file: ../../topologies/1-router-1-network-1-host.yml + - file: topologies/1-router-1-network-1-host.yml arguments: - no-arguments - ansible-installed @@ -19,7 +19,7 @@ topologies: - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false - - file: ../../topologies/1-router-2-networks-2-hosts.yml + - file: topologies/1-router-2-networks-2-hosts.yml arguments: - no-arguments - ansible-installed @@ -29,7 +29,7 @@ topologies: - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false - - file: ../../topologies/2-routers-2-networks-2-hosts.yml + - file: topologies/2-routers-2-networks-2-hosts.yml arguments: - no-arguments - ansible-installed @@ -39,7 +39,7 @@ topologies: - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false - - file: ../../topologies/2-routers-4-networks-4-hosts.yml + - file: topologies/2-routers-4-networks-4-hosts.yml arguments: - no-arguments - ansible-installed @@ -49,7 +49,7 @@ topologies: - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false - - file: ../../topologies/3-routers-5-networks-5-hosts.yml + - file: topologies/3-routers-5-networks-5-hosts.yml arguments: - no-arguments - ansible-installed @@ -59,7 +59,7 @@ topologies: - munikypo/windows-server-2019 - munikypo/windows-10 original_boxes: false - - file: ../../topologies/0-routers-1-network-4-hosts.yml + - file: topologies/0-routers-1-network-4-hosts.yml arguments: - no-arguments - ansible-installed diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index a766c33..4091902 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -325,9 +325,9 @@ do for box in "${boxes[@]}" do if [ "$box" = "no-box" ]; then - newfile=$file + newfile="$CSC_PATH/$file" else - newfile=$(change_boxes "$TEST_PATH/$file" "$box") + newfile=$(change_boxes "$CSC_PATH/$file" "$box") fi filename=$(basename "$newfile" .yml) -- GitLab From 197427163a55af00e68ce9d87e4ac7a891b89e2e Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 18:08:43 +0200 Subject: [PATCH 16/22] Test windows only without --ansible-installed --- tests/integration_tests/ci/config_windows_server.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/integration_tests/ci/config_windows_server.yml b/tests/integration_tests/ci/config_windows_server.yml index dcb9358..25ce9b8 100644 --- a/tests/integration_tests/ci/config_windows_server.yml +++ b/tests/integration_tests/ci/config_windows_server.yml @@ -2,28 +2,24 @@ topologies: - file: topologies/0-routers-1-network-1-host.yml arguments: - no-arguments - - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false - file: topologies/1-router-1-network-1-host.yml arguments: - no-arguments - - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false - file: topologies/1-router-2-networks-2-hosts.yml arguments: - no-arguments - - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false - file: topologies/2-routers-2-networks-2-hosts.yml arguments: - no-arguments - - ansible_installed boxes: - munikypo/windows-server-2019 original_boxes: false \ No newline at end of file -- GitLab From 02f67a60268e9bb465b80dae24aeb9ca70ecbd11 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 18:50:58 +0200 Subject: [PATCH 17/22] Test vagrantfile content --- tests/integration_tests/run_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 4091902..2fa702b 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -22,6 +22,7 @@ create_sandbox() echo '└── Generating intermediate definition...' PYTHONPATH=$CSC_PATH python3 "$CREATOR_PATH" "-o=${TEMP_TOPOLOGY_PATH}/sandbox" "$file" 1> /dev/null || { echo 'Error while creating intermediate definition.'; exit 1; } + cat "${TEMP_TOPOLOGY_PATH}/sandbox/Vagrantfile" } -- GitLab From b482612b3b8e3919b4077248d386272f60c938c8 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 18:59:02 +0200 Subject: [PATCH 18/22] Fix error message --- sandboxcreator/commands/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sandboxcreator/commands/command.py b/sandboxcreator/commands/command.py index bf9c240..65e7ecc 100644 --- a/sandboxcreator/commands/command.py +++ b/sandboxcreator/commands/command.py @@ -72,7 +72,7 @@ class Command(abc.ABC): check=True, text=True, capture_output=True) except subprocess.CalledProcessError: - raise RuntimeError("Could access list of machines") from None + raise RuntimeError("Could not access list of machines") from None output_lines: List = process_output.stdout.splitlines() output_csv: List[List] = list(csv.reader(output_lines)) machines: List[str] = [] -- GitLab From a34226a4e5c1bdc56c1367ae5e947150b3f33f9a Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 19:15:38 +0200 Subject: [PATCH 19/22] Forbid box name vagrant --- sandboxcreator/commands/command.py | 6 +----- tests/integration_tests/run_tests.sh | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/sandboxcreator/commands/command.py b/sandboxcreator/commands/command.py index 65e7ecc..ba2fe42 100644 --- a/sandboxcreator/commands/command.py +++ b/sandboxcreator/commands/command.py @@ -60,10 +60,6 @@ class Command(abc.ABC): return None raise ValueError('Invalid output device') - @abc.abstractmethod - def _check_machine_states(self) -> None: - pass - @staticmethod def list_machines(sandbox_dir: Path): status_command: List[str] = ["vagrant", "status", "--machine-readable"] @@ -78,7 +74,7 @@ class Command(abc.ABC): machines: List[str] = [] for line in output_csv: machine_name: str = line[1] - if machine_name and machine_name not in machines: + if machine_name and machine_name != 'vagrant' and machine_name not in machines: machines.append(machine_name) return machines diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 2fa702b..4091902 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -22,7 +22,6 @@ create_sandbox() echo '└── Generating intermediate definition...' PYTHONPATH=$CSC_PATH python3 "$CREATOR_PATH" "-o=${TEMP_TOPOLOGY_PATH}/sandbox" "$file" 1> /dev/null || { echo 'Error while creating intermediate definition.'; exit 1; } - cat "${TEMP_TOPOLOGY_PATH}/sandbox/Vagrantfile" } -- GitLab From 95d8eb37bac10347538bdd4d3b77debd4438e8bb Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 19:27:09 +0200 Subject: [PATCH 20/22] Fix test topology paths --- tests/integration_tests/run_tests.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 4091902..8b0e3ef 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -87,9 +87,9 @@ test_machines() cd "${TEMP_TOPOLOGY_PATH}/sandbox" || { echo "Could not find the intermediate definition"; cleanup_and_exit 1; } # Get list of host machines. - mapfile -t hosts < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_hosts; get_hosts('$TEST_PATH/$file')") + mapfile -t hosts < <(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_hosts; get_hosts('$file')") # Get list of router machines. - mapfile -t routers < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_routers; get_routers('$TEST_PATH/$file')") + mapfile -t routers < <(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_routers; get_routers('$file')") # check network settings on host machines. for host in "${hosts[@]}" @@ -115,8 +115,8 @@ test_machines() done # Check that route from host goes through the correct router. - network=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_network_for_host; get_network_for_host('$TEST_PATH/$file', '$host')") - router=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_router_for_network; get_router_for_network('$TEST_PATH/$file', '$network')") + network=$(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_network_for_host; get_network_for_host('$file', '$host')") + router=$(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_router_for_network; get_router_for_network('$file', '$network')") output=$(vagrant ssh "$host" -c "traceroute $router | head -n 2 | tail -n 1 | grep '$router'" 2> /dev/null | tr -d '\r') if [ -n "$output" ]; then @@ -142,7 +142,7 @@ test_machines() for target in "${hosts[@]}" do if [ "$host" != "$target" ]; then - ip=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$TEST_PATH/$file', '$target')") + ip=$(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$file', '$target')") vagrant ssh "$host" -c "ping -c 1 $ip" > /dev/null 2>&1 && echo " └── '$host' can access '$target'." || { echo "Test failed: $host can't reach $target."; cd "$current_path"; return 1; } fi done @@ -151,7 +151,7 @@ test_machines() # Check that machine can reach all router machines. for target in "${routers[@]}" do - ip=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$TEST_PATH/$file', '$target')") + ip=$(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$file', '$target')") output=$(vagrant powershell "$host" -c "ping -c 1 www.muni.cz" 2>&1 | tr -d '\r' | grep "output code 0") if [ -n "$output" ]; then echo " └── '$host' can access '$target'." -- GitLab From eccfe5362d758b30438824f5242966c733690312 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 19:35:53 +0200 Subject: [PATCH 21/22] Fix test topology paths --- tests/integration_tests/run_tests.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 8b0e3ef..55bf9c8 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -87,9 +87,9 @@ test_machines() cd "${TEMP_TOPOLOGY_PATH}/sandbox" || { echo "Could not find the intermediate definition"; cleanup_and_exit 1; } # Get list of host machines. - mapfile -t hosts < <(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_hosts; get_hosts('$file')") + mapfile -t hosts < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_hosts; get_hosts('$CSC_PATH/'$file')") # Get list of router machines. - mapfile -t routers < <(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_routers; get_routers('$file')") + mapfile -t routers < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_routers; get_routers('$CSC_PATH/$file')") # check network settings on host machines. for host in "${hosts[@]}" @@ -115,8 +115,8 @@ test_machines() done # Check that route from host goes through the correct router. - network=$(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_network_for_host; get_network_for_host('$file', '$host')") - router=$(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_router_for_network; get_router_for_network('$file', '$network')") + network=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_network_for_host; get_network_for_host('$CSC_PATH/$file', '$host')") + router=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_router_for_network; get_router_for_network('$CSC_PATH/$file', '$network')") output=$(vagrant ssh "$host" -c "traceroute $router | head -n 2 | tail -n 1 | grep '$router'" 2> /dev/null | tr -d '\r') if [ -n "$output" ]; then @@ -142,7 +142,7 @@ test_machines() for target in "${hosts[@]}" do if [ "$host" != "$target" ]; then - ip=$(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$file', '$target')") + ip=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$CSC_PATH/$file', '$target')") vagrant ssh "$host" -c "ping -c 1 $ip" > /dev/null 2>&1 && echo " └── '$host' can access '$target'." || { echo "Test failed: $host can't reach $target."; cd "$current_path"; return 1; } fi done @@ -151,7 +151,7 @@ test_machines() # Check that machine can reach all router machines. for target in "${routers[@]}" do - ip=$(PYTHONPATH=$CSC_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$file', '$target')") + ip=$(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_ip_for_host; get_ip_for_host('$CSC_PATH/$file', '$target')") output=$(vagrant powershell "$host" -c "ping -c 1 www.muni.cz" 2>&1 | tr -d '\r' | grep "output code 0") if [ -n "$output" ]; then echo " └── '$host' can access '$target'." -- GitLab From a511eda2dcd842ccedff39884bc6504d631e3792 Mon Sep 17 00:00:00 2001 From: Attila Farkas <394097@mail.muni.cz> Date: Thu, 30 Jun 2022 19:41:32 +0200 Subject: [PATCH 22/22] Fix test topology paths --- tests/integration_tests/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 55bf9c8..4776bfd 100755 --- a/tests/integration_tests/run_tests.sh +++ b/tests/integration_tests/run_tests.sh @@ -87,7 +87,7 @@ test_machines() cd "${TEMP_TOPOLOGY_PATH}/sandbox" || { echo "Could not find the intermediate definition"; cleanup_and_exit 1; } # Get list of host machines. - mapfile -t hosts < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_hosts; get_hosts('$CSC_PATH/'$file')") + mapfile -t hosts < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_hosts; get_hosts('$CSC_PATH/$file')") # Get list of router machines. mapfile -t routers < <(PYTHONPATH=$TEST_PATH python3 -c "from yaml_topology import get_routers; get_routers('$CSC_PATH/$file')") -- GitLab