~wesley-wiedenmeier/curtin/partial-testing

« back to all changes in this revision

Viewing changes to tests/unittests/test_block_mdadm.py

block: wipe_volume improvements
  
- move wipe_volume, find_sysfs_path, from block_meta to block
- improve wipe_volume:
  - do not shell out for 'dd' and ignore errors
  - add 'superblocks' mode that wipes start and end of existing
    partitions in addition to volume.
  - pick 4M as the default size for writes. This is easily modified.
- add block-wipe subcommand for:
  curtin block-wipe --mode=random /dev/vdb /dev/vdc
- sysfs_partition_data: this returns information on partitions on a
  given block device.
- sys_block_path: handle case where devpath is a partition and prepend
  parent dev into path.
  
Note, this does not call rereadpt as sgdisk --zap-all would.
We probably want to add the ability to do that. The reason I dont have it
yet is that in newer ubuntu systemd is watching readwrite opens on the
block devices and will issue rereadpt when those are closed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
597
597
        with self.assertRaises(ValueError):
598
598
            mdadm.md_device_key_dev(devname)
599
599
 
 
600
    @patch('curtin.block.get_blockdev_for_partition')
600
601
    @patch('curtin.block.mdadm.os.path.exists')
601
602
    @patch('curtin.block.mdadm.os.listdir')
602
 
    def tests_md_get_spares_list(self, mock_listdir, mock_exists):
 
603
    def tests_md_get_spares_list(self, mock_listdir, mock_exists,
 
604
                                 mock_getbdev):
603
605
        mdname = '/dev/md0'
604
606
        devices = ['dev-vda', 'dev-vdb', 'dev-vdc']
605
607
        states = ['in-sync', 'in-sync', 'spare']
607
609
        mock_exists.return_value = True
608
610
        mock_listdir.return_value = devices
609
611
        self.mock_util.load_file.side_effect = states
 
612
        mock_getbdev.return_value = ('md0', None)
610
613
 
611
614
        sysfs_path = '/sys/class/block/md0/md/'
612
615
 
618
621
        self.mock_util.load_file.assert_has_calls(expected_calls)
619
622
        self.assertEqual(['/dev/vdc'], spares)
620
623
 
 
624
    @patch('curtin.block.get_blockdev_for_partition')
621
625
    @patch('curtin.block.mdadm.os.path.exists')
622
 
    def tests_md_get_spares_list_nomd(self, mock_exists):
 
626
    def tests_md_get_spares_list_nomd(self, mock_exists, mock_getbdev):
623
627
        mdname = '/dev/md0'
624
628
        mock_exists.return_value = False
 
629
        mock_getbdev.return_value = ('md0', None)
625
630
        with self.assertRaises(OSError):
626
631
            mdadm.md_get_spares_list(mdname)
627
632
 
 
633
    @patch('curtin.block.get_blockdev_for_partition')
628
634
    @patch('curtin.block.mdadm.os.path.exists')
629
635
    @patch('curtin.block.mdadm.os.listdir')
630
 
    def tests_md_get_devices_list(self, mock_listdir, mock_exists):
 
636
    def tests_md_get_devices_list(self, mock_listdir, mock_exists,
 
637
                                  mock_getbdev):
631
638
        mdname = '/dev/md0'
632
639
        devices = ['dev-vda', 'dev-vdb', 'dev-vdc']
633
640
        states = ['in-sync', 'in-sync', 'spare']
635
642
        mock_exists.return_value = True
636
643
        mock_listdir.return_value = devices
637
644
        self.mock_util.load_file.side_effect = states
 
645
        mock_getbdev.return_value = ('md0', None)
638
646
 
639
647
        sysfs_path = '/sys/class/block/md0/md/'
640
648
 
646
654
        self.mock_util.load_file.assert_has_calls(expected_calls)
647
655
        self.assertEqual(sorted(['/dev/vda', '/dev/vdb']), sorted(devs))
648
656
 
 
657
    @patch('curtin.block.get_blockdev_for_partition')
649
658
    @patch('curtin.block.mdadm.os.path.exists')
650
 
    def tests_md_get_devices_list_nomd(self, mock_exists):
 
659
    def tests_md_get_devices_list_nomd(self, mock_exists, mock_getbdev):
651
660
        mdname = '/dev/md0'
652
661
        mock_exists.return_value = False
 
662
        mock_getbdev.return_value = ('md0', None)
653
663
        with self.assertRaises(OSError):
654
664
            mdadm.md_get_devices_list(mdname)
655
665