Ensure files are closed, ensure no ResourceWarning on console

Fixes an issue wich cause warnings such as the one below on the
console when using python3.
  ResourceWarning : unclosed file <_io.TextIOWrapper name='FILENAME'

Closes-Bug: #1836379
Change-Id: I4a80a339b2cc0c3fca992cfc456581a91dbf2eef
This commit is contained in:
Harald Jensås
2019-07-12 16:50:01 +02:00
parent cd42f44769
commit 317f3cff7d
6 changed files with 22 additions and 16 deletions

View File

@@ -488,6 +488,10 @@ def wait_for_stack_ready(orchestration_client, stack_name, marker=None,
continue
log.error("Error occured while waiting for stack to be ready.")
raise e
finally:
if not verbose:
out.close()
raise RuntimeError(
"wait_for_stack_ready: Max retries {} reached".format(max_retries))
@@ -1157,7 +1161,8 @@ def get_tripleo_ansible_inventory(inventory_file='',
message = _("Failed to generate inventory: %s") % str(e)
raise exceptions.InvalidConfiguration(message)
if os.path.exists(inventory_file):
inventory = open(inventory_file, 'r').read()
with open(inventory_file, "r") as f:
inventory = f.read()
return inventory
else:
raise exceptions.InvalidConfiguration(_(
@@ -1916,7 +1921,8 @@ def check_file_for_enabled_service(env_file):
# ODL is enabled.
if os.path.exists(env_file):
content = yaml.load(open(env_file))
with open(env_file, "r") as f:
content = yaml.load(f)
deprecated_services_enabled = []
for service in constants.DEPRECATED_SERVICES.keys():
try: