From 14a208b02877459c56029ac87341dac632a8dc81 Mon Sep 17 00:00:00 2001 From: Evan Cofsky Date: Mon, 7 Mar 2016 13:47:36 -0600 Subject: Fails on respin when it shouldn't recreate a Poudriere jail. We were using checkResult instead of check, and we weren't parsing the output of `jail -l -q` properly. Now it handles respins perfectly. --- src/Propellor/Property/FreeBSD/Poudriere.hs | 30 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Propellor/Property/FreeBSD/Poudriere.hs b/src/Propellor/Property/FreeBSD/Poudriere.hs index 3ebb4633..32234b27 100644 --- a/src/Propellor/Property/FreeBSD/Poudriere.hs +++ b/src/Propellor/Property/FreeBSD/Poudriere.hs @@ -1,5 +1,5 @@ -- | Maintainer: 2016 Evan Cofsky --- +-- -- FreeBSD Poudriere properties {-# Language GeneralizedNewtypeDeriving #-} @@ -10,6 +10,7 @@ import Propellor.Base import Propellor.Types.Info import Data.List import Data.String (IsString(..)) +import Data.String.Utils (splitWs) import qualified Propellor.Property.FreeBSD.Pkg as Pkg import qualified Propellor.Property.ZFS as ZFS @@ -52,26 +53,27 @@ runPoudriere cmd args = lines <$> readProcess p a listJails :: IO [String] -listJails = runPoudriere "jail" ["-l", "-q"] +listJails = + map ((\(n:_) -> n ) . take 1 . splitWs) <$> runPoudriere "jail" ["-l", "-q"] jailExists :: Jail -> IO Bool jailExists (Jail name _ _) = isInfixOf [name] <$> listJails jail :: Jail -> Property NoInfo jail j@(Jail name version arch) = - checkResult chk (\_ -> return MadeChange) createJail + let + chk = do + c <- poudriereConfigured <$> askInfo + nx <- liftIO $ not <$> jailExists j + return $ c && nx + + (cmd, args) = poudriereCommand "jail" ["-c", "-j", name, "-a", show arch, "-v", show version] + createJail = cmdProperty cmd args + in + check chk createJail `describe` unwords ["Create poudriere jail", name] - where - cfgd = poudriereConfigured <$> askInfo - - notExists :: IO Bool - notExists = not <$> jailExists j - chk = do - c <- cfgd - x <- liftIO notExists - return $ c && x - (cmd, args) = poudriereCommand "jail" ["-c", "-j", name, "-a", show arch, "-v", show version] - createJail = cmdProperty cmd args + +data JailInfo = JailInfo String data Poudriere = Poudriere { _resolvConf :: String -- cgit v1.2.3