Skip to content

Commit

Permalink
fix(tests): use appropriate file open mode based on python version
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Styk <[email protected]>
  • Loading branch information
StykMartin committed Oct 28, 2024
1 parent 97d2d4f commit 302fb26
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions LabController/src/bkr/labcontroller/test_netboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import tempfile
import random
import shutil

import six

from bkr.labcontroller import netboot
from bkr.common.helpers import makedirs_ignore

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -378,14 +382,15 @@ 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
custom = '''#!ipxe
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)
Expand Down

0 comments on commit 302fb26

Please sign in to comment.