File: check-networkmanager-settings

package info (click to toggle)
cockpit 358-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 317,272 kB
  • sloc: javascript: 775,788; python: 41,626; ansic: 33,970; cpp: 11,141; sh: 3,566; makefile: 581; xml: 262
file content (290 lines) | stat: -rwxr-xr-x 13,567 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)

#
# Copyright (C) 2013 Red Hat, Inc.
# SPDX-License-Identifier: LGPL-2.1-or-later


import netlib
import testlib
from lib.constants import TEST_OS_DEFAULT


class TestNetworkingSettings(netlib.NetworkCase):
    provision = {
        "machine1": {},
        "machine2": {"image": TEST_OS_DEFAULT, "address": "10.111.113.2/20", "dhcp": True}
    }

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

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

        iface = self.add_iface(activate=False)
        self.wait_for_iface(iface, active=False)
        # checkpoints are realtime sensitive, avoid long NM operations
        self.settle_cpu()

        self.select_iface(iface)
        b.wait_visible("#network-interface")

        # Check that there is no connection for the device
        cons = m.execute(f"nmcli -t -m tabular -f CONNECTIONS.AVAILABLE-CONNECTION-PATHS dev show {iface}")
        self.assertEqual(cons.strip(), "")

        # Edit and apply the ghost settings
        self.configure_iface_setting('IPv4')
        b.wait_visible("#network-ip-settings-dialog")
        b.select_from_dropdown("#network-ip-settings-select-method", "manual")
        b.set_input_text('#network-ip-settings-address-0', "1.2.3.4")
        b.set_input_text('#network-ip-settings-netmask-0', "24")
        b.click("#network-ip-settings-save")
        b.wait_not_present("#network-ip-settings-dialog")
        self.wait_for_iface_setting('IPv4', 'Address 1.2.3.4/24')

        def assert_connection_setting(con_id, field, value):
            self.assertEqual(m.execute(f'nmcli -m tabular -t -f {field} con show "{con_id}"').strip(),
                             value)

        # Check that we now have connection settings
        con_id = testlib.wait(lambda: self.iface_con_id(iface))
        assert_connection_setting(con_id, "ipv4.method", "manual")

        # The interface will be activated. Deactivate it.
        self.wait_for_iface_setting('Status', '1.2.3.4/24')
        self.toggle_onoff("label[for='interface-switch']")
        self.wait_for_iface_setting('Status', 'Inactive')

        # Delete the connection settings again and wait for the ghost
        # settings to be re-created.
        m.execute(f'nmcli con del "{con_id}"')
        self.wait_for_iface_setting('IPv4', 'Automatic')

        # Activate with ghost settings
        self.toggle_onoff("label[for='interface-switch']")
        self.wait_for_iface_setting('Status', '10.111.')

        # Check again that we now have connection settings
        con_id = testlib.wait(lambda: self.iface_con_id(iface))
        assert_connection_setting(con_id, "ipv4.method", "auto")

        # Change some more settings and check that the actual config
        # and dialog reflects the change

        self.configure_iface_setting('IPv4')
        b.wait_visible("#network-ip-settings-dialog")
        self.wait_onoff("[data-field=dns]", val=True)
        self.toggle_onoff("[data-field=dns]")
        self.wait_onoff("[data-field=dns_search]", val=False)
        b.click("#network-ip-settings-dns-add")
        b.set_input_text("#network-ip-settings-dns-server-0", "1.2.3.4")
        b.click("#network-ip-settings-dns-search-add")
        b.set_input_text("#network-ip-settings-search-domain-0", "foo.com")
        b.click("#network-ip-settings-save")
        b.wait_not_present("#network-ip-settings-dialog")

        assert_connection_setting(con_id, "ipv4.ignore-auto-dns", "yes")
        assert_connection_setting(con_id, "ipv4.dns", "1.2.3.4")
        assert_connection_setting(con_id, "ipv4.dns-search", "foo.com")

        self.configure_iface_setting('IPv4')
        self.wait_onoff("[data-field=dns]", val=False)
        self.wait_onoff("[data-field=dns_search]", val=False)
        b.wait_val("#network-ip-settings-dns-server-0", "1.2.3.4")
        b.wait_val("#network-ip-settings-search-domain-0", "foo.com")
        b.click("#network-ip-settings-cancel")
        b.wait_not_present("#network-ip-settings-dialog")

        self.configure_iface_setting('IPv6')
        b.wait_visible("#network-ip-settings-dialog")
        b.select_from_dropdown("#network-ip-settings-select-method", "disabled")
        b.click("#network-ip-settings-save")
        b.wait_not_present("#network-ip-settings-dialog")

        assert_connection_setting(con_id, "ipv6.method", "disabled")

        # Open the dialog, expand all the fields and assert pixels
        self.configure_iface_setting("IPv4")
        b.click("#network-ip-settings-address-add")
        b.click("#network-ip-settings-route-add")
        b.click("#network-ip-settings-dns-add")
        b.click("#network-ip-settings-dns-search-add")
        b.assert_pixels("#network-ip-settings-dialog", "network-ip-settings-dialog")

        # Check that IPv4/IPv6 settings dialogs only show the supported IP methods for wireguard
        # Skip images without the wireguard-tools package
        if m.image not in ["centos-10"] and not m.image.startswith("rhel-8"):
            b.go("/network")
            b.click("#networking-add-wg")
            b.set_input_text("#network-wireguard-settings-addresses-input", "1.2.3.4/24")
            wg_iface = b.val("#network-wireguard-settings-interface-name-input")
            b.click("#network-wireguard-settings-save")
            self.select_iface(wg_iface)
            self.configure_iface_setting("IPv4")
            b._wait_present("#network-ip-settings-select-method option[value='manual']")
            b._wait_present("#network-ip-settings-select-method option[value='disabled']")
            unsupported_ip4_methods = ['auto', 'dhcp', 'link-local', 'ignore', 'shared']
            for method in unsupported_ip4_methods:
                b.wait_not_present(f"#network-ip-settings-select-method option[value='{method}']")
            b.click("#network-ip-settings-cancel")
            b.wait_not_present("#network-ip-settings-dialog")
            self.configure_iface_setting("IPv6")
            supported_ip6_methods = ['link-local', 'manual', 'disabled']
            for method in supported_ip6_methods:
                b._wait_present(f"#network-ip-settings-select-method option[value='{method}']")
            unsupported_ip6_methods = ['auto', 'dhcp', 'ignore', 'shared']
            for method in unsupported_ip6_methods:
                b.wait_not_present(f"#network-ip-settings-select-method option[value='{method}']")

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

        iface = self.add_iface()
        con_id = self.iface_con_id(iface)
        m.execute(f"nmcli con mod '{con_id}' connection.gateway-ping-timeout 12")

        self.login_and_go("/network")
        self.wait_for_iface(iface)

        # IPv4 address sharing

        self.select_iface(iface)
        b.wait_visible("#network-interface")

        self.configure_iface_setting('IPv4')
        b.wait_visible("#network-ip-settings-dialog")
        b.select_from_dropdown("#network-ip-settings-select-method", "shared")
        b.click("#network-ip-settings-save")
        b.wait_not_present("#network-ip-settings-dialog")

        self.assertEqual(m.execute(f"nmcli -m tabular -t -f ipv4.method con show '{con_id}'").strip(),
                         "shared")
        self.assertEqual(m.execute(f"nmcli -m tabular -t -f connection.gateway-ping-timeout con show '{con_id}'").strip(),
                         "12")

        # IPv6 route

        # by default there's a route to link-local only (fe80::)
        show_cmd = f"ip -6 route show dev {iface}"
        testlib.wait(lambda: "fe80::/64" in m.execute(show_cmd))
        # add a manual one
        self.configure_iface_setting('IPv6')
        b.wait_visible("#network-ip-settings-dialog")
        b.click('#network-ip-settings-route-add')
        b.set_input_text('#network-ip-settings-route-address-0', "fe80:2::")
        b.set_input_text('#network-ip-settings-route-netmask-0', "60")
        b.set_input_text('#network-ip-settings-route-gateway-0', "fe80:2::3")
        b.set_input_text('#network-ip-settings-route-metric-0', "42")
        b.click('#network-ip-settings-save')
        b.wait_not_present("#network-ip-settings-dialog")

        # setting should be applied
        testlib.wait(lambda: "metric 42" in m.execute(show_cmd))
        out = m.execute(show_cmd)
        self.assertIn("fe80:2::/60 via fe80:2::3 proto static metric 42", out)
        self.assertIn("fe80:2::3 proto static metric 42", out)
        # original link-local route still exists
        self.assertIn("fe80::/64", out)

        b.wait_attr("#network-interface", "data-test-wait", "false")

        # dialog prefills fields with current settings
        self.configure_iface_setting('IPv6')
        b.wait_visible("#network-ip-settings-dialog")

        b.wait_val('#network-ip-settings-route-address-0', "fe80:2::")
        b.wait_val('#network-ip-settings-route-netmask-0', "60")
        b.wait_val('#network-ip-settings-route-gateway-0', "fe80:2::3")
        b.wait_val('#network-ip-settings-route-metric-0', "42")
        b.click('#network-ip-settings-cancel')
        b.wait_not_present("#network-ip-settings-dialog")

        # Test editing connection without a hardcoded interface
        iface = self.add_iface(activate=False)
        con_name = "cockpit-test-con"
        b.go("/network")
        b.wait_visible("#networking")

        m.execute(f"""
            nmcli con add con-name {con_name} connection.type 802-3-ethernet connection.autoconnect no \
                ipv4.meth auto ipv6.meth auto ipv6.addr-gen-mode eui64
            nmcli con sh | grep -q '{con_name}'
            nmcli con up {con_name} ifname {iface}
            # check that no connection.interface-name is configured
            [ -z "$(nmcli --get connection.interface-name con sh {con_name})" ]
        """)
        self.addCleanup(m.execute, f"nmcli con del {con_name}")

        self.select_iface(iface)
        b.wait_visible("#network-interface")
        self.configure_iface_setting('IPv4')
        b.click("#network-ip-settings-dns-add")
        b.set_input_text('#network-ip-settings-dns-server-0', "8.8.8.8")
        b.click("#network-ip-settings-save")
        # page should still display interface detail page after saving
        b.wait_visible("#network-interface")
        self.wait_for_iface_setting("IPv4", "AutomaticAdditional DNS 8.8.8.8")

        # Test multiconnect connection
        b.go("/network")
        b.wait_visible("#networking")
        iface1 = self.add_iface(activate=False)
        iface2 = self.add_iface(activate=False)
        # add temporary connections with multiconnect enabled
        m.execute(f"""
            nmcli con add con-name 'Wired Connection' save no connection.type 802-3-ethernet \
                connection.autoconnect no connection.multi-connect multiple \
                ipv4.meth auto ipv6.meth auto ipv6.addr-gen-mode eui64
            nmcli con sh | grep -q 'Wired Connection'

            for IFACE in {iface1} {iface2}; do
                nmcli con up 'Wired Connection' ifname ${{IFACE}}
            done
        """)

        # Edit interface with nonpersistent Wired Connection active
        self.select_iface(iface1)
        b.wait_visible("#network-interface")
        self.configure_iface_setting('IPv4')
        b.select_from_dropdown("#network-ip-settings-select-method", "manual")
        b.set_input_text('#network-ip-settings-address-0', "10.11.12.13")
        b.set_input_text('#network-ip-settings-netmask-0', "24")
        b.click("#network-ip-settings-dns-add")
        b.set_input_text('#network-ip-settings-dns-server-0', "8.8.8.8")
        b.click("#network-ip-settings-save")
        b.wait_not_present("#network-ip-settings-dialog")
        self.wait_for_iface_setting("IPv4", "Address 10.11.12.13/24Gateway 10.11.12.1DNS 8.8.8.8")
        # Check that new connection exists and is applied to the interface
        self.assertEqual(m.execute(f"nmcli --get connection.interface-name,connection.multi-connect,ipv4.addresses,ipv4.dns con sh {iface1}"),
                         f"{iface1}\n0\n10.11.12.13/24\n8.8.8.8\n")
        # Wired Connection is unmodified
        self.assertEqual(m.execute("nmcli --get ipv4.method con sh 'Wired Connection'"), "auto\n")

        # Further edits will edit the new connection
        self.configure_iface_setting('IPv4')
        b.set_input_text('#network-ip-settings-dns-server-0', "1.1.1.1")
        b.click("#network-ip-settings-save")
        b.wait_not_present("#network-ip-settings-dialog")
        self.wait_for_iface_setting("IPv4", "Address 10.11.12.13/24Gateway 10.11.12.1DNS 1.1.1.1")
        m.execute(f'[ $(nmcli --get ipv4.dns con sh {iface1}) == "1.1.1.1" ]')

        # Editing auto-connect also creates new connection when necessary
        b.go("/network")
        b.wait_visible("#networking")
        self.select_iface(iface2)
        b.wait_visible("#network-interface")
        b.wait_visible('#autoreconnect:not(:checked)')
        b.set_checked('#autoreconnect', val=True)
        b.wait_visible('#autoreconnect:checked')
        # Check that new connection exists and autoconnect is enabled
        self.assertEqual(
            m.execute(f"nmcli --get connection.interface-name,connection.autoconnect,connection.multi-connect con sh {iface2}"),
                        f"{iface2}\nyes\n0\n")


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