From d0c941eff7407b04b24b4368ceeed2d328bbe580 Mon Sep 17 00:00:00 2001 From: Alexander Petrukhin Date: Tue, 31 Dec 2024 20:39:26 +0300 Subject: [PATCH] Feature/ydbd slice/add confirmation on slice install (#13146) --- ydb/tools/ydbd_slice/__init__.py | 24 +++++++++++++++++++++- ydb/tools/ydbd_slice/handlers.py | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/ydb/tools/ydbd_slice/__init__.py b/ydb/tools/ydbd_slice/__init__.py index 891f2ee7ba93..0626d54e190f 100644 --- a/ydb/tools/ydbd_slice/__init__.py +++ b/ydb/tools/ydbd_slice/__init__.py @@ -300,6 +300,8 @@ def deduce_components_from_args(args, cluster_details): if 'dynamic_slots' in result: result['dynamic_slots'] = ['all'] + result['confirm'] = args.confirm + logger.debug("active components is '%s'", result) return result @@ -511,6 +513,18 @@ def ssh_args(): return args +def with_confirmation(): + args = argparse.ArgumentParser(add_help=False) + args.add_argument( + "--confirm", + "-y", + action="store_true", + default=False, + help="Confirm slice installation" + ) + return args + + def databases_config_path_args(): args = argparse.ArgumentParser(add_help=False) args.add_argument( @@ -648,6 +662,7 @@ def _run(args): component_args(), log_args(), ssh_args(), + with_confirmation(), # databases_config_path_args(), ], description="Full installation of the cluster from scratch. " @@ -747,7 +762,14 @@ def _run(args): mode = modes.add_parser( "format", - parents=[direct_nodes_args(), cluster_description_args(), binaries_args(), component_args(), ssh_args()], + parents=[ + direct_nodes_args(), + cluster_description_args(), + binaries_args(), + component_args(), + ssh_args(), + with_confirmation(), + ], description="Stop all ydbd instances at the nodes, format all ydbd drives at the nodes, start the instances. " "If you call format for all cluster, you will spoil it. " "Additional dynamic configuration will required after it. " diff --git a/ydb/tools/ydbd_slice/handlers.py b/ydb/tools/ydbd_slice/handlers.py index 7dbb324f3070..2198b3728559 100644 --- a/ydb/tools/ydbd_slice/handlers.py +++ b/ydb/tools/ydbd_slice/handlers.py @@ -65,11 +65,18 @@ def _format_drives(self): self.nodes._check_async_execution(tasks) def slice_format(self): + if not self.__confirm(): + print("Aborting slice formatting") + return self.slice_stop() self._format_drives() self.slice_start() def slice_clear(self): + if not self.__confirm(): + print("Aborting slice formatting") + return + self.slice_stop() if 'dynamic_slots' in self.components: @@ -113,7 +120,34 @@ def _dynamic_configure(self): ) ) + def __confirm(self) -> bool: + if self.components['confirm']: + return True + + confirm = input( + "You are trying to setup or format slice. Note, that during setup or format all previous data will be erased.\n" + + "Press [y] to continue or [n] to abort installation/formatting: " + ) + for i in range(0, 3): + lw = confirm.strip().lower() + if lw == "n": + return False + if lw == "y": + return True + confirm = input("Enter [y] or [n]") + lw = confirm.strip().lower() + if lw == "n": + return False + if lw == "y": + return True + + return False + def slice_install(self): + if not self.__confirm(): + print("Aborting installation") + return + self._ensure_berkanavt_exists() self.slice_stop()