Commit f8bd219e authored by Valentin Reis's avatar Valentin Reis

Updating the test pipeline to work with daemon arguments, refactoring the haskell code.

parent d2579fb5
Pipeline #4606 failed with stage
in 9 seconds
......@@ -5,7 +5,6 @@
, DataKinds
, DeriveGeneric
, FlexibleInstances
, OverloadedStrings
, TypeOperators #-}
module Argotest where
......@@ -22,32 +21,16 @@ import System.Console.ANSI
import System.Console.ANSI.Types (Color)
import System.Posix.Signals
--data Args w = Args
-- { dargs :: w ::: Text <?> "Daemon arguments. Properly quote this."
-- , app :: w ::: FilePath <?> "Input file, target application script"
-- , manifest :: w ::: FilePath <?> "Input file, manifest."
-- , app_out :: w ::: FilePath <?> "Output file, application stdout"
-- , app_err :: w ::: FilePath <?> "Output file, application stderr"
-- , daemon_out :: w ::: FilePath <?> "Output file, daemon stdout"
-- , daemon_err :: w ::: FilePath <?> "Output file, daemon stderr"
-- , log_progress :: w ::: FilePath <?> "Output file, daemon progress log"
-- , log_hardwareprogress :: w ::: FilePath <?> "Output file, daemon hardware progress log"
-- , log_power :: w ::: FilePath <?> "Output file, daemon power log"
-- , time_file :: w ::: FilePath <?> "Output file, application runtime" } deriving (Generic)
--instance ParseRecord (Args Wrapped)
data StackArgs = StackArgs
{ dargs :: Text
, app :: FilePath
, manifest :: FilePath
, cmd_out :: FilePath
, cmd_err :: FilePath
, daemon_out :: FilePath
, daemon_err :: FilePath
, nrm_log :: FilePath
, time_file :: FilePath }
{ dargs :: Text --"Daemon arguments. Properly quote this."
, app :: FilePath --"Input file, target application script"
, manifest :: FilePath --"Input file, manifest."
, cmd_out :: FilePath --"Output file, application stdout"
, cmd_err :: FilePath --"Output file, application stderr"
, daemon_out :: FilePath --"Output file, daemon stdout"
, daemon_err :: FilePath --"Output file, daemon stderr"
, nrm_log :: FilePath --"Output file, daemon log"
, time_file :: FilePath } --"Output file, application runtime"
instance Default StackArgs where
def = StackArgs
......@@ -82,7 +65,7 @@ sudoRemoveFile :: (Text -> Shell ()) -> Text -> FilePath -> Shell ()
sudoRemoveFile printer desc filePath = do
foundSocket <- (testfile filePath)
when foundSocket $ go False
printInfo $ format ("using "%s%" "%fp%"\n") desc filePath
printInfo $ format ("OK: "%s%" "%fp%"\n") desc filePath
where go useSudo = do
printer $ format ("found stale " %s%" at "%fp%"..") desc filePath
shell (format ((if useSudo then "sudo " else "")%"rm -f "%fp) filePath) empty >>= \case
......@@ -96,13 +79,15 @@ sudoRemoveFile printer desc filePath = do
cleanSocket = sudoRemoveFile printError "socket"
cleanLog = sudoRemoveFile printWarning "log file"
argoTest :: StackArgs -> IO ()
argoTest StackArgs{..} = sh $ do
--Cleaning
cleanLeftovers :: FilePath -> FilePath -> FilePath ->
FilePath -> FilePath -> FilePath -> Shell ()
cleanLeftovers daemon_out daemon_err cmd_out cmd_err time_file nrm_log = do
printInfo "Cleaning leftovers..\n"
mapM_ cleanLog [daemon_out, daemon_err, cmd_out, cmd_err, time_file, nrm_log]
mapM_ cleanSocket ["/tmp/nrm-downstream-in", "/tmp/nrm-upstream-in"]
--Retrieving binaries,setting suid bits and perms
prepareDaemonShell :: Text -> FilePath -> FilePath -> FilePath -> Shell (Shell ())
prepareDaemonShell dargs daemon_out daemon_err nrm_log = do
confPath <- myWhich "argo_nodeos_config"
daemonPath <- myWhich "daemon"
tempDirPath <- mktempdir "/tmp" "argo-expe"
......@@ -123,28 +108,6 @@ argoTest StackArgs{..} = sh $ do
ExitFailure n -> do printInfo "Contents of argo_nodeos_config_exit_message: \n"
view $ cat ["./argo_nodeos_config_exit_message"]
die ("Clean config failed with exit code " <> repr n)
printInfo "Running the daemon.\n"
printInfo $ format ("Running the daemon: see main log at "%fp%"\n") nrm_log
export "ARGO_NODEOS_CONFIG" (format fp confPath')
let daemon = inshell (format (fp%" "%s%" --nrm_log="%fp%" >"%fp%" 2>"%fp)
daemonPath dargs nrm_log daemon_out daemon_err) empty
daemonAsync <- fork $ sh $ daemon
printInfo "Daemon is running.\n"
let handler = do
sh $ printInfo "Interrupted. Killing daemon..."
cancel daemonAsync
sh $ colorShell Green $ printf "Killed daemon.\n"
liftIO $ installHandler keyboardSignal (Catch handler) Nothing
--Running the app
printInfo "Launching the application through cmd.\n"
(_,t) <- time $
shell (format ("cmd run -u toto "%fp%" "%fp%" > "%fp%" 2>"%fp) manifest app cmd_out cmd_err) empty >>= \case
ExitSuccess -> printInfo "cmd has exited successfuly.\n"
ExitFailure n -> die ("cmd failed with exit code " <> repr n <>
" . The application logs are at " <> repr cmd_out <> " " <> repr cmd_err )
liftIO $ writeTextFile time_file (repr t)
--Cleanup
printInfo "Killing the daemon.\n"
liftIO $ cancel daemonAsync
printInfo "Daemon killed.\n"
return $ sh $ inshell (format (fp%" "%s%" --nrm_log="%fp%" >"%fp%" 2>"%fp) daemonPath dargs nrm_log daemon_out daemon_err) empty
#! /usr/bin/env nix-shell
#! nix-shell -i runhaskell -A test
{-# LANGUAGE
OverloadedStrings
, LambdaCase
, RecordWildCards #-}
import Argotest
import Turtle
import Data.Default
import Control.Concurrent.Async
import System.Console.ANSI
import System.Console.ANSI.Types (Color)
import Options.Applicative
import System.Posix.Signals
import Control.Monad
opts :: Parser (IO ())
opts = subparser
( command "clean" (info (pure $ runClean def) idm)<> help "Target for the greeting"
<> command "daemon" (info (pure $ runDaemon def) idm)
<> command "helloworld" (info (pure $ runArgoTest def) idm) )
main :: IO ()
main = join $ execParser (info (opts <**>helper) idm)
runArgoTest :: StackArgs -> IO ()
runArgoTest a@StackArgs{..} = sh $ do
cleanLeftovers daemon_out daemon_err cmd_out cmd_err time_file nrm_log
daemonShell <- prepareDaemonShell dargs daemon_out daemon_err nrm_log
daemonAsync <- fork $ sh $ daemonShell
let handler = do
sh $ printInfo "Interrupted. Killing daemon..."
cancel daemonAsync
sh $ colorShell Green $ printf "Killed daemon.\n"
liftIO $ installHandler keyboardSignal (Catch handler) Nothing
printInfo "Launching the application through cmd.\n"
(_,t) <- time $
shell (format ("cmd run -u toto "%fp%" "%fp%" > "%fp%" 2>"%fp) manifest app cmd_out cmd_err) empty >>= \case
ExitSuccess -> printInfo "cmd has exited successfuly.\n"
ExitFailure n -> die ("cmd failed with exit code " <> repr n <>
" . The application logs are at " <> repr cmd_out <> " " <> repr cmd_err )
liftIO $ writeTextFile time_file (repr t)
printInfo "Killing the daemon.\n"
liftIO $ cancel daemonAsync
printInfo "Daemon killed.\n"
runClean :: StackArgs -> IO ()
runClean StackArgs{..} = sh $
cleanLeftovers daemon_out daemon_err cmd_out cmd_err time_file nrm_log
runDaemon :: StackArgs -> IO ()
runDaemon StackArgs{..} = sh $ do
daemonShell <- prepareDaemonShell dargs daemon_out daemon_err nrm_log
daemonShell
#! /usr/bin/env runhaskell
import Argotest
import Data.Default
main :: IO ()
main = argoTest def
#! /usr/bin/env runhaskell
import Argotest
import Data.Default
main :: IO ()
main = argoTest def
#! /usr/bin/env bash
nix-shell -A test --command ./integration.hs
nix-shell -A test --command "./argotk helloworld"
#! /usr/bin/env runhaskell
{-# LANGUAGE
OverloadedStrings #-}
import Argotest
import Data.Default
main :: IO ()
main = argoTest def {
app = "sleep 3333333"
}
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