From cb61b1187ca50e229fa54bdaf5c1f874704382e3 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Wed, 5 Apr 2023 17:21:54 +0200 Subject: [PATCH] Remove `alr test --docker` (#1366) * Local testing of crates with docker images WIP: write tests for local+docker default+custom tests This opens the doors to batch testing on many distros locally * Test for the use of docker with local `alr test` * Self-review * WIP: something funny with the testsuite output * Remove `alr test --docker` * Add user changes * Revert .vscode changes to unclutter PR * Fix PR number in user changes --- doc/user-changes.md | 10 +- src/alire/alire-defaults.ads | 3 - src/alire/alire-version.ads | 2 +- src/alr/alr-commands-test.adb | 155 +++------------------ src/alr/alr-commands-test.ads | 5 - testsuite/drivers/driver/docker_wrapper.py | 6 + testsuite/drivers/driver/python_script.py | 21 ++- testsuite/drivers/helpers.py | 7 +- 8 files changed, 45 insertions(+), 164 deletions(-) diff --git a/doc/user-changes.md b/doc/user-changes.md index c133ed28..b7b92b43 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -4,7 +4,15 @@ This document is a development diary summarizing changes in `alr` that notably affect the user experience. It is intended as a one-stop point for users to stay on top of `alr` new features. -## Release `1.3-dev` +## Release `2.0-dev` + +### Removal of `alr test --docker` + +PR [#1366](https://github.com/alire-project/alire/pull/1366) + +The option to test indexed releases with the local `alr` using a Docker image +has been removed, as it never made too much sense for `alr` to invoke itself, +and it introduced unwanted complexity into the `alr test` command. ### Global sharing of dependencies via config setting diff --git a/src/alire/alire-defaults.ads b/src/alire/alire-defaults.ads index 9820fd84..b98acde1 100644 --- a/src/alire/alire-defaults.ads +++ b/src/alire/alire-defaults.ads @@ -3,9 +3,6 @@ package Alire.Defaults with Preelaborate is Description : constant String := "Shiny new project"; -- TODO: replace this constant with a function that returns random fortunes - Docker_Test_Image : constant String := "alire/gnat:debian-stable"; - -- Docker image to be used with `alr test --docker` unless overridden - Maintainer : constant String := "your@email.here"; Maintainer_Login : constant String := "github-username"; diff --git a/src/alire/alire-version.ads b/src/alire/alire-version.ads index 2893a709..9028dc21 100644 --- a/src/alire/alire-version.ads +++ b/src/alire/alire-version.ads @@ -2,7 +2,7 @@ package Alire.Version with Preelaborate is -- Remember to update Alire.Index branch if needed too - Current : constant String := "1.3-dev"; + Current : constant String := "2.0-dev"; -- 1.2.1: build switches fix and other minor assorted fixes -- 1.2.0: rpm speed-up, silence propagation warning, early switch parse -- 1.2.0-rc1: release candidate for 1.2 diff --git a/src/alr/alr-commands-test.adb b/src/alr/alr-commands-test.adb index 99f3c045..cfe4c35d 100644 --- a/src/alr/alr-commands-test.adb +++ b/src/alr/alr-commands-test.adb @@ -4,7 +4,6 @@ with Ada.Exceptions; with Ada.Containers; with Alire.Crates; -with Alire.Defaults; with Alire.Dependencies; with Alire.Directories; with Alire.Errors; @@ -18,7 +17,6 @@ with Alire.Properties.Actions.Executor; with Alire.Releases.Containers; with Alire.Solutions; with Alire.Solver; -with Alire.Utils; with Alr.Files; with Alr.Testing.Collections; @@ -39,8 +37,6 @@ package body Alr.Commands.Test is package Platform renames Alire.Platforms.Current; package Query renames Alire.Solver; - Docker_Switch : constant String := "--docker"; - ----------------- -- Check_Files -- ----------------- @@ -108,8 +104,7 @@ package body Alr.Commands.Test is procedure Do_Test (Cmd : in out Command; Releases : Alire.Releases.Containers.Release_Sets.Set; - Local : Boolean; - Docker_Image : String) + Local : Boolean) is use Ada.Calendar; use GNATCOLL.VFS; @@ -155,25 +150,8 @@ package body Alr.Commands.Test is procedure Test_Action is use AAA.Strings; - use Ada.Directories; use Alire.OS_Lib.Subprocess; - Docker_Prefix : constant AAA.Strings.Vector := - Empty_Vector - & "sudo" - & "docker" - & "run" - & String'("-v" - & Locate_In_Path ("alr") - & ":/usr/bin/alr") - -- Map executable - & String'("-v" & Current_Directory & ":/work") - -- Map working folder - & "-w" & "/work" - & "--user" & Alire.OS_Lib.Getenv ("UID", "1000") - -- Map current user - & Docker_Image; - Regular_Alr_Switches : constant AAA.Strings.Vector := Empty_Vector & "-d" @@ -182,16 +160,6 @@ package body Alr.Commands.Test is then To_Vector ("--force") else Empty_Vector); - Custom_Alr : constant AAA.Strings.Vector := - Empty_Vector - & "alr" - & (if Alire.Force - then To_Vector ("--force") - else Empty_Vector) - & "-c" & "/tmp/alire"; - -- When running inside docker as regular user we need config to be - -- stored in a writable folder. - ------------------ -- Default_Test -- ------------------ @@ -211,39 +179,23 @@ package body Alr.Commands.Test is -- Used to test the local crate Alr_Local : constant AAA.Strings.Vector := Empty_Vector & - "alr" & Regular_Alr_Switches & "build" & "--release"; - -- Used to run inside docker - Docker_Default : constant AAA.Strings.Vector := - Docker_Prefix - & Custom_Alr - & Alr_Args; - Alr_Default : constant AAA.Strings.Vector := (if Local - then Alr_Local + then "alr" & Alr_Local else "alr" & Alr_Args); Exit_Code : Integer; begin - if Alire.Utils.Command_Line_Contains (Docker_Switch) then - Output.Append_Line ("Spawning: " & Docker_Default.Flatten); - Exit_Code := Unchecked_Spawn_And_Capture - (Docker_Default.First_Element, - Docker_Default.Tail, - Output, - Err_To_Out => True); - else - Output.Append_Line ("Spawning: " & Alr_Default.Flatten); - Exit_Code := Unchecked_Spawn_And_Capture - (Alr_Default.First_Element, - Alr_Default.Tail, - Output, - Err_To_Out => True); - end if; + Output.Append_Line ("Spawning: " & Alr_Default.Flatten); + Exit_Code := Unchecked_Spawn_And_Capture + (Alr_Default.First_Element, + Alr_Default.Tail, + Output, + Err_To_Out => True); if Exit_Code /= 0 then raise Child_Failed; @@ -267,33 +219,18 @@ package body Alr.Commands.Test is "alr" & Regular_Alr_Switches & "get" & R.Milestone.Image; - Dkr_Custom_Cmd : constant Vector := - Docker_Prefix - & Custom_Alr - & "get" - & R.Milestone.Image; begin -- Fetch the crate if not local test if not Local then - if Alire.Utils.Command_Line_Contains (Docker_Switch) then - Output.Append_Line - ("Spawning: " & Dkr_Custom_Cmd.Flatten); - Exit_Code := Unchecked_Spawn_And_Capture - (Dkr_Custom_Cmd.First_Element, - Dkr_Custom_Cmd.Tail, - Output, - Err_To_Out => True); - else - Output.Append_Line - ("Spawning: " & Alr_Custom_Cmd.Flatten); - Exit_Code := Unchecked_Spawn_And_Capture - (Alr_Custom_Cmd.First_Element, - Alr_Custom_Cmd.Tail, - Output, - Err_To_Out => True); - end if; + Output.Append_Line + ("Spawning: " & Alr_Custom_Cmd.Flatten); + Exit_Code := Unchecked_Spawn_And_Capture + (Alr_Custom_Cmd.First_Element, + Alr_Custom_Cmd.Tail, + Output, + Err_To_Out => True); if Exit_Code /= 0 then raise Child_Failed; @@ -322,11 +259,7 @@ package body Alr.Commands.Test is Capture => True, Err_To_Out => True, Code => Exit_Code, - Output => Output, - Prefix => - (if Alire.Utils.Command_Line_Contains (Docker_Switch) - then Docker_Prefix - else AAA.Strings.Empty_Vector)); + Output => Output); if Exit_Code /= 0 then raise Child_Failed; @@ -515,11 +448,6 @@ package body Alr.Commands.Test is Candidates : Alire.Releases.Containers.Release_Sets.Set; - Docker_Image : constant String := - (if Cmd.Docker.all = "" - then Alire.Defaults.Docker_Test_Image - else AAA.Strings.Replace (Cmd.Docker.all, "=", "")); - use Alire.Releases.Containers.Release_Sets; --------------------- @@ -582,39 +510,6 @@ package body Alr.Commands.Test is end if; end Find_Candidates; - -------------------- - -- Prepare_Docker -- - -------------------- - - procedure Pull_Docker is - use Alire.OS_Lib.Subprocess; - use AAA.Strings; - - Output : AAA.Strings.Vector; - Exit_Code : Integer; - begin - if Alire.Utils.Command_Line_Contains (Docker_Switch) then - - Trace.Info ("Running builds in docker image: " & Docker_Image); - - Exit_Code := Unchecked_Spawn_And_Capture - ("sudo", - Empty_Vector - & "docker" - & "pull" - & Docker_Image, - Output, - Err_To_Out => True); - - if Exit_Code /= 0 then - Reportaise_Command_Failed - ("Failed to pull docker image " & Docker_Image - & " with output: " - & Output.Flatten (Separator => "" & ASCII.LF)); - end if; - end if; - end Pull_Docker; - begin -- Validate command line if not Cmd.Search then @@ -635,12 +530,6 @@ package body Alr.Commands.Test is ("Either use --full or specify crate names, but not both"); end if; - -- For now, don't allow docker with local test - if No_Args and Cmd.Docker.all /= No_Docker then - Reportaise_Wrong_Arguments - ("Docker local testing is not yet supported."); - end if; - -- When doing testing over index contents, we request an empty dir if not No_Args then if Cmd.Cont then @@ -689,9 +578,7 @@ package body Alr.Commands.Test is end if; end if; - Pull_Docker; - - Do_Test (Cmd, Candidates, No_Args, Docker_Image); + Do_Test (Cmd, Candidates, No_Args); end Execute; ---------------------- @@ -730,14 +617,6 @@ package body Alr.Commands.Test is Long_Switch => "--continue", Help => "Skip testing of releases already in folder"); - Define_Switch - (Config, - Cmd.Docker'Access, - Long_Switch => Docker_Switch & "?", -- ? for optional image tag - Help => "Test releases within docker IMAGE" - & " (or " & Alire.Defaults.Docker_Test_Image & ")", - Argument => "=IMAGE"); - Define_Switch (Config, Cmd.Full'Access, diff --git a/src/alr/alr-commands-test.ads b/src/alr/alr-commands-test.ads index ad33bbdb..174c6f3d 100644 --- a/src/alr/alr-commands-test.ads +++ b/src/alr/alr-commands-test.ads @@ -1,7 +1,5 @@ with AAA.Strings; -with GNAT.Strings; - package Alr.Commands.Test is type Command is new Commands.Command with private; @@ -33,11 +31,8 @@ package Alr.Commands.Test is private - No_Docker : constant String := "unset"; - type Command is new Commands.Command with record Cont : aliased Boolean := False; - Docker : aliased GNAT.Strings.String_Access := new String'(No_Docker); Full : aliased Boolean := False; Last : aliased Boolean := False; Redo : aliased Boolean := False; diff --git a/testsuite/drivers/driver/docker_wrapper.py b/testsuite/drivers/driver/docker_wrapper.py index 7107f13a..2cf6558e 100644 --- a/testsuite/drivers/driver/docker_wrapper.py +++ b/testsuite/drivers/driver/docker_wrapper.py @@ -42,6 +42,12 @@ def is_docker_available() -> bool: return True +def skip_unless_docker_available() -> None: + if not is_docker_available(): + print("SKIP: Docker testing is disabled or not available") + exit(0) + + def get_client(): if is_docker_available(): import docker diff --git a/testsuite/drivers/driver/python_script.py b/testsuite/drivers/driver/python_script.py index e2a3a916..29fc90e5 100644 --- a/testsuite/drivers/driver/python_script.py +++ b/testsuite/drivers/driver/python_script.py @@ -1,11 +1,10 @@ import os import sys -from e3.fs import sync_tree -from e3.testsuite.driver.classic import ClassicTestDriver, TestAbortWithFailure -from e3.testsuite.result import TestStatus - from drivers.alr import prepare_env, prepare_indexes +from e3.testsuite.driver.classic import (ClassicTestDriver, + TestAbortWithFailure, + TestSkip) class PythonScriptDriver(ClassicTestDriver): @@ -52,14 +51,12 @@ class PythonScriptDriver(ClassicTestDriver): env=env, cwd=self.test_env['working_dir']) - # Check that stderr is empty - if False and p.err: - self.result.log += 'non-empty stderr:\n' - self.result.log += p.err - raise TestAbortWithFailure('non-empty stderr') - - # Check that the last line in stdout is "SUCCESS" + # Check that the last line in stdout is "SUCCESS" or "SKIP" out_lines = p.out.splitlines() - if not out_lines or out_lines[-1] != 'SUCCESS': + if out_lines and out_lines[-1] == 'SUCCESS': + pass + elif out_lines and (reason := out_lines[-1]).startswith('SKIP:'): + raise TestSkip(reason.split(":")[-1].strip()) + else: self.result.log += 'missing SUCCESS output line' raise TestAbortWithFailure('missing SUCCESS output line') diff --git a/testsuite/drivers/helpers.py b/testsuite/drivers/helpers.py index 88ee90e5..6a5b83f0 100644 --- a/testsuite/drivers/helpers.py +++ b/testsuite/drivers/helpers.py @@ -2,15 +2,14 @@ Assorted helpers that are reused by several tests. """ -from subprocess import run -from zipfile import ZipFile - import hashlib -import re import os import platform +import re import shutil import stat +from subprocess import run +from zipfile import ZipFile # Return the entries (sorted) under a given folder, both folders and files -- 2.39.5