Fix for random test failure on restore.py

This patch fixes a random failure that was happening during
the jenkins build.

Change-Id: I1f13fc9b047e8014acbf645c86c93de7e963145b
This commit is contained in:
Fausto Marzi 2015-06-21 14:02:58 +01:00
parent 1a69e26f34
commit 58356772fa
2 changed files with 24 additions and 12 deletions

View File

@ -205,7 +205,8 @@ class FakeBackup:
class FakeMultiProcessing:
def __init__(self, *args, **kwargs):
def __init__(self):
return None
class Queue:
@ -252,8 +253,9 @@ class FakeMultiProcessing:
class Process:
def __init__(self, target=True, args=True):
self.target = target
self.args = args
self.exitcode = 0
return None
def start(self):
return True
@ -317,8 +319,9 @@ class FakeMultiProcessing1:
class Process:
def __init__(self, target=True, args=True):
self.target = target
self.args = args
self.exitcode = 1
return None
def start(self):
return True
@ -762,12 +765,12 @@ class BackupOpt1:
'test-hostname_test-backup-name_1234567_0',
'test-hostname_test-backup-name_1234568_1',
'test-hostname_test-backup-name_1234569_2',
'test-hostname_test-backup-name_1234569_3',
'test-hostname_test-backup-name_1234569_4',
'test-hostname_test-backup-name_1234569_5',
'tar_metadata_test-hostname_test-backup-name_1234569_5',
'tar_metadata_test-hostname_test-backup-name_1234569_4',
'tar_metadata_test-hostname_test-backup-name_1234569_3',
'test-hostname_test-backup-name_1234570_3',
'test-hostname_test-backup-name_1234571_4',
'test-hostname_test-backup-name_1234572_5',
'tar_metadata_test-hostname_test-backup-name_1234572_5',
'tar_metadata_test-hostname_test-backup-name_1234571_4',
'tar_metadata_test-hostname_test-backup-name_1234570_3',
'tar_metadata_test-hostname_test-backup-name_1234569_2',
'tar_metadata_test-hostname_test-backup-name_1234568_1',
'tar_metadata_test-hostname_test-backup-name_1234567_0']

View File

@ -68,18 +68,27 @@ class TestRestore:
def test_restore_fs_sort_obj(self, monkeypatch):
backup_opt = BackupOpt1()
fakelogging = FakeLogging()
# TEST 1
backup_opt = BackupOpt1()
fakemultiprocessing = FakeMultiProcessing()
monkeypatch.setattr(logging, 'critical', fakelogging.critical)
monkeypatch.setattr(logging, 'warning', fakelogging.warning)
monkeypatch.setattr(logging, 'exception', fakelogging.exception)
monkeypatch.setattr(logging, 'error', fakelogging.error)
monkeypatch.setattr(multiprocessing, 'Process', fakemultiprocessing.Process)
assert restore_fs_sort_obj(backup_opt) is None
# TEST 2
backup_opt = BackupOpt1()
backup_opt.backup_name = 'abcdtest'
monkeypatch.setattr(multiprocessing, 'Process', fakemultiprocessing.Process)
pytest.raises(Exception, restore_fs_sort_obj, backup_opt)
# TEST 3
backup_opt = BackupOpt1()
fakemultiprocessing = FakeMultiProcessing1()
monkeypatch.setattr(multiprocessing, 'Process', fakemultiprocessing.Process)
pytest.raises(Exception, restore_fs_sort_obj, backup_opt)
def test_restore_cinder_by_glance(self):