Skip to content

Commit

Permalink
refac: Parallelize instances deployment and destruction #1754
Browse files Browse the repository at this point in the history
  • Loading branch information
jmv74211 committed Aug 23, 2021
1 parent 0a49d21 commit 46e94c3
Showing 1 changed file with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Copyright (C) 2015-2021, Wazuh Inc.
# Created by Wazuh, Inc. <info@wazuh.com>.
# This program is free software; you can redistribute it and/or modify it under the terms of GPLv2
from wazuh_testing.qa_ctl.deployment.DockerWrapper import DockerWrapper
from wazuh_testing.qa_ctl.deployment.VagrantWrapper import VagrantWrapper
import ipaddress
import docker

from wazuh_testing.qa_ctl.deployment.DockerWrapper import DockerWrapper
from wazuh_testing.qa_ctl.deployment.VagrantWrapper import VagrantWrapper
from wazuh_testing.tools.thread_executor import ThreadExecutor


class QAInfraestructure:
"""Class to handle multiples instances objects.
Expand Down Expand Up @@ -87,23 +89,43 @@ def __init__(self, instance_list):

def run(self):
"""Execute the run method on every configured instance."""
for instance in self.instances:
instance.run()
runner_threads = [ThreadExecutor(instance.run) for instance in self.instances]

for runner_thread in runner_threads:
runner_thread.start()

for runner_thread in runner_threads:
runner_thread.join()

def halt(self):
"""Execute the 'halt' method on every configured instance."""
for instance in self.instances:
instance.halt()
runner_threads = [ThreadExecutor(instance.halt) for instance in self.instances]

for runner_thread in runner_threads:
runner_thread.start()

for runner_thread in runner_threads:
runner_thread.join()

def restart(self):
"""Execute the 'restart' method on every configured instance."""
for instance in self.instances:
instance.restart()
runner_threads = [ThreadExecutor(instance.restart) for instance in self.instances]

for runner_thread in runner_threads:
runner_thread.start()

for runner_thread in runner_threads:
runner_thread.join()

def destroy(self):
"""Execute the 'destroy' method on every configured instance."""
for instance in self.instances:
instance.destroy()
runner_threads = [ThreadExecutor(instance.destroy) for instance in self.instances]

for runner_thread in runner_threads:
runner_thread.start()

for runner_thread in runner_threads:
runner_thread.join()

if self.docker_network:
try:
Expand Down

0 comments on commit 46e94c3

Please sign in to comment.