Unit test included. Resolves: rhbz#740222 --- booty/bootloaderInfo.py | 32 +++++++++++++++++++++++++++++++ tests/booty_test/bootloaderInfo_test.py | 28 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 0 deletions(-) create mode 100644 tests/booty_test/bootloaderInfo_test.py diff --git a/booty/bootloaderInfo.py b/booty/bootloaderInfo.py index e3b5d34..4e1e7d3 100644 --- a/booty/bootloaderInfo.py +++ b/booty/bootloaderInfo.py @@ -86,6 +86,36 @@ def rootIsDevice(dev): class KernelArguments: + def _merge_ip(self, args): + """ + Find ip= arguments targetting the same interface and merge them. + """ + # partition the input + def partition_p(arg): + # we are only interested in ip= parameters that use some kind of + # automatic network setup: + return arg.startswith("ip=") and arg.count(":") == 1 + ip_params = filter(partition_p, args) + rest = set(filter(lambda p: not partition_p(p), args)) + # strip away 'ip=' and split at the colon: + ip_params = map(lambda p: p[3:], ip_params) + ip_params = map(lambda p: p.split(":"), ip_params) + # create mapping from nics to their configurations + config = {} + for (nic, cfg) in ip_params: + if nic in config: + config[nic].append(cfg) + else: + config[nic] = [cfg] + + # output the new parameters: + ip_params = set() + for nic in config: + ip_params.add("ip=%s:%s" % (nic, ",".join(sorted(config[nic])))) + rest.update(ip_params) + + return rest + def getDracutStorageArgs(self, devices): args = set() types = {} @@ -135,6 +165,8 @@ class KernelArguments: all_args.update(self.args) all_args.update(self.appendArgs) + all_args = self._merge_ip(all_args) + return " ".join(all_args) def set(self, args): diff --git a/tests/booty_test/bootloaderInfo_test.py b/tests/booty_test/bootloaderInfo_test.py new file mode 100644 index 0000000..fe057a8 --- /dev/null +++ b/tests/booty_test/bootloaderInfo_test.py @@ -0,0 +1,28 @@ +import mock + +class KernelArgumentsTestCase(mock.TestCase): + def setUp(self): + self.setupModules( + ['_isys', 'logging', 'anaconda_log', 'block']) + + def tearDown(self): + self.tearDownModules() + + def test_merge_ip(self): + import booty + ka = booty.KernelArguments(mock.Mock()) + + # test that _merge_ip() doesnt break the simple case: + args = set(["one", "two", "ip=eth0:dhcp"]) + self.assertEqual(ka._merge_ip(args), + set(["one", "two", "ip=eth0:dhcp"])) + + # test that it does what it's supposed to: + args = set(["one", "two", "ip=eth0:dhcp", "ip=eth0:auto6", + "ip=wlan0:dhcp", + "ip=10.34.102.102::10.34.39.255:24:aklab:eth2:none"]) + self.assertEqual(ka._merge_ip(args), set([ + "one", "two", + "ip=wlan0:dhcp", + "ip=10.34.102.102::10.34.39.255:24:aklab:eth2:none", + "ip=eth0:auto6,dhcp"])) -- 1.7.6 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list