summaryrefslogtreecommitdiff
path: root/test/lib/ansible_test/_internal/executor.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/ansible_test/_internal/executor.py')
-rw-r--r--test/lib/ansible_test/_internal/executor.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/test/lib/ansible_test/_internal/executor.py b/test/lib/ansible_test/_internal/executor.py
index ef54d6f6d1..b1e18f328f 100644
--- a/test/lib/ansible_test/_internal/executor.py
+++ b/test/lib/ansible_test/_internal/executor.py
@@ -40,13 +40,20 @@ from .cloud import (
CloudEnvironmentConfig,
)
+from .io import (
+ make_dirs,
+ open_text_file,
+ read_binary_file,
+ read_text_file,
+ write_text_file,
+)
+
from .util import (
ApplicationWarning,
ApplicationError,
SubprocessError,
display,
remove_tree,
- make_dirs,
is_shippable,
is_binary_file,
find_executable,
@@ -71,7 +78,6 @@ from .util_common import (
intercept_command,
named_temporary_file,
run_command,
- write_text_file,
write_json_test_results,
ResultType,
handle_layout_messages,
@@ -1200,12 +1206,12 @@ def inject_httptester(args):
"""
comment = ' # ansible-test httptester\n'
append_lines = ['127.0.0.1 %s%s' % (host, comment) for host in HTTPTESTER_HOSTS]
+ hosts_path = '/etc/hosts'
- with open('/etc/hosts', 'r+') as hosts_fd:
- original_lines = hosts_fd.readlines()
+ original_lines = read_text_file(hosts_path).splitlines(True)
- if not any(line.endswith(comment) for line in original_lines):
- hosts_fd.writelines(append_lines)
+ if not any(line.endswith(comment) for line in original_lines):
+ write_text_file(hosts_path, ''.join(original_lines + append_lines))
# determine which forwarding mechanism to use
pfctl = find_executable('pfctl', required=False)
@@ -1510,8 +1516,7 @@ def detect_changes(args):
elif args.changed_from or args.changed_path:
paths = args.changed_path or []
if args.changed_from:
- with open(args.changed_from, 'r') as changes_fd:
- paths += changes_fd.read().splitlines()
+ paths += read_text_file(args.changed_from).splitlines()
elif args.changed:
paths = detect_changes_local(args)
else:
@@ -1599,8 +1604,7 @@ def detect_changes_local(args):
args.metadata.changes[path] = ((0, 0),)
continue
- with open(path, 'r') as source_fd:
- line_count = len(source_fd.read().splitlines())
+ line_count = len(read_text_file(path).splitlines())
args.metadata.changes[path] = ((1, line_count),)
@@ -2056,7 +2060,7 @@ class EnvironmentDescription:
:type path: str
:rtype: str
"""
- with open(path) as script_fd:
+ with open_text_file(path) as script_fd:
return script_fd.readline().strip()
@staticmethod
@@ -2070,8 +2074,7 @@ class EnvironmentDescription:
file_hash = hashlib.md5()
- with open(path, 'rb') as file_fd:
- file_hash.update(file_fd.read())
+ file_hash.update(read_binary_file(path))
return file_hash.hexdigest()