-
Notifications
You must be signed in to change notification settings - Fork 9
[GSOC Taks 2] ceph-devstack Cli logs feature : To Display Teuthology Logs #18
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
Open
abhi4578
wants to merge
10
commits into
zmc:main
Choose a base branch
from
abhi4578:cli-feature/logs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
69fe365
Add logs and --log-file option in parse_args
abhi4578 2a2b473
Add implementation of logs and --logs-file option
abhi4578 e90948e
Add type hints to teuthology function and comments
abhi4578 22d944b
Adding pytest unit tests to test 'logs' command
abhi4578 534cb99
Update README with 'logs' command
abhi4578 8276573
Update README.md
abhi4578 683b7b0
Update ceph_devstack/resources/test/test_logs.py
abhi4578 b48f79f
Resolving issues raised in review
abhi4578 3a0626f
Fix teuthology.log file exists and add test cases
abhi4578 fe0f8b8
Replacing test config yaml file with toml file
abhi4578 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
data_dir = "/tmp/ceph-devstack" | ||
|
||
[containers.archive] | ||
image = "python:alpine" | ||
|
||
[containers.beanstalk] | ||
image = "quay.io/ceph-infra/teuthology-beanstalkd:latest" | ||
|
||
[containers.paddles] | ||
image = "quay.io/ceph-infra/paddles:latest" | ||
|
||
[containers.postgres] | ||
image = "quay.io/ceph-infra/teuthology-postgresql:latest" | ||
|
||
[containers.pulpito] | ||
image = "quay.io/ceph-infra/pulpito:latest" | ||
|
||
[containers.testnode] | ||
count = 3 | ||
image = "quay.io/ceph-infra/teuthology-testnode:latest" | ||
|
||
[containers.teuthology] | ||
image = "quay.io/ceph-infra/teuthology-dev:latest" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import pytest | ||
import os | ||
from datetime import datetime,timedelta | ||
from ceph_devstack.cli import main | ||
import random | ||
import shutil | ||
import string | ||
import sys | ||
import logging | ||
|
||
''' | ||
Using pytest paramtrization to test logs command with different | ||
combinations of runs, jobs, selection and if view file path flag is set. | ||
Following parameter combination results in 7*2=14 test cases. | ||
''' | ||
@pytest.mark.parametrize("num_runs,num_jobs,selection,teuthology_file_present",[(0,0,0,True),(2,0,0,True),(4,1,0,True),(4,1,0,False),(4,3,2,True),((4,3,2,False)),(3, 2, 3,True)]) | ||
@pytest.mark.parametrize("flag_set",[ True, False]) | ||
def test_teuthology_logs(num_runs:int,num_jobs:int,selection:int, flag_set:bool,teuthology_file_present:bool,capsys:pytest.CaptureFixture,monkeypatch:pytest.MonkeyPatch,caplog:pytest.LogCaptureFixture) -> int: | ||
""" This function tests the 'logs' command of ceph-devstack. | ||
|
||
Creates a directory structure with random logs and runs the 'logs' command. | ||
Checks if the logs are displayed correctly. | ||
Removes the directory structure after the test. | ||
|
||
Args: | ||
num_runs (int): Number of runs to be created. | ||
num_jobs (int): Number of jobs to be created. | ||
selection (int): The job id to be selected. | ||
flag_set (bool): Flag to set log file path. | ||
capsys (fixture): To capture stdout and stderr. | ||
monkeypatch (fixture): To patch the sys.argv for invoking cli with args and stdin for job selection. | ||
caplog (fixture): To capture logs. | ||
""" | ||
logger = logging.getLogger(__name__) | ||
|
||
if flag_set: | ||
monkeypatch.setattr(sys, 'argv', [ sys.argv[0],'-c', 'ceph_devstack/resources/test/test_config.toml', 'logs','--log-file']) | ||
else: | ||
monkeypatch.setattr(sys, 'argv', [ sys.argv[0],'-c', 'ceph_devstack/resources/test/test_config.toml', 'logs']) | ||
monkeypatch.setattr('builtins.input', lambda name: str(selection)) | ||
data_path = '/tmp/ceph-devstack' | ||
try: | ||
os.makedirs(data_path+'/archive', exist_ok=True) | ||
except Exception as e: | ||
logger.error(f"Error creating directory: {e}") | ||
exit(1) | ||
runs_dir={} | ||
if num_runs>0: | ||
for i in range(num_runs): | ||
end = datetime.now() | ||
start = end - timedelta(days=4) | ||
random_date = start + (end - start) * random.random() | ||
random_date=random_date.strftime('%Y-%m-%d_%H:%M:%S') | ||
try: | ||
os.makedirs(data_path+'/archive'+'/root-'+random_date+'-teuthology', exist_ok=True) | ||
except Exception as e: | ||
logger.error(f"Error creating directory: {e}") | ||
exit(1) | ||
random_logs = [] | ||
if num_jobs>0: | ||
for j in range(num_jobs): | ||
try: | ||
os.makedirs(data_path+'/archive'+'/root-'+random_date+'-teuthology/'+str(j), exist_ok=True) | ||
except Exception as e: | ||
logger.error(f"Error creating directory: {e}") | ||
exit(1) | ||
if teuthology_file_present: | ||
try: | ||
with open(data_path+'/archive'+'/root-'+random_date+'-teuthology/'+str(j)+'/teuthology.log', 'w') as f: | ||
random_logs.append(''.join(random.choices(string.ascii_letters, k=200))) | ||
f.write(random_logs[-1]) | ||
except Exception as e: | ||
logger.error(f"Error creating file: {e}") | ||
exit(1) | ||
runs_dir[data_path+'/archive'+'/root-'+random_date+'-teuthology']=random_logs | ||
try: | ||
with pytest.raises(SystemExit) as main_exit: | ||
main() | ||
except Exception as e: | ||
logger.error(f"Error running main: {e}") | ||
exit(1) | ||
|
||
output, err = capsys.readouterr() | ||
try: | ||
shutil.rmtree(data_path+'/archive') | ||
except Exception as e: | ||
logger.error(f"Error removing directory: {e}") | ||
exit(1) | ||
|
||
runs_dir_list=list(runs_dir.keys()) | ||
if num_runs>0: | ||
runs_dir_list.sort(key=lambda x: datetime.strptime(x.split('/')[-1].split('root-')[1].split('-teuthology')[0], '%Y-%m-%d_%H:%M:%S')) | ||
if num_runs < 1: | ||
assert main_exit.value.code == 1 | ||
assert "No runs found!" in caplog.text | ||
elif num_jobs < 1: | ||
assert main_exit.value.code == 1 | ||
assert "No jobs found!" in caplog.text | ||
elif selection not in range(num_jobs): | ||
assert main_exit.value.code == 1 | ||
assert "Invalid job id!" in caplog.text | ||
elif not teuthology_file_present: | ||
assert main_exit.value.code == 1 | ||
assert "teuthology.log file not found!" in caplog.text | ||
elif flag_set: | ||
assert main_exit.value.code == 0 | ||
assert f"Log file path: {runs_dir_list[-1]}/{selection}/teuthology.log" in output | ||
else: | ||
assert main_exit.value.code == 0 | ||
assert runs_dir[runs_dir_list[-1]][int(selection)] in output |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.