diff options
author | Zuul <zuul@review.opendev.org> | 2023-02-14 07:51:38 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-02-14 07:51:38 +0000 |
commit | 5e276007c68f34ee0f49303a8064831ff6d492c9 (patch) | |
tree | d50490d844a0555a82eb318e2775fbd7872b020d | |
parent | 776bbc6a6eb7f88f0c0ba5c680815cee22316a4f (diff) | |
parent | ee3339c8e6d76562983ca0da117234eac434671e (diff) | |
download | zuul-5e276007c68f34ee0f49303a8064831ff6d492c9.tar.gz |
Merge "Fix more file opening ResourceWarnings"
-rwxr-xr-x | tests/make_playbooks.py | 3 | ||||
-rw-r--r-- | tests/unit/test_git_driver.py | 3 | ||||
-rw-r--r-- | tests/unit/test_scheduler.py | 3 | ||||
-rw-r--r-- | zuul/ansible/logconfig.py | 3 |
4 files changed, 8 insertions, 4 deletions
diff --git a/tests/make_playbooks.py b/tests/make_playbooks.py index 93c37bc81..cb7a98096 100755 --- a/tests/make_playbooks.py +++ b/tests/make_playbooks.py @@ -40,7 +40,8 @@ def handle_repo(path): config_path = os.path.join(path, fn) break try: - config = yaml.safe_load(open(config_path)) + with open(config_path) as f: + config = yaml.safe_load(f) except Exception: print(" Has yaml errors") return diff --git a/tests/unit/test_git_driver.py b/tests/unit/test_git_driver.py index 06e2ac7c8..95fca30d3 100644 --- a/tests/unit/test_git_driver.py +++ b/tests/unit/test_git_driver.py @@ -62,7 +62,8 @@ class TestGitDriver(ZuulTestCase): # Update zuul.yaml to force a tenant reconfiguration path = os.path.join(self.upstream_root, 'common-config', 'zuul.yaml') - config = yaml.safe_load(open(path, 'r').read()) + with open(path, 'r') as f: + config = yaml.safe_load(f) change = { 'name': 'org/project', 'check': { diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py index 30db44b62..b3948e519 100644 --- a/tests/unit/test_scheduler.py +++ b/tests/unit/test_scheduler.py @@ -6216,7 +6216,8 @@ For CI problems and help debugging, contact ci@example.org""" build = self.getBuildByName('check-job') inv_path = os.path.join(build.jobdir.root, 'ansible', 'inventory.yaml') - inventory = yaml.safe_load(open(inv_path, 'r')) + with open(inv_path, 'r') as f: + inventory = yaml.safe_load(f) label = inventory['all']['hosts']['controller']['nodepool']['label'] self.assertEqual('slow-label', label) diff --git a/zuul/ansible/logconfig.py b/zuul/ansible/logconfig.py index 66881336a..2d7c37463 100644 --- a/zuul/ansible/logconfig.py +++ b/zuul/ansible/logconfig.py @@ -140,7 +140,8 @@ def _read_config_file(filename: str): raise ValueError("Unable to read logging config file at %s" % filename) if os.path.splitext(filename)[1] in ('.yml', '.yaml', '.json'): - return yaml.safe_load(open(filename, 'r')) + with open(filename, 'r') as f: + return yaml.safe_load(f) return filename |