11import org .scalacheck .Gen
22import org .scalacheck .commands .Commands
33
4- import util .{Try ,Success ,Failure }
4+ import util .{Try , Success , Failure }
55
66object CommandsNix extends org.scalacheck.Properties (" CommandsNix" ) {
77
@@ -13,14 +13,14 @@ object MachineSpec extends Commands {
1313
1414 val con = new org.libvirt.Connect (" qemu:///session" )
1515
16- def runSshCmd (ip : String , cmd : String ): Either [String ,String ] = {
16+ def runSshCmd (ip : String , cmd : String ): Either [String , String ] = {
1717 import scala .sys .process ._
1818 val err = new StringBuffer ()
1919 val logger = ProcessLogger (err.append(_))
2020
2121 val sshcmd =
2222 s " ssh -q -i test-key_rsa -l root -o UserKnownHostsFile=/dev/null " +
23- s " -o StrictHostKeyChecking=no -o ConnectTimeout=1 ${ip}"
23+ s " -o StrictHostKeyChecking=no -o ConnectTimeout=1 ${ip}"
2424
2525 if (s " $sshcmd true " ! logger != 0 )
2626 throw new Exception (err.toString)
@@ -55,10 +55,10 @@ object MachineSpec extends Commands {
5555 prefixLength = 24;
5656 };
5757 boot.kernelPackages =
58- pkgs.linuxPackages_ ${m.kernelVer.replace('.' ,'_' )};
58+ pkgs.linuxPackages_ ${m.kernelVer.replace('.' , '_' )};
5959 """
6060
61- def toLibvirtXMLs (machines : State ): Map [String ,String ] = {
61+ def toLibvirtXMLs (machines : State ): Map [String , String ] = {
6262 import scala .sys .process ._
6363 import java .io .ByteArrayInputStream
6464
@@ -74,23 +74,23 @@ object MachineSpec extends Commands {
7474
7575 // Check that all expected output files can be read
7676 xmlFiles.values foreach { f =>
77- if (! (new java.io.File (f)).canRead) throw new Exception (raw """
77+ if (! (new java.io.File (f)).canRead) throw new Exception (raw """
7878 No Libvirt XML produced ( ${f})
7979 out = ${out.toString}
8080 err = ${err.toString}
8181 """ )
8282 }
8383
84- xmlFiles map { case (id,f) => id -> io.Source .fromFile(f).mkString }
84+ xmlFiles map { case (id, f) => id -> io.Source .fromFile(f).mkString }
8585 }
8686
87- case class Machine (
88- id : String ,
89- uuid : java.util.UUID ,
90- ip : String ,
91- kernelVer : String ,
92- memory : Int ,
93- running : Boolean
87+ case class Machine (
88+ id : String ,
89+ uuid : java.util.UUID ,
90+ ip : String ,
91+ kernelVer : String ,
92+ memory : Int ,
93+ running : Boolean
9494 )
9595
9696 // Machine.id mapped to a machine state
@@ -100,12 +100,10 @@ object MachineSpec extends Commands {
100100 type Sut = Map [String , org.libvirt.Domain ]
101101
102102 // TODO we should check for example total amount of memory used here
103- def canCreateNewSut (newState : State , initSuts : Traversable [State ],
104- runningSuts : Traversable [Sut ]
105- ): Boolean = true
103+ def canCreateNewSut (newState : State , initSuts : Traversable [State ], runningSuts : Traversable [Sut ]): Boolean = true
106104
107105 def newSut (state : State ): Sut = {
108- toLibvirtXMLs(state) map { case (id,xml) => id -> con.domainDefineXML(xml) }
106+ toLibvirtXMLs(state) map { case (id, xml) => id -> con.domainDefineXML(xml) }
109107 }
110108
111109 def destroySut (sut : Sut ) = sut.values foreach { d =>
@@ -121,22 +119,22 @@ object MachineSpec extends Commands {
121119
122120 // generate a 10.x.y subnet
123121 val genSubnet : Gen [List [Int ]] = for {
124- x <- Gen .choose(0 ,255 )
125- y <- Gen .choose(0 ,255 )
126- } yield List (10 ,x, y)
122+ x <- Gen .choose(0 , 255 )
123+ y <- Gen .choose(0 , 255 )
124+ } yield List (10 , x, y)
127125
128126 def hasDuplicates (xs : Seq [Any ]): Boolean = xs.distinct.length != xs.length
129127
130128 def genMachine (id : String , subnet : List [Int ]): Gen [Machine ] = for {
131129 uuid <- Gen .uuid
132- // ip <- Gen.choose(2,254).map(n => (subnet :+ n).mkString("."))
133- ip <- Gen .choose(2 ,254 ).map(n => s " 172.16.2. $n" )
130+ // ip <- Gen.choose(2,254).map(n => (subnet :+ n).mkString("."))
131+ ip <- Gen .choose(2 , 254 ).map(n => s " 172.16.2. $n" )
134132 memory <- Gen .choose(96 , 256 )
135133 kernel <- Gen .oneOf(" 3.14" , " 3.13" , " 3.12" , " 3.10" )
136- } yield Machine (id, uuid, ip, kernel, memory, false )
134+ } yield Machine (id, uuid, ip, kernel, memory, false )
137135
138136 val genInitialState : Gen [State ] = for {
139- machineCount <- Gen .choose(5 ,5 )
137+ machineCount <- Gen .choose(5 , 5 )
140138 idGen = Gen .listOfN(8 , Gen .alphaLowerChar).map(_.mkString)
141139 ids <- Gen .listOfN(machineCount, idGen)
142140 subnet <- genSubnet
@@ -162,8 +160,8 @@ object MachineSpec extends Commands {
162160 )
163161
164162 def genCommand (state : State ): Gen [Command ] =
165- if (state.forall(! _.running)) genBoot(state)
166- else if (state.forall(_.running)) Gen .frequency(
163+ if (state.forall(! _.running)) genBoot(state)
164+ else if (state.forall(_.running)) Gen .frequency(
167165 (1 , genShutdown(state)),
168166 (4 , genPingOnline(state))
169167 )
0 commit comments