def test_cmd_read_only_filter_stale(fake_devices, fake_runner): # Make a call to load the cache. initial_devices = fake_devices[:] lc = lvm.LVMCache() lc.cmd(["fake"]) del fake_runner.calls[:] # Add a new device to the system. This will makes the cached filter stale, # so the command will be retried with a new filter. fake_devices.append("/dev/mapper/c") # Require max retries + 1 calls to succeed. fake_runner.retries = lc.READ_ONLY_RETRIES + 1 lc.set_read_only(True) rc, out, err = lc.cmd(["fake"]) # Call should succeed after one call with stale filter, one call with wider # filter and max retries identical calls. assert rc == 0 assert len(fake_runner.calls) == lc.READ_ONLY_RETRIES + 2 # The first call used the stale cache filter. cmd, kwargs = fake_runner.calls[0] assert cmd == [ constants.EXT_LVM, "fake", "--config", lvm._buildConfig( dev_filter=lvm._buildFilter(initial_devices), locking_type="4"), ] assert kwargs == {"sudo": True} # The seocnd call used a wider filter. cmd, kwargs = fake_runner.calls[1] assert cmd == [ constants.EXT_LVM, "fake", "--config", lvm._buildConfig( dev_filter=lvm._buildFilter(fake_devices), locking_type="4"), ] assert kwargs == {"sudo": True} # And then indentical retries with the wider filter. assert len(set(repr(c) for c in fake_runner.calls[1:])) == 1
def test_build_config(): expected = ( 'devices { ' ' preferred_names=["^/dev/mapper/"] ' ' ignore_suspended_devices=1 ' ' write_cache_state=0 ' ' disable_after_error_count=3 ' ' filter=["a|^/dev/a$|^/dev/b$|", "r|.*|"] ' ' hints="none" ' ' obtain_device_list_from_udev=0 ' '} ' 'global { ' ' locking_type=1 ' ' prioritise_write_locks=1 ' ' wait_for_locks=1 ' ' use_lvmetad=0 ' '} ' 'backup { ' ' retain_min=50 ' ' retain_days=0 ' '}' ) assert expected == lvm._buildConfig( dev_filter='["a|^/dev/a$|^/dev/b$|", "r|.*|"]', locking_type="1")
def test_cmd_retry_filter_stale(fake_devices, fake_runner): # Make a call to load the cache. initial_devices = fake_devices[:] lc = lvm.LVMCache() lc.cmd(["fake"]) del fake_runner.calls[:] # Add a new device to the system. This will makes the cached filter stale, # so the command will be retried with a new filter. fake_devices.append("/dev/mapper/c") # Require 2 calls to succeed. assert lc.READ_ONLY_RETRIES > 1 fake_runner.retries = 1 rc, out, err = lc.cmd(["fake"]) assert rc == 0 assert len(fake_runner.calls) == 2 # The first call used the stale cache filter. cmd, kwargs = fake_runner.calls[0] assert cmd == [ constants.EXT_LVM, "fake", "--config", lvm._buildConfig( dev_filter=lvm._buildFilter(initial_devices), locking_type="1"), ] assert kwargs == {"sudo": True} # The seocnd call used a wider filter. cmd, kwargs = fake_runner.calls[1] assert cmd == [ constants.EXT_LVM, "fake", "--config", lvm._buildConfig( dev_filter=lvm._buildFilter(fake_devices), locking_type="1"), ] assert kwargs == {"sudo": True}
def test_rebuild_filter_after_invaliation(fake_devices): # Check that adding a device and invalidating the filter rebuilds the # config with the correct filter. lc = lvm.LVMCache() lc._addExtraCfg(["lvs"]) fake_devices.append("/dev/mapper/c") lc.invalidateFilter() cmd = lc._addExtraCfg(["lvs"]) assert cmd[3] == lvm._buildConfig( dev_filter=lvm._buildFilter(fake_devices), locking_type="1")
def test_build_command_long_filter(fake_devices): # If the devices are not specified, include all devices reported by # multipath. lc = lvm.LVMCache() cmd = lc._addExtraCfg(["lvs", "-o", "+tags"]) assert cmd == [ constants.EXT_LVM, "lvs", "--config", lvm._buildConfig( dev_filter=lvm._buildFilter(fake_devices), locking_type="1"), "-o", "+tags", ]
def test_cmd_success(fake_devices, no_delay): fake_runner = FakeRunner() lc = lvm.LVMCache(fake_runner) rc, out, err = lc.cmd(["lvs", "-o", "+tags"]) assert rc == 0 assert len(fake_runner.calls) == 1 cmd = fake_runner.calls[0] assert cmd == [ constants.EXT_LVM, "lvs", "--config", lvm._buildConfig( dev_filter=lvm._buildFilter(fake_devices), locking_type="1"), "-o", "+tags", ]
def test_cmd_success(fake_devices, fake_runner): lc = lvm.LVMCache() rc, out, err = lc.cmd(["lvs", "-o", "+tags"]) assert rc == 0 assert len(fake_runner.calls) == 1 cmd, kwargs = fake_runner.calls[0] assert cmd == [ constants.EXT_LVM, "lvs", "--config", lvm._buildConfig( dev_filter=lvm._buildFilter(fake_devices), locking_type="1"), "-o", "+tags", ] assert kwargs == {"sudo": True}
def test_build_config(): expected = ( 'devices { ' ' preferred_names=["^/dev/mapper/"] ' ' ignore_suspended_devices=1 ' ' write_cache_state=0 ' ' disable_after_error_count=3 ' ' filter=["a|^/dev/a$|^/dev/b$|", "r|.*|"] ' '} ' 'global { ' ' locking_type=1 ' ' prioritise_write_locks=1 ' ' wait_for_locks=1 ' ' use_lvmetad=0 ' '} ' 'backup { ' ' retain_min=50 ' ' retain_days=0 ' '}' ) assert expected == lvm._buildConfig( dev_filter='["a|^/dev/a$|^/dev/b$|", "r|.*|"]', locking_type="1")