From dde2e1a7e4c08103840ff83829ec1b2c51a16a0f Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Sun, 6 Oct 2019 15:05:34 +0300 Subject: [PATCH] Added some documentation and improved logging in Blackbox --- envs/monkey_zoo/blackbox/README.md | 14 ++++++++++++++ .../island_client/monkey_island_requests.py | 5 +++-- .../blackbox/utils/gcp_machine_handlers.py | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/envs/monkey_zoo/blackbox/README.md b/envs/monkey_zoo/blackbox/README.md index 12b33ebce..f1b66de91 100644 --- a/envs/monkey_zoo/blackbox/README.md +++ b/envs/monkey_zoo/blackbox/README.md @@ -3,3 +3,17 @@ 1. Download google sdk: https://cloud.google.com/sdk/docs/ 2. Download service account key for MonkeyZoo project (if you deployed MonkeyZoo via terraform scripts then you already have it). GCP console -> IAM -> service accounts(you can use the same key used to authenticate terraform scripts) +3. Deploy the relevant branch + complied executables to the Island machine on GCP. + +### Running the tests +In order to execute the entire test suite, you must know the external IP of the Island machine on GCP. You can find +this information in the GCP Console `Compute Engine/VM Instances` under _External IP_. + +#### Running in command line +Run the following command: + +`monkey\envs\monkey_zoo\blackbox>python -m pytest --island=35.207.152.72:5000 test_blackbox.py` + +#### Running in PyCharm +Configure a PyTest configuration with the additional argument `--island=35.207.152.72` on the +`monkey\envs\monkey_zoo\blackbox`. diff --git a/envs/monkey_zoo/blackbox/island_client/monkey_island_requests.py b/envs/monkey_zoo/blackbox/island_client/monkey_island_requests.py index 1f9fc2642..e62cb2121 100644 --- a/envs/monkey_zoo/blackbox/island_client/monkey_island_requests.py +++ b/envs/monkey_zoo/blackbox/island_client/monkey_island_requests.py @@ -16,8 +16,9 @@ class MonkeyIslandRequests(object): def try_get_jwt_from_server(self): try: return self.get_jwt_from_server() - except requests.ConnectionError: - LOGGER.error("Unable to connect to island, aborting!") + except requests.ConnectionError as err: + LOGGER.error( + "Unable to connect to island, aborting! Error information: {}. Server: {}".format(err, self.addr)) assert False def get_jwt_from_server(self): diff --git a/envs/monkey_zoo/blackbox/utils/gcp_machine_handlers.py b/envs/monkey_zoo/blackbox/utils/gcp_machine_handlers.py index ac9e63d3e..3cb2ad6af 100644 --- a/envs/monkey_zoo/blackbox/utils/gcp_machine_handlers.py +++ b/envs/monkey_zoo/blackbox/utils/gcp_machine_handlers.py @@ -26,6 +26,11 @@ class GCPHandler(object): LOGGER.error("GCP Handler failed to initialize: %s." % e) def start_machines(self, machine_list): + """ + Start all the machines in the list. + :param machine_list: A space-separated string with all the machine names. Example: + start_machines(`" ".join(["elastic-3", "mssql-16"])`) + """ LOGGER.info("Setting up all GCP machines...") try: subprocess.call((GCPHandler.MACHINE_STARTING_COMMAND % (machine_list, self.zone)), shell=True)