Skip to content

Commit 55b5395

Browse files
committed
feat: print configuration at the start of agent container
1 parent 0e4a035 commit 55b5395

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

agent/skyhook-agent/src/skyhook_agent/controller.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,7 @@ def summarize_check_results(results: list[bool], step_data: dict[Mode, list[Step
339339

340340
return False
341341

342-
def do_interrupt(interrupt_data: str, root_mount: str, copy_dir: str, on_host: bool) -> bool:
343-
"""
344-
Run an interrupt if there hasn't been an interrupt already for the skyhook ID.
345-
"""
346-
342+
def make_config_data_from_resource_id() -> dict:
347343
SKYHOOK_RESOURCE_ID, _ = _get_env_config()
348344

349345
# Interrupts don't really have config data we can read from the Package as it is run standalone.
@@ -354,6 +350,16 @@ def do_interrupt(interrupt_data: str, root_mount: str, copy_dir: str, on_host: b
354350
"package_name": package,
355351
"package_version": version,
356352
}
353+
return config_data
354+
355+
def do_interrupt(interrupt_data: str, root_mount: str, copy_dir: str, on_host: bool) -> bool:
356+
"""
357+
Run an interrupt if there hasn't been an interrupt already for the skyhook ID.
358+
"""
359+
360+
SKYHOOK_RESOURCE_ID, _ = _get_env_config()
361+
362+
config_data = make_config_data_from_resource_id()
357363

358364
interrupt = interrupts.inflate(interrupt_data)
359365

@@ -514,11 +520,36 @@ def cli(sys_argv: list[str]=sys.argv):
514520
# new way with interrupt data
515521
mode, root_mount, copy_dir, interrupt_data = args
516522

517-
if os.getenv("COPY_RESOLV", "true").lower() == "true":
523+
copy_resolv = os.getenv("COPY_RESOLV", "true").lower() == "true"
524+
if copy_resolv:
518525
shutil.copyfile("/etc/resolv.conf", f"{root_mount}/etc/resolv.conf")
519526

520527
always_run_step = os.getenv("OVERLAY_ALWAYS_RUN_STEP", "false").lower() == "true"
521528

529+
# Print all of the configuration flags as a separate line
530+
print("-" * 20)
531+
print(str.center("CLI CONFIGURATION", 20, "-"))
532+
print(f"mode: {mode}")
533+
print(f"root_mount: {root_mount}")
534+
print(f"copy_dir: {copy_dir}")
535+
print(f"interrupt_data: {interrupt_data}")
536+
print(f"always_run_step: {always_run_step}")
537+
print(str.center("ENV CONFIGURATION", 20, "-"))
538+
print(f"COPY_RESOLV: {copy_resolv}")
539+
print(f"OVERLAY_ALWAYS_RUN_STEP: {always_run_step}")
540+
SKYHOOK_RESOURCE_ID, SKYHOOK_DATA_DIR = _get_env_config()
541+
print(f"SKYHOOK_RESOURCE_ID: {SKYHOOK_RESOURCE_ID}")
542+
print(f"SKYHOOK_DATA_DIR: {SKYHOOK_DATA_DIR}")
543+
print(f"SKYHOOK_AGENT_BUFFER_LIMIT: {buff_size}")
544+
print(str.center("Directory CONFIGURATION", 20, "-"))
545+
# print flag dir and log dir
546+
config_data = make_config_data_from_resource_id()
547+
print(f"flag_dir: {get_flag_dir(root_mount)}/{config_data['package_name']}/{config_data['package_version']}")
548+
log_dir = '/'.join(get_log_file(root_mount, 'step',copy_dir, config_data, timestamp='timestamp').split('/')[:-1])
549+
print(f"log_dir: {log_dir}")
550+
print(f"history_file: {get_history_dir(root_mount)}/{config_data['package_name']}.json")
551+
print("-" * 20)
552+
522553
return main(mode, root_mount, copy_dir, interrupt_data, always_run_step)
523554

524555

agent/skyhook-agent/tests/test_controller.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,34 +1212,36 @@ def test_interrupt_makes_config_from_skyhook_resource_id(self, run_mock, datetim
12121212
@mock.patch("skyhook_agent.controller.main")
12131213
def test_interrupt_mode_reads_extra_argument(self, main_mock):
12141214
argv = ["controller.py", str(Mode.INTERRUPT), "root_mount", "copy_dir", "interrupt_data"]
1215-
with set_env(COPY_RESOLV="false"):
1215+
with set_env(COPY_RESOLV="false", SKYHOOK_RESOURCE_ID="customer-25633c77-11ac-471a-9928-bc6969cead5f-2_tuning_2.0.2"):
12161216
controller.cli(argv)
12171217

12181218
main_mock.assert_called_once_with(str(Mode.INTERRUPT), "root_mount", "copy_dir", "interrupt_data", False)
12191219

12201220
@mock.patch("skyhook_agent.controller.main")
12211221
def test_cli_overlay_always_run_step_is_correct(self, main_mock):
1222-
with set_env(OVERLAY_ALWAYS_RUN_STEP="true", COPY_RESOLV="false"):
1222+
with set_env(OVERLAY_ALWAYS_RUN_STEP="true", COPY_RESOLV="false",
1223+
SKYHOOK_RESOURCE_ID="customer-25633c77-11ac-471a-9928-bc6969cead5f-2_tuning_2.0.2"):
12231224
controller.cli(["controller.py", str(Mode.APPLY), "root_mount", "copy_dir"])
12241225

12251226
main_mock.assert_called_once_with(str(Mode.APPLY), "root_mount", "copy_dir", None, True)
12261227
main_mock.reset_mock()
12271228

1228-
with set_env(OVERLAY_ALWAYS_RUN_STEP="false", COPY_RESOLV="false"):
1229+
with set_env(OVERLAY_ALWAYS_RUN_STEP="false", COPY_RESOLV="false",
1230+
SKYHOOK_RESOURCE_ID="customer-25633c77-11ac-471a-9928-bc6969cead5f-2_tuning_2.0.2"):
12291231
controller.cli(["controller.py", str(Mode.APPLY), "root_mount", "copy_dir"])
12301232
main_mock.assert_called_once_with(str(Mode.APPLY), "root_mount", "copy_dir", None, False)
12311233

12321234
@mock.patch("skyhook_agent.controller.main")
12331235
@mock.patch("skyhook_agent.controller.shutil")
12341236
def test_cli_COPY_RESOLV(self, shutil_mock, main_mock):
12351237
argv = ["controller.py", str(Mode.APPLY), "root_mount", "copy_dir"]
1236-
with set_env(COPY_RESOLV="true"):
1238+
with set_env(COPY_RESOLV="true", SKYHOOK_RESOURCE_ID="customer-25633c77-11ac-471a-9928-bc6969cead5f-2_tuning_2.0.2"):
12371239
controller.cli(argv)
12381240

12391241
shutil_mock.copyfile.assert_called_once()
12401242
shutil_mock.copyfile.reset_mock()
12411243

1242-
with set_env(COPY_RESOLV="false"):
1244+
with set_env(COPY_RESOLV="false", SKYHOOK_RESOURCE_ID="customer-25633c77-11ac-471a-9928-bc6969cead5f-2_tuning_2.0.2"):
12431245
controller.cli(argv)
12441246

12451247
shutil_mock.copyfile.assert_not_called()

0 commit comments

Comments
 (0)