Revision 6429e8d8

b/htools/Ganeti/HTools/QC.hs
506 506

  
507 507
prop_Text_Load_Instance name mem dsk vcpus status
508 508
                        (NonEmpty pnode) snode
509
                        (NonNegative pdx) (NonNegative sdx) autobal =
509
                        (NonNegative pdx) (NonNegative sdx) autobal dt =
510 510
    pnode /= snode && pdx /= sdx ==>
511 511
    let vcpus_s = show vcpus
512 512
        dsk_s = show dsk
......
517 517
        nl = Data.Map.fromList ndx
518 518
        tags = ""
519 519
        sbal = if autobal then "Y" else "N"
520
        sdt = Types.dtToString dt
520 521
        inst = Text.loadInst nl
521 522
               [name, mem_s, dsk_s, vcpus_s, status,
522
                sbal, pnode, snode, tags]:: Maybe (String, Instance.Instance)
523
                sbal, pnode, snode, sdt, tags]
523 524
        fail1 = Text.loadInst nl
524 525
               [name, mem_s, dsk_s, vcpus_s, status,
525
                sbal, pnode, pnode, tags]:: Maybe (String, Instance.Instance)
526
                sbal, pnode, pnode, tags]
526 527
        _types = ( name::String, mem::Int, dsk::Int
527 528
                 , vcpus::Int, status::String
528 529
                 , snode::String
529 530
                 , autobal::Bool)
530 531
    in
531 532
      case inst of
532
        Nothing -> False
533
        Just (_, i) ->
533
        Types.Bad msg -> printTestCase ("Failed to load instance: " ++ msg)
534
                         False
535
        Types.Ok (_, i) -> printTestCase ("Mismatch in some field while\
536
                                          \ loading the instance") $
534 537
            Instance.name i == name &&
535 538
            Instance.vcpus i == vcpus &&
536 539
            Instance.mem i == mem &&
......
539 542
                                 then Node.noSecondary
540 543
                                 else sdx) &&
541 544
            Instance.autoBalance i == autobal &&
542
            isNothing fail1
545
            Types.isBad fail1
543 546

  
544 547
prop_Text_Load_InstanceFail ktn fields =
545
    length fields /= 9 ==>
548
    length fields /= 10 ==>
546 549
    case Text.loadInst nl fields of
547
      Types.Ok _ -> False
548
      Types.Bad msg -> "Invalid/incomplete instance data: '" `isPrefixOf` msg
550
      Types.Ok _ -> printTestCase "Managed to load instance from invalid\
551
                                  \ data" False
552
      Types.Bad msg -> printTestCase ("Unrecognised error message: " ++ msg) $
553
                       "Invalid/incomplete instance data: '" `isPrefixOf` msg
549 554
    where nl = Data.Map.fromList ktn
550 555

  
551 556
prop_Text_Load_Node name tm nm fm td fd tc fo =
b/htools/Ganeti/HTools/Text.hs
93 93
                    then ""
94 94
                    else Container.nameOf nl sidx)
95 95
    in
96
      printf "%s|%d|%d|%d|%s|%s|%s|%s|%s"
96
      printf "%s|%d|%d|%d|%s|%s|%s|%s|%s|%s"
97 97
             iname (Instance.mem inst) (Instance.dsk inst)
98 98
             (Instance.vcpus inst) (Instance.runSt inst)
99 99
             (if Instance.autoBalance inst then "Y" else "N")
100
             pnode snode (intercalate "," (Instance.tags inst))
100
             pnode snode (dtToString (Instance.diskTemplate inst))
101
             (intercalate "," (Instance.tags inst))
101 102

  
102 103
-- | Generate instance file data from instance objects.
103 104
serializeInstances :: Node.List -> Instance.List -> String
......
148 149
loadNode _ s = fail $ "Invalid/incomplete node data: '" ++ show s ++ "'"
149 150

  
150 151
-- | Load an instance from a field list.
151
loadInst :: (Monad m) =>
152
            NameAssoc                     -- ^ Association list with
153
                                          -- the current nodes
154
         -> [String]                      -- ^ Input data as a list of
155
                                          -- fields
156
         -> m (String, Instance.Instance) -- ^ The result, a tuple of
157
                                          -- instance name and the
158
                                          -- instance object
159
loadInst ktn [name, mem, dsk, vcpus, status, auto_bal, pnode, snode, tags] = do
152
loadInst :: NameAssoc -- ^ Association list with the current nodes
153
         -> [String]  -- ^ Input data as a list of fields
154
         -> Result (String, Instance.Instance) -- ^ A tuple of
155
                                               -- instance name and
156
                                               -- the instance object
157
loadInst ktn [ name, mem, dsk, vcpus, status, auto_bal, pnode, snode
158
             , dt, tags ] = do
160 159
  pidx <- lookupNode ktn name pnode
161 160
  sidx <- (if null snode then return Node.noSecondary
162 161
           else lookupNode ktn name snode)
......
168 167
                    "N" -> return False
169 168
                    _ -> fail $ "Invalid auto_balance value '" ++ auto_bal ++
170 169
                         "' for instance " ++ name
170
  disk_template <- annotateResult ("Instance " ++ name) (dtFromString dt)
171 171
  when (sidx == pidx) $ fail $ "Instance " ++ name ++
172 172
           " has same primary and secondary node - " ++ pnode
173 173
  let vtags = sepSplit ',' tags
174 174
      newinst = Instance.create name vmem vdsk vvcpus status vtags
175
                auto_balance pidx sidx DTDrbd8
175
                auto_balance pidx sidx disk_template
176 176
  return (name, newinst)
177 177
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ show s ++ "'"
178 178

  

Also available in: Unified diff