Commit 6429e8d8 authored by Iustin Pop's avatar Iustin Pop
Browse files

htools: read/save the disk template in Text backend



This requires that we change the signature of loadInst in order to
properly annotate the error messages, which in turn requires more
unittest changes.

Also, this invalidates yet again saved data files…
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent b3c5e8de
...@@ -506,7 +506,7 @@ testInstance = ...@@ -506,7 +506,7 @@ testInstance =
prop_Text_Load_Instance name mem dsk vcpus status prop_Text_Load_Instance name mem dsk vcpus status
(NonEmpty pnode) snode (NonEmpty pnode) snode
(NonNegative pdx) (NonNegative sdx) autobal = (NonNegative pdx) (NonNegative sdx) autobal dt =
pnode /= snode && pdx /= sdx ==> pnode /= snode && pdx /= sdx ==>
let vcpus_s = show vcpus let vcpus_s = show vcpus
dsk_s = show dsk dsk_s = show dsk
...@@ -517,20 +517,23 @@ prop_Text_Load_Instance name mem dsk vcpus status ...@@ -517,20 +517,23 @@ prop_Text_Load_Instance name mem dsk vcpus status
nl = Data.Map.fromList ndx nl = Data.Map.fromList ndx
tags = "" tags = ""
sbal = if autobal then "Y" else "N" sbal = if autobal then "Y" else "N"
sdt = Types.dtToString dt
inst = Text.loadInst nl inst = Text.loadInst nl
[name, mem_s, dsk_s, vcpus_s, status, [name, mem_s, dsk_s, vcpus_s, status,
sbal, pnode, snode, tags]:: Maybe (String, Instance.Instance) sbal, pnode, snode, sdt, tags]
fail1 = Text.loadInst nl fail1 = Text.loadInst nl
[name, mem_s, dsk_s, vcpus_s, status, [name, mem_s, dsk_s, vcpus_s, status,
sbal, pnode, pnode, tags]:: Maybe (String, Instance.Instance) sbal, pnode, pnode, tags]
_types = ( name::String, mem::Int, dsk::Int _types = ( name::String, mem::Int, dsk::Int
, vcpus::Int, status::String , vcpus::Int, status::String
, snode::String , snode::String
, autobal::Bool) , autobal::Bool)
in in
case inst of case inst of
Nothing -> False Types.Bad msg -> printTestCase ("Failed to load instance: " ++ msg)
Just (_, i) -> False
Types.Ok (_, i) -> printTestCase ("Mismatch in some field while\
\ loading the instance") $
Instance.name i == name && Instance.name i == name &&
Instance.vcpus i == vcpus && Instance.vcpus i == vcpus &&
Instance.mem i == mem && Instance.mem i == mem &&
...@@ -539,13 +542,15 @@ prop_Text_Load_Instance name mem dsk vcpus status ...@@ -539,13 +542,15 @@ prop_Text_Load_Instance name mem dsk vcpus status
then Node.noSecondary then Node.noSecondary
else sdx) && else sdx) &&
Instance.autoBalance i == autobal && Instance.autoBalance i == autobal &&
isNothing fail1 Types.isBad fail1
prop_Text_Load_InstanceFail ktn fields = prop_Text_Load_InstanceFail ktn fields =
length fields /= 9 ==> length fields /= 10 ==>
case Text.loadInst nl fields of case Text.loadInst nl fields of
Types.Ok _ -> False Types.Ok _ -> printTestCase "Managed to load instance from invalid\
Types.Bad msg -> "Invalid/incomplete instance data: '" `isPrefixOf` msg \ data" False
Types.Bad msg -> printTestCase ("Unrecognised error message: " ++ msg) $
"Invalid/incomplete instance data: '" `isPrefixOf` msg
where nl = Data.Map.fromList ktn where nl = Data.Map.fromList ktn
prop_Text_Load_Node name tm nm fm td fd tc fo = prop_Text_Load_Node name tm nm fm td fd tc fo =
......
...@@ -93,11 +93,12 @@ serializeInstance nl inst = ...@@ -93,11 +93,12 @@ serializeInstance nl inst =
then "" then ""
else Container.nameOf nl sidx) else Container.nameOf nl sidx)
in in
printf "%s|%d|%d|%d|%s|%s|%s|%s|%s" printf "%s|%d|%d|%d|%s|%s|%s|%s|%s|%s"
iname (Instance.mem inst) (Instance.dsk inst) iname (Instance.mem inst) (Instance.dsk inst)
(Instance.vcpus inst) (Instance.runSt inst) (Instance.vcpus inst) (Instance.runSt inst)
(if Instance.autoBalance inst then "Y" else "N") (if Instance.autoBalance inst then "Y" else "N")
pnode snode (intercalate "," (Instance.tags inst)) pnode snode (dtToString (Instance.diskTemplate inst))
(intercalate "," (Instance.tags inst))
-- | Generate instance file data from instance objects. -- | Generate instance file data from instance objects.
serializeInstances :: Node.List -> Instance.List -> String serializeInstances :: Node.List -> Instance.List -> String
...@@ -148,15 +149,13 @@ loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu] = do ...@@ -148,15 +149,13 @@ loadNode ktg [name, tm, nm, fm, td, fd, tc, fo, gu] = do
loadNode _ s = fail $ "Invalid/incomplete node data: '" ++ show s ++ "'" loadNode _ s = fail $ "Invalid/incomplete node data: '" ++ show s ++ "'"
-- | Load an instance from a field list. -- | Load an instance from a field list.
loadInst :: (Monad m) => loadInst :: NameAssoc -- ^ Association list with the current nodes
NameAssoc -- ^ Association list with -> [String] -- ^ Input data as a list of fields
-- the current nodes -> Result (String, Instance.Instance) -- ^ A tuple of
-> [String] -- ^ Input data as a list of -- instance name and
-- fields -- the instance object
-> m (String, Instance.Instance) -- ^ The result, a tuple of loadInst ktn [ name, mem, dsk, vcpus, status, auto_bal, pnode, snode
-- instance name and the , dt, tags ] = do
-- instance object
loadInst ktn [name, mem, dsk, vcpus, status, auto_bal, pnode, snode, tags] = do
pidx <- lookupNode ktn name pnode pidx <- lookupNode ktn name pnode
sidx <- (if null snode then return Node.noSecondary sidx <- (if null snode then return Node.noSecondary
else lookupNode ktn name snode) else lookupNode ktn name snode)
...@@ -168,11 +167,12 @@ loadInst ktn [name, mem, dsk, vcpus, status, auto_bal, pnode, snode, tags] = do ...@@ -168,11 +167,12 @@ loadInst ktn [name, mem, dsk, vcpus, status, auto_bal, pnode, snode, tags] = do
"N" -> return False "N" -> return False
_ -> fail $ "Invalid auto_balance value '" ++ auto_bal ++ _ -> fail $ "Invalid auto_balance value '" ++ auto_bal ++
"' for instance " ++ name "' for instance " ++ name
disk_template <- annotateResult ("Instance " ++ name) (dtFromString dt)
when (sidx == pidx) $ fail $ "Instance " ++ name ++ when (sidx == pidx) $ fail $ "Instance " ++ name ++
" has same primary and secondary node - " ++ pnode " has same primary and secondary node - " ++ pnode
let vtags = sepSplit ',' tags let vtags = sepSplit ',' tags
newinst = Instance.create name vmem vdsk vvcpus status vtags newinst = Instance.create name vmem vdsk vvcpus status vtags
auto_balance pidx sidx DTDrbd8 auto_balance pidx sidx disk_template
return (name, newinst) return (name, newinst)
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ show s ++ "'" loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ show s ++ "'"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment