#!/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) 2015 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 storagelib
import testlib


@testlib.nondestructive
class TestStorageRaid1(storagelib.StorageCase):

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

        self.login_and_go("/storage")

        # Create two disks and make a RAID out of them
        disk1 = self.add_loopback_disk()
        disk2 = self.add_loopback_disk()
        b.wait_visible(self.card_row("Storage", name=disk1))
        b.wait_visible(self.card_row("Storage", name=disk2))

        self.addCleanup(m.execute, "mdadm --manage --stop /dev/md/SOMERAID")
        self.click_dropdown(self.card_header("Storage"), "Create MDRAID device")
        self.dialog_wait_open()
        # No swap block devices should show up
        b.wait_not_in_text("#dialog .pf-v5-c-data-list", "zram")
        self.dialog_set_val("level", "raid1")
        self.dialog_set_val("disks", {disk1: True, disk2: True})
        self.dialog_set_val("name", "SOMERAID")
        # The dialog should make sure that the Chunk size is ignored (has to be 0 for RAID 1)
        self.dialog_apply()
        self.dialog_wait_close()
        b.wait_visible(self.card_row("Storage", name="/dev/md/SOMERAID"))


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