def test_reset_layout(self):
        '''Validate that existing partitions are restored with reset_layout.'''
        if platform.processor() != "i386":
            raise SkipTest("test not supported on sparc")

        discovered_disks = self._get_discovered_disks()
        tc = TargetController(self.doc, debug=True)

        # Set disk.label to VTOC explicitly. If there is no label set
        # then TargetController will default it to GPT and remove the
        # MBR partitions.
        discovered_disks[3].label = "VTOC"

        selected_disks = tc.select_disk(discovered_disks[3])
        self.assertEqual(len(selected_disks), 1,
                         "there should be 1 Disk returned")

        # When wipe_disk is True the default layout becomes GPT based rather
        # than VTOC.
        tc.apply_default_layout(selected_disks[0], use_whole_disk=False, \
                                wipe_disk=True)
        self.assertEqual(selected_disks[0].label, "GPT",
            "disk should have a GPT label now. Has %s instead." \
            % selected_disks[0].label)
        self.assertEqual(
            len(selected_disks[0].get_children(class_type=GPTPartition)), 3,
            "disk should have 3 GPT partitions now")
        copy_disks = tc.reset_layout(selected_disks[0], use_whole_disk=False)

        self.assertEqual(len(copy_disks), 1, "there should be 1 Disk returned")
        self.assertEqual(copy_disks[0].ctd, discovered_disks[3].ctd,
                         "incorrect disk returned")
        self.assertEqual(len(copy_disks[0].get_children(class_type=Partition)),
                         2, "disk should have 2 partitions again")
    def test_clears_existing_partitions(self):
        '''Validate that existing partitions are removed with wipe_disk set.'''
        if platform.processor() != "i386":
            raise SkipTest("test not supported on sparc")

        discovered_disks = self._get_discovered_disks()
        tc = TargetController(self.doc, dry_run=True)
        selected_disks = tc.select_disk(discovered_disks[3])
        tc.apply_default_layout(selected_disks[0], False, True)

        self.assertEqual(len(selected_disks), 1,
                         "there should be 1 Disk returned")
        self.assertEqual(selected_disks[0].ctd, discovered_disks[3].ctd,
                         "incorrect disk returned")

        # Since this is X86, wiping the disk and applying default layout
        # should result in a GPT partitioned disk with 3 GPTPartitions:
        # 1 - EFI system or BIOS boot depending on firmware
        # 2 - Solaris
        # 3 - Solaris reserved
        partitions = selected_disks[0].get_children(class_type=GPTPartition)

        self.assertEqual(len(partitions), 3,
                         "disk should only have 1 partition now")
        self.assertEqual(partitions[0].guid, selected_disks[0].sysboot_guid,
                         "GPTPartition 1 is not the correct type for boot")
        self.assertTrue(partitions[1].is_solaris,
                        "GPTPartition 2 is not a solaris partition")
        self.assertTrue(partitions[2].is_reserved,
                        "GPTPartition 3 is not a reserved partition")
    def test_existing_partitions(self):
        '''Validate that existing partitions can be presevered.'''
        discovered_disks = self._get_discovered_disks()
        tc = TargetController(self.doc)
        selected_disks = tc.select_disk(discovered_disks[3])
        tc.apply_default_layout(selected_disks[0], False, False)

        self.assertEqual(len(selected_disks), 1,
            "there should be 1 Disk returned")
        self.assertEqual(selected_disks[0].ctd, discovered_disks[3].ctd,
            "incorrect disk returned")
        self.assertEqual(
            len(selected_disks[0].get_children(class_type=Partition)),
            2,
            "disk should still have 2 partitions")
    def test_clears_existing_partitions(self):
        '''Validate that existing partitions are removed with wipe_disk set.'''
        if platform.processor() != "i386":
            raise SkipTest("test not supported on sparc")

        discovered_disks = self._get_discovered_disks()
        tc = TargetController(self.doc)
        selected_disks = tc.select_disk(discovered_disks[3])
        tc.apply_default_layout(selected_disks[0], False, True)

        self.assertEqual(len(selected_disks), 1,
            "there should be 1 Disk returned")
        self.assertEqual(selected_disks[0].ctd, discovered_disks[3].ctd,
            "incorrect disk returned")
        self.assertEqual(
            len(selected_disks[0].get_children(class_type=Partition)),
            1,
            "disk should only have 1 partition now")
    def test_existing_partitions(self):
        '''Validate that existing MBR partitions can be presevered.'''
        discovered_disks = self._get_discovered_disks()
        tc = TargetController(self.doc, dry_run=True)

        # Set disk.label to VTOC explicitly. If there is no label set
        # then TargetController will default it to GPT and remove the
        # MBR partitions.
        discovered_disks[3].label = "VTOC"
        selected_disks = tc.select_disk(discovered_disks[3])
        tc.apply_default_layout(selected_disks[0], False, False)

        self.assertEqual(len(selected_disks), 1,
                         "there should be 1 Disk returned")
        self.assertEqual(selected_disks[0].ctd, discovered_disks[3].ctd,
                         "incorrect disk returned")
        self.assertEqual(
            len(selected_disks[0].get_children(class_type=Partition)), 2,
            "disk should still have 2 partitions")
    def test_reset_layout(self):
        '''Validate that existing partitions are restored with reset_layout.'''
        if platform.processor() != "i386":
            raise SkipTest("test not supported on sparc")

        discovered_disks = self._get_discovered_disks()
        tc = TargetController(self.doc, debug=True)
        selected_disks = tc.select_disk(discovered_disks[3])
        self.assertEqual(len(selected_disks), 1,
            "there should be 1 Disk returned")
        tc.apply_default_layout(selected_disks[0], use_whole_disk=False, \
                                wipe_disk=True)
        self.assertEqual(
            len(selected_disks[0].get_children(class_type=Partition)),
            1, "disk should have 1 partition now")
        copy_disks = tc.reset_layout(selected_disks[0], use_whole_disk=False)

        self.assertEqual(len(copy_disks), 1,
            "there should be 1 Disk returned")
        self.assertEqual(copy_disks[0].ctd, discovered_disks[3].ctd,
            "incorrect disk returned")
        self.assertEqual(
            len(copy_disks[0].get_children(class_type=Partition)),
            2, "disk should have 2 partitions again")