From 48dcc8803536136b0c5f48de701b8defea27ad35 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Tue, 17 Dec 2019 12:01:58 +0200 Subject: [PATCH] Added a pytest to test compatibility, fixed typo in folder name --- .../README.md | 7 ++ .../aws_keys/.gitignore | 0 envs/os_compatibility/conftest.py | 11 ++++ .../terraform/config.tf | 0 .../terraform/infra.tf | 0 .../terraform/instance_template/main.tf | 0 .../terraform/instance_template/variables.tf | 0 .../terraform/instances.tf | 4 ++ envs/os_compatibility/test_compatibility.py | 64 +++++++++++++++++++ 9 files changed, 86 insertions(+) rename envs/{os_compatability => os_compatibility}/README.md (66%) rename envs/{os_compatability => os_compatibility}/aws_keys/.gitignore (100%) create mode 100644 envs/os_compatibility/conftest.py rename envs/{os_compatability => os_compatibility}/terraform/config.tf (100%) rename envs/{os_compatability => os_compatibility}/terraform/infra.tf (100%) rename envs/{os_compatability => os_compatibility}/terraform/instance_template/main.tf (100%) rename envs/{os_compatability => os_compatibility}/terraform/instance_template/variables.tf (100%) rename envs/{os_compatability => os_compatibility}/terraform/instances.tf (98%) create mode 100644 envs/os_compatibility/test_compatibility.py diff --git a/envs/os_compatability/README.md b/envs/os_compatibility/README.md similarity index 66% rename from envs/os_compatability/README.md rename to envs/os_compatibility/README.md index efeb04319..9dd136ae7 100644 --- a/envs/os_compatability/README.md +++ b/envs/os_compatibility/README.md @@ -26,3 +26,10 @@ Launch the environment by going into `terraform` folder and running terraform init terraform apply ``` + +## Usage +1. Launch os_compat_ISLAND machine and upload your binaries/update island +2. Launch/Reboot all other os_compat test machines +3. Wait until machines boot and run monkey +4. Launch `test_compatibility.py` pytest script with island ip parameter +(e.g. `test_compatibility.py --island 111.111.111.111:5000`) diff --git a/envs/os_compatability/aws_keys/.gitignore b/envs/os_compatibility/aws_keys/.gitignore similarity index 100% rename from envs/os_compatability/aws_keys/.gitignore rename to envs/os_compatibility/aws_keys/.gitignore diff --git a/envs/os_compatibility/conftest.py b/envs/os_compatibility/conftest.py new file mode 100644 index 000000000..13aabf5b6 --- /dev/null +++ b/envs/os_compatibility/conftest.py @@ -0,0 +1,11 @@ +import pytest + + +def pytest_addoption(parser): + parser.addoption("--island", action="store", default="", + help="Specify the Monkey Island address (host+port).") + + +@pytest.fixture(scope='module') +def island(request): + return request.config.getoption("--island") diff --git a/envs/os_compatability/terraform/config.tf b/envs/os_compatibility/terraform/config.tf similarity index 100% rename from envs/os_compatability/terraform/config.tf rename to envs/os_compatibility/terraform/config.tf diff --git a/envs/os_compatability/terraform/infra.tf b/envs/os_compatibility/terraform/infra.tf similarity index 100% rename from envs/os_compatability/terraform/infra.tf rename to envs/os_compatibility/terraform/infra.tf diff --git a/envs/os_compatability/terraform/instance_template/main.tf b/envs/os_compatibility/terraform/instance_template/main.tf similarity index 100% rename from envs/os_compatability/terraform/instance_template/main.tf rename to envs/os_compatibility/terraform/instance_template/main.tf diff --git a/envs/os_compatability/terraform/instance_template/variables.tf b/envs/os_compatibility/terraform/instance_template/variables.tf similarity index 100% rename from envs/os_compatability/terraform/instance_template/variables.tf rename to envs/os_compatibility/terraform/instance_template/variables.tf diff --git a/envs/os_compatability/terraform/instances.tf b/envs/os_compatibility/terraform/instances.tf similarity index 98% rename from envs/os_compatability/terraform/instances.tf rename to envs/os_compatibility/terraform/instances.tf index 7a3cd9285..3f5cc8658 100644 --- a/envs/os_compatability/terraform/instances.tf +++ b/envs/os_compatibility/terraform/instances.tf @@ -1,3 +1,7 @@ +// Instances of machines in os_compat environment +// !!! Don't forget to add machines to test_compatibility.py if you add here !!! + + resource "aws_instance" "island" { ami = "ami-01cc9554aa0b4c00e" instance_type = "t2.micro" diff --git a/envs/os_compatibility/test_compatibility.py b/envs/os_compatibility/test_compatibility.py new file mode 100644 index 000000000..da46bc71c --- /dev/null +++ b/envs/os_compatibility/test_compatibility.py @@ -0,0 +1,64 @@ +import pytest + +from envs.monkey_zoo.blackbox.island_client.monkey_island_client import MonkeyIslandClient + + +machine_list = { + "10.0.0.36": "centos_6", + "10.0.0.37": "centos_7", + "10.0.0.38": "centos_8", + "10.0.0.42": "suse_12", + "10.0.0.41": "suse_11", + "10.0.0.99": "kali_2019", + "10.0.0.86": "rhel_6", + "10.0.0.87": "rhel_7", + "10.0.0.88": "rhel_8", + "10.0.0.77": "debian_7", + "10.0.0.78": "debian_8", + "10.0.0.79": "debian_9", + "10.0.0.66": "oracle_6", + "10.0.0.67": "oracle_7", + "10.0.0.22": "ubuntu_12", + "10.0.0.23": "ubuntu_12_32", + "10.0.0.24": "ubuntu_14", + "10.0.0.29": "ubuntu_19", + "10.0.0.4": "windows_2003_r2_32", + "10.0.0.5": "windows_2003", + "10.0.0.8": "windows_2008", + "10.0.0.6": "windows_2008_32", + "10.0.0.7": "windows_2008_r2", + "10.0.0.12": "windows_2012", + "10.0.0.11": "windows_2012_r2", + "10.0.0.16": "windows_2016", + "10.0.0.19": "windows_2019", +} + + +@pytest.fixture(scope='class') +def island_client(island): + island_client_object = MonkeyIslandClient(island) + yield island_client_object + + +@pytest.mark.usefixtures('island_client') +# noinspection PyUnresolvedReferences +class TestOSCompatibility(object): + + def test_os_compat(self, island_client): + print() + all_monkeys = island_client.get_all_monkeys_from_db() + ips_that_communicated = [] + for monkey in all_monkeys: + for ip in monkey['ip_addresses']: + if ip in machine_list: + ips_that_communicated.append(ip) + break + for ip, os in machine_list.items(): + if ip not in ips_that_communicated: + print("{} didn't communicate to island".format(os)) + + if len(ips_that_communicated) < len(machine_list): + assert False + + +