<s> import mock <EOL> from oslo_concurrency import processutils <EOL> from oslo_config import cfg <EOL> from nova import exception <EOL> from nova import test <EOL> from nova import utils <EOL> from nova . virt . libvirt . storage import lvm <EOL> from nova . virt . libvirt import utils as libvirt_utils <EOL> CONF = cfg . CONF <EOL> class LvmTestCase ( test . NoDBTestCase ) : <EOL> def test_get_volume_size ( self ) : <EOL> executes = [ ] <EOL> def fake_execute ( * cmd , ** kwargs ) : <EOL> executes . append ( cmd ) <EOL> return <NUM_LIT> , None <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> self . stubs . Set ( utils , '<STR_LIT>' , fake_execute ) <EOL> size = lvm . get_volume_size ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> self . assertEqual ( size , <NUM_LIT> ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' , <EOL> side_effect = processutils . ProcessExecutionError ( <EOL> stderr = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) ) <EOL> def test_get_volume_size_not_found ( self , mock_execute ) : <EOL> self . assertRaises ( exception . VolumeBDMPathNotFound , <EOL> lvm . get_volume_size , '<STR_LIT>' ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' , <EOL> side_effect = processutils . ProcessExecutionError ( <EOL> stderr = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) ) <EOL> def test_get_volume_size_not_found_file ( self , mock_execute ) : <EOL> self . assertRaises ( exception . VolumeBDMPathNotFound , <EOL> lvm . get_volume_size , '<STR_LIT>' ) <EOL> @ mock . patch . object ( libvirt_utils , '<STR_LIT>' , return_value = True ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' , <EOL> side_effect = processutils . ProcessExecutionError ( <EOL> stderr = '<STR_LIT>' ) ) <EOL> def test_get_volume_size_unexpectd_error ( self , mock_execute , <EOL> mock_path_exists ) : <EOL> self . assertRaises ( processutils . ProcessExecutionError , <EOL> lvm . get_volume_size , '<STR_LIT>' ) <EOL> def test_lvm_clear ( self ) : <EOL> def fake_lvm_size ( path ) : <EOL> return lvm_size <EOL> def fake_execute ( * cmd , ** kwargs ) : <EOL> executes . append ( cmd ) <EOL> self . stubs . Set ( lvm , '<STR_LIT>' , fake_lvm_size ) <EOL> self . stubs . Set ( utils , '<STR_LIT>' , fake_execute ) <EOL> lvm_size = <NUM_LIT:1> <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> lvm_size = <NUM_LIT> <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> lvm_size = <NUM_LIT> <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> expected_commands += [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> lvm_size = <NUM_LIT> <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> lvm_size = <NUM_LIT> <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> expected_commands += [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> lvm_size = <NUM_LIT> <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> expected_commands += [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> expected_commands += [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> lvm_size = <NUM_LIT> <EOL> CONF . set_override ( '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT>' ) <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> CONF . set_override ( '<STR_LIT>' , '<STR_LIT:2>' , '<STR_LIT>' ) <EOL> lvm_size = <NUM_LIT> <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CONF . set_override ( '<STR_LIT>' , '<STR_LIT:0>' , '<STR_LIT>' ) <EOL> lvm_size = <NUM_LIT> <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CONF . set_override ( '<STR_LIT>' , '<STR_LIT:1>' , '<STR_LIT>' ) <EOL> lvm_size = <NUM_LIT> <EOL> executes = [ ] <EOL> expected_commands = [ ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> CONF . set_override ( '<STR_LIT>' , '<STR_LIT:none>' , '<STR_LIT>' ) <EOL> executes = [ ] <EOL> expected_commands = [ ] <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> self . assertEqual ( expected_commands , executes ) <EOL> @ mock . patch . object ( utils , '<STR_LIT>' , <EOL> side_effect = processutils . ProcessExecutionError ( <EOL> stderr = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) ) <EOL> def test_lvm_clear_ignore_lvm_not_found ( self , mock_execute ) : <EOL> lvm . clear_volume ( '<STR_LIT>' ) <EOL> def test_fail_remove_all_logical_volumes ( self ) : <EOL> def fake_execute ( * args , ** kwargs ) : <EOL> if '<STR_LIT>' in args : <EOL> raise processutils . ProcessExecutionError ( '<STR_LIT>' ) <EOL> with test . nested ( <EOL> mock . patch . object ( lvm , '<STR_LIT>' ) , <EOL> mock . patch . object ( libvirt_utils , '<STR_LIT>' , <EOL> side_effect = fake_execute ) ) as ( mock_clear , mock_execute ) : <EOL> self . assertRaises ( exception . VolumesNotRemoved , <EOL> lvm . remove_volumes , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:3> , mock_execute . call_count ) </s>
