def config_with_devices(args): # Check if the lvm devices is already configured. if lvmdevices.is_configured(): print("LVM devices already configured for vdsm") return mounts = lvmfilter.find_lvm_mounts() wanted_wwids = lvmfilter.find_wwids(mounts) current_wwids = mpathconf.read_blacklist() # Find VGs of mounted devices. vgs = {mnt.vg_name for mnt in mounts} # Print config summary for the user. _print_summary(mounts, None, None, wanted_wwids, vgs) if not args.assume_yes: if not common.confirm("Configure host? [yes,NO] "): return NEEDS_CONFIG # Before creating devices file we have to also configure multipath # blacklist. if current_wwids != wanted_wwids: mpathconf.configure_blacklist(wanted_wwids) # Enable lvm devices, configure devices file and remove lvm filter. lvmdevices.configure(vgs) _print_success()
def config_with_filter(args): mounts = lvmfilter.find_lvm_mounts() wanted_wwids = lvmfilter.find_wwids(mounts) current_wwids = mpathconf.read_blacklist() wanted_filter = lvmfilter.build_filter(mounts) with lvmconf.LVMConfig() as lvm_config: current_filter = lvm_config.getlist("devices", "filter") advice = lvmfilter.analyze( current_filter, wanted_filter, current_wwids, wanted_wwids) # This is the expected condition on a correctly configured host. if advice.action == lvmfilter.UNNEEDED: print("LVM filter is already configured for Vdsm") return # We need to configure LVM filter. _print_summary(mounts, current_filter, wanted_filter, advice.wwids, None) if advice.action == lvmfilter.CONFIGURE: if not args.assume_yes: if not common.confirm("Configure host? [yes,NO] "): return NEEDS_CONFIG mpathconf.configure_blacklist(advice.wwids) with lvmconf.LVMConfig() as config: config.setlist("devices", "filter", advice.filter) config.setint("devices", "use_devicesfile", 0) config.save() _print_success() elif advice.action == lvmfilter.RECOMMEND: _print_filter_warning() return CANNOT_CONFIG
def test_read_no_blacklist(fake_conf): wwids = mpathconf.read_blacklist() assert not wwids
def test_read_empty_blacklist(fake_conf): mpathconf.configure_blacklist([]) wwids = mpathconf.read_blacklist() assert not wwids
def test_read_blacklist(fake_conf): wwids = {"wwid1", "wwid2", "wwid3"} mpathconf.configure_blacklist(wwids) assert mpathconf.read_blacklist() == wwids
def test_read_bad_blacklist(fake_conf): mpathconf.configure_blacklist([]) # Overwrite conf with a bad conf. fake_conf.write(BAD_CONF) wwids = mpathconf.read_blacklist() assert wwids == {"wwid1", "wwid2", "wwid5"}
def main(*args): """ config-lvm-filter Configure LVM filter allowing LVM to access only the local storage needed by the hypervisor, but not shared storage owned by Vdsm. Return codes: 0 - Successful completion. 1 - Exception caught during operation. 2 - Wrong arguments. 3 - LVM filter configuration was found to be required but could not be completed since there is already another filter configured on the host. 4 - User has chosen not to allow LVM filter reconfiguration, although found as required. """ args = parse_args(args) print("Analyzing host...") mounts = lvmfilter.find_lvm_mounts() wanted_filter = lvmfilter.build_filter(mounts) wanted_wwids = lvmfilter.find_wwids(mounts) with lvmconf.LVMConfig() as config: current_filter = config.getlist("devices", "filter") current_wwids = mpathconf.read_blacklist() advice = lvmfilter.analyze( current_filter, wanted_filter, current_wwids, wanted_wwids) # This is the expected condition on a correctly configured host. if advice.action == lvmfilter.UNNEEDED: print("LVM filter is already configured for Vdsm") return # We need to configure LVM filter. print("Found these mounted logical volumes on this host:") print() for mnt in mounts: print(" logical volume: ", mnt.lv) print(" mountpoint: ", mnt.mountpoint) print(" devices: ", ", ".join(mnt.devices)) print() print("This is the recommended LVM filter for this host:") print() print(" " + lvmfilter.format_option(wanted_filter)) print() print("""\ This filter allows LVM to access the local devices used by the hypervisor, but not shared storage owned by Vdsm. If you add a new device to the volume group, you will need to edit the filter manually. """) if current_filter: print("This is the current LVM filter:") print() print(" " + lvmfilter.format_option(current_filter)) print() if advice.wwids: print("To use the recommended filter we need to add multipath") print("blacklist in /etc/multipath/conf.d/vdsm_blacklist.conf:") print() print(textwrap.indent(mpathconf.format_blacklist(advice.wwids), " ")) print() if advice.action == lvmfilter.CONFIGURE: if not args.assume_yes: if not common.confirm("Configure host? [yes,NO] "): return NEEDS_CONFIG mpathconf.configure_blacklist(advice.wwids) with lvmconf.LVMConfig() as config: config.setlist("devices", "filter", advice.filter) config.save() print("""\ Configuration completed successfully! Please reboot to verify the configuration. """) elif advice.action == lvmfilter.RECOMMEND: print("""\ WARNING: The current LVM filter does not match the recommended filter, Vdsm cannot configure the filter automatically. Please edit /etc/lvm/lvm.conf and set the 'filter' option in the 'devices' section to the recommended value. Make sure /etc/multipath/conf.d/vdsm_blacklist.conf is set with the recommended 'blacklist' section. It is recommended to reboot to verify the new configuration. """) return CANNOT_CONFIG