@error.context_aware
def lv_take_snapshot(vg_name, lv_name, lv_snapshot_name, lv_snapshot_size):
 error.context('Taking snapshot from original logical volume', logging.info)
 if (not vg_check(vg_name)):
  raise error.TestError('Volume group could not be found')
 if lv_check(vg_name, lv_snapshot_name):
  raise error.TestError('Snapshot already exists')
 if (not lv_check(vg_name, lv_name)):
  raise error.TestError("Snapshot's origin could not be found")
 cmd = ('lvcreate --size %s --snapshot --name %s /dev/%s/%s' % (lv_snapshot_size, lv_snapshot_name, vg_name, lv_name))
 try:
  result = utils.run(cmd)
 except error.CmdError as ex:
  if ((('Logical volume "%s" already exists in volume group "%s"' % (lv_snapshot_name, vg_name)) in ex.result_obj.stderr) and re.search(re.escape((lv_snapshot_name + ' [active]')), utils.run('lvdisplay').stdout)):
   logging.warning(('Logical volume %s is still active! ' + 'Attempting to deactivate...'), lv_name)
   lv_reactivate(vg_name, lv_name)
   result = utils.run(cmd)
  else:
   raise ex
 logging.info(result.stdout.rstrip())

@ error . context_aware def lv_take_snapshot ( vg_name , lv_name , lv_snapshot_name , lv_snapshot_size ) : error . context ( 'Taking snapshot from original logical volume' , logging . info ) if ( not vg_check ( vg_name ) ) : raise error . TestError ( 'Volume group could not be found' ) if lv_check ( vg_name , lv_snapshot_name ) : raise error . TestError ( 'Snapshot already exists' ) if ( not lv_check ( vg_name , lv_name ) ) : raise error . TestError ( "Snapshot's origin could not be found" ) cmd = ( 'lvcreate --size %s --snapshot --name %s /dev/%s/%s' % ( lv_snapshot_size , lv_snapshot_name , vg_name , lv_name ) ) try : result = utils . run ( cmd ) except error . CmdError as ex : if ( ( ( 'Logical volume "%s" already exists in volume group "%s"' % ( lv_snapshot_name , vg_name ) ) in ex . result_obj . stderr ) and re . search ( re . escape ( ( lv_snapshot_name + ' [active]' ) ) , utils . run ( 'lvdisplay' ) . stdout ) ) : logging . warning ( ( 'Logical volume %s is still active! ' + 'Attempting to deactivate...' ) , lv_name ) lv_reactivate ( vg_name , lv_name ) result = utils . run ( cmd ) else : raise ex logging . info ( result . stdout . rstrip ( ) )
take a snapshot of the original logical volume .