Skip to content

Commit 12b269e

Browse files
authored
[ydbd_slice] add confirmation before ydbd build (#13241)
1 parent 275b86e commit 12b269e

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

ydb/tools/ydbd_slice/__init__.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,12 @@ def _run(args):
614614
mode.set_defaults(handler=_run)
615615

616616

617-
def dispatch_run(func, args, walle_provider):
617+
def dispatch_run(func, args, walle_provider, need_confirmation=False):
618+
if need_confirmation and not __confirm(args):
619+
print("Aborting slice installation/formatting")
620+
# TODO(shmel1k@): add confirmation message.
621+
return
622+
618623
logger.debug("run func '%s' with cmd args is '%s'", func.__name__, args)
619624

620625
cluster_details = safe_load_cluster_details(args.cluster, walle_provider)
@@ -654,9 +659,33 @@ def dispatch_run(func, args, walle_provider):
654659
# shutil.rmtree(temp_dir)
655660

656661

662+
def __confirm(args) -> bool:
663+
if hasattr(args, "confirm") and args.confirm:
664+
return True
665+
666+
confirm = input(
667+
"You are trying to setup or format slice. Note, that during setup or format all previous data will be erased.\n"
668+
+ "Press [y] to continue or [n] to abort installation/formatting: "
669+
)
670+
for i in range(0, 3):
671+
lw = confirm.strip().lower()
672+
if lw == "n":
673+
return False
674+
if lw == "y":
675+
return True
676+
confirm = input("Enter [y] or [n]")
677+
lw = confirm.strip().lower()
678+
if lw == "n":
679+
return False
680+
if lw == "y":
681+
return True
682+
683+
return False
684+
685+
657686
def add_install_mode(modes, walle_provider):
658687
def _run(args):
659-
dispatch_run(handlers.Slice.slice_install, args, walle_provider)
688+
dispatch_run(handlers.Slice.slice_install, args, walle_provider, True)
660689

661690
mode = modes.add_parser(
662691
"install",
@@ -701,7 +730,6 @@ def _run(args):
701730

702731
def add_update_raw_configs(modes, walle_provider):
703732
def _run(args):
704-
705733
dispatch_run(lambda self: handlers.Slice.slice_update_raw_configs(self, args.raw_cfg), args, walle_provider)
706734

707735
mode = modes.add_parser(
@@ -750,7 +778,7 @@ def _run(args):
750778

751779
def add_clear_mode(modes, walle_provider):
752780
def _run(args):
753-
dispatch_run(handlers.Slice.slice_clear, args, walle_provider)
781+
dispatch_run(handlers.Slice.slice_clear, args, walle_provider, True)
754782

755783
mode = modes.add_parser(
756784
"clear",
@@ -771,7 +799,7 @@ def _run(args):
771799

772800
def add_format_mode(modes, walle_provider):
773801
def _run(args):
774-
dispatch_run(handlers.Slice.slice_format, args, walle_provider)
802+
dispatch_run(handlers.Slice.slice_format, args, walle_provider, True)
775803

776804
mode = modes.add_parser(
777805
"format",

ydb/tools/ydbd_slice/handlers.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,11 @@ def _format_drives(self):
6565
self.nodes._check_async_execution(tasks)
6666

6767
def slice_format(self):
68-
if not self.__confirm():
69-
print("Aborting slice formatting")
70-
return
7168
self.slice_stop()
7269
self._format_drives()
7370
self.slice_start()
7471

7572
def slice_clear(self):
76-
if not self.__confirm():
77-
print("Aborting slice formatting")
78-
return
79-
8073
self.slice_stop()
8174

8275
if 'dynamic_slots' in self.components:
@@ -120,34 +113,7 @@ def _dynamic_configure(self):
120113
)
121114
)
122115

123-
def __confirm(self) -> bool:
124-
if self.components['confirm']:
125-
return True
126-
127-
confirm = input(
128-
"You are trying to setup or format slice. Note, that during setup or format all previous data will be erased.\n"
129-
+ "Press [y] to continue or [n] to abort installation/formatting: "
130-
)
131-
for i in range(0, 3):
132-
lw = confirm.strip().lower()
133-
if lw == "n":
134-
return False
135-
if lw == "y":
136-
return True
137-
confirm = input("Enter [y] or [n]")
138-
lw = confirm.strip().lower()
139-
if lw == "n":
140-
return False
141-
if lw == "y":
142-
return True
143-
144-
return False
145-
146116
def slice_install(self):
147-
if not self.__confirm():
148-
print("Aborting installation")
149-
return
150-
151117
self._ensure_berkanavt_exists()
152118
self.slice_stop()
153119

0 commit comments

Comments
 (0)