diff --git a/virttest/env_process.py b/virttest/env_process.py index 3f1d7dd772..d1abcaffea 100644 --- a/virttest/env_process.py +++ b/virttest/env_process.py @@ -17,7 +17,7 @@ from avocado.core import exceptions from avocado.utils import archive from avocado.utils import cpu as cpu_utils -from avocado.utils import crypto, distro, path +from avocado.utils import crypto, path from avocado.utils import process as a_process from six.moves import xrange @@ -32,7 +32,6 @@ qemu_storage, storage, test_setup, - utils_iptables, utils_kernel_module, utils_libguestfs, utils_logfile, @@ -46,10 +45,13 @@ # lazy imports for dependencies that are not needed in all modes of use from virttest._wrappers import lazy_import -from virttest.staging import service from virttest.test_setup.core import SetupManager from virttest.test_setup.libvirt_setup import LibvirtdDebugLogConfig -from virttest.test_setup.networking import BridgeConfig, NetworkProxies +from virttest.test_setup.networking import ( + BridgeConfig, + FirewalldService, + NetworkProxies, +) from virttest.test_setup.os_posix import UlimitConfig from virttest.test_setup.storage import StorageConfig from virttest.utils_conn import SSHConnection @@ -1098,37 +1100,13 @@ def preprocess(test, params, env): _setup_manager.register(LibvirtdDebugLogConfig) _setup_manager.register(BridgeConfig) _setup_manager.register(StorageConfig) + _setup_manager.register(FirewalldService) _setup_manager.do_setup() vm_type = params.get("vm_type") base_dir = data_dir.get_data_dir() - firewalld_service = params.get("firewalld_service") - if firewalld_service == "disable": - firewalld = service.Service("firewalld") - if firewalld.status(): - firewalld.stop() - if firewalld.status(): - test.log.warning("Failed to stop firewalld") - else: - if firewalld_service == "enable": - firewalld = service.Service("firewalld") - if not firewalld.status(): - firewalld.start() - if not firewalld.status(): - test.log.warning("Failed to start firewalld") - - if distro.detect().name == "Ubuntu": - params["firewalld_dhcp_workaround"] = "no" - - # Workaround know issue where firewall blocks dhcp from guest - # through virbr0 - if params.get("firewalld_dhcp_workaround", "no") == "yes": - firewall_cmd = utils_iptables.Firewall_cmd() - if not firewall_cmd.add_service("dhcp", permanent=True): - test.log.warning("Failed to add dhcp service to be permitted") - # Start ip sniffing if it isn't already running # The fact it has to be started here is so that the test params # have to be honored. diff --git a/virttest/test_setup/networking.py b/virttest/test_setup/networking.py index 70fb878567..05a83fc15e 100644 --- a/virttest/test_setup/networking.py +++ b/virttest/test_setup/networking.py @@ -3,6 +3,10 @@ import re import urllib.request +from avocado.utils import distro + +from virttest import utils_iptables +from virttest.staging import service from virttest.test_setup import PrivateBridgeConfig, PrivateOvsBridgeConfig from virttest.test_setup.core import Setuper @@ -70,3 +74,34 @@ def cleanup(self): else: brcfg = PrivateBridgeConfig(params_pb) brcfg.cleanup() + + +class FirewalldService(Setuper): + def setup(self): + firewalld_service = self.params.get("firewalld_service") + if firewalld_service == "disable": + firewalld = service.Service("firewalld") + if firewalld.status(): + firewalld.stop() + if firewalld.status(): + self.test.log.warning("Failed to stop firewalld") + else: + if firewalld_service == "enable": + firewalld = service.Service("firewalld") + if not firewalld.status(): + firewalld.start() + if not firewalld.status(): + self.test.log.warning("Failed to start firewalld") + + if distro.detect().name == "Ubuntu": + self.params["firewalld_dhcp_workaround"] = "no" + + # Workaround know issue where firewall blocks dhcp from guest + # through virbr0 + if self.params.get("firewalld_dhcp_workaround", "no") == "yes": + firewall_cmd = utils_iptables.Firewall_cmd() + if not firewall_cmd.add_service("dhcp", permanent=True): + self.test.log.warning("Failed to add dhcp service to be permitted") + + def cleanup(self): + pass