Update for differences from py3 in the backported code

In py3 dicts are not predictable, make sure the keys are sorted so that
the tests are useful.

Use StringIO.StringIO instead of io.StringIO which requires unicode
text.

kickstart timezone.ntpservers is a set() so adjust the test for it.

Related: rhbz#1718473
This commit is contained in:
Brian C. Lane 2019-06-11 16:33:58 -07:00 committed by Alexander Todorov
parent 406dddafef
commit 8e650d1d07
4 changed files with 14 additions and 12 deletions

View File

@ -202,7 +202,7 @@ def pretty_dict(d):
key="str", key="str1,str2", ...
"""
result = []
for k in d:
for k in sorted(d.keys()):
if type(d[k]) == type(""):
result.append('%s="%s"' % (k, d[k]))
elif type(d[k]) == type([]) and type(d[k][0]) == type(""):

View File

@ -36,7 +36,7 @@ log = logging.getLogger("lorax-composer")
import os
from glob import glob
from io import StringIO
from StringIO import StringIO
from math import ceil
import pytoml as toml
import shutil
@ -448,7 +448,7 @@ def customize_ks_template(ks_template, recipe):
output = StringIO()
for line in ks_template.splitlines():
for cmd in commands:
for cmd in sorted(commands.keys()):
(new_command, value, default, replace) = commands[cmd]
if line.startswith(cmd):
found[cmd] = True
@ -466,7 +466,7 @@ def customize_ks_template(ks_template, recipe):
# Write out defaults for the ones not found
# These must go FIRST because the template still needs to have the packages added
defaults = StringIO()
for cmd in commands:
for cmd in sorted(commands.keys()):
if cmd in found:
continue
(new_command, value, default, _) = commands[cmd]

View File

@ -636,7 +636,7 @@ version = "*"
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("bootloader")]), 1)
self.assertTrue(self._checkBootloader(result, "none", line_limit=2))
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("timezone")]), 1)
self.assertTrue(self._checkTimezone(result, {"timezone": "UTC", "ntpservers": []}, line_limit=2))
self.assertTrue(self._checkTimezone(result, {"timezone": "UTC", "ntpservers": []}, line_limit=5))
self.assertTrue("services" not in result)
# Make sure that a kickstart with a bootloader, and no timezone has timezone added to the top
@ -645,7 +645,7 @@ version = "*"
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("bootloader")]), 1)
self.assertTrue(self._checkBootloader(result, "mbr"))
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("timezone")]), 1)
self.assertTrue(self._checkTimezone(result, {"timezone": "UTC", "ntpservers": []}, line_limit=1))
self.assertTrue(self._checkTimezone(result, {"timezone": "UTC", "ntpservers": []}, line_limit=5))
self.assertTrue("services" not in result)
# Make sure that a kickstart with a bootloader and timezone has neither added
@ -690,13 +690,14 @@ disabled = ["postfix", "telnetd"]
# Test against a kickstart without bootloader
result = customize_ks_template("firewall --enabled\n", recipe)
print(result)
self.assertTrue(self._checkBootloader(result, "nosmt=force", line_limit=2))
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("bootloader")]), 1)
self.assertTrue(self._checkTimezone(result, tz_dict, line_limit=2))
self.assertTrue(self._checkTimezone(result, tz_dict, line_limit=5))
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("timezone")]), 1)
self.assertTrue(self._checkLang(result, ["en_CA.utf8", "en_HK.utf8"], line_limit=4))
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("lang")]), 1)
self.assertTrue(self._checkKeyboard(result, "de (dvorak)", line_limit=4))
self.assertTrue(self._checkKeyboard(result, "de (dvorak)", line_limit=3))
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("keyboard")]), 1)
self.assertTrue(self._checkFirewall(result,
{"ports": ["22:tcp", "80:tcp", "imap:tcp", "53:tcp", "53:udp"],
@ -704,13 +705,14 @@ disabled = ["postfix", "telnetd"]
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("firewall")]), 1)
self.assertTrue(self._checkServices(result,
{"enabled": ["cockpit.socket", "httpd", "sshd"], "disabled": ["postfix", "telnetd"]},
line_limit=8))
line_limit=6))
self.assertEqual(sum([1 for l in result.splitlines() if l.startswith("services")]), 1)
# Test against a kickstart with a bootloader line
result = customize_ks_template("firewall --enabled\nbootloader --location=mbr\n", recipe)
print(result)
self.assertTrue(self._checkBootloader(result, "nosmt=force"))
self.assertTrue(self._checkTimezone(result, tz_dict, line_limit=2))
self.assertTrue(self._checkTimezone(result, tz_dict, line_limit=5))
# Test against all of the available templates
share_dir = "./share/"

View File

@ -804,7 +804,7 @@ ntpservers = ["1.north-america.pool.ntp.org"]
"""
ks = self._blueprint_to_ks(blueprint_data)
self.assertEqual(ks.handler.timezone.timezone, "US/Samoa")
self.assertEqual(ks.handler.timezone.ntpservers, ["1.north-america.pool.ntp.org"])
self.assertEqual(ks.handler.timezone.ntpservers, set(["1.north-america.pool.ntp.org"]))
def test_locale_languages(self):
blueprint_data = """name = "test-locale"
@ -1078,4 +1078,4 @@ ntpservers = ["0.north-america.pool.ntp.org", "1.north-america.pool.ntp.org"]
self.assertEqual(studentsGroup.name, "students")
self.assertEqual(ks.handler.timezone.timezone, "US/Samoa")
self.assertEqual(ks.handler.timezone.ntpservers, ["0.north-america.pool.ntp.org", "1.north-america.pool.ntp.org"])
self.assertEqual(ks.handler.timezone.ntpservers, set(["0.north-america.pool.ntp.org", "1.north-america.pool.ntp.org"]))