diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs index 0c1ff5adbaccf4be6d56e4eea5e07685d6352511..78b88a638c2c671c8ded6f8fae48f2ada36e274c 100644 --- a/htools/Ganeti/HTools/QC.hs +++ b/htools/Ganeti/HTools/QC.hs @@ -41,6 +41,7 @@ module Ganeti.HTools.QC , testCLI , testJSON , testLUXI + , testSsconf ) where import Test.QuickCheck @@ -58,6 +59,7 @@ import qualified Data.IntMap as IntMap import qualified Ganeti.OpCodes as OpCodes import qualified Ganeti.Jobs as Jobs import qualified Ganeti.Luxi as Luxi +import qualified Ganeti.Ssconf as Ssconf import qualified Ganeti.HTools.CLI as CLI import qualified Ganeti.HTools.Cluster as Cluster import qualified Ganeti.HTools.Container as Container @@ -1731,3 +1733,16 @@ prop_Luxi_CallEncoding op = testSuite "LUXI" [ 'prop_Luxi_CallEncoding ] + +-- * Ssconf tests + +instance Arbitrary Ssconf.SSKey where + arbitrary = elements [minBound..maxBound] + +prop_Ssconf_filename key = + printTestCase "Key doesn't start with correct prefix" $ + Ssconf.sSFilePrefix `isPrefixOf` Ssconf.keyToFilename (Just "") key + +testSuite "Ssconf" + [ 'prop_Ssconf_filename + ] diff --git a/htools/Ganeti/Ssconf.hs b/htools/Ganeti/Ssconf.hs index 5910cd1a3d00c3331af70c19845e722fdcca0e29..39a3d95dfaac6badae2dfdb5148ee17bb731fc3c 100644 --- a/htools/Ganeti/Ssconf.hs +++ b/htools/Ganeti/Ssconf.hs @@ -30,6 +30,8 @@ module Ganeti.Ssconf , sSKeyToRaw , sSKeyFromRaw , getPrimaryIPFamily + , keyToFilename + , sSFilePrefix ) where import Ganeti.THH @@ -51,6 +53,10 @@ import Ganeti.HTools.Utils maxFileSize :: Int maxFileSize = 131072 +-- | ssconf file prefix, re-exported from Constants. +sSFilePrefix :: FilePath +sSFilePrefix = C.ssconfFileprefix + $(declareSADT "SSKey" [ ("SSClusterName", 'C.ssClusterName) , ("SSClusterTags", 'C.ssClusterTags) @@ -80,7 +86,8 @@ $(declareSADT "SSKey" keyToFilename :: Maybe FilePath -- ^ Optional config path override -> SSKey -- ^ ssconf key -> FilePath -keyToFilename optpath key = fromMaybe C.dataDir optpath </> sSKeyToRaw key +keyToFilename optpath key = fromMaybe C.dataDir optpath </> + sSFilePrefix ++ sSKeyToRaw key -- | Runs an IO action while transforming any error into 'Bad' -- values. It also accepts an optional value to use in case the error diff --git a/htools/test.hs b/htools/test.hs index eedefd35ba6a021be43a6bfc62b9db9608241d86..6e434274bc11ab5b9af918395897fbba307400b4 100644 --- a/htools/test.hs +++ b/htools/test.hs @@ -125,6 +125,7 @@ allTests = , (fast, testCLI) , (fast, testJSON) , (fast, testLUXI) + , (fast, testSsconf) , (slow, testCluster) ]