From 7c75e56fa13c73b25bec5fff1bf455ebd6d3ae87 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 18 Nov 2024 04:39:04 +0100 Subject: [PATCH 1/7] Add `--check-and-predict-local` The `--check-and-predict-local` flag allows running consistency checks and deployment predictions using the local host's state, without connecting to the remote host. This flag can only be used with the `--consistency-only` or `--predict-only` options. --- ...likowa_add_check_and_predict_local_flag.md | 11 ++ doc/source/cli/index.txt | 8 +- .../gocept/secret-foobar.yaml.gpg | Bin 0 -> 629 bytes src/batou/deploy.py | 17 ++- src/batou/environment.py | 5 + src/batou/main.py | 7 ++ src/batou/tests/test_endtoend.py | 117 ++++++++++++++++++ 7 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md create mode 100644 examples/tutorial-secrets/environments/gocept/secret-foobar.yaml.gpg diff --git a/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md b/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md new file mode 100644 index 000000000..cc3aec068 --- /dev/null +++ b/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md @@ -0,0 +1,11 @@ + +- Adds a `--check-and-predict-local` flag to `./batou deploy`, which can + be used in tandem with `--consistency-only` or `--predict-only` to + check and predict using the local host's state, without connecting to + the remote host. diff --git a/doc/source/cli/index.txt b/doc/source/cli/index.txt index cd5fa41be..3debb714e 100644 --- a/doc/source/cli/index.txt +++ b/doc/source/cli/index.txt @@ -30,7 +30,9 @@ batou deploy .. code-block:: console - usage: batou deploy [-h] [-p PLATFORM] [-t TIMEOUT] [-D] [-c] [-P] [-j JOBS] + usage: batou deploy [-h] [-p PLATFORM] [-t TIMEOUT] [-D] [-c] [-P] + [--check-and-predict-local] [-j JOBS] + [--provision-rebuild] environment positional arguments: @@ -50,6 +52,10 @@ batou deploy Does not touch anything. -P, --predict-only Only predict what updates would happen. Do not change anything. + --check-and-predict-local + When running in consistency-only or predict-only mode, + do not connect to the remote host, but check and + predict using the local host's state. -j JOBS, --jobs JOBS Defines number of jobs running parallel to deploy. The default results in a serial deployment of components. Will override the environment settings for operational diff --git a/examples/tutorial-secrets/environments/gocept/secret-foobar.yaml.gpg b/examples/tutorial-secrets/environments/gocept/secret-foobar.yaml.gpg new file mode 100644 index 0000000000000000000000000000000000000000..2c542f1c5c5f574f6a5d5a56380beb8b3e5fb2b4 GIT binary patch literal 629 zcmV-*0*d{G0Sp5!%VyU_>YL612mqU~e75;~a&kSNLuM6qx@~&#ri&)Yi&ScgOB1Xb zftji`X7bDHnw;g)d77u>lgkx`TB&Y)oJja|f6*&BM>|Qld3S|K%(Y%g7aEU)sd8z0s;y|!B+3_T>hYqMcCt4arH5P;)Y!1sLPh6+B(Nb;W9hjGQ-GToTaxN~+nqXhyd`5UDefeu+`GdXP}%M? z1WDMMgt&uwLY^qbfr;5HPt%0~3R^$ebYcZXCKZc# z)8g0mqo|se-ndV2w^>4n(mhN+Tcdd8^N;IH}~tmPekW#c5K+q>^`xzMs*Y_OxdK%X?LC8$mdH?;=MwG$PVZZaH%v zU{ki@c>37N%cc23u`1cqzZ>heAYUX)M6(X(PtsKZwI(hOWYg5v$igUfOChl{F1tEd z@~!J9{YDC+>eDEJ^=0MZy*N0dNcLFmEf!P3nkrp^rPSGz^$`l_57+>-FMnu;0(La@ P`Y7lVyi%?{Ew&9 None: help="Only predict what updates would happen. " "Do not change anything.", ) + p.add_argument( + "--check-and-predict-local", + action="store_true", + help="When running in consistency-only or predict-only mode, " + "do not connect to the remote host, but check and predict " + "using the local host's state.", + ) p.add_argument( "-j", "--jobs", diff --git a/src/batou/tests/test_endtoend.py b/src/batou/tests/test_endtoend.py index a412bd15f..bc80898f0 100644 --- a/src/batou/tests/test_endtoend.py +++ b/src/batou/tests/test_endtoend.py @@ -372,3 +372,120 @@ def test_durations_are_shown_for_components(): ============================= DEPLOYMENT FINISHED ============================== """ ) + + +def test_check_consistency_works(): + os.chdir("examples/tutorial-secrets") + out, _ = cmd("./batou deploy tutorial --consistency-only") + assert out == Ellipsis( + """\ +batou/2... (cpython 3...) +================================== Preparing =================================== +main: Loading environment `tutorial`... +main: Verifying repository ... +main: Loading secrets ... +================== Connecting hosts and configuring model ... ================== +localhost: Connecting via local (1/1) +=================================== Summary ==================================== +Deployment took total=...s, connect=...s, deploy=NaN +========================== CONSISTENCY CHECK FINISHED ========================== +""" + ) + + +def test_predicting_deployment_works(): + os.chdir("examples/tutorial-secrets") + out, _ = cmd("./batou deploy tutorial --predict-only") + assert out == Ellipsis( + """\ +batou/2... (cpython 3...) +================================== Preparing =================================== +main: Loading environment `tutorial`... +main: Verifying repository ... +main: Loading secrets ... +================== Connecting hosts and configuring model ... ================== +localhost: Connecting via local (1/1) +======================== Predicting deployment actions ========================= +localhost: Scheduling component hello ... +localhost > Hello > File('work/hello/hello') > Presence('hello') +localhost > Hello > File('work/hello/hello') > Content('hello') +Not showing diff as it contains sensitive data, +see .../examples/tutorial-secrets/work/.batou-diffs/...diff for the diff. +localhost > Hello > File('work/hello/other-secrets.yaml') > Presence('other-secrets.yaml') +localhost > Hello > File('work/hello/other-secrets.yaml') > Content('other-secrets.yaml') +Not showing diff as it contains sensitive data, +see .../examples/tutorial-secrets/work/.batou-diffs/...diff for the diff. +=================================== Summary ==================================== +Deployment took total=...s, connect=...s, deploy=...s +======================= DEPLOYMENT PREDICTION FINISHED ========================= +""" + ) + + +def test_check_consistency_works_with_local(): + os.chdir("examples/tutorial-secrets") + out, _ = cmd( + "./batou deploy gocept --consistency-only --check-and-predict-local" + ) + assert out == Ellipsis( + """\ +batou/2... (cpython 3...) +================================== Preparing =================================== +main: Loading environment `gocept`... +main: Verifying repository ... +main: Loading secrets ... +================== Connecting hosts and configuring model ... ================== +test01: Connecting via local (1/2) +test02: Connecting via local (2/2) +=================================== Summary ==================================== +Deployment took total=...s, connect=...s, deploy=NaN +====================== CONSISTENCY CHECK (local) FINISHED ====================== +""" + ) + + +def test_predicting_deployment_works_with_local(): + os.chdir("examples/tutorial-secrets") + out, _ = cmd( + "./batou deploy gocept --predict-only --check-and-predict-local" + ) + assert out == Ellipsis( + """\ +batou/2... (cpython 3...) +================================== Preparing =================================== +main: Loading environment `gocept`... +main: Verifying repository ... +main: Loading secrets ... +================== Connecting hosts and configuring model ... ================== +test01: Connecting via local (1/2) +test02: Connecting via local (2/2) +======================== Predicting deployment actions ========================= +test01: Scheduling component hello ... +test02: Scheduling component hello ... +test01 > Hello > File('work/hello/hello') > Presence('hello') +test01 > Hello > File('work/hello/hello') > Content('hello') + hello --- + hello +++ + hello @@ -0,0 +1,2 @@ + hello +The magic word is None. + hello +The other word is None. +test01 > Hello > File('work/hello/other-secrets.yaml') > Presence('other-secrets.yaml') +test01 > Hello > File('work/hello/other-secrets.yaml') > Content('other-secrets.yaml') +Not showing diff as it contains sensitive data, +see .../batou/examples/tutorial-secrets/work/.batou-diffs/...diff for the diff. +test02 > Hello > File('work/hello/hello') > Presence('hello') +test02 > Hello > File('work/hello/hello') > Content('hello') + hello --- + hello +++ + hello @@ -0,0 +1,2 @@ + hello +The magic word is None. + hello +The other word is None. +test02 > Hello > File('work/hello/other-secrets.yaml') > Presence('other-secrets.yaml') +test02 > Hello > File('work/hello/other-secrets.yaml') > Content('other-secrets.yaml') +Not showing diff as it contains sensitive data, +see .../batou/examples/tutorial-secrets/work/.batou-diffs/...diff for the diff. +=================================== Summary ==================================== +Deployment took total=...s, connect=...s, deploy=...s +==================== DEPLOYMENT PREDICTION (local) FINISHED ==================== +""" + ) From 86f06b4bedf0573b051e456b794960c38e4628d9 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 18 Nov 2024 04:46:07 +0100 Subject: [PATCH 2/7] Fix tests --- src/batou/tests/test_deploy.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/batou/tests/test_deploy.py b/src/batou/tests/test_deploy.py index 5703389fc..d47aa6a05 100644 --- a/src/batou/tests/test_deploy.py +++ b/src/batou/tests/test_deploy.py @@ -18,6 +18,7 @@ def test_main_with_errors(capsys): dirty=False, consistency_only=False, predict_only=False, + check_and_predict_local=False, jobs=None, provision_rebuild=False, ) @@ -81,6 +82,7 @@ def test_main_fails_if_no_host_in_environment(capsys): dirty=False, consistency_only=False, predict_only=False, + check_and_predict_local=False, jobs=None, provision_rebuild=False, ) From aad4e13de4d6d049c75ea62f1cf59d4876e5109f Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 18 Nov 2024 04:51:23 +0100 Subject: [PATCH 3/7] Fix changelog, tests --- ...1118_043939_elikowa_add_check_and_predict_local_flag.md | 7 ------- src/batou/tests/test_endtoend.py | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md b/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md index cc3aec068..f6e68ef22 100644 --- a/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md +++ b/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md @@ -1,10 +1,3 @@ - - Adds a `--check-and-predict-local` flag to `./batou deploy`, which can be used in tandem with `--consistency-only` or `--predict-only` to check and predict using the local host's state, without connecting to diff --git a/src/batou/tests/test_endtoend.py b/src/batou/tests/test_endtoend.py index bc80898f0..fdf92cd9e 100644 --- a/src/batou/tests/test_endtoend.py +++ b/src/batou/tests/test_endtoend.py @@ -417,7 +417,7 @@ def test_predicting_deployment_works(): see .../examples/tutorial-secrets/work/.batou-diffs/...diff for the diff. =================================== Summary ==================================== Deployment took total=...s, connect=...s, deploy=...s -======================= DEPLOYMENT PREDICTION FINISHED ========================= +======================== DEPLOYMENT PREDICTION FINISHED ======================== """ ) From fbe4e6a70b3b71e110066d9838e51d87e67e99ab Mon Sep 17 00:00:00 2001 From: Christian Zagrodnick Date: Fri, 22 Nov 2024 07:11:17 +0100 Subject: [PATCH 4/7] testing --- src/batou/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/batou/main.py b/src/batou/main.py index d36c8d6eb..6bc8c0c15 100644 --- a/src/batou/main.py +++ b/src/batou/main.py @@ -77,7 +77,8 @@ def main(args: Optional[list] = None) -> None: "Do not change anything.", ) p.add_argument( - "--check-and-predict-local", + "-L" "--check-and-predict-local", + "--local", action="store_true", help="When running in consistency-only or predict-only mode, " "do not connect to the remote host, but check and predict " From 97206fb93bbb2e085fa3b593069d276f5776f1ae Mon Sep 17 00:00:00 2001 From: Christian Zagrodnick Date: Fri, 22 Nov 2024 07:12:39 +0100 Subject: [PATCH 5/7] testing --- src/batou/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/batou/main.py b/src/batou/main.py index 6bc8c0c15..fe90ea8c4 100644 --- a/src/batou/main.py +++ b/src/batou/main.py @@ -77,9 +77,10 @@ def main(args: Optional[list] = None) -> None: "Do not change anything.", ) p.add_argument( - "-L" "--check-and-predict-local", + "-L", "--local", action="store_true", + dest="check_and_predict_local", help="When running in consistency-only or predict-only mode, " "do not connect to the remote host, but check and predict " "using the local host's state.", From 9a9fd6cd054545e59cab708b52f66bd2150982d8 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 2 Dec 2024 09:04:20 +0100 Subject: [PATCH 6/7] Rename `--check-and-predict-local` flag to `--local` (`-L`) in `batou deploy` command --- ...118_043939_elikowa_add_check_and_predict_local_flag.md | 2 +- doc/source/cli/index.txt | 4 ++-- src/batou/deploy.py | 2 +- src/batou/tests/test_endtoend.py | 8 ++------ 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md b/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md index f6e68ef22..622053c19 100644 --- a/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md +++ b/CHANGES.d/20241118_043939_elikowa_add_check_and_predict_local_flag.md @@ -1,4 +1,4 @@ -- Adds a `--check-and-predict-local` flag to `./batou deploy`, which can +- Adds a `--local` flag to `./batou deploy`, which can be used in tandem with `--consistency-only` or `--predict-only` to check and predict using the local host's state, without connecting to the remote host. diff --git a/doc/source/cli/index.txt b/doc/source/cli/index.txt index 3debb714e..6b2419066 100644 --- a/doc/source/cli/index.txt +++ b/doc/source/cli/index.txt @@ -31,7 +31,7 @@ batou deploy .. code-block:: console usage: batou deploy [-h] [-p PLATFORM] [-t TIMEOUT] [-D] [-c] [-P] - [--check-and-predict-local] [-j JOBS] + [--local] [-j JOBS] [--provision-rebuild] environment @@ -52,7 +52,7 @@ batou deploy Does not touch anything. -P, --predict-only Only predict what updates would happen. Do not change anything. - --check-and-predict-local + --local When running in consistency-only or predict-only mode, do not connect to the remote host, but check and predict using the local host's state. diff --git a/src/batou/deploy.py b/src/batou/deploy.py index baef1bea5..210337ac4 100644 --- a/src/batou/deploy.py +++ b/src/batou/deploy.py @@ -370,7 +370,7 @@ def main( if check_and_predict_local: if (not consistency_only) and (not predict_only): output.error( - "The --check-and-predict-local option is only to be used with --consistency-only or --predict-only." + "The --local option is only to be used with --consistency-only or --predict-only." ) sys.exit(1) ACTION += " (local)" diff --git a/src/batou/tests/test_endtoend.py b/src/batou/tests/test_endtoend.py index fdf92cd9e..737f2318b 100644 --- a/src/batou/tests/test_endtoend.py +++ b/src/batou/tests/test_endtoend.py @@ -424,9 +424,7 @@ def test_predicting_deployment_works(): def test_check_consistency_works_with_local(): os.chdir("examples/tutorial-secrets") - out, _ = cmd( - "./batou deploy gocept --consistency-only --check-and-predict-local" - ) + out, _ = cmd("./batou deploy gocept --consistency-only --local") assert out == Ellipsis( """\ batou/2... (cpython 3...) @@ -446,9 +444,7 @@ def test_check_consistency_works_with_local(): def test_predicting_deployment_works_with_local(): os.chdir("examples/tutorial-secrets") - out, _ = cmd( - "./batou deploy gocept --predict-only --check-and-predict-local" - ) + out, _ = cmd("./batou deploy gocept --predict-only --local") assert out == Ellipsis( """\ batou/2... (cpython 3...) From f4cbefbe2a99674cbe0950e167319cae87764482 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 2 Dec 2024 13:03:30 +0100 Subject: [PATCH 7/7] Update documentation for `--local` flag in `batou deploy` command --- doc/source/cli/index.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/cli/index.txt b/doc/source/cli/index.txt index 6b2419066..3ceab66ec 100644 --- a/doc/source/cli/index.txt +++ b/doc/source/cli/index.txt @@ -52,8 +52,7 @@ batou deploy Does not touch anything. -P, --predict-only Only predict what updates would happen. Do not change anything. - --local - When running in consistency-only or predict-only mode, + -L, --local When running in consistency-only or predict-only mode, do not connect to the remote host, but check and predict using the local host's state. -j JOBS, --jobs JOBS Defines number of jobs running parallel to deploy. The