Commit 0cf8edad authored by Michele Tartara's avatar Michele Tartara

Add tests for LVs parser

Add unit tests and Quickcheck tests for the LV parser.

Also, fix the alphabetic order of some imports in htest.hs.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent b5334d80
......@@ -83,6 +83,7 @@ HS_DIRS = \
test/hs/Test/Ganeti/Storage \
test/hs/Test/Ganeti/Storage/Diskstats \
test/hs/Test/Ganeti/Storage/Drbd \
test/hs/Test/Ganeti/Storage/Lvm \
test/hs/Test/Ganeti/Confd \
test/hs/Test/Ganeti/HTools \
test/hs/Test/Ganeti/HTools/Backend \
......@@ -659,6 +660,7 @@ HS_TEST_SRCS = \
test/hs/Test/Ganeti/Storage/Diskstats/Parser.hs \
test/hs/Test/Ganeti/Storage/Drbd/Parser.hs \
test/hs/Test/Ganeti/Storage/Drbd/Types.hs \
test/hs/Test/Ganeti/Storage/Lvm/LVParser.hs \
test/hs/Test/Ganeti/THH.hs \
test/hs/Test/Ganeti/TestCommon.hs \
test/hs/Test/Ganeti/TestHTools.hs \
......@@ -1142,6 +1144,7 @@ TEST_FILES = \
test/data/kvm_0.9.1_help_boot_test.txt \
test/data/kvm_1.0_help.txt \
test/data/kvm_1.1.2_help.txt \
test/data/lvs_lv.txt \
test/data/NEWS_OK.txt \
test/data/NEWS_previous_unreleased.txt \
test/data/ovfdata/compr_disk.vmdk.gz \
......
nhasjL-cnZi-uqLS-WRLj-tkXI-nvCB-n0o2lj;df9ff3f6-a833-48ff-8bd5-bff2eaeab759.disk0_data;-wi-ao;-1;-1;253;0;1073741824B;1;originstname+instance1.example.com;;uZgXit-eiRr-vRqe-xpEo-e9nU-mTuR-9nfVIU;xenvg;linear;0B;0;1073741824B;;/dev/sda5:0-15;/dev/sda5(0)
5fW5mE-SBSs-GSU0-KZDg-hnwb-sZOC-zZt736;df9ff3f6-a833-48ff-8bd5-bff2eaeab759.disk0_meta;-wi-ao;-1;-1;253;1;134217728B;1;originstname+instance1.example.com;;uZgXit-eiRr-vRqe-xpEo-e9nU-mTuR-9nfVIU;xenvg;linear;0B;0;134217728B;;/dev/sda5:16-17;/dev/sda5(16)
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-| Unittests for the LV Parser -}
{-
Copyright (C) 2013 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
module Test.Ganeti.Storage.Lvm.LVParser (testStorage_Lvm_LVParser) where
import Test.QuickCheck as QuickCheck hiding (Result)
import Test.HUnit
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import Control.Applicative ((<$>), (<*>))
import Data.List (intercalate)
import Ganeti.Storage.Lvm.LVParser
import Ganeti.Storage.Lvm.Types
{-# ANN module "HLint: ignore Use camelCase" #-}
-- | Test parsing a LV @lvs@ output.
case_lvs_lv :: Assertion
case_lvs_lv = testParser lvParser "lvs_lv.txt"
[ LVInfo "nhasjL-cnZi-uqLS-WRLj-tkXI-nvCB-n0o2lj"
"df9ff3f6-a833-48ff-8bd5-bff2eaeab759.disk0_data" "-wi-ao" (negate 1)
(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)"
, 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)"
]
-- | Serialize a LVInfo in the same format that is output by @lvs@.
serializeLVInfo :: LVInfo -> String
serializeLVInfo l = intercalate ";"
[ lviUuid l
, lviName l
, lviAttr l
, show $ lviMajor l
, show $ lviMinor l
, show $ lviKernelMajor l
, show $ lviKernelMinor l
, show (lviSize l) ++ "B"
, show $ lviSegCount l
, lviTags l
, lviModules l
, lviVgUuid l
, lviVgName l
, lviSegtype l
, show (lviSegStart l) ++ "B"
, show $ lviSegStartPe l
, show (lviSegSize l) ++ "B"
, lviSegTags l
, lviSegPeRanges l
, lviDevices l
] ++ "\n"
-- | Serialize a list of LVInfo in the same format that is output by @lvs@.
serializeLVInfos :: [LVInfo] -> String
serializeLVInfos = concatMap serializeLVInfo
-- | Arbitrary instance for LVInfo.
instance Arbitrary LVInfo where
arbitrary =
LVInfo
<$> genUUID -- uuid
<*> genName -- name
<*> genName -- attr
<*> arbitrary -- major
<*> arbitrary -- minor
<*> arbitrary -- kernel_major
<*> arbitrary -- kernel_minor
<*> genNonNegative -- size
<*> arbitrary -- seg_cont
<*> genName -- tags
<*> genName -- modules
<*> genUUID -- vg_uuid
<*> genName -- vg_name
<*> genName -- segtype
<*> genNonNegative -- seg_start
<*> arbitrary -- seg_start_pe
<*> genNonNegative -- seg_size
<*> genName -- seg_tags
<*> genName -- seg_pe_ranges
<*> genName -- devices
-- | Test if a randomly generated LV lvs output is properly parsed.
prop_parse_lvs_lv :: [LVInfo] -> Property
prop_parse_lvs_lv expected =
genPropParser lvParser (serializeLVInfos expected) expected
testSuite "Storage/Lvm/LVParser"
[ 'case_lvs_lv,
'prop_parse_lvs_lv
]
......@@ -33,9 +33,6 @@ import System.Log.Logger
import Test.Ganeti.TestImports ()
import Test.Ganeti.Attoparsec
import Test.Ganeti.BasicTypes
import Test.Ganeti.Storage.Diskstats.Parser
import Test.Ganeti.Storage.Drbd.Parser
import Test.Ganeti.Storage.Drbd.Types
import Test.Ganeti.Common
import Test.Ganeti.Confd.Utils
import Test.Ganeti.Confd.Types
......@@ -67,6 +64,10 @@ import Test.Ganeti.Query.Query
import Test.Ganeti.Rpc
import Test.Ganeti.Runtime
import Test.Ganeti.Ssconf
import Test.Ganeti.Storage.Diskstats.Parser
import Test.Ganeti.Storage.Drbd.Parser
import Test.Ganeti.Storage.Drbd.Types
import Test.Ganeti.Storage.Lvm.LVParser
import Test.Ganeti.THH
import Test.Ganeti.Types
import Test.Ganeti.Utils
......@@ -122,6 +123,7 @@ allTests =
, testRpc
, testRuntime
, testSsconf
, testStorage_Lvm_LVParser
, testTHH
, testTypes
, testUtils
......
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