diff --git a/tests/integration_tests/.gitlab-ci.yml b/.gitlab-ci.yml similarity index 67% rename from tests/integration_tests/.gitlab-ci.yml rename to .gitlab-ci.yml index 6c6ac7fb46a8dfe85661afb16b4ba587a48960a3..bac334fc5995244fc0a15b40608133ad3b015855 100644 --- a/tests/integration_tests/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,23 +3,24 @@ 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 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 tests/integration_tests/ci/config_debian.yml -p # run even when other stages fail when: always # only run for merge requests @@ -27,17 +28,18 @@ 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 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 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 tests/integration_tests/ci/config_kali.yml -p # run even when other stages fail when: always # only run for and merge requests @@ -47,7 +49,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 tests/integration_tests/ci/config_windows_server.yml -p # run even when other stages fail when: always # only run for merge requests diff --git a/sandboxcreator/commands/command.py b/sandboxcreator/commands/command.py index bf9c240163ab27e0b15c357af395929f137e22e4..ba2fe429fb799619311cb5cf73d08b8ffbc3b92a 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"] @@ -72,13 +68,13 @@ 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] = [] 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/sandboxcreator/scripts/create.py b/sandboxcreator/scripts/create.py index af98a0b0d7d98a33e4a0c0f76f2fc201f5b2eaac..331f72f844cff735e2590b27328f53215fa69661 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 34b01b9fc59c34746ab7e4a2b1d140275734d312..bee0985ab3e19a2bec0068b05f5ce7131514b2dc 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: diff --git a/tests/integration_tests/ci/config_debian.yml b/tests/integration_tests/ci/config_debian.yml index 32c472a4d14800404c7672f8c5e9b0dfe2746a7f..4e0be8cf3f6c4a8d992e6db793fd62323905c45f 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 0000000000000000000000000000000000000000..463d0f1f4d65cf0d2998f14c98109d0db247cc04 --- /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 90aff42de5a05828df6a2256db87bc9b769bb3b4..0000000000000000000000000000000000000000 --- 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 4bfdad921f12a2859def4e147553c0886cc05a5d..25ce9b87c9d8ad879347770c416b77990cc0cea5 100644 --- a/tests/integration_tests/ci/config_windows_server.yml +++ b/tests/integration_tests/ci/config_windows_server.yml @@ -1,27 +1,25 @@ topologies: - - file: ./topologies/0-routers-1-network-1-host.yml + - file: topologies/0-routers-1-network-1-host.yml arguments: - - ansible_local + - no-arguments 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 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 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 boxes: - munikypo/windows-server-2019 original_boxes: false \ No newline at end of file diff --git a/tests/integration_tests/config.yml b/tests/integration_tests/config.yml index c433827676779140d2ea4e7d8b7bf67c90eea647..d84aae14e3c966c1dcdfd0c09ac27f56becc5198 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 diff --git a/tests/integration_tests/config_complete_test.yml b/tests/integration_tests/config_complete_test.yml new file mode 100644 index 0000000000000000000000000000000000000000..e297f46df21cb49779cc4a67da992941d2957e2e --- /dev/null +++ b/tests/integration_tests/config_complete_test.yml @@ -0,0 +1,71 @@ +topologies: + - file: topologies/0-routers-1-network-1-host.yml + arguments: + - no-arguments + - ansible-installed + boxes: + - munikypo/debian-10 + - munikypo/kali + - 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/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/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/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/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/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/windows-server-2019 + - munikypo/windows-10 + original_boxes: false \ No newline at end of file diff --git a/tests/integration_tests/run_tests.sh b/tests/integration_tests/run_tests.sh index 7d93541d0a397d955f4fc7226d85e0cb545046e9..4776bfd8465daeb7d4e03eff01881c389784f7ef 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" 1> /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('$CSC_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('$CSC_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('$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')") - # 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('$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 @@ -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('$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'." + 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. @@ -295,25 +223,29 @@ 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" - newfile="$creator_path/tmp_topologies/${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" } -# 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=( "$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=$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 +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,81 +313,60 @@ 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=$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. - 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[@]} - do + for box in "${boxes[@]}" + do if [ "$box" = "no-box" ]; then - newfile=$file + newfile="$CSC_PATH/$file" else - newfile=$(change_boxes "$creator_path/$file" "$box") + newfile=$(change_boxes "$CSC_PATH/$file" "$box") fi 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 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 0000000000000000000000000000000000000000..62f52ae721699d369d4ef8a3ffb10c8ef6747ec4 --- /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 0000000000000000000000000000000000000000..29319b199012ac5abaa34225e3aac8c6b67056f2 --- /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 0000000000000000000000000000000000000000..a119563872bf09a79a87e2b0fffa95756969cccb --- /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 0000000000000000000000000000000000000000..23bf0a54859c99a664ecd20628dbc2f97b06bbee --- /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 0000000000000000000000000000000000000000..7d9928a2c1067bea3145fb0f541ba26c3be3c156 --- /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 0000000000000000000000000000000000000000..e49a1c64ee11a8d4a395288a14aed65e56c8079f --- /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 diff --git a/tests/integration_tests/yaml_config.py b/tests/integration_tests/yaml_config.py index ce4a38805a519db77988925e4f4ecbe5ec6fd07c..7934c208ac7d304db2e950dd0065942ef01747ef 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.""" diff --git a/tests/integration_tests/yaml_topology.py b/tests/integration_tests/yaml_topology.py index 9e317d3d366f17d0f700057aeb409edd29aea5a2..1e0fa13939cdef9fc36645b9517428ce3ff1eb3a 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)