Fix resource warnings when running tests

There are some open calls that are not protected using with.

Change-Id: I98a45c4df38c7a22282fa6abf911a1815fb6bbfa
This commit is contained in:
Tobias Henkel 2019-12-21 11:26:44 +01:00
parent 2a3d4f842b
commit 58ad5123f1
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
3 changed files with 6 additions and 3 deletions

View File

@ -79,7 +79,8 @@ class ConfigValidator:
log.info("validating %s" % self.config_file)
try:
config = yaml.safe_load(open(self.config_file))
with open(self.config_file) as f:
config = yaml.safe_load(f)
except Exception:
log.exception('YAML parsing failed')
return 1

View File

@ -229,7 +229,8 @@ def openConfig(path):
# attempt to reload it.
while True:
try:
config = yaml.safe_load(open(path))
with open(path) as f:
config = yaml.safe_load(f)
break
except IOError as e:
if e.errno == 2:

View File

@ -55,7 +55,8 @@ class TestDriverAws(tests.DBTestCase):
ec2_template = os.path.join(
os.path.dirname(__file__), '..', 'fixtures', 'aws.yaml')
raw_config = yaml.safe_load(open(ec2_template))
with open(ec2_template) as f:
raw_config = yaml.safe_load(f)
raw_config['zookeeper-servers'][0] = {
'host': self.zookeeper_host,
'port': self.zookeeper_port,