Example #1
0
    def test_list_block_devices(self, mock_ureport, mock_breport, mock_ereport,
                                mock_isdisk, mock_get_devs):
        # should run blockdev --report command
        # in order to get a list of block devices
        # should call report methods to get device info
        # should call is_disk method to filter out
        # those block devices which are not disks
        mock_get_devs.return_value = ['/dev/fake', '/dev/fake1', '/dev/sr0']

        def isdisk_side_effect(arg, uspec=None, bspec=None):
            if arg == '/dev/fake':
                return True
            elif arg in ('/dev/fake1', '/dev/sr0'):
                return False
        mock_isdisk.side_effect = isdisk_side_effect
        mock_ureport.return_value = {'key0': 'value0'}
        mock_breport.return_value = {'key1': 'value1'}
        mock_ereport.return_value = {'key2': 'value2'}

        expected = [{
            'device': '/dev/fake',
            'uspec': {'key0': 'value0'},
            'bspec': {'key1': 'value1'},
            'espec': {'key2': 'value2'}
        }]
        self.assertEqual(hu.list_block_devices(), expected)
        self.assertEqual(mock_ureport.call_args_list, [mock.call('/dev/fake'),
                         mock.call('/dev/fake1'), mock.call('/dev/sr0')])
        self.assertEqual(mock_breport.call_args_list, [mock.call('/dev/fake'),
                         mock.call('/dev/fake1'), mock.call('/dev/sr0')])
        self.assertEqual(mock_ereport.call_args_list, [mock.call('/dev/fake'),
                         mock.call('/dev/fake1'), mock.call('/dev/sr0')])
Example #2
0
 def hu_disks(self):
     """Actual disks which are available on this node
     it is a list of dicts which are formatted other way than
     ks_spaces disks. To match both of those formats use
     _match_device method.
     """
     if not getattr(self, '_hu_disks', None):
         self._hu_disks = hu.list_block_devices(disks=True)
     return self._hu_disks
Example #3
0
 def hu_disks(self):
     """Actual disks which are available on this node
     it is a list of dicts which are formatted other way than
     ks_spaces disks. To match both of those formats use
     _match_device method.
     """
     if not getattr(self, '_hu_disks', None):
         self._hu_disks = hu.list_block_devices(disks=True)
     return self._hu_disks
Example #4
0
def mdcreate(mdname, level, device, *args):
    mds = mddisplay()

    # check if md device already exists
    if filter(lambda x: x['name'] == mdname, mds):
        raise errors.MDAlreadyExistsError(
            'Error while creating md: md %s already exists' % mdname)

    # check if level argument is valid
    supported_levels = ('0', '1', 'raid0', 'raid1', 'stripe', 'mirror')
    if level not in supported_levels:
        raise errors.MDWrongSpecError('Error while creating md device: '
                                      'level must be one of: %s' %
                                      ', '.join(supported_levels))

    devices = [device] + list(args)

    # check if all necessary devices exist
    if not set(devices).issubset(
            set([bd['device'] for bd in hu.list_block_devices(disks=False)])):
        raise errors.MDNotFoundError(
            'Error while creating md: at least one of devices is not found')

    # check if devices are not parts of some md array
    if set(devices) & \
            set(reduce(lambda x, y: x + y,
                       [md.get('devices', []) for md in mds], [])):
        raise errors.MDDeviceDuplicationError(
            'Error while creating md: at least one of devices is '
            'already in belongs to some md')

    #FIXME: mdadm will ask user to continue creating if any device appears to
    #       be a part of raid array. Superblock zeroing helps to avoid that.
    map(mdclean, devices)
    utils.execute('mdadm',
                  '--create',
                  '--force',
                  mdname,
                  '-e0.90',
                  '--level=%s' % level,
                  '--raid-devices=%s' % len(devices),
                  *devices,
                  check_exit_code=[0])
    def test_list_block_devices(self, mock_exec, mock_ureport, mock_breport,
                                mock_ereport, mock_isdisk):
        # should run blockdev --report command
        # in order to get a list of block devices
        # should call report methods to get device info
        # should call is_disk method to filter out
        # those block devices which are not disks
        mock_exec.return_value = (
            'RO    RA   SSZ   BSZ   StartSec            Size   Device\n'
            'rw   256   512  4096          0    320072933376   /dev/fake\n'
            'rw   256   512  4096       2048      7998537728   /dev/fake1\n'
            'rw   256   512   512          0      1073741312   /dev/sr0\n',
            ''
        )

        def isdisk_side_effect(arg, uspec=None, bspec=None):
            if arg == '/dev/fake':
                return True
            elif arg in ('/dev/fake1', '/dev/sr0'):
                return False
        mock_isdisk.side_effect = isdisk_side_effect
        mock_ureport.return_value = {'key0': 'value0'}
        mock_breport.return_value = {'key1': 'value1'}
        mock_ereport.return_value = {'key2': 'value2'}

        expected = [{
            'device': '/dev/fake',
            'startsec': '0',
            'size': 320072933376,
            'uspec': {'key0': 'value0'},
            'bspec': {'key1': 'value1'},
            'espec': {'key2': 'value2'}
        }]
        self.assertEqual(hu.list_block_devices(), expected)
        mock_exec.assert_called_once_with('blockdev', '--report',
                                          check_exit_code=[0])
        self.assertEqual(mock_ureport.call_args_list, [mock.call('/dev/fake'),
                         mock.call('/dev/fake1'), mock.call('/dev/sr0')])
        self.assertEqual(mock_breport.call_args_list, [mock.call('/dev/fake'),
                         mock.call('/dev/fake1'), mock.call('/dev/sr0')])
        self.assertEqual(mock_ereport.call_args_list, [mock.call('/dev/fake'),
                         mock.call('/dev/fake1'), mock.call('/dev/sr0')])
Example #6
0
def mdcreate(mdname, level, device, *args):
    mds = mddisplay()

    # check if md device already exists
    if filter(lambda x: x['name'] == mdname, mds):
        raise errors.MDAlreadyExistsError(
            'Error while creating md: md %s already exists' % mdname)

    # check if level argument is valid
    supported_levels = ('0', '1', 'raid0', 'raid1', 'stripe', 'mirror')
    if level not in supported_levels:
        raise errors.MDWrongSpecError(
            'Error while creating md device: '
            'level must be one of: %s' % ', '.join(supported_levels))

    devices = [device] + list(args)

    # check if all necessary devices exist
    if not set(devices).issubset(
            set([bd['device'] for bd in hu.list_block_devices(disks=False)])):
        raise errors.MDNotFoundError(
            'Error while creating md: at least one of devices is not found')

    # check if devices are not parts of some md array
    if set(devices) & \
            set(reduce(lambda x, y: x + y,
                       [md.get('devices', []) for md in mds], [])):
        raise errors.MDDeviceDuplicationError(
            'Error while creating md: at least one of devices is '
            'already in belongs to some md')

    #FIXME: mdadm will ask user to continue creating if any device appears to
    #       be a part of raid array. Superblock zeroing helps to avoid that.
    map(mdclean, devices)
    utils.execute('mdadm', '--create', '--force', mdname, '-e0.90',
                  '--level=%s' % level,
                  '--raid-devices=%s' % len(devices), *devices,
                  check_exit_code=[0])