From c59178a69a937a0971181fab0ed7475d9c80a3c3 Mon Sep 17 00:00:00 2001 From: Chandan Kumar Date: Thu, 31 Jan 2019 12:43:32 +0530 Subject: [PATCH] Use with keyword for opening target file Simply reading a file is dangerous, it might happens that the file might be open but not closed will leads to ResourceWarning: unclosed file error, It is necessary to use with keyword which will close the file first and then allow it to open it. Changing r mode to rb mode as in Python3, While r mode is used then it reads the file based on file encoding provided but with rb mode it reads the stream as a binary which avoides the encoding issue. Change-Id: Ia48c1cb0e436ac2c53fc6bd46c4a906c70a51325 --- tripleoclient/v1/tripleo_deploy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tripleoclient/v1/tripleo_deploy.py b/tripleoclient/v1/tripleo_deploy.py index 1f508fbd9..8798dcb07 100644 --- a/tripleoclient/v1/tripleo_deploy.py +++ b/tripleoclient/v1/tripleo_deploy.py @@ -1089,7 +1089,8 @@ class Deploy(command.Command): raise exceptions.DeploymentError(msg) target = override_file - data = open(target, 'r').read() + with open(target, 'rb') as fb: + data = fb.read() if not data.strip(): # since an empty file isn't valid yaml, let's be more specific msg = (_("hieradata override file (%s) cannot be empty") % target)