summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClark Boylan <clark.boylan@gmail.com>2023-02-07 15:59:04 -0800
committerClark Boylan <clark.boylan@gmail.com>2023-02-07 16:17:09 -0800
commit18db219e3819e098d07dee2d180016f60905d694 (patch)
tree8acb951494e1e0dc9d1d756d6c6cc0bb83bc1ba8
parent753bebbb2c4d78a2be7c204865e841729c43c032 (diff)
downloadzuul-18db219e3819e098d07dee2d180016f60905d694.tar.gz
Fix ResourceWarnings in inventory testing
Inventory testing was opening yaml files to parse them and not explicitly closing them when done. Fix this through the use of with open() context managers. Change-Id: I41a8ee607fcf13e86dd800cefb00d7e120265ed4
-rw-r--r--tests/unit/test_inventory.py13
-rw-r--r--tests/unit/test_v3.py3
2 files changed, 11 insertions, 5 deletions
diff --git a/tests/unit/test_inventory.py b/tests/unit/test_inventory.py
index 5b30a139f..5cafe2ddf 100644
--- a/tests/unit/test_inventory.py
+++ b/tests/unit/test_inventory.py
@@ -57,7 +57,8 @@ class TestInventoryBase(ZuulTestCase):
build = self.getBuildByName(name)
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)
return inventory
def _get_setup_inventory(self, name):
@@ -65,7 +66,9 @@ class TestInventoryBase(ZuulTestCase):
build = self.getBuildByName(name)
setup_inv_path = build.jobdir.setup_playbook.inventory
- return yaml.ansible_unsafe_load(open(setup_inv_path, 'r'))
+ with open(setup_inv_path, 'r') as f:
+ inventory = yaml.ansible_unsafe_load(f)
+ return inventory
def runJob(self, name):
self.hold_jobs_in_queue = False
@@ -409,10 +412,12 @@ class TestAnsibleInventory(AnsibleZuulTestCase):
build = self.history[0]
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)
zv_path = os.path.join(build.jobdir.root, 'ansible', 'zuul_vars.yaml')
- zv = yaml.safe_load(open(zv_path, 'r'))
+ with open(zv_path, 'r') as f:
+ zv = yaml.safe_load(f)
# TODO(corvus): zuul vars aren't really stored here anymore;
# rework these tests to examine them separately.
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 81d95927a..de8b8f3ad 100644
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -5283,7 +5283,8 @@ class TestRoleBranches(RoleTestCase):
def getBuildInventory(self, name):
build = self.getBuildByName(name)
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)
return inventory
def getCheckout(self, build, path):