Revision a2a0bcd8
b/htools/Ganeti/HTools/QC.hs | ||
---|---|---|
209 | 209 |
il' = Container.add maxiidx inst' il |
210 | 210 |
in (nl', il') |
211 | 211 |
|
212 |
-- | Generates a list of a given size with non-duplicate elements. |
|
213 |
genUniquesList :: (Eq a, Arbitrary a) => Int -> Gen [a] |
|
214 |
genUniquesList cnt = |
|
215 |
foldM (\lst _ -> do |
|
216 |
newelem <- arbitrary `suchThat` (`notElem` lst) |
|
217 |
return (newelem:lst)) [] [1..cnt] |
|
218 |
|
|
212 | 219 |
-- * Arbitrary instances |
213 | 220 |
|
214 | 221 |
-- | Defines a DNS name. |
... | ... | |
219 | 226 |
x <- elements (['a'..'z'] ++ ['0'..'9'] ++ "_-") |
220 | 227 |
return (DNSChar x) |
221 | 228 |
|
229 |
-- | Generates a single name component. |
|
222 | 230 |
getName :: Gen String |
223 | 231 |
getName = do |
224 | 232 |
n <- choose (1, 64) |
225 | 233 |
dn <- vector n::Gen [DNSChar] |
226 | 234 |
return (map dnsGetChar dn) |
227 | 235 |
|
236 |
-- | Generates an entire FQDN. |
|
228 | 237 |
getFQDN :: Gen String |
229 | 238 |
getFQDN = do |
230 |
felem <- getName |
|
231 | 239 |
ncomps <- choose (1, 4) |
232 |
frest <- vector ncomps::Gen [[DNSChar]] |
|
233 |
let frest' = map (map dnsGetChar) frest |
|
234 |
return (felem ++ "." ++ intercalate "." frest') |
|
240 |
names <- mapM (const getName) [1..ncomps::Int] |
|
241 |
return $ intercalate "." names |
|
235 | 242 |
|
236 | 243 |
-- | Defines a tag type. |
237 | 244 |
newtype TagChar = TagChar { tagGetChar :: Char } |
... | ... | |
566 | 573 |
-- | We test that in a cluster, given a random node, we can find it by |
567 | 574 |
-- its name and alias, as long as all names and aliases are unique, |
568 | 575 |
-- and that we fail to find a non-existing name. |
569 |
prop_Container_findByName node othername =
|
|
576 |
prop_Container_findByName node = |
|
570 | 577 |
forAll (choose (1, 20)) $ \ cnt -> |
571 | 578 |
forAll (choose (0, cnt - 1)) $ \ fidx -> |
572 |
forAll (vector cnt) $ \ names -> |
|
573 |
(length . nub) (map fst names ++ map snd names) == |
|
574 |
length names * 2 && |
|
575 |
othername `notElem` (map fst names ++ map snd names) ==> |
|
576 |
let nl = makeSmallCluster node cnt |
|
579 |
forAll (genUniquesList (cnt * 2)) $ \ allnames -> |
|
580 |
forAll (arbitrary `suchThat` (`notElem` allnames)) $ \ othername -> |
|
581 |
let names = zip (take cnt allnames) (drop cnt allnames) |
|
582 |
nl = makeSmallCluster node cnt |
|
577 | 583 |
nodes = Container.elems nl |
578 | 584 |
nodes' = map (\((name, alias), nn) -> (Node.idx nn, |
579 | 585 |
nn { Node.name = name, |
... | ... | |
906 | 912 |
_ -> False |
907 | 913 |
|
908 | 914 |
prop_Node_addSecOffline pdx = |
909 |
forAll (arbitrary `suchThat` ((> 0) . Node.fMem)) $ \node ->
|
|
915 |
forAll genOnlineNode $ \node ->
|
|
910 | 916 |
forAll (arbitrary `suchThat` |
911 |
(\ x -> (Instance.dsk x < Node.fDsk node) && |
|
912 |
Instance.instanceOffline x)) $ \inst -> |
|
913 |
case Node.addSec node inst pdx of |
|
917 |
(\ inst -> Instance.dsk inst < Node.availDisk node)) $ \inst -> |
|
918 |
case Node.addSec node (inst { Instance.runSt = Types.AdminOffline }) pdx of |
|
914 | 919 |
Types.OpGood _ -> True |
915 | 920 |
_ -> False |
916 | 921 |
|
Also available in: Unified diff