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
|
#!/usr/bin/python3
# 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 <http://www.gnu.org/licenses/>.
import parent
from netlib import *
from testlib import *
from machine_core.constants import TEST_OS_DEFAULT
@skipImage("Do not test BaseOS packages", "rhel-8-3-distropkg", "rhel-8-4-distropkg")
class TestNetworkingSettings(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("nmcli -t -m tabular -f CONNECTIONS.AVAILABLE-CONNECTION-PATHS dev show %s" % iface)
self.assertEqual(cons.strip(), "")
# Edit and apply the ghost settings
self.configure_iface_setting('IPv4')
b.wait_popup("network-ip-settings-dialog")
b.select_from_dropdown("#network-ip-settings-dialog select", "manual")
b.set_val('#network-ip-settings-dialog input[placeholder="Address"]', "1.2.3.4")
b.set_val('#network-ip-settings-dialog input[placeholder*="netmask"]', "24")
b.click("#network-ip-settings-dialog button:contains('Apply')")
b.wait_popdown("network-ip-settings-dialog")
self.wait_for_iface_setting('IPv4', 'Address 1.2.3.4/24')
# Check that we now have connection settings
con_id = wait(lambda: self.iface_con_id(iface))
self.assertEqual(m.execute('nmcli -m tabular -t -f ipv4.method con show "%s"' % con_id).strip(),
"manual")
# The interface will be activated. Deactivate it.
self.wait_for_iface_setting('Status', '1.2.3.4/24')
self.toggle_onoff(".pf-c-card__header:contains('%s')" % iface)
self.wait_for_iface_setting('Status', 'Inactive')
# Delete the connection settings again and wait for the ghost
# settings to be re-created.
m.execute('nmcli con del "%s"' % con_id)
self.wait_for_iface_setting('IPv4', 'Automatic')
# Activate with ghost settings
self.toggle_onoff(".pf-c-card__header:contains('%s')" % iface)
self.wait_for_iface_setting('Status', '10.111.')
# Check again that we now have connection settings
con_id = wait(lambda: self.iface_con_id(iface))
self.assertEqual(m.execute('nmcli -m tabular -t -f ipv4.method con show "%s"' % con_id).strip(),
"auto")
def testOtherSettings(self):
b = self.browser
m = self.machine
iface = self.add_iface()
con_id = self.iface_con_id(iface)
m.execute("nmcli con mod '%s' connection.gateway-ping-timeout 12" % con_id)
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_popup("network-ip-settings-dialog")
b.select_from_dropdown("#network-ip-settings-dialog select", "shared")
b.click("#network-ip-settings-dialog button:contains('Apply')")
b.wait_popdown("network-ip-settings-dialog")
self.assertEqual(m.execute("nmcli -m tabular -t -f ipv4.method con show '%s'" % con_id).strip(),
"shared")
self.assertEqual(m.execute("nmcli -m tabular -t -f connection.gateway-ping-timeout con show '%s'" % con_id).strip(),
"12")
# IPv6 route
# by default there's a route to link-local only (fe80::)
show_cmd = "ip -6 route show dev %s" % iface
wait(lambda: "fe80::/64" in m.execute(show_cmd))
# add a manual one
self.configure_iface_setting('IPv6')
b.wait_popup("network-ip-settings-dialog")
b.click('.network-ip-settings-row[data-field="routes"] button') # +
b.set_val('#network-ip-settings-dialog input[placeholder="Address"]', "fe80:2::")
b.set_val('#network-ip-settings-dialog input[placeholder="Prefix length"]', "60")
b.set_val('#network-ip-settings-dialog input[placeholder="Gateway"]', "fe80:2::3")
b.set_val('#network-ip-settings-dialog input[placeholder="Metric"]', "42")
b.click('#network-ip-settings-apply')
b.wait_popdown("network-ip-settings-dialog")
# setting should be applied
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)
# dialog prefills fields with current settings
self.configure_iface_setting('IPv6')
b.wait_popup("network-ip-settings-dialog")
b.wait_val('#network-ip-settings-dialog input[placeholder="Address"]', "fe80:2:0:0:0:0:0:0")
b.wait_val('#network-ip-settings-dialog input[placeholder="Prefix length"]', "60")
b.wait_val('#network-ip-settings-dialog input[placeholder="Gateway"]', "fe80:2:0:0:0:0:0:3")
b.wait_val('#network-ip-settings-dialog input[placeholder="Metric"]', "42")
b.click('#network-ip-settings-cancel')
b.wait_popdown("network-ip-settings-dialog")
if __name__ == '__main__':
test_main()
|