@@ -57,16 +57,9 @@ redirs = remote_shell
guest_port_remote_shell = 22
# NIC parameters
-#nic_mode = user
nic_mode = tap
-bridge = private
-# You can set bridge to
-# be a specific bridge
-# name, such as 'virbr0'
-#bridge = virbr0
-# If you need more ports to be available for comm between host and guest,
-# please add them here
-priv_bridge_ports = 53 67
+# By default we use libvirt's bridge
+bridge = virbr0
run_tcpdump = yes
# Misc
@@ -617,7 +617,6 @@ class VM(virt_vm.BaseVM):
@raise TAPCreationError: If fail to create tap fd
@raise BRAddIfError: If fail to add a tap to a bridge
@raise TAPBringUpError: If fail to bring up a tap
- @raise PrivateBridgeError: If fail to bring the private bridge
"""
error.context("creating '%s'" % self.name)
self.destroy(free_mac_addresses=False)
@@ -692,8 +691,6 @@ class VM(virt_vm.BaseVM):
if nic_params.get("nic_mode") == "tap":
ifname = self.get_ifname(vlan)
brname = nic_params.get("bridge")
- if brname == "private":
- brname = virt_test_setup.PrivateBridgeConfig().brname
tapfd = virt_utils.open_tap("/dev/net/tun", ifname)
virt_utils.add_to_bridge(ifname, brname)
virt_utils.bring_up_ifname(ifname)
@@ -205,10 +205,6 @@ def preprocess(test, params, env):
"""
error.context("preprocessing")
- if params.get("bridge") == "private":
- brcfg = virt_test_setup.PrivateBridgeConfig(params)
- brcfg.setup()
-
# Start tcpdump if it isn't already running
if "address_cache" not in env:
env["address_cache"] = {}
@@ -375,10 +371,6 @@ def postprocess(test, params, env):
int(params.get("post_command_timeout", "600")),
params.get("post_command_noncritical") == "yes")
- if params.get("bridge") == "private":
- brcfg = virt_test_setup.PrivateBridgeConfig()
- brcfg.cleanup()
-
def postprocess_on_error(test, params, env):
"""
@@ -289,189 +289,3 @@ class HugePageConfig(object):
return
utils.system("echo 0 > %s" % self.kernel_hp_file)
logging.debug("Hugepage memory successfuly dealocated")
-
-
-class PrivateBridgeError(Exception):
- def __init__(self, brname):
- self.brname = brname
-
- def __str__(self):
- return "Bridge %s not available after setup" % self.brname
-
-
-class PrivateBridgeConfig(object):
- __shared_state = {}
- def __init__(self, params=None):
- self.__dict__ = self.__shared_state
- if params is not None:
- self.brname = params.get("priv_brname", 'atbr0')
- self.subnet = params.get("priv_subnet", '192.168.58')
- self.ip_version = params.get("bridge_ip_version", "ipv4")
- self.dhcp_server_pid = None
- ports = params.get("priv_bridge_ports", '53 67').split()
- s_port = params.get("guest_port_remote_shell", "10022")
- if s_port not in ports:
- ports.append(s_port)
- ft_port = params.get("guest_port_file_transfer", "10023")
- if ft_port not in ports:
- ports.append(ft_port)
- u_port = params.get("guest_port_unattended_install", "13323")
- if u_port not in ports:
- ports.append(u_port)
- self.iptables_rules = self._assemble_iptables_rules(ports)
-
-
- def _assemble_iptables_rules(self, port_list):
- rules = []
- index = 0
- for port in port_list:
- index += 1
- rules.append("INPUT %s -i %s -p tcp -m tcp --dport %s -j ACCEPT" %
- (index, self.brname, port))
- index += 1
- rules.append("INPUT %s -i %s -p udp -m udp --dport %s -j ACCEPT" %
- (index, self.brname, port))
- rules.append("FORWARD 1 -m physdev --physdev-is-bridged -j ACCEPT")
- rules.append("FORWARD 2 -d %s.0/24 -o %s -m state "
- "--state RELATED,ESTABLISHED -j ACCEPT" %
- (self.subnet, self.brname))
- rules.append("FORWARD 3 -s %s.0/24 -i %s -j ACCEPT" %
- (self.subnet, self.brname))
- rules.append("FORWARD 4 -i %s -o %s -j ACCEPT" %
- (self.brname, self.brname))
- return rules
-
-
- def _add_bridge(self):
- utils.system("brctl addbr %s" % self.brname)
- ip_fwd_path = "/proc/sys/net/%s/ip_forward" % self.ip_version
- ip_fwd = open(ip_fwd_path, "w")
- ip_fwd.write("1\n")
- utils.system("brctl stp %s on" % self.brname)
- utils.system("brctl setfd %s 0" % self.brname)
-
-
- def _bring_bridge_up(self):
- utils.system("ifconfig %s %s.1 up" % (self.brname, self.subnet))
-
-
- def _iptables_add(self, cmd):
- return utils.system("iptables -I %s" % cmd)
-
-
- def _iptables_del(self, cmd):
- return utils.system("iptables -D %s" % cmd)
-
-
- def _enable_nat(self):
- for rule in self.iptables_rules:
- self._iptables_add(rule)
-
-
- def _start_dhcp_server(self):
- utils.run("service dnsmasq stop")
- utils.run("dnsmasq --strict-order --bind-interfaces "
- "--listen-address %s.1 --dhcp-range %s.2,%s.254 "
- "--dhcp-lease-max=253 "
- "--dhcp-no-override "
- "--pid-file=/tmp/dnsmasq.pid "
- "--log-facility=/tmp/dnsmasq.log" %
- (self.subnet, self.subnet, self.subnet))
- self.dhcp_server_pid = None
- try:
- self.dhcp_server_pid = int(open('/tmp/dnsmasq.pid', 'r').read())
- except ValueError:
- raise PrivateBridgeError(self.brname)
- logging.debug("Started internal DHCP server with PID %s",
- self.dhcp_server_pid)
-
-
- def _verify_bridge(self):
- brctl_output = utils.system_output("brctl show")
- if self.brname not in brctl_output:
- raise PrivateBridgeError(self.brname)
-
-
- def setup(self):
- brctl_output = utils.system_output("brctl show")
- if self.brname not in brctl_output:
- logging.debug("Configuring KVM test private bridge %s", self.brname)
- try:
- self._add_bridge()
- except:
- self._remove_bridge()
- raise
- try:
- self._bring_bridge_up()
- except:
- self._bring_bridge_down()
- self._remove_bridge()
- raise
- try:
- self._enable_nat()
- except:
- self._disable_nat()
- self._bring_bridge_down()
- self._remove_bridge()
- raise
- try:
- self._start_dhcp_server()
- except:
- self._stop_dhcp_server()
- self._disable_nat()
- self._bring_bridge_down()
- self._remove_bridge()
- raise
- self._verify_bridge()
-
-
- def _stop_dhcp_server(self):
- if self.dhcp_server_pid is not None:
- try:
- os.kill(self.dhcp_server_pid, 15)
- except OSError:
- pass
- else:
- try:
- dhcp_server_pid = int(open('/tmp/dnsmasq.pid', 'r').read())
- except ValueError:
- return
- try:
- os.kill(dhcp_server_pid, 15)
- except OSError:
- pass
-
-
- def _bring_bridge_down(self):
- utils.system("ifconfig %s down" % self.brname, ignore_status=True)
-
-
- def _disable_nat(self):
- for rule in self.iptables_rules:
- split_list = rule.split(' ')
- # We need to remove numbering here
- split_list.pop(1)
- rule = " ".join(split_list)
- self._iptables_del(rule)
-
-
- def _remove_bridge(self):
- utils.system("brctl delbr %s" % self.brname, ignore_status=True)
-
-
- def cleanup(self):
- brctl_output = utils.system_output("brctl show")
- cleanup = False
- for line in brctl_output.split("\n"):
- if line.startswith(self.brname):
- # len == 4 means there is a TAP using the bridge
- # so don't try to clean it up
- if len(line.split()) < 4:
- cleanup = True
- break
- if cleanup:
- logging.debug("Cleaning up KVM test private bridge %s", self.brname)
- self._stop_dhcp_server()
- self._disable_nat()
- self._bring_bridge_down()
- self._remove_bridge()
Since we already require some deps to run KVM autotest, and since the majority of the potential KVM autotest users do have libvirt installed and running, it makes little sense to maintain custom code to manage an internal bridge. Let's just require libvirt and use virbr0 as the default kvm autotest virt bridge. It's functional, available and allows to do everything we want. CC: Cleber Rosa <cleber@redhat.com> CC: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com> --- client/tests/kvm/tests_base.cfg.sample | 11 +-- client/virt/kvm_vm.py | 3 - client/virt/virt_env_process.py | 8 -- client/virt/virt_test_setup.py | 186 -------------------------------- 4 files changed, 2 insertions(+), 206 deletions(-)