Skip to content

Commit 558f78f

Browse files
author
suryapratapdesai
committed
DSE-38906 Provision to take various ini files at runtime.
This is most sought feature request by customers in cases of Shared Multi-user machines with different ini. files for each customer.
1 parent cc83981 commit 558f78f

File tree

3 files changed

+66
-25
lines changed

3 files changed

+66
-25
lines changed

cmlutils/project_entrypoint.py

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,31 @@ def project_cmd():
8585
"""
8686

8787

88+
@click.group(name="experimental")
89+
def experimental_cmd():
90+
"""
91+
Sub-entrypoint for WIP/Experimental commands
92+
"""
93+
94+
8895
@project_cmd.command(name="export")
8996
@click.option(
9097
"--project_name",
9198
"-p",
9299
help="Name of the project to be migrated. Make sure the name matches with the section name in export-config.ini file",
93100
required=True,
94101
)
95-
def project_export_cmd(project_name):
102+
@click.option(
103+
"--ini_location",
104+
"-l",
105+
default="/.cmlutils/export-config.ini",
106+
show_default=True,
107+
help="filepath of the export-config.ini file. default is <home-dir>/.cmlutils/export-config.ini",
108+
)
109+
def project_export_cmd(project_name, ini_location):
96110
pexport = None
97111
config = _read_config_file(
98-
os.path.expanduser("~") + "/.cmlutils/export-config.ini", project_name
112+
os.path.expanduser("~") + ini_location, project_name
99113
)
100114

101115
username = config[USERNAME_KEY]
@@ -207,17 +221,24 @@ def project_export_cmd(project_name):
207221
help="Name of the project to be migrated. Make sure the name matches with the section name in import-config.ini file",
208222
required=True,
209223
)
224+
@click.option(
225+
"--ini_location",
226+
"-l",
227+
default="/.cmlutils/import-config.ini",
228+
show_default=True,
229+
help="filepath of the import-config.ini file. default is <home-dir>/.cmlutils/import-config.ini",
230+
)
210231
@click.option(
211232
"--verify",
212233
"-v",
213-
is_flag=True,
234+
is_flag=False,
214235
help="Flag to automatically trigger migration validation after import.",
215236
)
216-
def project_import_cmd(project_name, verify):
237+
def project_import_cmd(project_name, ini_location, verify=False):
217238
pimport = None
218239
import_diff_file_list = None
219240
config = _read_config_file(
220-
os.path.expanduser("~") + "/.cmlutils/import-config.ini", project_name
241+
os.path.expanduser("~") + ini_location, project_name
221242
)
222243

223244
username = config[USERNAME_KEY]
@@ -299,11 +320,10 @@ def project_import_cmd(project_name, verify):
299320
)
300321
start_time = time.time()
301322
if verify:
302-
import_diff_file_list=pimport.transfer_project(log_filedir=log_filedir, verify=True)
323+
import_diff_file_list = pimport.transfer_project(log_filedir=log_filedir, verify=True)
303324
else:
304325
pimport.transfer_project(log_filedir=log_filedir)
305326

306-
307327
if uses_engine:
308328
proj_patch_metadata = {"default_project_engine_type": "legacy_engine"}
309329
pimport.convert_project_to_engine_based(
@@ -340,7 +360,9 @@ def project_import_cmd(project_name, verify):
340360
pimport.terminate_ssh_session()
341361
# If verification is also needed after import
342362
if verify:
343-
print("***************************************************** Started verifying migration for project: {} ***************************************************** ".format(project_name))
363+
print(
364+
"***************************************************** Started verifying migration for project: {} ***************************************************** ".format(
365+
project_name))
344366
(
345367
imported_project_data,
346368
imported_project_list,
@@ -578,8 +600,9 @@ def project_import_cmd(project_name, verify):
578600
True if (job_diff or job_config_diff) else False,
579601
message="Job Verification",
580602
)
581-
result = [export_diff_file_list,import_diff_file_list,proj_diff,
582-
proj_config_diff,app_diff,app_config_diff,model_diff,model_config_diff,job_diff, job_config_diff]
603+
result = [export_diff_file_list, import_diff_file_list, proj_diff,
604+
proj_config_diff, app_diff, app_config_diff, model_diff, model_config_diff, job_diff,
605+
job_config_diff]
583606
migration_status = all(not sublist for sublist in result)
584607
validation_data["isMigrationSuccessful"] = migration_status
585608
update_verification_status(
@@ -605,7 +628,7 @@ def project_import_cmd(project_name, verify):
605628
exit()
606629

607630

608-
@project_cmd.command(name="validate-migration")
631+
@experimental_cmd.command(name="validate-migration")
609632
@click.option(
610633
"--project_name",
611634
"-p",
@@ -742,8 +765,8 @@ def project_verify_cmd(project_name):
742765
for v in validators:
743766
validation_response = v.validate()
744767
if (
745-
validation_response.validation_status
746-
== ValidationResponseStatus.FAILED
768+
validation_response.validation_status
769+
== ValidationResponseStatus.FAILED
747770
):
748771
logging.error(
749772
"Validation error for project %s: %s",
@@ -924,8 +947,9 @@ def project_verify_cmd(project_name):
924947
True if (job_diff or job_config_diff) else False,
925948
message="Job Verification",
926949
)
927-
result = [export_diff_file_list,import_diff_file_list,proj_diff,
928-
proj_config_diff,app_diff,app_config_diff,model_diff,model_config_diff,job_diff, job_config_diff]
950+
result = [export_diff_file_list, import_diff_file_list, proj_diff,
951+
proj_config_diff, app_diff, app_config_diff, model_diff, model_config_diff, job_diff,
952+
job_config_diff]
929953
migration_status = all(not sublist for sublist in result)
930954
update_verification_status(
931955
not migration_status,
@@ -961,11 +985,18 @@ def project_helpers_cmd():
961985
"""
962986

963987

988+
@click.option(
989+
"--ini_location",
990+
"-l",
991+
default="/.cmlutils/import-config.ini",
992+
show_default=True,
993+
help="filepath of the import-config.ini file. default is <home-dir>/.cmlutils/import-config.ini",
994+
)
964995
@project_helpers_cmd.command("populate_engine_runtimes_mapping")
965-
def populate_engine_runtimes_mapping():
996+
def populate_engine_runtimes_mapping(ini_location):
966997
project_name = "DEFAULT"
967998
config = _read_config_file(
968-
os.path.expanduser("~") + "/.cmlutils/import-config.ini", project_name
999+
os.path.expanduser("~") + ini_location, project_name
9691000
)
9701001

9711002
username = config[USERNAME_KEY]
@@ -1020,10 +1051,10 @@ def populate_engine_runtimes_mapping():
10201051
# Please make sure utility is having necessary permissions to write/overwrite data
10211052
try:
10221053
with open(
1023-
os.path.expanduser("~")
1024-
+ "/.cmlutils/"
1025-
+ "legacy_engine_runtime_constants.json",
1026-
"w",
1054+
os.path.expanduser("~")
1055+
+ "/.cmlutils/"
1056+
+ "legacy_engine_runtime_constants.json",
1057+
"w",
10271058
) as legacy_engine_runtime_constants:
10281059
dump(legacy_runtime_image_map, legacy_engine_runtime_constants)
10291060
except:

examples/batch_export.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ def _get_project_list(file_path: str):
3333

3434

3535
def main():
36+
37+
# Change the ini location as per the convenience
38+
ini_location = "/.cmlutils/export-config.ini"
39+
3640
project_names = _get_project_list(
37-
os.path.expanduser("~") + "/.cmlutils/export-config.ini"
41+
os.path.expanduser("~") + ini_location
3842
)
3943
print(project_names)
4044
project_iter = []

examples/batch_import.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
# This variable controls if user want to trigger migration validation automatically after import
1818
# NOTE: Migration validation is resource intensive task keep the BATCH_SIZE to optimal size
19+
20+
# DO NOT ENABLE this flag
1921
VERIFY = False
2022

2123

@@ -85,9 +87,12 @@ def _get_project_list(file_path: str):
8587

8688

8789
def main():
88-
failed_validation_list = list()
90+
91+
# Change the ini location as per the convenience
92+
ini_location = "/.cmlutils/export-config.ini"
93+
8994
project_names = _get_project_list(
90-
os.path.expanduser("~") + "/.cmlutils/import-config.ini"
95+
os.path.expanduser("~") + ini_location
9196
)
9297
project_iter = []
9398

@@ -100,8 +105,9 @@ def main():
100105
# call a function on each item in a list
101106
pool.starmap(import_project, project_iter)
102107

103-
# validation summary if VERIFY=True
108+
# Please DO NOT enable this feature.
104109
if VERIFY:
110+
failed_validation_list = list()
105111
for project in project_names:
106112
result = import_validate(project)
107113
if not result:

0 commit comments

Comments
 (0)