package Ġcom . github . ker ub istan . ker ub . planner . steps . storage . l vm . pool . create Ċ Ċ import Ġcom . github . ker ub istan . ker ub . data . config . Host Configuration Dao Ċ import Ġcom . github . ker ub istan . ker ub . host . Host Command Executor Ċ import Ġcom . github . ker ub istan . ker ub . host . mock Host Ċ import Ġcom . github . ker ub istan . ker ub . model . L vm Storage Capability Ċ import Ġcom . github . ker ub istan . ker ub . model . config . Host Configuration Ċ import Ġcom . github . ker ub istan . ker ub . model . hardware . Block Device Ċ import Ġcom . github . ker ub istan . ker ub . ss ht est utils . mock Command Execution Ċ import Ġcom . github . ker ub istan . ker ub . ss ht est utils . mock Command Execution Sequence Ċ import Ġcom . github . ker ub istan . ker ub . test Host Ċ import Ġcom . github . ker ub istan . ker ub . test Host Capabilities Ċ import Ġcom . github . ker ub istan . ker ub . utils . j unix . storage manager . l vm . Logical Volume Ċ import Ġcom . n ha ar man . mockito _ kotlin . any Ċ import Ġcom . n ha ar man . mockito _ kotlin . do Answer Ċ import Ġcom . n ha ar man . mockito _ kotlin . eq Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġio . github . ker ub istan . k ro ki . size . GB Ċ import Ġio . github . ker ub istan . k ro ki . size . TB Ċ import Ġorg . apache . ss hd . client . session . Client Session Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . jupiter . api . assert Throws Ċ import Ġjava . math . BigInteger Ċ import Ġjava . util . UUID Ċ import Ġjava . util . UUID . randomUUID Ċ import Ġkotlin . test . assertEquals Ċ Ċ class ĠCreate L vm Pool Executor Test Ġ{ ĊĊ ĉ @ Test Ċ ĉ fun Ġprepare () Ġ{ Ċĉ ĉ assert Throws < IllegalStateException >(" request ing Ġmore Ġspace Ġthan Ġwhat Ġis Ġavailable ") Ġ{ Ċĉĉ ĉ simulate With Capability ( vg Free Ġ= Ġ 1 2 8 . GB , Ġpool Size Ġ= Ġ 5 1 2 . GB ) Ċĉ ĉ } Ċĉ ĉ assert Throws < IllegalStateException >(" request ing Ġall Ġavailable Ġ( nothing Ġleft Ġfor Ġmeta )") Ġ{ Ċĉĉ ĉ simulate With Capability ( vg Free Ġ= Ġ 5 1 2 . GB , Ġpool Size Ġ= Ġ 5 1 2 . GB ) Ċĉ ĉ } Ċĉ ĉ assert Throws < IllegalStateException >(" request ing Ġal mos Ġall Ġavailable Ġ( not Ġenough Ġleft Ġfor Ġmeta )") Ġ{ Ċĉĉ ĉ simulate With Capability ( vg Free Ġ= Ġ 5 1 2 . GB , Ġpool Size Ġ= Ġ 5 1 1 . GB ) Ċĉ ĉ } ĊĊĉ ĉ // Ġshould Ġwork Ċĉ ĉ simulate With Capability ( vg Free Ġ= Ġ 5 1 2 . GB , Ġpool Size Ġ= Ġ 4 0 0 . GB ) ĊĊ ĉ } ĊĊ ĉ private Ġfun Ġsimulate With Capability ( vg Free : ĠBigInteger , Ġpool Size : ĠBigInteger ) Ġ{ Ċĉ ĉ val Ġhost Command Executor Ġ= Ġmock < Host Command Executor >() Ċĉ ĉ val Ġsession Ġ= Ġmock < Client Session >() Ċĉ ĉ val Ġl vm Storage Capability Ġ= ĠL vm Storage Capability ( Ċĉĉĉ ĉ volume GroupName Ġ= Ġ" vg - 1 ", Ċĉĉĉ ĉ size Ġ= Ġ 1 . TB , Ċĉĉĉ ĉ id Ġ= Ġrandom UUID (), Ċĉĉĉ ĉ physical Volumes Ġ= Ġmap Of ("/ dev / sda " Ġto Ġ 1 . TB ) Ċĉ ĉ ) Ċĉ ĉ val Ġhost Ġ= Ġtest Host . copy ( Ċĉĉĉ ĉ capabilities Ġ= Ġtest Host Capabilities . copy ( Ċĉĉĉĉĉ ĉ block Devices Ġ= ĠlistOf ( Ċĉĉĉĉĉĉĉ ĉ Block Device ( device Name Ġ= Ġ"/ dev / sda ", Ġstorage Capacity Ġ= Ġ 1 . TB ) Ċĉĉĉĉĉ ĉ ), Ċĉĉĉĉĉ ĉ storage Capabilities Ġ= ĠlistOf ( Ċĉĉĉĉĉĉĉ ĉ l vm Storage Capability Ċĉĉĉĉĉ ĉ ) Ċĉĉĉ ĉ ) Ċĉ ĉ ) Ċĉ ĉ host Command Executor . mock Host ( host , Ġsession ) Ċĉ ĉ session . mock Command Execution ( Ċĉĉĉ ĉ " l vm Ġv gs .* ". to Regex (), Ċĉĉĉ ĉ output Ġ= Ġ" u P PT 5 K - R ty m - cx QX - f 3 iu - oi Z f - M 4 Z 3 - t 8 v 4 We :${ l vm Storage Capability . volume GroupName }" Ġ+ Ċĉĉĉĉĉ ĉ ": ${ l vm Storage Capability . size } B :${ vg Free } B : 1 0 2 2 : 2 5 4 \ n ") Ċĉ ĉ Create L vm Pool Executor ( host Command Executor , Ġmock ()). prepare ( Ċĉĉĉ ĉ Create L vm Pool ( Ċĉĉĉĉĉ ĉ host Ġ= Ġhost , Ċĉĉĉĉĉ ĉ vg Name Ġ= Ġl vm Storage Capability . volume GroupName , Ċĉĉĉĉĉ ĉ size Ġ= Ġpool Size , Ċĉĉĉĉĉ ĉ name Ġ= Ġrandom UUID (). toString () Ċĉĉĉ ĉ ) Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġperform () Ġ{ Ċĉ ĉ val Ġhost Command Executor Ġ= Ġmock < Host Command Executor >() Ċĉ ĉ val Ġhost Cfg Dao Ġ= Ġmock < Host Configuration Dao >() Ċĉ ĉ val Ġsession Ġ= Ġmock < Client Session >() Ċĉ ĉ val Ġl vm Storage Capability Ġ= ĠL vm Storage Capability ( Ċĉĉĉ ĉ volume GroupName Ġ= Ġ" vg - 1 ", Ċĉĉĉ ĉ size Ġ= Ġ 1 . TB , Ċĉĉĉ ĉ id Ġ= Ġrandom UUID (), Ċĉĉĉ ĉ physical Volumes Ġ= Ġmap Of ("/ dev / sda " Ġto Ġ 1 . TB ) Ċĉ ĉ ) Ċĉ ĉ val Ġhost Ġ= Ġtest Host . copy ( Ċĉĉĉ ĉ capabilities Ġ= Ġtest Host Capabilities . copy ( Ċĉĉĉĉĉ ĉ block Devices Ġ= ĠlistOf ( Ċĉĉĉĉĉĉĉ ĉ Block Device ( device Name Ġ= Ġ"/ dev / sda ", Ġstorage Capacity Ġ= Ġ 1 . TB ) Ċĉĉĉĉĉ ĉ ), Ċĉĉĉĉĉ ĉ storage Capabilities Ġ= ĠlistOf ( Ċĉĉĉĉĉĉĉ ĉ l vm Storage Capability Ċĉĉĉĉĉ ĉ ) Ċĉĉĉ ĉ ) Ċĉ ĉ ) Ċĉ ĉ val Ġhost Cfg Ġ= ĠHost Configuration ( Ċĉĉĉ ĉ id Ġ= Ġhost . id Ċĉ ĉ ) ĊĊĉ ĉ wh enever ( host Cfg Dao [ host . id ]). thenReturn ( host Cfg ) Ċĉ ĉ session . mock Command Execution Sequence ( Ċĉĉĉ ĉ ". * ". to Regex (), Ġoutputs Ġ= ĠlistOf ( Ċĉĉĉ ĉ "\ n ", Ċĉĉĉ ĉ " vg - 1 : la 6 xp 4 - En 1 K - fk h X - 0 Z us - PW p 7 - 1 cat - m BX KU k : test - pool :: 2 1 4 7 4 8 3 6 4 8 0 B ::: thin , pool : 0 . 0 0 \ n " Ċĉ ĉ )) Ċĉ ĉ host Command Executor . mock Host ( host , Ġsession ) ĊĊĉ ĉ val Ġupdate Ġ= ĠCreate L vm Pool Executor ( host Command Executor , Ġhost Cfg Dao ). perform ( Ċĉĉĉ ĉ Create L vm Pool ( Ċĉĉĉĉĉ ĉ vg Name Ġ= Ġl vm Storage Capability . volume GroupName , Ċĉĉĉĉĉ ĉ size Ġ= Ġ 1 2 . GB , Ċĉĉĉĉĉ ĉ host Ġ= Ġhost , Ċĉĉĉĉĉ ĉ name Ġ= Ġ" test - pool " Ċĉĉĉ ĉ ) Ċĉ ĉ ) Ċĉ ĉ assertEquals (" test - pool ", Ġupdate . name ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġupdate () Ġ{ Ċĉ ĉ val Ġl vm Storage Capability Ġ= ĠL vm Storage Capability ( Ċĉĉĉ ĉ volume GroupName Ġ= Ġ" vg - 1 ", Ċĉĉĉ ĉ size Ġ= Ġ 1 . TB , Ċĉĉĉ ĉ id Ġ= Ġrandom UUID (), Ċĉĉĉ ĉ physical Volumes Ġ= Ġmap Of ("/ dev / sda " Ġto Ġ 1 . TB ) Ċĉ ĉ ) Ċĉ ĉ val Ġhost Ġ= Ġtest Host . copy ( Ċĉĉ ĉ capabilities Ġ= Ġtest Host Capabilities . copy ( Ċĉĉĉĉ ĉ block Devices Ġ= ĠlistOf ( Ċĉĉĉĉĉĉ ĉ Block Device ( device Name Ġ= Ġ"/ dev / sda ", Ġstorage Capacity Ġ= Ġ 1 . TB ) Ċĉĉĉĉ ĉ ), Ċĉĉĉĉ ĉ storage Capabilities Ġ= ĠlistOf ( Ċĉĉĉĉĉĉ ĉ l vm Storage Capability Ċĉĉĉĉ ĉ ) Ċĉĉ ĉ ) Ċĉ ĉ ) Ċĉ ĉ val Ġhost Cfg Ġ= ĠHost Configuration ( Ċĉĉĉ ĉ id Ġ= Ġhost . id Ċĉ ĉ ) ĊĊĉ ĉ val Ġhost Cfg Dao Ġ= Ġmock < Host Configuration Dao >() ĊĊĉ ĉ wh enever ( host Cfg Dao [ eq ( host . id )] ). thenReturn ( host Cfg ) Ċĉ ĉ do Answer Ġ{ Ċĉĉ ĉ val Ġcfg Ġ= Ġ( it . arguments [ 1 ] Ġas Ġ( UUID ) Ġ-> ĠHost Configuration ). invoke ( it . arguments [ 0 ] Ġas ĠUUID ) Ċĉĉ ĉ ( it . arguments [ 2 ] Ġas Ġ( Host Configuration ) Ġ-> ĠHost Configuration ). invoke ( cfg ) Ċĉ ĉ }. wh enever ( host Cfg Dao ). update ( eq ( host . id ), Ġany (), Ġany ()) ĊĊĉ ĉ Create L vm Pool Executor ( mock (), Ġhost Cfg Dao ). update ( Ċĉĉĉ ĉ Create L vm Pool ( Ċĉĉĉĉĉ ĉ vg Name Ġ= Ġl vm Storage Capability . volume GroupName , Ċĉĉĉĉĉ ĉ size Ġ= Ġ 1 2 . GB , Ċĉĉĉĉĉ ĉ host Ġ= Ġhost , Ċĉĉĉĉĉ ĉ name Ġ= Ġ" test - pool " Ċĉĉĉ ĉ ), Ċĉĉĉ ĉ Logical Volume ( Ċĉĉĉĉĉ ĉ id Ġ= Ġ" la 6 xp 4 - En 1 K - fk h X - 0 Z us - PW p 7 - 1 cat - m BX KU k ", Ċĉĉĉĉĉ ĉ size Ġ= Ġ 1 2 . GB , Ċĉĉĉĉĉ ĉ volume GroupName Ġ= Ġ" vg - 1 ", Ċĉĉĉĉĉ ĉ path Ġ= Ġ"", Ċĉĉĉĉĉ ĉ name Ġ= Ġ" test - pool ", Ċĉĉĉĉĉ ĉ layout Ġ= ĠlistOf (), Ċĉĉĉĉĉ ĉ data Percent Ġ= Ġnull , Ċĉĉĉĉĉ ĉ max Recovery Ġ= Ġnull , Ċĉĉĉĉĉ ĉ min Recovery Ġ= Ġnull Ċĉĉĉ ĉ ) Ċĉ ĉ ) ĊĊĉ ĉ verify ( host Cfg Dao ). update ( eq ( host . id ), Ġany (), Ġany ()) Ċ ĉ } Ċ Ċ }