Skip to content

Commit 19d1216

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 19d1216

File tree

3 files changed

+88
-28
lines changed

3 files changed

+88
-28
lines changed

cmlutils/project_entrypoint.py

Lines changed: 70 additions & 23 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(
@@ -612,13 +635,29 @@ def project_import_cmd(project_name, verify):
612635
help="Name of project migrated. Make sure the name matches with the section name in import-config.ini and export-config.ini file",
613636
required=True,
614637
)
615-
def project_verify_cmd(project_name):
638+
@click.option(
639+
"--export_ini_location",
640+
"-el",
641+
default="/.cmlutils/export-config.ini",
642+
show_default=True,
643+
help="filepath of the export-config.ini file. default is <home-dir>/.cmlutils/export-config.ini",
644+
)
645+
@click.option(
646+
"--import_ini_location",
647+
"-il",
648+
default="/.cmlutils/import-config.ini",
649+
show_default=True,
650+
help="filepath of the import-config.ini file. default is <home-dir>/.cmlutils/import-config.ini",
651+
)
652+
def project_verify_cmd(project_name, export_ini_location, import_ini_location):
653+
616654
pexport = None
617655
validation_data = dict()
618656
config = _read_config_file(
619-
os.path.expanduser("~") + "/.cmlutils/export-config.ini", project_name
657+
os.path.expanduser("~") + export_ini_location, project_name
620658
)
621659

660+
622661
export_username = config[USERNAME_KEY]
623662
export_url = config[URL_KEY]
624663
export_apiv1_key = config[API_V1_KEY]
@@ -709,7 +748,7 @@ def project_verify_cmd(project_name):
709748
pexport.terminate_ssh_session()
710749
pimport = None
711750
import_config = _read_config_file(
712-
os.path.expanduser("~") + "/.cmlutils/import-config.ini", project_name
751+
os.path.expanduser("~") + import_ini_location, project_name
713752
)
714753

715754
import_username = import_config[USERNAME_KEY]
@@ -742,8 +781,8 @@ def project_verify_cmd(project_name):
742781
for v in validators:
743782
validation_response = v.validate()
744783
if (
745-
validation_response.validation_status
746-
== ValidationResponseStatus.FAILED
784+
validation_response.validation_status
785+
== ValidationResponseStatus.FAILED
747786
):
748787
logging.error(
749788
"Validation error for project %s: %s",
@@ -924,8 +963,9 @@ def project_verify_cmd(project_name):
924963
True if (job_diff or job_config_diff) else False,
925964
message="Job Verification",
926965
)
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]
966+
result = [export_diff_file_list, import_diff_file_list, proj_diff,
967+
proj_config_diff, app_diff, app_config_diff, model_diff, model_config_diff, job_diff,
968+
job_config_diff]
929969
migration_status = all(not sublist for sublist in result)
930970
update_verification_status(
931971
not migration_status,
@@ -961,11 +1001,18 @@ def project_helpers_cmd():
9611001
"""
9621002

9631003

1004+
@click.option(
1005+
"--ini_location",
1006+
"-l",
1007+
default="/.cmlutils/import-config.ini",
1008+
show_default=True,
1009+
help="filepath of the import-config.ini file. default is <home-dir>/.cmlutils/import-config.ini",
1010+
)
9641011
@project_helpers_cmd.command("populate_engine_runtimes_mapping")
965-
def populate_engine_runtimes_mapping():
1012+
def populate_engine_runtimes_mapping(ini_location):
9661013
project_name = "DEFAULT"
9671014
config = _read_config_file(
968-
os.path.expanduser("~") + "/.cmlutils/import-config.ini", project_name
1015+
os.path.expanduser("~") + ini_location, project_name
9691016
)
9701017

9711018
username = config[USERNAME_KEY]
@@ -1020,10 +1067,10 @@ def populate_engine_runtimes_mapping():
10201067
# Please make sure utility is having necessary permissions to write/overwrite data
10211068
try:
10221069
with open(
1023-
os.path.expanduser("~")
1024-
+ "/.cmlutils/"
1025-
+ "legacy_engine_runtime_constants.json",
1026-
"w",
1070+
os.path.expanduser("~")
1071+
+ "/.cmlutils/"
1072+
+ "legacy_engine_runtime_constants.json",
1073+
"w",
10271074
) as legacy_engine_runtime_constants:
10281075
dump(legacy_runtime_image_map, legacy_engine_runtime_constants)
10291076
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: 13 additions & 4 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

@@ -39,7 +41,10 @@ def get_absolute_path(path: str) -> str:
3941

4042

4143
def import_validate(project_name: str):
42-
output_dir = _read_config_file((os.path.expanduser("~") + "/.cmlutils/import-config.ini"),
44+
# Change the ini location as per the convenience
45+
ini_location = "/.cmlutils/import-config.ini"
46+
47+
output_dir = _read_config_file((os.path.expanduser("~") + ini_location),
4348
project_name)
4449
import_metrics_file_path = os.path.join(get_absolute_path(output_dir[OUTPUT_DIR_KEY]), project_name, IMPORT_METRIC_FILE)
4550

@@ -85,9 +90,12 @@ def _get_project_list(file_path: str):
8590

8691

8792
def main():
88-
failed_validation_list = list()
93+
94+
# Change the ini location as per the convenience
95+
ini_location = "/.cmlutils/import-config.ini"
96+
8997
project_names = _get_project_list(
90-
os.path.expanduser("~") + "/.cmlutils/import-config.ini"
98+
os.path.expanduser("~") + ini_location
9199
)
92100
project_iter = []
93101

@@ -100,8 +108,9 @@ def main():
100108
# call a function on each item in a list
101109
pool.starmap(import_project, project_iter)
102110

103-
# validation summary if VERIFY=True
111+
# Please DO NOT enable this feature.
104112
if VERIFY:
113+
failed_validation_list = list()
105114
for project in project_names:
106115
result = import_validate(project)
107116
if not result:

0 commit comments

Comments
 (0)