forked from p15670423/monkey
Refactored tests to use the new configuration parser
This commit is contained in:
parent
aaab827e32
commit
5837240107
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
from envs.monkey_zoo.blackbox.island_client.island_config_parser import IslandConfigParser
|
||||||
from envs.monkey_zoo.blackbox.tests.basic_test import BasicTest
|
from envs.monkey_zoo.blackbox.tests.basic_test import BasicTest
|
||||||
from envs.monkey_zoo.blackbox.utils.test_timer import TestTimer
|
from envs.monkey_zoo.blackbox.utils.test_timer import TestTimer
|
||||||
|
|
||||||
|
@ -13,16 +14,16 @@ LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
class ExploitationTest(BasicTest):
|
class ExploitationTest(BasicTest):
|
||||||
|
|
||||||
def __init__(self, name, island_client, config_parser, analyzers, timeout, log_handler):
|
def __init__(self, name, island_client, raw_config, analyzers, timeout, log_handler):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.island_client = island_client
|
self.island_client = island_client
|
||||||
self.config_parser = config_parser
|
self.raw_config = raw_config
|
||||||
self.analyzers = analyzers
|
self.analyzers = analyzers
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.log_handler = log_handler
|
self.log_handler = log_handler
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.island_client.import_config(self.config_parser.config_raw)
|
self.island_client.import_config(self.raw_config)
|
||||||
self.print_test_starting_info()
|
self.print_test_starting_info()
|
||||||
try:
|
try:
|
||||||
self.island_client.run_monkey_local()
|
self.island_client.run_monkey_local()
|
||||||
|
@ -36,7 +37,8 @@ class ExploitationTest(BasicTest):
|
||||||
|
|
||||||
def print_test_starting_info(self):
|
def print_test_starting_info(self):
|
||||||
LOGGER.info("Started {} test".format(self.name))
|
LOGGER.info("Started {} test".format(self.name))
|
||||||
LOGGER.info("Machines participating in test: " + ", ".join(self.config_parser.get_ips_of_targets()))
|
machine_list = ", ".join(IslandConfigParser.get_ips_of_targets(self.raw_config))
|
||||||
|
LOGGER.info(f"Machines participating in test: {machine_list}")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
def test_until_timeout(self):
|
def test_until_timeout(self):
|
||||||
|
|
|
@ -17,12 +17,11 @@ class MapGenerationTest(PerformanceTest):
|
||||||
|
|
||||||
TEST_NAME = "Map generation performance test"
|
TEST_NAME = "Map generation performance test"
|
||||||
|
|
||||||
def __init__(self, island_client, config_parser, analyzers,
|
def __init__(self, island_client, raw_config, analyzers,
|
||||||
timeout, log_handler, break_on_timeout):
|
timeout, log_handler, break_on_timeout):
|
||||||
self.island_client = island_client
|
self.island_client = island_client
|
||||||
self.config_parser = config_parser
|
|
||||||
exploitation_test = ExploitationTest(MapGenerationTest.TEST_NAME, island_client,
|
exploitation_test = ExploitationTest(MapGenerationTest.TEST_NAME, island_client,
|
||||||
config_parser, analyzers, timeout, log_handler)
|
raw_config, analyzers, timeout, log_handler)
|
||||||
performance_config = PerformanceTestConfig(max_allowed_single_page_time=MAX_ALLOWED_SINGLE_PAGE_TIME,
|
performance_config = PerformanceTestConfig(max_allowed_single_page_time=MAX_ALLOWED_SINGLE_PAGE_TIME,
|
||||||
max_allowed_total_time=MAX_ALLOWED_TOTAL_TIME,
|
max_allowed_total_time=MAX_ALLOWED_TOTAL_TIME,
|
||||||
endpoints_to_test=MAP_RESOURCES,
|
endpoints_to_test=MAP_RESOURCES,
|
||||||
|
|
|
@ -6,7 +6,7 @@ from envs.monkey_zoo.blackbox.tests.basic_test import BasicTest
|
||||||
class PerformanceTest(BasicTest, metaclass=ABCMeta):
|
class PerformanceTest(BasicTest, metaclass=ABCMeta):
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self, island_client, config_parser, analyzers,
|
def __init__(self, island_client, raw_config, analyzers,
|
||||||
timeout, log_handler, break_on_timeout):
|
timeout, log_handler, break_on_timeout):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,11 @@ class PerformanceTestWorkflow(BasicTest):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.exploitation_test = exploitation_test
|
self.exploitation_test = exploitation_test
|
||||||
self.island_client = exploitation_test.island_client
|
self.island_client = exploitation_test.island_client
|
||||||
self.config_parser = exploitation_test.config_parser
|
self.raw_config = exploitation_test.raw_config
|
||||||
self.performance_config = performance_config
|
self.performance_config = performance_config
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.island_client.import_config(self.config_parser.config_raw)
|
self.island_client.import_config(self.raw_config)
|
||||||
self.exploitation_test.print_test_starting_info()
|
self.exploitation_test.print_test_starting_info()
|
||||||
try:
|
try:
|
||||||
self.island_client.run_monkey_local()
|
self.island_client.run_monkey_local()
|
||||||
|
|
|
@ -20,12 +20,11 @@ REPORT_RESOURCES = [
|
||||||
class ReportGenerationTest(PerformanceTest):
|
class ReportGenerationTest(PerformanceTest):
|
||||||
TEST_NAME = "Report generation performance test"
|
TEST_NAME = "Report generation performance test"
|
||||||
|
|
||||||
def __init__(self, island_client, config_parser, analyzers,
|
def __init__(self, island_client, raw_config, analyzers,
|
||||||
timeout, log_handler, break_on_timeout):
|
timeout, log_handler, break_on_timeout):
|
||||||
self.island_client = island_client
|
self.island_client = island_client
|
||||||
self.config_parser = config_parser
|
|
||||||
exploitation_test = ExploitationTest(ReportGenerationTest.TEST_NAME, island_client,
|
exploitation_test = ExploitationTest(ReportGenerationTest.TEST_NAME, island_client,
|
||||||
config_parser, analyzers, timeout, log_handler)
|
raw_config, analyzers, timeout, log_handler)
|
||||||
performance_config = PerformanceTestConfig(max_allowed_single_page_time=MAX_ALLOWED_SINGLE_PAGE_TIME,
|
performance_config = PerformanceTestConfig(max_allowed_single_page_time=MAX_ALLOWED_SINGLE_PAGE_TIME,
|
||||||
max_allowed_total_time=MAX_ALLOWED_TOTAL_TIME,
|
max_allowed_total_time=MAX_ALLOWED_TOTAL_TIME,
|
||||||
endpoints_to_test=REPORT_RESOURCES,
|
endpoints_to_test=REPORT_RESOURCES,
|
||||||
|
|
Loading…
Reference in New Issue