From 302fb26bb5b151d6ead5fb687a4adafbfc96a621 Mon Sep 17 00:00:00 2001 From: Martin Styk Date: Mon, 28 Oct 2024 20:51:54 +0100 Subject: [PATCH] fix(tests): use appropriate file open mode based on python version Signed-off-by: Martin Styk --- LabController/src/bkr/labcontroller/test_netboot.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/LabController/src/bkr/labcontroller/test_netboot.py b/LabController/src/bkr/labcontroller/test_netboot.py index 2398d7634..4dcbfffa5 100644 --- a/LabController/src/bkr/labcontroller/test_netboot.py +++ b/LabController/src/bkr/labcontroller/test_netboot.py @@ -9,6 +9,9 @@ import tempfile import random import shutil + +import six + from bkr.labcontroller import netboot from bkr.common.helpers import makedirs_ignore @@ -313,7 +316,8 @@ def test_kernel_options_are_not_quoted(self): config) def test_doesnt_overwrite_existing_default_config(self): - pxelinux_dir = os.path.join(self.tftp_root, 'pxelinux.cfg') + mode = "x" if six.PY3 else "wx" + pxelinux_dir = os.path.join(self.tftp_root, "pxelinux.cfg") makedirs_ignore(pxelinux_dir, mode=0o755) pxelinux_default_path = os.path.join(pxelinux_dir, 'default') # in reality it will probably be a menu @@ -325,7 +329,7 @@ def test_doesnt_overwrite_existing_default_config(self): localboot 0 label jabberwocky boot the thing''' - open(pxelinux_default_path, 'wx').write(custom) + open(pxelinux_default_path, mode).write(custom) netboot.configure_pxelinux(TEST_FQDN, 'console=ttyS0,115200 ks=http://lol/', self.tftp_root) self.assertEquals(open(pxelinux_default_path).read(), custom) @@ -378,6 +382,7 @@ def test_kernel_options_are_not_quoted(self): def test_doesnt_overwrite_existing_default_config(self): ipxe_dir = os.path.join(self.tftp_root, 'ipxe') + mode = "x" if six.PY3 else "wx" makedirs_ignore(ipxe_dir, mode=0o755) ipxe_default_path = os.path.join(ipxe_dir, 'default') # in reality it will probably be a menu @@ -385,7 +390,7 @@ def test_doesnt_overwrite_existing_default_config(self): chain /ipxe/beaker_menu exit 1 ''' - open(ipxe_default_path, 'wx').write(custom) + open(ipxe_default_path, mode).write(custom) netboot.configure_ipxe(TEST_FQDN, 'console=ttyS0,115200 ks=http://lol/', self.tftp_root) self.assertEquals(open(ipxe_default_path).read(), custom)