Skip to content

Commit

Permalink
Feature/ydbd slice/add confirmation on slice install (#13146)
Browse files Browse the repository at this point in the history
  • Loading branch information
shmel1k authored Dec 31, 2024
1 parent ec34bf1 commit d0c941e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ydb/tools/ydbd_slice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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. "
Expand Down Expand Up @@ -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. "
Expand Down
34 changes: 34 additions & 0 deletions ydb/tools/ydbd_slice/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit d0c941e

Please sign in to comment.