Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Debian User (http://www.linux-archive.org/debian-user/)
-   -   Fix iscsi udev info parsing (#811426) (http://www.linux-archive.org/debian-user/654914-fix-iscsi-udev-info-parsing-811426-a.html)

David Cantrell 04-11-2012 02:53 PM

Fix iscsi udev info parsing (#811426)
 
---
storage/udev.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/storage/udev.py b/storage/udev.py
index 7890c17..493c03e 100644
--- a/storage/udev.py
+++ b/storage/udev.py
@@ -554,7 +554,7 @@ def udev_device_get_iscsi_port(info):
return path_components[address_field].split(":")[-1]

def udev_device_get_iscsi_nic(info):
- session = info["sysfs_path"].split("/")[4]
+ session = re.match('/.*/(sessiond+)', info["sysfs_path"]).groups()[0]
iface = open("/sys/class/iscsi_session/%s/ifacename" %
session).read().strip()
return iface
--
1.7.1

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

"Brian C. Lane" 04-11-2012 03:05 PM

Fix iscsi udev info parsing (#811426)
 
On Wed, Apr 11, 2012 at 10:53:07AM -0400, David Cantrell wrote:
> ---
> storage/udev.py | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/storage/udev.py b/storage/udev.py
> index 7890c17..493c03e 100644
> --- a/storage/udev.py
> +++ b/storage/udev.py
> @@ -554,7 +554,7 @@ def udev_device_get_iscsi_port(info):
> return path_components[address_field].split(":")[-1]
>
> def udev_device_get_iscsi_nic(info):
> - session = info["sysfs_path"].split("/")[4]
> + session = re.match('/.*/(sessiond+)', info["sysfs_path"]).groups()[0]
> iface = open("/sys/class/iscsi_session/%s/ifacename" %
> session).read().strip()
> return iface
> --
> 1.7.1

Ack.

For regexes like this it might be useful to add an example string in a
comment.

--
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

Chris Lumens 04-11-2012 03:06 PM

Fix iscsi udev info parsing (#811426)
 
> diff --git a/storage/udev.py b/storage/udev.py
> index 7890c17..493c03e 100644
> --- a/storage/udev.py
> +++ b/storage/udev.py
> @@ -554,7 +554,7 @@ def udev_device_get_iscsi_port(info):
> return path_components[address_field].split(":")[-1]
>
> def udev_device_get_iscsi_nic(info):
> - session = info["sysfs_path"].split("/")[4]
> + session = re.match('/.*/(sessiond+)', info["sysfs_path"]).groups()[0]
> iface = open("/sys/class/iscsi_session/%s/ifacename" %
> session).read().strip()
> return iface

Ugh, regular expressions.

In the case where re.match doesn't match anything, it'll return None in
which case we'll get a "NoneType has no attribute groups" here.

- Chris

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

David Cantrell 04-11-2012 03:17 PM

Fix iscsi udev info parsing (#811426)
 
On Wed, Apr 11, 2012 at 11:06:59AM -0400, Chris Lumens wrote:
> > diff --git a/storage/udev.py b/storage/udev.py
> > index 7890c17..493c03e 100644
> > --- a/storage/udev.py
> > +++ b/storage/udev.py
> > @@ -554,7 +554,7 @@ def udev_device_get_iscsi_port(info):
> > return path_components[address_field].split(":")[-1]
> >
> > def udev_device_get_iscsi_nic(info):
> > - session = info["sysfs_path"].split("/")[4]
> > + session = re.match('/.*/(sessiond+)', info["sysfs_path"]).groups()[0]
> > iface = open("/sys/class/iscsi_session/%s/ifacename" %
> > session).read().strip()
> > return iface
>
> Ugh, regular expressions.
>
> In the case where re.match doesn't match anything, it'll return None in
> which case we'll get a "NoneType has no attribute groups" here.

Yeah, that's true. I think this is still an in-progress thing.

--
David Cantrell <dcantrell@redhat.com>
Supervisor, Installer Engineering Team
Red Hat, Inc. | Westford, MA | EST5EDT

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

Radek Vykydal 04-12-2012 10:29 AM

Fix iscsi udev info parsing (#811426)
 
On 04/11/2012 05:06 PM, Chris Lumens wrote:

diff --git a/storage/udev.py b/storage/udev.py
index 7890c17..493c03e 100644
--- a/storage/udev.py
+++ b/storage/udev.py
@@ -554,7 +554,7 @@ def udev_device_get_iscsi_port(info):
return path_components[address_field].split(":")[-1]

def udev_device_get_iscsi_nic(info):
- session = info["sysfs_path"].split("/")[4]
+ session = re.match('/.*/(sessiond+)', info["sysfs_path"]).groups()[0]
iface = open("/sys/class/iscsi_session/%s/ifacename" %
session).read().strip()
return iface

Ugh, regular expressions.



Generally I am trying to avoid using REs when not
necessary but I see it more suitable than filtering
path segments with startswith in this case. Beside that
it is already used in similar case in the module.


In the case where re.match doesn't match anything, it'll return None in
which case we'll get a "NoneType has no attribute groups" here.



Alright, I'll return None in the case. Sending new version.



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

Radek Vykydal 04-12-2012 10:30 AM

Fix iscsi udev info parsing (#811426)
 
On 04/11/2012 05:05 PM, Brian C. Lane wrote:

For regexes like this it might be useful to add an example string in a
comment.



Agreed, added.

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


All times are GMT. The time now is 03:22 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.