-
Notifications
You must be signed in to change notification settings - Fork 9
Implemented the show-log command along with flag: -f, --filepath #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cee3f65
254964e
0f97b34
9af5959
acc527d
145c030
9113182
ea1ebc3
4f926ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||||||||||
import contextlib | ||||||||||||||
import os | ||||||||||||||
import tempfile | ||||||||||||||
from datetime import datetime | ||||||||||||||
|
||||||||||||||
from subprocess import CalledProcessError | ||||||||||||||
|
||||||||||||||
|
@@ -226,3 +227,68 @@ async def wait(self, container_name: str): | |||||||||||||
return await object.wait() | ||||||||||||||
logger.error(f"Could not find container {container_name}") | ||||||||||||||
return 1 | ||||||||||||||
|
||||||||||||||
async def show_log(self, filepath: bool = False): | ||||||||||||||
home_dir = os.path.expanduser("~") | ||||||||||||||
target_dir = os.path.join(home_dir, ".local", "share", "ceph-devstack", "archive") | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
run_directories_list = None | ||||||||||||||
if os.path.exists(target_dir) and os.path.isdir(target_dir): | ||||||||||||||
run_directories_list = os.listdir(target_dir) | ||||||||||||||
else: | ||||||||||||||
logger.error(f"Error: {target_dir} does not exist or is not a directory") | ||||||||||||||
return 1 | ||||||||||||||
def extract_timestamp(dir_name): | ||||||||||||||
try: | ||||||||||||||
parts = dir_name.split("-") | ||||||||||||||
year, month, day_time = parts[1], parts[2], parts[3] | ||||||||||||||
day, time = day_time.split("_") | ||||||||||||||
timestamp = f"{year}-{month}-{day} {time}" | ||||||||||||||
return datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S") | ||||||||||||||
except Exception as e: | ||||||||||||||
logger.error(f"Error extracting timestamp from {dir_name}: {e}") | ||||||||||||||
return None | ||||||||||||||
run_directories_list.sort(key=lambda dir: extract_timestamp(dir), reverse=True) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is nice! |
||||||||||||||
latest_directory = run_directories_list[0] if run_directories_list else None | ||||||||||||||
try: | ||||||||||||||
latest_directory = os.path.join(target_dir, latest_directory) | ||||||||||||||
all_job_ids = [jobID for jobID in os.listdir(latest_directory) if os.path.isdir(os.path.join(latest_directory, jobID)) and jobID.isdigit()] | ||||||||||||||
if not all_job_ids: | ||||||||||||||
logger.info("No latest jobIDs") # We could add a feature to go to the "next" latest directory | ||||||||||||||
else: | ||||||||||||||
if(len(all_job_ids)>1): | ||||||||||||||
print("ALERT: Multiple jobIDs found: ", ", ".join(all_job_ids)) | ||||||||||||||
while True: | ||||||||||||||
selected_jobID = input("Select jobID to view corresponding log: ") | ||||||||||||||
if selected_jobID in all_job_ids: | ||||||||||||||
log_file_path = os.path.join(latest_directory, selected_jobID, "teuthology.log") | ||||||||||||||
if os.path.exists(log_file_path) and os.path.isfile(log_file_path) and not filepath: | ||||||||||||||
print("<-----------teuthology.log contents----------->") | ||||||||||||||
with open(log_file_path, "r") as file: | ||||||||||||||
print(file.read()) | ||||||||||||||
return 0 | ||||||||||||||
elif filepath: | ||||||||||||||
logger.info(f"{log_file_path}") | ||||||||||||||
return 0 | ||||||||||||||
Comment on lines
+269
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
otherwise it'll print the teuthology.log file path even if job directory exists but teuthology.log file does not exist |
||||||||||||||
else: | ||||||||||||||
logger.error(f"Error: teuthology.log file not found in {os.path.join(latest_directory, selected_jobID)}") | ||||||||||||||
return 1 | ||||||||||||||
else: | ||||||||||||||
logger.error(f"Error: {selected_jobID} is not a valid jobID") | ||||||||||||||
else: | ||||||||||||||
selected_jobID = all_job_ids[0] | ||||||||||||||
log_file_path = os.path.join(latest_directory, selected_jobID, "teuthology.log") | ||||||||||||||
if os.path.exists(log_file_path) and os.path.isfile(log_file_path) and not filepath: | ||||||||||||||
print("<-----------teuthology.log contents----------->") | ||||||||||||||
with open(log_file_path, "r") as file: | ||||||||||||||
print(file.read()) | ||||||||||||||
return 0 | ||||||||||||||
elif filepath: | ||||||||||||||
logger.info(f"{log_file_path}") | ||||||||||||||
Comment on lines
+285
to
+286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
same comment as above |
||||||||||||||
return 0 | ||||||||||||||
else: | ||||||||||||||
logger.error(f"Error: teuthology.log file not found in {os.path.join(latest_directory, selected_jobID)}") | ||||||||||||||
return 1 | ||||||||||||||
return 0 | ||||||||||||||
except Exception as e: | ||||||||||||||
logger.error(f"Error: {e}") | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: boolean variables can be named something like
is_filepath
for readability