File: check-networkmanager-bridge

package info (click to toggle)
cockpit 337-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 36,232 kB
  • sloc: javascript: 47,090; python: 38,766; ansic: 35,470; xml: 6,048; sh: 3,413; makefile: 614
file content (124 lines) | stat: -rwxr-xr-x 5,762 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)

# This file is part of Cockpit.
#
# Copyright (C) 2013 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <https://www.gnu.org/licenses/>.

import netlib
import testlib


@testlib.nondestructive
class TestBridge(netlib.NetworkCase):
    def testBasic(self):
        b = self.browser

        self.login_and_go("/network")
        b.wait_visible("#networking")

        # These are two independent networks. Thus there is no loop between the
        # bridge that all VMs are connected to, and the bridge we are creating here.
        iface1 = "cockpit1"
        self.add_veth(iface1, dhcp_cidr="10.111.113.1/24", dhcp_range=['10.111.113.2', '10.111.113.254'])
        self.nm_activate_eth(iface1)
        iface2 = "cockpit2"
        self.add_veth(iface2, dhcp_cidr="10.111.114.1/24", dhcp_range=['10.111.114.2', '10.111.114.254'])
        self.nm_activate_eth(iface2)
        self.wait_for_iface(iface1)
        self.wait_for_iface(iface2)

        # Bridge them
        b.click("button:contains('Add bridge')")
        b.wait_visible("#network-bridge-settings-dialog")

        # wait until dialog initialized
        b.wait_visible("#network-bridge-settings-dialog button[aria-label=Close]")
        b.wait_in_text("#network-bridge-settings-body", "cockpit2")
        b.assert_pixels("#network-bridge-settings-dialog", "networking-bridge-settings-dialog")

        b.set_input_text("#network-bridge-settings-interface-name-input", "tbridge")
        b.set_checked(f"input[data-iface='{iface1}']", val=True)
        b.set_checked(f"input[data-iface='{iface2}']", val=True)
        b.click("#network-bridge-settings-dialog button:contains('Add')")
        b.wait_not_present("#network-bridge-settings-dialog")
        b.wait_visible("#networking-interfaces tr[data-interface='tbridge']")

        # Check that the members are displayed and both On
        b.click("#networking-interfaces tr[data-interface='tbridge'] button")
        b.wait_visible("#network-interface")
        self.wait_onoff(f"#network-interface-members tr[data-interface='{iface1}']", val=True)
        self.wait_onoff(f"#network-interface-members tr[data-interface='{iface2}']", val=True)

        b.wait_text_not("#network-interface-mac", "")
        self.configure_iface_setting('Bridge')
        b.click("#network-bridge-settings-dialog button:contains('Cancel')")
        b.wait_not_present("#network-bridge-settings-dialog")

        # Delete the bridge
        b.click("#network-interface button:contains('Delete')")
        b.wait_visible("#networking")
        b.wait_not_present("#networking-interfaces tr[data-interface='tbridge']")

        # Check that the former members are displayed and both On
        self.wait_for_iface(iface1)
        self.wait_for_iface(iface2)

    def testActive(self):
        b = self.browser
        m = self.machine

        self.login_and_go("/network")
        b.wait_visible("#networking")

        iface = "cockpit1"
        self.add_veth(iface, dhcp_cidr="10.111.112.2/20")
        self.nm_activate_eth(iface)
        self.wait_for_iface(iface)

        # Put an active interface into a bridge. We can't select/copy the MAC, so we can't expect to
        # get the same IP as the active interface, but it should get a valid DHCP IP.

        b.click("button:contains('Add bridge')")
        b.wait_visible("#network-bridge-settings-dialog")
        b.set_input_text("#network-bridge-settings-interface-name-input", "tbridge")
        b.set_checked(f"input[data-iface='{iface}']", val=True)
        b.click("#network-bridge-settings-dialog button:contains('Add')")
        b.wait_not_present("#network-bridge-settings-dialog")

        # Check that it has the interface and the right IP address
        b.click("#networking-interfaces tr[data-interface='tbridge'] th button")
        b.wait_visible("#network-interface")
        b.wait_visible(f"#network-interface-members tr[data-interface='{iface}']")
        b.wait_in_text("#network-interface .pf-v6-c-card:contains('tbridge')", "10.111")

        # Check bridge port
        b.click("#network-interface-members button:contains(cockpit1)")
        b.click("#networking-edit-bridgeport")
        b.wait_visible("#network-bridge-port-settings-dialog")
        b.set_input_text("#network-bridge-port-settings-prio-input", "35")
        b.set_input_text("#network-bridge-port-settings-path-cost-input", "90")
        b.set_checked("#network-bridge-port-settings-hairPin-mode-input", val=True)
        b.click("#network-bridge-port-settings-save")
        b.wait_not_present("#network-bridge-port-settings-dialog")

        # Confirm that bridge port settings are applied
        self.assertEqual(m.execute("nmcli con show cockpit1 | grep -i bridge-port.priority | awk '{print $2}'").strip(), "35")
        self.assertEqual(m.execute("nmcli con show cockpit1 | grep -i bridge-port.path-cost | awk '{print $2}'").strip(), "90")
        self.assertEqual(m.execute("nmcli con show cockpit1 | grep -i bridge-port.hairpin-mode | awk '{print $2}'").strip(), "yes")


if __name__ == '__main__':
    testlib.test_main()