def test_lvm_clear_ignore_lvm_not_found(self, mock_execute): lvm.clear_volume('/dev/foo')
def test_lvm_clear(self, mock_execute): def fake_lvm_size(path): return lvm_size self.stub_out('nova.virt.libvirt.storage.lvm.get_volume_size', fake_lvm_size) # Test zeroing volumes works lvm_size = 1024 lvm.clear_volume('/dev/v1') mock_execute.assert_has_calls([ mock.call('shred', '-n0', '-z', '-s1024', '/dev/v1', run_as_root=True) ]) mock_execute.reset_mock() # Test volume_clear_size limits the size lvm_size = 10485761 CONF.set_override('volume_clear_size', '1', 'libvirt') lvm.clear_volume('/dev/v7') mock_execute.assert_has_calls([ mock.call('shred', '-n0', '-z', '-s1048576', '/dev/v7', run_as_root=True) ]) mock_execute.reset_mock() CONF.set_override('volume_clear_size', '2', 'libvirt') lvm_size = 1048576 lvm.clear_volume('/dev/v9') mock_execute.assert_has_calls([ mock.call('shred', '-n0', '-z', '-s1048576', '/dev/v9', run_as_root=True) ]) mock_execute.reset_mock() # Test volume_clear=shred CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '0', 'libvirt') lvm_size = 1048576 lvm.clear_volume('/dev/va') mock_execute.assert_has_calls([ mock.call('shred', '-n3', '-s1048576', '/dev/va', run_as_root=True) ]) mock_execute.reset_mock() CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '1', 'libvirt') lvm_size = 10485761 lvm.clear_volume('/dev/vb') mock_execute.assert_has_calls([ mock.call('shred', '-n3', '-s1048576', '/dev/vb', run_as_root=True) ]) mock_execute.reset_mock() # Test volume_clear=none does nothing CONF.set_override('volume_clear', 'none', 'libvirt') lvm.clear_volume('/dev/vc') mock_execute.assert_not_called()
def test_lvm_clear(self): def fake_lvm_size(path): return lvm_size def fake_execute(*cmd, **kwargs): executes.append(cmd) self.stubs.Set(lvm, 'get_volume_size', fake_lvm_size) self.stubs.Set(utils, 'execute', fake_execute) # Test the correct dd commands are run for various sizes lvm_size = 1 executes = [] expected_commands = [('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v1', 'seek=0', 'count=1', 'conv=fdatasync')] lvm.clear_volume('/dev/v1') self.assertEqual(expected_commands, executes) lvm_size = 1024 executes = [] expected_commands = [('dd', 'bs=1024', 'if=/dev/zero', 'of=/dev/v2', 'seek=0', 'count=1', 'conv=fdatasync')] lvm.clear_volume('/dev/v2') self.assertEqual(expected_commands, executes) lvm_size = 1025 executes = [] expected_commands = [('dd', 'bs=1024', 'if=/dev/zero', 'of=/dev/v3', 'seek=0', 'count=1', 'conv=fdatasync')] expected_commands += [('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v3', 'seek=1024', 'count=1', 'conv=fdatasync')] lvm.clear_volume('/dev/v3') self.assertEqual(expected_commands, executes) lvm_size = 1048576 executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v4', 'seek=0', 'count=1', 'oflag=direct')] lvm.clear_volume('/dev/v4') self.assertEqual(expected_commands, executes) lvm_size = 1048577 executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v5', 'seek=0', 'count=1', 'oflag=direct')] expected_commands += [('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v5', 'seek=1048576', 'count=1', 'conv=fdatasync')] lvm.clear_volume('/dev/v5') self.assertEqual(expected_commands, executes) lvm_size = 1234567 executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v6', 'seek=0', 'count=1', 'oflag=direct')] expected_commands += [('dd', 'bs=1024', 'if=/dev/zero', 'of=/dev/v6', 'seek=1024', 'count=181', 'conv=fdatasync')] expected_commands += [('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v6', 'seek=1233920', 'count=647', 'conv=fdatasync')] lvm.clear_volume('/dev/v6') self.assertEqual(expected_commands, executes) # Test volume_clear_size limits the size lvm_size = 10485761 CONF.set_override('volume_clear_size', '1', 'libvirt') executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v7', 'seek=0', 'count=1', 'oflag=direct')] lvm.clear_volume('/dev/v7') self.assertEqual(expected_commands, executes) CONF.set_override('volume_clear_size', '2', 'libvirt') lvm_size = 1048576 executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v9', 'seek=0', 'count=1', 'oflag=direct')] lvm.clear_volume('/dev/v9') self.assertEqual(expected_commands, executes) # Test volume_clear=shred CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '0', 'libvirt') lvm_size = 1048576 executes = [] expected_commands = [('shred', '-n3', '-s1048576', '/dev/va')] lvm.clear_volume('/dev/va') self.assertEqual(expected_commands, executes) CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '1', 'libvirt') lvm_size = 10485761 executes = [] expected_commands = [('shred', '-n3', '-s1048576', '/dev/vb')] lvm.clear_volume('/dev/vb') self.assertEqual(expected_commands, executes) # Test volume_clear=none does nothing CONF.set_override('volume_clear', 'none', 'libvirt') executes = [] expected_commands = [] lvm.clear_volume('/dev/vc') self.assertEqual(expected_commands, executes)
def test_lvm_clear(self): def fake_lvm_size(path): return lvm_size def fake_execute(*cmd, **kwargs): executes.append(cmd) self.stub_out('nova.virt.libvirt.storage.lvm.get_volume_size', fake_lvm_size) self.stub_out('nova.utils.execute', fake_execute) # One test for thin volumes CONF.set_override('thin_logical_volumes', True, 'libvirt') executes = [] expected_commands = [] lvm.clear_volume('/dev/v1') self.assertEqual(expected_commands, executes) # Explicitly set fat volumes for the rest of the tests. CONF.set_override('thin_logical_volumes', False, 'libvirt') # Test the correct dd commands are run for various sizes lvm_size = 1 executes = [] expected_commands = [('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v1', 'seek=0', 'count=1', 'conv=fdatasync')] lvm.clear_volume('/dev/v1') self.assertEqual(expected_commands, executes) lvm_size = 1024 executes = [] expected_commands = [('dd', 'bs=1024', 'if=/dev/zero', 'of=/dev/v2', 'seek=0', 'count=1', 'conv=fdatasync')] lvm.clear_volume('/dev/v2') self.assertEqual(expected_commands, executes) lvm_size = 1025 executes = [] expected_commands = [('dd', 'bs=1024', 'if=/dev/zero', 'of=/dev/v3', 'seek=0', 'count=1', 'conv=fdatasync')] expected_commands += [('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v3', 'seek=1024', 'count=1', 'conv=fdatasync')] lvm.clear_volume('/dev/v3') self.assertEqual(expected_commands, executes) lvm_size = 1048576 executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v4', 'seek=0', 'count=1', 'oflag=direct')] lvm.clear_volume('/dev/v4') self.assertEqual(expected_commands, executes) lvm_size = 1048577 executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v5', 'seek=0', 'count=1', 'oflag=direct')] expected_commands += [('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v5', 'seek=1048576', 'count=1', 'conv=fdatasync')] lvm.clear_volume('/dev/v5') self.assertEqual(expected_commands, executes) lvm_size = 1234567 executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v6', 'seek=0', 'count=1', 'oflag=direct')] expected_commands += [('dd', 'bs=1024', 'if=/dev/zero', 'of=/dev/v6', 'seek=1024', 'count=181', 'conv=fdatasync')] expected_commands += [('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v6', 'seek=1233920', 'count=647', 'conv=fdatasync')] lvm.clear_volume('/dev/v6') self.assertEqual(expected_commands, executes) # Test volume_clear_size limits the size lvm_size = 10485761 CONF.set_override('volume_clear_size', '1', 'libvirt') executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v7', 'seek=0', 'count=1', 'oflag=direct')] lvm.clear_volume('/dev/v7') self.assertEqual(expected_commands, executes) CONF.set_override('volume_clear_size', '2', 'libvirt') lvm_size = 1048576 executes = [] expected_commands = [('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v9', 'seek=0', 'count=1', 'oflag=direct')] lvm.clear_volume('/dev/v9') self.assertEqual(expected_commands, executes) # Test volume_clear=shred CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '0', 'libvirt') lvm_size = 1048576 executes = [] expected_commands = [('shred', '-n3', '-s1048576', '/dev/va')] lvm.clear_volume('/dev/va') self.assertEqual(expected_commands, executes) CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '1', 'libvirt') lvm_size = 10485761 executes = [] expected_commands = [('shred', '-n3', '-s1048576', '/dev/vb')] lvm.clear_volume('/dev/vb') self.assertEqual(expected_commands, executes) # Test volume_clear=none does nothing CONF.set_override('volume_clear', 'none', 'libvirt') executes = [] expected_commands = [] lvm.clear_volume('/dev/vc') self.assertEqual(expected_commands, executes)
def test_lvm_clear(self, mock_execute): def fake_lvm_size(path): return lvm_size self.stub_out('nova.virt.libvirt.storage.lvm.get_volume_size', fake_lvm_size) # Test the correct dd commands are run for various sizes lvm_size = 1 lvm.clear_volume('/dev/v1') mock_execute.assert_has_calls( [mock.call('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v1', 'seek=0', 'count=1', 'conv=fdatasync', run_as_root=True)]) mock_execute.reset_mock() lvm_size = 1024 lvm.clear_volume('/dev/v2') mock_execute.assert_has_calls( [mock.call('dd', 'bs=1024', 'if=/dev/zero', 'of=/dev/v2', 'seek=0', 'count=1', 'conv=fdatasync', run_as_root=True)]) mock_execute.reset_mock() lvm_size = 1025 lvm.clear_volume('/dev/v3') mock_execute.assert_has_calls( [mock.call('dd', 'bs=1024', 'if=/dev/zero', 'of=/dev/v3', 'seek=0', 'count=1', 'conv=fdatasync', run_as_root=True), mock.call('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v3', 'seek=1024', 'count=1', 'conv=fdatasync', run_as_root=True)]) mock_execute.reset_mock() lvm_size = 1048576 lvm.clear_volume('/dev/v4') mock_execute.assert_has_calls( [mock.call('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v4', 'seek=0', 'count=1', 'oflag=direct', run_as_root=True)]) mock_execute.reset_mock() lvm_size = 1048577 lvm.clear_volume('/dev/v5') mock_execute.assert_has_calls( [mock.call('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v5', 'seek=0', 'count=1', 'oflag=direct', run_as_root=True), mock.call('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v5', 'seek=1048576', 'count=1', 'conv=fdatasync', run_as_root=True)]) mock_execute.reset_mock() lvm_size = 1234567 lvm.clear_volume('/dev/v6') mock_execute.assert_has_calls( [mock.call('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v6', 'seek=0', 'count=1', 'oflag=direct', run_as_root=True), mock.call('dd', 'bs=1024', 'if=/dev/zero', 'of=/dev/v6', 'seek=1024', 'count=181', 'conv=fdatasync', run_as_root=True), mock.call('dd', 'bs=1', 'if=/dev/zero', 'of=/dev/v6', 'seek=1233920', 'count=647', 'conv=fdatasync', run_as_root=True)]) mock_execute.reset_mock() # Test volume_clear_size limits the size lvm_size = 10485761 CONF.set_override('volume_clear_size', '1', 'libvirt') lvm.clear_volume('/dev/v7') mock_execute.assert_has_calls( [mock.call('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v7', 'seek=0', 'count=1', 'oflag=direct', run_as_root=True)]) mock_execute.reset_mock() CONF.set_override('volume_clear_size', '2', 'libvirt') lvm_size = 1048576 lvm.clear_volume('/dev/v9') mock_execute.assert_has_calls( [mock.call('dd', 'bs=1048576', 'if=/dev/zero', 'of=/dev/v9', 'seek=0', 'count=1', 'oflag=direct', run_as_root=True)]) mock_execute.reset_mock() # Test volume_clear=shred CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '0', 'libvirt') lvm_size = 1048576 lvm.clear_volume('/dev/va') mock_execute.assert_has_calls( [mock.call('shred', '-n3', '-s1048576', '/dev/va', run_as_root=True)]) mock_execute.reset_mock() CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '1', 'libvirt') lvm_size = 10485761 lvm.clear_volume('/dev/vb') mock_execute.assert_has_calls( [mock.call('shred', '-n3', '-s1048576', '/dev/vb', run_as_root=True)]) mock_execute.reset_mock() # Test volume_clear=none does nothing CONF.set_override('volume_clear', 'none', 'libvirt') lvm.clear_volume('/dev/vc') mock_execute.assert_not_called()
def test_lvm_clear(self, mock_clear): def fake_lvm_size(path): return lvm_size self.stub_out('nova.virt.libvirt.storage.lvm.get_volume_size', fake_lvm_size) # Test zeroing volumes works CONF.set_override('volume_clear', 'zero', 'libvirt') lvm_size = 1024 lvm.clear_volume('/dev/v1') mock_clear.assert_has_calls([ mock.call('/dev/v1', 1024, shred=False)]) mock_clear.reset_mock() # Test volume_clear_size limits the size lvm_size = 10485761 CONF.set_override('volume_clear_size', '1', 'libvirt') lvm.clear_volume('/dev/v7') mock_clear.assert_has_calls( [mock.call('/dev/v7', 1048576, shred=False)]) mock_clear.reset_mock() CONF.set_override('volume_clear_size', '2', 'libvirt') lvm_size = 1048576 lvm.clear_volume('/dev/v9') mock_clear.assert_has_calls( [mock.call('/dev/v9', 1048576, shred=False)]) mock_clear.reset_mock() # Test volume_clear=shred CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '0', 'libvirt') lvm_size = 1048576 lvm.clear_volume('/dev/va') mock_clear.assert_has_calls([ mock.call('/dev/va', 1048576, shred=True)]) mock_clear.reset_mock() CONF.set_override('volume_clear', 'shred', 'libvirt') CONF.set_override('volume_clear_size', '1', 'libvirt') lvm_size = 10485761 lvm.clear_volume('/dev/vb') mock_clear.assert_has_calls([ mock.call('/dev/vb', 1 * units.Mi, shred=True)]) mock_clear.reset_mock() # Test volume_clear=none does nothing CONF.set_override('volume_clear', 'none', 'libvirt') lvm.clear_volume('/dev/vc') mock_clear.assert_not_called()
def test_lvm_clear_ignore_lvm_not_found(self, mock_blockdev_size): lvm.clear_volume('/dev/foo')