Add "instance" field to LVInfo
authorMichele Tartara <mtartara@google.com>
Tue, 2 Jul 2013 09:24:26 +0000 (11:24 +0200)
committerMichele Tartara <mtartara@google.com>
Thu, 4 Jul 2013 17:03:08 +0000 (19:03 +0200)
Extend the LVInfo data structure with the field for storing the name of
the instance it is paired with.

Update the tests accordingly.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

src/Ganeti/Storage/Lvm/LVParser.hs
src/Ganeti/Storage/Lvm/Types.hs
test/hs/Test/Ganeti/Storage/Lvm/LVParser.hs

index 9d355d9..54d1bdf 100644 (file)
@@ -112,7 +112,8 @@ oneLvParser =
         <$> uuidP <*> nameP <*> attrP <*> majorP <*> minorP <*> kernelMajorP
         <*> kernelMinorP <*> sizeP <*> segCountP <*> tagsP <*> modulesP
         <*> vgUuidP <*> vgNameP <*> segtypeP <*> segStartP <*> segStartPeP
-        <*> segSizeP <*> segTagsP <*> segPeRangesP <*> devicesP <* A.endOfLine
+        <*> segSizeP <*> segTagsP <*> segPeRangesP <*> devicesP 
+        <*> return Nothing <* A.endOfLine
 
 -- | The parser for a whole diskstatus file.
 lvParser :: Parser [LVInfo]
index 162e2be..e4c096f 100644 (file)
@@ -54,4 +54,6 @@ $(buildObject "LVInfo" "lvi"
   , simpleField "seg_tags"          [t| String |]
   , simpleField "seg_pe_ranges"     [t| String |]
   , simpleField "devices"           [t| String |]
+  , optionalNullSerField $
+    simpleField "instance"          [t| String |]
   ])
index 0971e64..7c3d7bd 100644 (file)
@@ -49,16 +49,18 @@ case_lvs_lv = testParser lvParser "lvs_lv.txt"
       (negate 1) 253 0 1073741824 1
       "originstname+instance1.example.com" ""
       "uZgXit-eiRr-vRqe-xpEo-e9nU-mTuR-9nfVIU" "xenvg" "linear" 0 0 1073741824
-      "" "/dev/sda5:0-15" "/dev/sda5(0)"
+      "" "/dev/sda5:0-15" "/dev/sda5(0)" Nothing
   , LVInfo "5fW5mE-SBSs-GSU0-KZDg-hnwb-sZOC-zZt736"
       "df9ff3f6-a833-48ff-8bd5-bff2eaeab759.disk0_meta" "-wi-ao" (negate 1)
       (negate 1) 253 1 134217728 1
       "originstname+instance1.example.com" ""
       "uZgXit-eiRr-vRqe-xpEo-e9nU-mTuR-9nfVIU" "xenvg" "linear" 0 0 134217728 ""
-      "/dev/sda5:16-17" "/dev/sda5(16)"
+      "/dev/sda5:16-17" "/dev/sda5(16)" Nothing
   ]
 
 -- | Serialize a LVInfo in the same format that is output by @lvs@.
+-- The "instance" field is not serialized because it's not provided by @lvs@
+-- so it is not part of this test.
 serializeLVInfo :: LVInfo -> String
 serializeLVInfo l = intercalate ";"
   [ lviUuid l
@@ -88,6 +90,8 @@ serializeLVInfos :: [LVInfo] -> String
 serializeLVInfos = concatMap serializeLVInfo
 
 -- | Arbitrary instance for LVInfo.
+-- The instance is always Nothing because it is not part of the parsed data:
+-- it is added afterwards from a different source.
 instance Arbitrary LVInfo where
   arbitrary =
     LVInfo
@@ -111,6 +115,7 @@ instance Arbitrary LVInfo where
       <*> genName        -- seg_tags
       <*> genName        -- seg_pe_ranges
       <*> genName        -- devices
+      <*> return Nothing -- instance
 
 -- | Test if a randomly generated LV lvs output is properly parsed.
 prop_parse_lvs_lv :: [LVInfo] -> Property