Skip to content

Commit

Permalink
Reopen stdin after appinspect because it is
Browse files Browse the repository at this point in the history
closed. If we do not do this, then interactive
mode fails because it cannot read CTRL-D
or Enter from stdin and produces and error.
  • Loading branch information
pyth0n1c committed Jul 13, 2023
1 parent bfa36f1 commit 26ee1c3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DetectionTestingManagerOutputDto:
start_time: Union[datetime.datetime, None] = None
replay_index: str = "CONTENTCTL_TESTING_INDEX"
replay_host: str = "CONTENTCTL_HOST"
timeout_seconds: int = 30
timeout_seconds: int = 15
terminate: bool = False


Expand Down Expand Up @@ -465,11 +465,8 @@ def execute_test(
)

try:
self.pbar.write("waiting for input")
_ = input()
self.pbar.write("got input")
except Exception as e:
self.pbar.write(f"got exception: {str(e)}")
pass

self.format_pbar_string(f"{detection.name}:{test.name}", f"Deleting Data", start_time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def getETA(self) -> datetime.timedelta:
try:
runtime = self.getRuntime()
time_per_detection = runtime / num_tested
remaining_time = num_untested * time_per_detection
remaining_time = (num_untested+.5) * time_per_detection
remaining_time -= datetime.timedelta(
microseconds=remaining_time.microseconds
)
Expand Down
8 changes: 7 additions & 1 deletion contentctl/contentctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ def test(args: argparse.Namespace):
# For example, if the detection(s) we are trying to test do not exist
githubService = GithubService(config.test)


director_output_dto = build(args, config)



# All this information will later come from the config, so we will
# be able to do it in Test().execute. For now, we will do it here
app = App(
Expand All @@ -176,14 +179,17 @@ def test(args: argparse.Namespace):

config.test.apps = [app] + config.test.apps


test_input_dto = TestInputDto(
director_output_dto=director_output_dto,
githubService=githubService,
config=config.test,
)

test = Test()

try:

result = test.execute(test_input_dto)
# This return code is important. Even if testing
# fully completes, if everything does not pass then
Expand All @@ -194,7 +200,7 @@ def test(args: argparse.Namespace):
sys.exit(1)

except Exception as e:
print("Error running contentctl test: {str(e)}")
print(f"Error running contentctl test: {str(e)}")
sys.exit(1)


Expand Down
3 changes: 3 additions & 0 deletions contentctl/output/conf_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def inspectApp(self)-> None:

except SystemExit as e:
if e.code == 0:
# The sys.exit called inside of appinspect validate closes stdin. We need to
# reopen it.
sys.stdin = open("/dev/stdin","r")
print(f"AppInspect passed! Please check [ {appinspect_output} , {appinspect_logging} ] for verbose information.")
else:
if sys.version.startswith('3.11') or sys.version.startswith('3.12'):
Expand Down

0 comments on commit 26ee1c3

Please sign in to comment.