Debian Codegraph @

test/verify/check-networkmanager-checkpoints

raw
1 #!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)
2
3 #
4 # Copyright (C) 2013 Red Hat, Inc.
5 # SPDX-License-Identifier: LGPL-2.1-or-later
6
7
8 import re
9
10 import netlib
11 import testlib
12
13
14 @testlib.skipImage("No network checkpoint support", "ubuntu-*")
15 @testlib.nondestructive
16 class TestNetworkingCheckpoints(netlib.NetworkCase):
17 def testCheckpoint(self):
18 b = self.browser
19 m = self.machine
20
21 iface = self.get_iface("52:54:00:12:34:56")
22
23 if "debian" in m.image:
24 self.sed_file("s/managed=false/managed=true/", "/etc/NetworkManager/NetworkManager.conf",
25 "systemctl restart NetworkManager")
26
27 if m.image == "arch":
28 self.sed_file("s/unmanaged-devices=interface-name:eth0//", "/etc/NetworkManager/conf.d/noauto.conf",
29 "systemctl restart NetworkManager")
30
31 self.login_and_go("/network")
32 self.nm_checkpoints_enable()
33 self.wait_for_iface(iface, prefix="172.")
34 self.select_iface(iface)
35 b.wait_visible("#network-interface")
36
37 # Disconnect
38 self.wait_onoff("label[for='interface-switch']", val=True)
39 self.toggle_onoff("label[for='interface-switch']")
40
41 # Wait for dialog to appear and dismiss it
42 with b.wait_timeout(60):
43 b.click("#confirm-breaking-change-popup button:contains('Keep connection')")
44 b.wait_not_present("#confirm-breaking-change-popup")
45
46 # Change IP
47 self.configure_iface_setting('IPv4')
48 b.wait_visible("#network-ip-settings-dialog")
49 b.select_from_dropdown("#network-ip-settings-select-method", "manual")
50 b.set_input_text('#network-ip-settings-address-0', "1.2.3.4")
51 b.set_input_text('#network-ip-settings-netmask-0', "24")
52 b.click("#network-ip-settings-save")
53 with b.wait_timeout(60):
54 b.click("#confirm-breaking-change-popup button:contains('Keep connection')")
55 b.wait_not_present("#confirm-breaking-change-popup")
56
57 @testlib.skipImage("Main interface settings are read-only", "debian-*")
58 @testlib.skipImage("no dhclient on OS image", "arch", "centos-10*", "rhel-10*")
59 @testlib.skipOstree("not using dhclient")
60 def testCheckpointSlowRollback(self):
61 b = self.browser
62 m = self.machine
63
64 # A slow rollback would normally cause the global health check
65 # to fail during rollback and prevent showing the
66 # #confirm-breaking-change-popup. We expect the global health
67 # check failure to be ignored.
68 #
69 # We test slow rollbacks by slowing down DHCP requests.
70 #
71 # We need at least 60 seconds of network disconnection to let
72 # the health check fail reliably. A rollback is started 7
73 # seconds after disconnection, so we need to delay the DHCP
74 # request by at least 53 seconds. However, NetworkManager has
75 # a default DHCP timeout of 45 seconds, so we need to increase
76 # that.
77 #
78 # Sometimes, NetworkManager extends the DHCP timeout by an
79 # additional 480 seconds grace period. This doesn't always
80 # happen, so we don't rely on it.
81
82 dhcp_delay = 60
83 dhcp_timeout = 120
84
85 # There are a couple of considerations for ordering the
86 # following actions:
87 #
88 # - Changing the main.dhcp config value requires a restart of NM.
89 #
90 # - A restart of NM might run dhclient, and we don't want it
91 # to be slowed down already at that point.
92 #
93 # - After restarting NM, we need to wait for it to settle
94 # again before messing with dhclient.
95 #
96 # - Simply setting ipv4.dhcp_timeout is not enough if it
97 # should be used immediately for a checkpoint rollback, see
98 # https://bugzilla.redhat.com/show_bug.cgi?id=1690389. A
99 # additional restart is enough.
100 #
101 # So we set ipv4.dhcp_timeout and main.dhcp, do a restart, log
102 # into the UI and wait for the expected interface to appear
103 # and be active, and then slow down dhclient.
104
105 iface = self.get_iface("52:54:00:12:34:56")
106 con_id = self.iface_con_id(iface)
107 m.execute(f'nmcli con mod "{con_id}" ipv4.dhcp-timeout {dhcp_timeout}')
108
109 self.ensure_nm_uses_dhclient()
110
111 self.login_and_go("/network")
112 self.nm_checkpoints_enable()
113 self.wait_for_iface(iface, prefix="172.")
114 self.select_iface(iface)
115 b.wait_visible("#network-interface")
116
117 # checkpoints are realtime sensitive, avoid long NM operations
118 self.settle_cpu()
119
120 self.slow_down_dhclient(dhcp_delay)
121
122 # Disconnect and trigger a slow rollback
123 self.wait_onoff("label[for='interface-switch']", val=True)
124 self.toggle_onoff("label[for='interface-switch']")
125 with b.wait_timeout(120):
126 b.click("#confirm-breaking-change-popup button:contains('Keep connection')")
127 b.wait_not_present("#confirm-breaking-change-popup")
128
129 def testNoRollback(self):
130 b = self.browser
131 m = self.machine
132
133 self.login_and_go("/network")
134 self.nm_checkpoints_enable()
135 b.wait_visible("#networking")
136
137 iface = 'cockpit1'
138 self.add_veth(iface, dhcp_cidr="10.111.113.2/20")
139 self.nm_activate_eth(iface)
140 self.wait_for_iface(iface)
141
142 self.select_iface(iface)
143 b.wait_visible("#network-interface")
144
145 # Disconnect
146 self.wait_onoff("label[for='interface-switch']", val=True)
147 self.toggle_onoff("label[for='interface-switch']")
148
149 # The checkpoint should be destroyed before it is being rolled
150 # back.
151
152 def checkpoint_was_destroyed():
153 lines = m.execute("journalctl -u NetworkManager | grep op=").split("\n")
154 last_checkpoint = None
155 for line in lines:
156 match = re.search(r'op="checkpoint-create" arg="([^"]*)"', line)
157 if match:
158 last_checkpoint = match[1]
159 if last_checkpoint:
160 for line in lines:
161 if f'op="checkpoint-destroy" arg="{last_checkpoint}"' in line:
162 return True
163 return False
164
165 testlib.wait(checkpoint_was_destroyed)
166
167 def testCheckpointSessionStorageEventSuccess(self):
168 b = self.browser
169
170 self.login_and_go("/network")
171 self.nm_checkpoints_enable()
172 b.wait_visible("#networking")
173
174 iface = 'cockpit1'
175 self.add_veth(iface, dhcp_cidr="10.111.114.2/20")
176 self.nm_activate_eth(iface)
177 self.wait_for_iface(iface)
178
179 self.select_iface(iface)
180 b.wait_visible("#network-interface")
181
182 # Verify sessionStorage is initially false or not set
183 initial_value = b.call_js_func("window.sessionStorage.getItem", "cockpit_has_checkpoint")
184 self.assertIn(initial_value, [None, "false"])
185
186 # Change IP settings which will trigger a checkpoint
187 self.configure_iface_setting('IPv4')
188 b.wait_visible("#network-ip-settings-dialog")
189 b.select_from_dropdown("#network-ip-settings-select-method", "manual")
190 b.set_input_text('#network-ip-settings-address-0', "10.111.114.100")
191 b.set_input_text('#network-ip-settings-netmask-0', "20")
192
193 # Click save, which triggers checkpoint creation
194 b.click("#network-ip-settings-save")
195
196 # Verify sessionStorage becomes true during checkpoint operation
197 def checkpoint_active():
198 value = b.call_js_func("window.sessionStorage.getItem", "cockpit_has_checkpoint")
199 return value == "true"
200
201 testlib.wait(checkpoint_active)
202
203 # Wait for operation to complete and sessionStorage to be cleared
204 def checkpoint_cleared():
205 value = b.call_js_func("window.sessionStorage.getItem", "cockpit_has_checkpoint")
206 return value == "false"
207
208 testlib.wait(checkpoint_cleared)
209
210 def testCheckpointSessionStorageEventRollback(self):
211 b = self.browser
212 m = self.machine
213
214 self.login_and_go("/network")
215 self.nm_checkpoints_enable()
216 b.wait_visible("#networking")
217
218 iface = self.get_iface("52:54:00:12:34:56")
219
220 if "debian" in m.image:
221 self.sed_file("s/managed=false/managed=true/", "/etc/NetworkManager/NetworkManager.conf",
222 "systemctl restart NetworkManager")
223
224 if m.image == "arch":
225 self.sed_file("s/unmanaged-devices=interface-name:eth0//", "/etc/NetworkManager/conf.d/noauto.conf",
226 "systemctl restart NetworkManager")
227
228 self.wait_for_iface(iface, prefix="172.")
229 self.select_iface(iface)
230 b.wait_visible("#network-interface")
231
232 # Verify sessionStorage is initially false or not set
233 initial_value = b.call_js_func("window.sessionStorage.getItem", "cockpit_has_checkpoint")
234 self.assertIn(initial_value, [None, "false"])
235
236 # Disconnect interface which will trigger checkpoint and should cause rollback dialog
237 self.wait_onoff("label[for='interface-switch']", val=True)
238 self.toggle_onoff("label[for='interface-switch']")
239
240 # Verify sessionStorage becomes true during checkpoint operation
241 def checkpoint_active():
242 value = b.call_js_func("window.sessionStorage.getItem", "cockpit_has_checkpoint")
243 return value == "true"
244
245 testlib.wait(checkpoint_active)
246
247 # Wait for dialog to appear (this happens when checkpoint_destroy fails)
248 with b.wait_timeout(60):
249 b.wait_visible("#confirm-breaking-change-popup")
250
251 # By the time dialog is visible, sessionStorage should already be cleared
252 checkpoint_cleared_value = b.call_js_func("window.sessionStorage.getItem", "cockpit_has_checkpoint")
253 self.assertEqual(checkpoint_cleared_value, "false")
254
255 # Keep the connection (rollback)
256 b.click("#confirm-breaking-change-popup button:contains('Keep connection')")
257
258 b.wait_not_present("#confirm-breaking-change-popup")
259
260
261 if __name__ == '__main__':
262 testlib.test_main()