コード例 #1
0
ファイル: test_partition.py プロジェクト: sd-hd/subiquity
 def test_format_entire_unusual_filesystem(self):
     model, disk = make_model_and_disk()
     fs = model.add_filesystem(disk, "ntfs")
     fs.preserve = True
     disk._original_fs = fs
     view, stretchy = make_format_entire_view(model, disk)
     self.assertEqual(stretchy.form.fstype.value, None)
コード例 #2
0
    def test_edit_boot_partition(self):
        form_data = {
            'size': "256M",
        }
        model, disk = make_model_and_disk()
        partition = model.add_partition(disk, 512 * (2**20), "boot")
        fs = model.add_filesystem(partition, "fat32")
        model.add_mount(fs, '/boot/efi')
        view, stretchy = make_partition_view(model, disk, partition)

        self.assertFalse(stretchy.form.fstype.enabled)
        self.assertEqual(stretchy.form.fstype.value, "fat32")
        self.assertFalse(stretchy.form.mount.enabled)
        self.assertEqual(stretchy.form.mount.value, "/boot/efi")

        view_helpers.enter_data(stretchy.form, form_data)
        view_helpers.click(stretchy.form.done_btn.base_widget)
        expected_data = {
            'size': dehumanize_size(form_data['size']),
            'fstype': "fat32",
            'mount': '/boot/efi',
            'use_swap': False,
        }
        view.controller.partition_disk_handler.assert_called_once_with(
            stretchy.disk, stretchy.partition, expected_data)
コード例 #3
0
 def test_format_entire_unusual_filesystem(self):
     model, disk = make_model_and_disk()
     fs = model.add_filesystem(disk, "ntfs")
     fs.preserve = True
     model._orig_config = model._render_actions()
     view, stretchy = make_format_entire_view(model, disk)
     self.assertEqual(stretchy.form.fstype.value, None)
コード例 #4
0
 def test_disk_action_FORMAT(self):
     model, disk = make_model_and_disk()
     self.assertActionPossible(disk, DeviceAction.FORMAT)
     make_partition(model, disk)
     self.assertActionNotPossible(disk, DeviceAction.FORMAT)
     disk2 = make_disk(model)
     model.add_volgroup('vg1', {disk2})
     self.assertActionNotPossible(disk2, DeviceAction.FORMAT)
コード例 #5
0
 def test_initial_focus(self):
     model, disk = make_model_and_disk()
     view, stretchy = make_partition_view(model, disk)
     focus_path = view_helpers.get_focus_path(view)
     for w in reversed(focus_path):
         if w is stretchy.form.size.widget:
             return
     else:
         self.fail("Size widget not focus")
コード例 #6
0
 def test_size_clamping(self):
     model, disk = make_model_and_disk()
     partition = model.add_partition(disk, 512 * (2**20))
     model.add_filesystem(partition, "ext4")
     view, stretchy = make_partition_view(model, disk, partition)
     self.assertTrue(stretchy.form.done_btn.enabled)
     stretchy.form.size.value = "1000T"
     stretchy.form.size.widget.lost_focus()
     self.assertTrue(stretchy.form.size.showing_extra)
     self.assertIn("Capped partition size",
                   stretchy.form.size.under_text.text)
コード例 #7
0
def make_controller_and_disk():
    common = defaultdict(type(None))
    bm = Thing()
    bm.filesystem, disk = make_model_and_disk()
    common['base_model'] = bm
    common['answers'] = {}
    opts = Thing()
    opts.dry_run = True
    opts.bootloader = "UEFI"
    common['opts'] = opts
    controller = FilesystemController(common)
    return controller, disk
コード例 #8
0
 def test_create_partition(self):
     valid_data = {
         'size': "1M",
         'fstype': "ext4",
     }
     model, disk = make_model_and_disk()
     view, stretchy = make_view(model, disk)
     view_helpers.enter_data(stretchy.form, valid_data)
     view_helpers.click(stretchy.form.done_btn.base_widget)
     valid_data['mount'] = '/'
     valid_data['size'] = dehumanize_size(valid_data['size'])
     view.controller.partition_disk_handler.assert_called_once_with(
         stretchy.disk, None, valid_data)
コード例 #9
0
    def test_disk_action_PARTITION(self):
        model, disk = make_model_and_disk()
        self.assertActionPossible(disk, DeviceAction.PARTITION)
        make_partition(model, disk, size=disk.free_for_partitions // 2)
        self.assertActionPossible(disk, DeviceAction.PARTITION)
        make_partition(model, disk, size=disk.free_for_partitions)
        self.assertActionNotPossible(disk, DeviceAction.PARTITION)

        # Can partition a disk with .preserve=True
        disk2 = make_disk(model)
        disk2.preserve = True
        self.assertActionPossible(disk2, DeviceAction.PARTITION)
        # But not if it has a partition.
        make_partition(model, disk2, preserve=True)
        self.assertActionNotPossible(disk2, DeviceAction.PARTITION)
コード例 #10
0
 def test_edit_partition(self):
     form_data = {
         'size': "256M",
         'fstype': "xfs",
     }
     model, disk = make_model_and_disk()
     partition = model.add_partition(disk, 512 * (2**20))
     model.add_filesystem(partition, "ext4")
     view, stretchy = make_view(model, disk, partition)
     self.assertTrue(stretchy.form.done_btn.enabled)
     view_helpers.enter_data(stretchy.form, form_data)
     view_helpers.click(stretchy.form.done_btn.base_widget)
     expected_data = {
         'size': dehumanize_size(form_data['size']),
         'fstype': 'xfs',
         'mount': None,
     }
     view.controller.partition_disk_handler.assert_called_once_with(
         stretchy.disk, stretchy.partition, expected_data)
コード例 #11
0
 def test_edit_existing_partition(self):
     form_data = {
         'fstype': "xfs",
     }
     model, disk = make_model_and_disk()
     partition = model.add_partition(disk, 512 * (2**20))
     partition.preserve = True
     model.add_filesystem(partition, "ext4")
     view, stretchy = make_partition_view(model, disk, partition)
     self.assertFalse(stretchy.form.size.enabled)
     self.assertTrue(stretchy.form.done_btn.enabled)
     view_helpers.enter_data(stretchy.form, form_data)
     view_helpers.click(stretchy.form.done_btn.base_widget)
     expected_data = {
         'fstype': 'xfs',
         'mount': None,
         'use_swap': False,
     }
     view.controller.partition_disk_handler.assert_called_once_with(
         stretchy.disk, stretchy.partition, expected_data)
コード例 #12
0
    def test_edit_existing_unused_boot_partition(self):
        model, disk = make_model_and_disk()
        partition = model.add_partition(disk, 512 * (2**20), "boot")
        fs = model.add_filesystem(partition, "fat32")
        model._orig_config = model._render_actions()
        disk.preserve = partition.preserve = fs.preserve = True
        view, stretchy = make_partition_view(model, disk, partition)

        self.assertTrue(stretchy.form.fstype.enabled)
        self.assertEqual(stretchy.form.fstype.value, None)
        self.assertFalse(stretchy.form.mount.enabled)
        self.assertEqual(stretchy.form.mount.value, None)

        view_helpers.click(stretchy.form.done_btn.base_widget)
        expected_data = {
            'fstype': None,
            'mount': None,
            'use_swap': False,
        }
        view.controller.partition_disk_handler.assert_called_once_with(
            stretchy.disk, stretchy.partition, expected_data)
コード例 #13
0
    def test_edit_existing_partition_mountpoints(self):
        # Set up a PartitionStretchy for editing a partition with an
        # existing filesystem.
        model, disk = make_model_and_disk()
        partition = model.add_partition(disk, 512 * (2**20))
        partition.preserve = True
        fs = model.add_filesystem(partition, "ext4")
        fs.preserve = True
        model._orig_config = model._render_actions()
        view, stretchy = make_partition_view(model, disk, partition)
        self.assertFalse(stretchy.form.size.enabled)
        self.assertTrue(stretchy.form.done_btn.enabled)

        # By default, the "leave formatted as xxx" option is selected.
        self.assertIs(stretchy.form.fstype.value, None)
        # As is "leave unmounted"
        self.assertIs(stretchy.form.mount.value, None)

        # The option for mounting at / is disabled. But /srv is still
        # enabled.
        selector = stretchy.form.mount.widget._selector
        self.assertFalse(selector.option_by_value('/').enabled)
        self.assertTrue(selector.option_by_value('/srv').enabled)

        # Typing in an unsuitable mountpoint triggers a message.
        stretchy.form.mount.value = "/boot"
        stretchy.form.mount.validate()
        self.assertTrue(stretchy.form.mount.showing_extra)
        self.assertIn("bad idea", stretchy.form.mount.under_text.text)
        self.assertIn("/boot", stretchy.form.mount.under_text.text)

        # Selecting to reformat the partition clears the message and
        # reenables the / option.
        stretchy.form.select_fstype(None, "ext4")
        self.assertFalse(stretchy.form.mount.showing_extra)
        self.assertTrue(selector.option_by_value('/').enabled)
コード例 #14
0
 def test_disk_action_TOGGLE_BOOT_NONE(self):
     model, disk = make_model_and_disk(Bootloader.NONE)
     self.assertActionNotSupported(disk, DeviceAction.TOGGLE_BOOT)
コード例 #15
0
 def test_disk_annotations(self):
     # disks never have annotations
     model, disk = make_model_and_disk()
     self.assertEqual(annotations(disk), [])
     disk.preserve = True
     self.assertEqual(annotations(disk), [])
コード例 #16
0
 def test_vg_default_annotations(self):
     model, disk = make_model_and_disk()
     vg = model.add_volgroup('vg-0', {disk})
     self.assertEqual(annotations(vg), ['new'])
     vg.preserve = True
     self.assertEqual(annotations(vg), ['existing'])
コード例 #17
0
 def test_vg_encrypted_annotations(self):
     model, disk = make_model_and_disk()
     dm_crypt = model.add_dm_crypt(disk, key='passw0rd')
     vg = model.add_volgroup('vg-0', {dm_crypt})
     self.assertEqual(annotations(vg), ['new', 'encrypted'])
コード例 #18
0
 def test_disk_action_EDIT(self):
     model, disk = make_model_and_disk()
     self.assertActionNotSupported(disk, DeviceAction.EDIT)
コード例 #19
0
 def test_disk_action_INFO(self):
     model, disk = make_model_and_disk()
     self.assertActionPossible(disk, DeviceAction.INFO)
コード例 #20
0
 def test_disk_action_CREATE_LV(self):
     model, disk = make_model_and_disk()
     self.assertActionNotSupported(disk, DeviceAction.CREATE_LV)