Commit c5b4a186 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix prefix bug in Haskell ssconf implementation



This patch fixes a (brown-bag) bug in the ssconf implementation where
the looked-for filenames were not prefixed with the ssconf file
prefix.

Additionally, a test for this is added (which fails without the fix).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent c09254c2
......@@ -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
]
......@@ -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
......
......@@ -125,6 +125,7 @@ allTests =
, (fast, testCLI)
, (fast, testJSON)
, (fast, testLUXI)
, (fast, testSsconf)
, (slow, testCluster)
]
......
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