Exemplo n.º 1
0
    def _override_lvm_config(self, chroot):
        # NOTE(sslypushenko) Due to possible races between LVM and multipath,
        # we need to adjust LVM devices filter.
        # This code is required only for Ubuntu 14.04, because in trusty,
        # LVM filters, does not recognize partions on multipath devices
        # out of the box. It is fixed in latest LVM versions
        multipath_devs = [parted.name
                          for parted in self.driver.partition_scheme.parteds
                          if hw.is_multipath_device(parted.name)]
        # If there are no multipath devices on the node, we should not do
        # anything to prevent regression.
        if multipath_devs:
            # We need to explicitly whitelist each non-mutlipath device
            lvm_filter = []
            for parted in self.driver.partition_scheme.parteds:
                device = parted.name
                if device in multipath_devs:
                    continue
                # We use devlinks from /dev/disk/by-id instead of /dev/sd*,
                # because the first one are persistent.
                devlinks_by_id = [
                    link for link in hw.udevreport(device).get('DEVLINKS', [])
                    if link.startswith('/dev/disk/by-id/')]
                for link in devlinks_by_id:
                    lvm_filter.append(
                        'a|^{}(p)?(-part)?[0-9]*|'.format(link))

            # Multipath devices should be whitelisted. All other devlinks
            # should be blacklisted, to prevent LVM from grubbing underlying
            # multipath devices.
            lvm_filter.extend(CONF.lvm_filter_for_mpath)
            # Setting devices/preferred_names also helps LVM to find devices by
            # the proper devlinks
            bu.override_lvm_config(
                chroot,
                {'devices': {
                    'scan': CONF.mpath_lvm_scan_dirs,
                    'global_filter': lvm_filter,
                    'preferred_names': CONF.mpath_lvm_preferred_names}},
                lvm_conf_path=CONF.lvm_conf_path,
                update_initramfs=True)
Exemplo n.º 2
0
 def test_udevreport(self, mock_exec):
     # should run udevadm info OS command
     # in order to get udev properties for a device
     mock_exec.return_value = (
         'DEVLINKS=\'/dev/disk/by-id/fakeid1 /dev/disk/by-id/fakeid2\'\n'
         'DEVNAME=\'/dev/fake\'\n'
         'DEVPATH=\'/devices/fakepath\'\n'
         'DEVTYPE=\'disk\'\n'
         'MAJOR=\'11\'\n'
         'MINOR=\'0\'\n'
         'ID_BUS=\'fakebus\'\n'
         'ID_MODEL=\'fakemodel\'\n'
         'ID_SERIAL_SHORT=\'fakeserial\'\n'
         'ID_WWN=\'fakewwn\'\n'
         'ID_CDROM=\'1\'\n'
         'ANOTHER=\'another\'\n',
         ''
     )
     expected = {
         'DEVLINKS': ['/dev/disk/by-id/fakeid1', '/dev/disk/by-id/fakeid2'],
         'DEVNAME': '/dev/fake',
         'DEVPATH': '/devices/fakepath',
         'DEVTYPE': 'disk',
         'MAJOR': '11',
         'MINOR': '0',
         'ID_BUS': 'fakebus',
         'ID_MODEL': 'fakemodel',
         'ID_SERIAL_SHORT': 'fakeserial',
         'ID_WWN': 'fakewwn',
         'ID_CDROM': '1'
     }
     self.assertEqual(expected, hu.udevreport('/dev/fake'))
     mock_exec.assert_called_once_with('udevadm',
                                       'info',
                                       '--query=property',
                                       '--export',
                                       '--name=/dev/fake',
                                       check_exit_code=[0])
 def test_udevreport(self, mock_exec):
     # should run udevadm info OS command
     # in order to get udev properties for a device
     mock_exec.return_value = (
         'DEVLINKS=\'/dev/disk/by-id/fakeid1 /dev/disk/by-id/fakeid2\'\n'
         'DEVNAME=\'/dev/fake\'\n'
         'DEVPATH=\'/devices/fakepath\'\n'
         'DEVTYPE=\'disk\'\n'
         'MAJOR=\'11\'\n'
         'MINOR=\'0\'\n'
         'ID_BUS=\'fakebus\'\n'
         'ID_MODEL=\'fakemodel\'\n'
         'ID_SERIAL_SHORT=\'fakeserial\'\n'
         'ID_WWN=\'fakewwn\'\n'
         'ID_CDROM=\'1\'\n'
         'ANOTHER=\'another\'\n', '')
     expected = {
         'DEVLINKS': ['/dev/disk/by-id/fakeid1', '/dev/disk/by-id/fakeid2'],
         'DEVNAME': '/dev/fake',
         'DEVPATH': '/devices/fakepath',
         'DEVTYPE': 'disk',
         'MAJOR': '11',
         'MINOR': '0',
         'ID_BUS': 'fakebus',
         'ID_MODEL': 'fakemodel',
         'ID_SERIAL_SHORT': 'fakeserial',
         'ID_WWN': 'fakewwn',
         'ID_CDROM': '1'
     }
     self.assertEqual(expected, hu.udevreport('/dev/fake'))
     mock_exec.assert_called_once_with('udevadm',
                                       'info',
                                       '--query=property',
                                       '--export',
                                       '--name=/dev/fake',
                                       check_exit_code=[0])