|
11 | 11 | '''
|
12 | 12 | Using pytest paramtrization to test logs command with different
|
13 | 13 | combinations of runs, jobs, selection and if view file path flag is set.
|
14 |
| -Following parameter combination results in 5*2=10 test cases. |
| 14 | +Following parameter combination results in 7*2=14 test cases. |
15 | 15 | '''
|
16 |
| -@pytest.mark.parametrize("num_runs,num_jobs,selection",[(0,0,0),(2,0,0),(4,1,0),(4,3,2),(3, 2, 3)]) |
| 16 | +@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)]) |
17 | 17 | @pytest.mark.parametrize("flag_set",[ True, False])
|
18 |
| -def test_teuthology_logs(num_runs:int,num_jobs:int,selection:int, flag_set:bool,capsys:pytest.CaptureFixture,monkeypatch:pytest.MonkeyPatch,caplog:pytest.LogCaptureFixture) -> int: |
| 18 | +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: |
19 | 19 | """ This function tests the 'logs' command of ceph-devstack.
|
20 | 20 |
|
21 | 21 | Creates a directory structure with random logs and runs the 'logs' command.
|
@@ -64,13 +64,14 @@ def test_teuthology_logs(num_runs:int,num_jobs:int,selection:int, flag_set:bool,
|
64 | 64 | except Exception as e:
|
65 | 65 | logger.error(f"Error creating directory: {e}")
|
66 | 66 | return 1
|
67 |
| - try: |
68 |
| - with open(data_path+'/archive'+'/root-'+random_date+'-teuthology/'+str(j)+'/teuthology.log', 'w') as f: |
69 |
| - random_logs.append(''.join(random.choices(string.ascii_letters, k=200))) |
70 |
| - f.write(random_logs[-1]) |
71 |
| - except Exception as e: |
72 |
| - logger.error(f"Error creating file: {e}") |
73 |
| - return 1 |
| 67 | + if teuthology_file_present: |
| 68 | + try: |
| 69 | + with open(data_path+'/archive'+'/root-'+random_date+'-teuthology/'+str(j)+'/teuthology.log', 'w') as f: |
| 70 | + random_logs.append(''.join(random.choices(string.ascii_letters, k=200))) |
| 71 | + f.write(random_logs[-1]) |
| 72 | + except Exception as e: |
| 73 | + logger.error(f"Error creating file: {e}") |
| 74 | + return 1 |
74 | 75 | runs_dir[data_path+'/archive'+'/root-'+random_date+'-teuthology']=random_logs
|
75 | 76 | try:
|
76 | 77 | with pytest.raises(SystemExit) as main_exit:
|
@@ -98,6 +99,9 @@ def test_teuthology_logs(num_runs:int,num_jobs:int,selection:int, flag_set:bool,
|
98 | 99 | elif selection not in range(num_jobs):
|
99 | 100 | assert main_exit.value.code == 1
|
100 | 101 | assert "Invalid job id!" in caplog.text
|
| 102 | + elif not teuthology_file_present: |
| 103 | + assert main_exit.value.code == 1 |
| 104 | + assert "teuthology.log file not found!" in caplog.text |
101 | 105 | elif flag_set:
|
102 | 106 | assert main_exit.value.code == 0
|
103 | 107 | assert f"Log file path: {runs_dir_list[-1]}/{selection}/teuthology.log" in output
|
|
0 commit comments