Re: [Linux-ha-dev] [PATCH][crmsh] deal with the case-insentive hostname

2013-04-23 Thread Dejan Muhamedagic
Hi Junko-san,

Can you try the attached patch, instead of this one?

Cheers,

Dejan

On Wed, Apr 10, 2013 at 06:13:45PM +0900, Junko IKEDA wrote:
> Hi,
> I set upper-case hostname (GUEST03/GUEST4) and run Pacemaker 1.1.9 +
> Corosync 2.3.0.
> 
> [root@GUEST04 ~]# crm_mon -1
> Last updated: Wed Apr 10 15:12:48 2013
> Last change: Wed Apr 10 14:02:36 2013 via crmd on GUEST04
> Stack: corosync
> Current DC: GUEST04 (3232242817) - partition with quorum
> Version: 1.1.9-e8caee8
> 2 Nodes configured, unknown expected votes
> 1 Resources configured.
> 
> 
> Online: [ GUEST03 GUEST04 ]
> 
>  dummy  (ocf::pacemaker:Dummy): Started GUEST03
> 
> 
> for example, call crm shell with lower-case hostname.
> 
> [root@GUEST04 ~]# crm node standby guest03
> ERROR: bad lifetime: guest03
> 
> "crm node standby GUEST03" surely works well,
> so crm shell just doesn't take into account the hostname conversion.
> It's better to accept the both of the upper/lower-case.
> 
> "node standby", "node delete", "resource migrate(move)"  get hit with this
> issue.
> Please see the attached.
> 
> Thanks,
> Junko


> ___
> Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
> http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
> Home Page: http://linux-ha.org/

# HG changeset patch
# User Dejan Muhamedagic 
# Date 1366728211 -7200
# Node ID cd4d36b347c17b06b76f3386c041947a03c708bb
# Parent  4a47465b1fe1f48123080b4336f0b4516d9264f6
Medium: node: ignore case when looking up nodes (thanks to Junko Ikeda)

diff -r 4a47465b1fe1 -r cd4d36b347c1 modules/ui.py.in
--- a/modules/ui.py.in	Tue Apr 23 11:23:10 2013 +0200
+++ b/modules/ui.py.in	Tue Apr 23 16:43:31 2013 +0200
@@ -924,7 +924,7 @@ class RscMgmt(UserInterface):
 lifetime = None
 opt_l = fetch_opts(argl, ["force"])
 if len(argl) == 1:
-if not argl[0] in listnodes():
+if not is_node(argl[0]):
 lifetime = argl[0]
 else:
 node = argl[0]
@@ -1186,7 +1186,7 @@ class NodeMgmt(UserInterface):
 if not args:
 node = vars.this_node
 if len(args) == 1:
-if not args[0] in listnodes():
+if not is_node(args[0]):
 node = vars.this_node
 lifetime = args[0]
 else:
@@ -1249,7 +1249,7 @@ class NodeMgmt(UserInterface):
 'usage: delete '
 if not is_name_sane(node):
 return False
-if not node in listnodes():
+if not is_node(node):
 common_err("node %s not found in the CIB" % node)
 return False
 rc = True
diff -r 4a47465b1fe1 -r cd4d36b347c1 modules/xmlutil.py
--- a/modules/xmlutil.py	Tue Apr 23 11:23:10 2013 +0200
+++ b/modules/xmlutil.py	Tue Apr 23 16:43:31 2013 +0200
@@ -159,6 +159,15 @@ def mk_rsc_type(n):
 if ra_provider:
 s2 = "%s:"%ra_provider
 return ''.join((s1,s2,ra_type))
+def is_node(s):
+'''
+Check if s is in a list of our nodes (ignore case).
+This is not fast, perhaps should be cached.
+'''
+for n in listnodes():
+if n.lower() == s.lower():
+return True
+return False
 def listnodes():
 nodes_elem = cibdump2elem("nodes")
 if nodes_elem is None:
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] [PATCH][crmsh] deal with the case-insentive hostname

2013-04-23 Thread Dejan Muhamedagic
Hi Lars,

On Tue, Apr 23, 2013 at 03:37:30PM +0200, Lars Ellenberg wrote:
> On Wed, Apr 10, 2013 at 06:13:45PM +0900, Junko IKEDA wrote:
> > Hi,
> > I set upper-case hostname (GUEST03/GUEST4) and run Pacemaker 1.1.9 +
> > Corosync 2.3.0.
> > 
> > [root@GUEST04 ~]# crm_mon -1
> > Last updated: Wed Apr 10 15:12:48 2013
> > Last change: Wed Apr 10 14:02:36 2013 via crmd on GUEST04
> > Stack: corosync
> > Current DC: GUEST04 (3232242817) - partition with quorum
> > Version: 1.1.9-e8caee8
> > 2 Nodes configured, unknown expected votes
> > 1 Resources configured.
> > 
> > 
> > Online: [ GUEST03 GUEST04 ]
> > 
> >  dummy  (ocf::pacemaker:Dummy): Started GUEST03
> > 
> > 
> > for example, call crm shell with lower-case hostname.
> > 
> > [root@GUEST04 ~]# crm node standby guest03
> > ERROR: bad lifetime: guest03
> > 
> > "crm node standby GUEST03" surely works well,
> > so crm shell just doesn't take into account the hostname conversion.
> > It's better to accept the both of the upper/lower-case.
> > 
> > "node standby", "node delete", "resource migrate(move)"  get hit with this
> > issue.
> > Please see the attached.
> > 
> > Thanks,
> > Junko
> 
> Sorry for the late reaction.
> 
> > diff -r da93d3523e6a modules/ui.py.in
> > --- a/modules/ui.py.in  Tue Mar 26 11:44:17 2013 +0100
> > +++ b/modules/ui.py.in  Mon Apr 08 17:49:00 2013 +0900
> > @@ -924,10 +924,14 @@
> >  lifetime = None
> >  opt_l = fetch_opts(argl, ["force"])
> >  if len(argl) == 1:
> > -if not argl[0] in listnodes():
> > -lifetime = argl[0]
> > -else:
> > -node = argl[0]
> > +   for i in listnodes():
> > +   pattern = re.compile(i, re.IGNORECASE)
> > +   if pattern.match(argl[1]) and len(i) == len(argl[1]):
> > +   node = argl[1]
> 
> 
> This is not exactly equivalent.
> 
>Before, we had a string comparison.
>Now we have a regexp match.
> 
>This may be considered as a new feature.
>But it should then be done intentionally.
> 
>Otherwise, "i" would need to be "quote-meta"ed first.
>In Perl I'd write "\Q$i\E", in python we probably have to
>insert some '\' into it first.
> 
>I admit in most setups it would not make any difference,
>as there should at most be dots in there ".",
>and they should be at places where they won't be ambiguous,
>especially with the additional "len()" check.
> 
> Maybe rather compare argl[0].lower() with listnodes(), which
> should also return all elements as .lower().

Looks like I forgot about this patch, wanted to take a closer
look before applying, thanks for the analysis. There also seems
to be some code repetion, IIRC.

Cheers,

Dejan

> 
>   Lars
> ___
> Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
> http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
> Home Page: http://linux-ha.org/
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


Re: [Linux-ha-dev] [PATCH][crmsh] deal with the case-insentive hostname

2013-04-23 Thread Lars Ellenberg
On Wed, Apr 10, 2013 at 06:13:45PM +0900, Junko IKEDA wrote:
> Hi,
> I set upper-case hostname (GUEST03/GUEST4) and run Pacemaker 1.1.9 +
> Corosync 2.3.0.
> 
> [root@GUEST04 ~]# crm_mon -1
> Last updated: Wed Apr 10 15:12:48 2013
> Last change: Wed Apr 10 14:02:36 2013 via crmd on GUEST04
> Stack: corosync
> Current DC: GUEST04 (3232242817) - partition with quorum
> Version: 1.1.9-e8caee8
> 2 Nodes configured, unknown expected votes
> 1 Resources configured.
> 
> 
> Online: [ GUEST03 GUEST04 ]
> 
>  dummy  (ocf::pacemaker:Dummy): Started GUEST03
> 
> 
> for example, call crm shell with lower-case hostname.
> 
> [root@GUEST04 ~]# crm node standby guest03
> ERROR: bad lifetime: guest03
> 
> "crm node standby GUEST03" surely works well,
> so crm shell just doesn't take into account the hostname conversion.
> It's better to accept the both of the upper/lower-case.
> 
> "node standby", "node delete", "resource migrate(move)"  get hit with this
> issue.
> Please see the attached.
> 
> Thanks,
> Junko

Sorry for the late reaction.

> diff -r da93d3523e6a modules/ui.py.in
> --- a/modules/ui.py.inTue Mar 26 11:44:17 2013 +0100
> +++ b/modules/ui.py.inMon Apr 08 17:49:00 2013 +0900
> @@ -924,10 +924,14 @@
>  lifetime = None
>  opt_l = fetch_opts(argl, ["force"])
>  if len(argl) == 1:
> -if not argl[0] in listnodes():
> -lifetime = argl[0]
> -else:
> -node = argl[0]
> + for i in listnodes():
> + pattern = re.compile(i, re.IGNORECASE)
> + if pattern.match(argl[1]) and len(i) == len(argl[1]):
> + node = argl[1]


This is not exactly equivalent.

   Before, we had a string comparison.
   Now we have a regexp match.

   This may be considered as a new feature.
   But it should then be done intentionally.

   Otherwise, "i" would need to be "quote-meta"ed first.
   In Perl I'd write "\Q$i\E", in python we probably have to
   insert some '\' into it first.

   I admit in most setups it would not make any difference,
   as there should at most be dots in there ".",
   and they should be at places where they won't be ambiguous,
   especially with the additional "len()" check.

Maybe rather compare argl[0].lower() with listnodes(), which
should also return all elements as .lower().


Lars
___
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/