|
| 1 | +# Verify if a physical volume, volume group, logical volume, or filesystem resource type is created |
| 2 | +# |
| 3 | +# ==== Attributes |
| 4 | +# |
| 5 | +# * +resource_type+ - resorce type, i.e 'physical_volume', 'volume_group', 'logical_volume', or 'filesystem' |
| 6 | +# * +resource_name+ - The name of resource type, i.e '/dev/sdb' for physical volume, vg_1234 for volume group |
| 7 | +# * +vg+ - volume group name associated with logical volume (if any) |
| 8 | +# * +properties+ - a matching string or regular expression in logical volume properties |
| 9 | +# ==== Returns |
| 10 | +# |
| 11 | +# +nil+ |
| 12 | +# |
| 13 | +# ==== Raises |
| 14 | +# assert_match failure message |
| 15 | +# ==== Examples |
| 16 | +# |
| 17 | +# verify_if_created?(agent, 'physical_volume', /dev/sdb', VolumeGroup_123, "Size 7GB") |
| 18 | +def verify_if_created?(agent, resource_type, resource_name, vg=nil, properties=nil) |
| 19 | + case resource_type |
| 20 | + when 'physical_volume' |
| 21 | + on(agent, "pvdisplay") do |result| |
| 22 | + assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected') |
| 23 | + end |
| 24 | + when 'volume_group' |
| 25 | + on(agent, "vgdisplay") do |result| |
| 26 | + assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected') |
| 27 | + end |
| 28 | + when 'logical_volume' |
| 29 | + fail_test "Error: missing volume group that the logical volume is associated with" unless vg |
| 30 | + on(agent, "lvdisplay /dev/#{vg}/#{resource_name}") do |result| |
| 31 | + assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected') |
| 32 | + if properties |
| 33 | + assert_match(/#{properties}/, result.stdout, 'Unexpected error was detected') |
| 34 | + end |
| 35 | + end |
| 36 | + end |
| 37 | +end |
| 38 | + |
| 39 | +# Clean the box after each test, make sure the newly created logical volumes, volume groups, |
| 40 | +# and physical volumes are removed at the end of each test to make the server ready for the |
| 41 | +# next test case. |
| 42 | +# |
| 43 | +# ==== Attributes |
| 44 | +# |
| 45 | +# * +pv+ - physical volume, can be one volume or an array of multiple volumes |
| 46 | +# * +vg+ - volume group, can be one group or an array of multiple volume groups |
| 47 | +# * +lv+ - logical volume, can be one volume or an array of multiple volumes |
| 48 | +# |
| 49 | +# ==== Returns |
| 50 | +# |
| 51 | +# +nil+ |
| 52 | +# |
| 53 | +# ==== Raises |
| 54 | +# +nil+ |
| 55 | +# ==== Examples |
| 56 | +# |
| 57 | +# remove_all(agent, '/dev/sdb', 'VolumeGroup_1234', 'LogicalVolume_fa13') |
| 58 | +def remove_all(agent, pv=nil, vg=nil, lv=nil) |
| 59 | + step 'remove logical volume if any:' |
| 60 | + if lv |
| 61 | + if lv.kind_of?(Array) |
| 62 | + lv.each do |logical_volume| |
| 63 | + on(agent, "umount /dev/#{vg}/#{logical_volume}", :acceptable_exit_codes => [0,1]) |
| 64 | + on(agent, "lvremove /dev/#{vg}/#{logical_volume} --force") |
| 65 | + end |
| 66 | + else |
| 67 | + #note: in some test cases, for example, the test case 'create_vg_property_logical_volume' |
| 68 | + # the logical volume must be unmount before being able to delete it |
| 69 | + on(agent, "umount /dev/#{vg}/#{lv}", :acceptable_exit_codes => [0,1]) |
| 70 | + on(agent, "lvremove /dev/#{vg}/#{lv} --force") |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + step 'remove volume group if any:' |
| 75 | + if vg |
| 76 | + if vg.kind_of?(Array) |
| 77 | + vg.each do |volume_group| |
| 78 | + on(agent, "vgremove /dev/#{volume_group}") |
| 79 | + end |
| 80 | + else |
| 81 | + on(agent, "vgremove /dev/#{vg}") |
| 82 | + end |
| 83 | + end |
| 84 | + |
| 85 | + step 'remove logical volume if any:' |
| 86 | + if pv |
| 87 | + if pv.kind_of?(Array) |
| 88 | + pv.each do |physical_volume| |
| 89 | + on(agent, "pvremove #{physical_volume}") |
| 90 | + end |
| 91 | + else |
| 92 | + on(agent, "pvremove #{pv}") |
| 93 | + end |
| 94 | + end |
| 95 | +end |
0 commit comments