FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 09-22-2011, 03:58 PM
Ales Kozumplik
 
Default grub: write 'ip=eth0:dhcp, auto6' instead of 'ip=eth0:dhcp ip=eth0:auto6'

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@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 09-26-2011, 11:09 AM
Ales Kozumplik
 
Default grub: write 'ip=eth0:dhcp, auto6' instead of 'ip=eth0:dhcp ip=eth0:auto6'

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@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 09-26-2011, 01:01 PM
Ales Kozumplik
 
Default grub: write 'ip=eth0:dhcp, auto6' instead of 'ip=eth0:dhcp ip=eth0:auto6'

On 09/26/2011 02:26 PM, Martin Gracik wrote:

I don't see any errors in here, but it took me a while to wrap my brain
around it. I think in this particular case you would be better of with
list comprehensions instead of map.


Thats why I used the map to make the extracting steps evident. I am not
going to take over your entire function just some bits of it which I
find most useful.



# create mapping from nics to their configurations
config = collections.defaultdict(list)
for nic, cfg in ip_params:
config[nic].append(cfg)


This is a really cute idiom I wasn't aware of. We can use this in tens
of places.



I use set() on ip_params in the beginning to make sure we don't have
more of the same arguments, if this can happen here...


The passed in argument is a set already.


Also, as I see it, you don't need to strip the "ip=" because all the
parameters in that list have it, and later you are prepending it again
to all members.


Good point, this saves some lines and makes it look simpler.


So you can take this as an ACK to your solution, and this is just my
suggestion to make the function a little bit simpler.


I'll push it with the tweaks suggested in your solution.

Thanks for taking the time to inspect this in so much detail.

Ales

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 02:25 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org