#!/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 *


@skipImage("Do not test BaseOS packages", "rhel-8-3-distropkg")
class TestNetworkingOther(NetworkCase):

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

        iface = "tun0"

        # Create a tun device and let NetworkManager manage it
        m.execute("ip tuntap add mode tun dev %s" % iface)
        wait(lambda: m.execute('nmcli device | grep %s | grep -v unavailable' % iface))
        m.execute("nmcli dev set %s managed yes" % iface)

        self.login_and_go("/network")
        self.wait_for_iface(iface, active=False)
        b.click("#networking-interfaces tr[data-interface='%s']" % iface)
        b.wait_visible("#network-interface")

        # Configure a manual IP address
        #
        b.click("tr:contains('IPv4') a")
        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")
        b.wait_in_text("tr:contains('Status')", "1.2.3.4/24")


if __name__ == '__main__':
    test_main()
