diff --git a/src/ipaclustercheck/ipa/plugin.py b/src/ipaclustercheck/ipa/plugin.py index a1119886..6ca0e1e4 100644 --- a/src/ipaclustercheck/ipa/plugin.py +++ b/src/ipaclustercheck/ipa/plugin.py @@ -92,7 +92,7 @@ def load_files(self, dir): fname = join(dir, file) logger.debug("Reading %s", fname) try: - with open(fname, 'r') as fd: + with open(fname, 'r', encoding="utf-8") as fd: data = fd.read() except Exception as e: logger.error("Unable to read %s: %s", fname, e) diff --git a/src/ipahealthcheck/core/core.py b/src/ipahealthcheck/core/core.py index 685dbd72..610b8736 100644 --- a/src/ipahealthcheck/core/core.py +++ b/src/ipahealthcheck/core/core.py @@ -409,7 +409,7 @@ def run_healthcheck(self): if 'infile' in options and options.infile: try: - with open(options.infile, 'r') as f: + with open(options.infile, 'r', encoding="utf-8") as f: raw_data = f.read() json_data = json.loads(raw_data) diff --git a/src/ipahealthcheck/core/output.py b/src/ipahealthcheck/core/output.py index b29bc0c8..225e40af 100644 --- a/src/ipahealthcheck/core/output.py +++ b/src/ipahealthcheck/core/output.py @@ -61,7 +61,7 @@ def render(self, results): def write_file(self, output): """Write the output to a file or sys.stdout""" if self.filename: - with open(self.filename, 'w') as fd: + with open(self.filename, 'w', encoding="utf-8") as fd: fd.write(output) else: sys.stdout.write(output) diff --git a/src/ipahealthcheck/ipa/certs.py b/src/ipahealthcheck/ipa/certs.py index 71971184..cf023077 100644 --- a/src/ipahealthcheck/ipa/certs.py +++ b/src/ipahealthcheck/ipa/certs.py @@ -173,7 +173,7 @@ def get_dogtag_cert_password(): """ ca_passwd = None token = 'internal' - with open(paths.PKI_TOMCAT_PASSWORD_CONF, 'r') as f: + with open(paths.PKI_TOMCAT_PASSWORD_CONF, 'r', encoding="utf-8") as f: for line in f: (tok, pin) = line.split('=', 1) if token == tok: diff --git a/src/ipahealthcheck/ipa/proxy.py b/src/ipahealthcheck/ipa/proxy.py index 5b4fcee0..a22ac14a 100644 --- a/src/ipahealthcheck/ipa/proxy.py +++ b/src/ipahealthcheck/ipa/proxy.py @@ -22,7 +22,7 @@ def read_ipa_pki_proxy(): Split out to make it easier to mock """ - with open(paths.HTTPD_IPA_PKI_PROXY_CONF, "r") as fd: + with open(paths.HTTPD_IPA_PKI_PROXY_CONF, "r", encoding="utf-8") as fd: lines = fd.readlines() return lines diff --git a/src/ipahealthcheck/system/filesystemspace.py b/src/ipahealthcheck/system/filesystemspace.py index 379ae66c..b77515ca 100644 --- a/src/ipahealthcheck/system/filesystemspace.py +++ b/src/ipahealthcheck/system/filesystemspace.py @@ -13,10 +13,10 @@ def in_container(): """Determine if we're running in a container.""" - with open('/proc/1/sched', 'r') as sched: + with open('/proc/1/sched', 'r', encoding="utf-8") as sched: data_sched = sched.readline() - with open('/proc/self/cgroup', 'r') as cgroup: + with open('/proc/self/cgroup', 'r', encoding="utf-8") as cgroup: data_cgroup = cgroup.readline() checks = [ diff --git a/tests/test_options.py b/tests/test_options.py index da1866f8..6fbe59f2 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -28,7 +28,7 @@ def test_options_merge(mock_parse, mock_run, mock_service): mock_parse.return_value = options fd, config_path = tempfile.mkstemp() os.close(fd) - with open(config_path, "w") as fd: + with open(config_path, "w", encoding="utf-8") as fd: fd.write('[default]\n') fd.write('output_type=human\n') fd.write('indent=5\n') diff --git a/tests/test_suppress.py b/tests/test_suppress.py index 18dc706c..27a3c715 100644 --- a/tests/test_suppress.py +++ b/tests/test_suppress.py @@ -76,7 +76,7 @@ def test_suppress_none(mock_find, mock_parse, mock_service): fd, config_path = tempfile.mkstemp() os.close(fd) - with open(config_path, "w") as fd: + with open(config_path, "w", encoding="utf-8") as fd: fd.write('[default]\n') try: @@ -104,7 +104,7 @@ def test_suppress_source(mock_find, mock_parse, mock_service): fd, config_path = tempfile.mkstemp() os.close(fd) - with open(config_path, "w") as fd: + with open(config_path, "w", encoding="utf-8") as fd: fd.write('[default]\n') fd.write('[excludes]\n') fd.write('source=test_suppress\n') @@ -134,7 +134,7 @@ def test_suppress_check(mock_find, mock_parse, mock_service): fd, config_path = tempfile.mkstemp() os.close(fd) - with open(config_path, "w") as fd: + with open(config_path, "w", encoding="utf-8") as fd: fd.write('[default]\n') fd.write('[excludes]\n') fd.write('check=PluginOne\n') @@ -166,7 +166,7 @@ def test_suppress_key(mock_find, mock_parse, mock_service): fd, config_path = tempfile.mkstemp() os.close(fd) - with open(config_path, "w") as fd: + with open(config_path, "w", encoding="utf-8") as fd: fd.write('[default]\n') fd.write('[excludes]\n') fd.write('key=test2\n')