Fix tox py27 error
The backup.test_backupagent.BackupAgentTest.test_backup_impl_MongoDump unit test throws the following error when we run tox -r -e py27: AttributeError: 'NoneType' object has no attribute 'rfind' The error is caused by a 'None' CONFIG_FILE value being passed into the os.path.dirname(CONFIG_FILE) call. The CONFIG_FILE value is derived from the return value of the trove.guestagent.common.operating_system.file_discovery() method, which shouldn't be None. This commit ensures the file_discovery() method would never return a 'None' value. Change-Id: Id2f1f72e1a9e303c7b59ff0d25c556bc89de4669 Closes-Bug: 1515642
This commit is contained in:
parent
4e2724021b
commit
175c15cec1
@ -248,6 +248,7 @@ def file_discovery(file_candidates):
|
||||
for file in file_candidates:
|
||||
if os.path.isfile(file):
|
||||
return file
|
||||
return ''
|
||||
|
||||
|
||||
def start_service(service_candidates):
|
||||
|
@ -819,6 +819,10 @@ class TestOperatingSystem(trove_testtools.TestCase):
|
||||
config_file = operating_system.file_discovery(
|
||||
["/etc/mongodb.conf", "/etc/mongod.conf"])
|
||||
self.assertEqual('/etc/mongod.conf', config_file)
|
||||
with patch.object(os.path, 'isfile', side_effect=[False]):
|
||||
config_file = operating_system.file_discovery(
|
||||
["/etc/mongodb.conf"])
|
||||
self.assertEqual('', config_file)
|
||||
|
||||
def test_list_files_in_directory(self):
|
||||
root_path = tempfile.mkdtemp()
|
||||
|
Loading…
x
Reference in New Issue
Block a user