Options

PATCH for Vertica 7 vertica/network/SSH.py in nicInfoFromIfconfig in getNetworkProfiles, fix for reg

Hello,
 
I was having problems with a clean install of Vertica 7 on RHEL6 hosts.  Initially as an error when creating a new database after the install:
 https://community.vertica.com/vertica/topics/error_when_creating_database_after_clean_install_of_ver...
spread was not running, the vertica.log showed it either failing to start or only starting on one host, the spread config which as of Veritca 7 is named spread.conf, auto-generated by vertica and located in the database catalog directory looked to be incorrect as it just had entries for 127.0.0.1 and not the 3 hosts/nodes I was passing to the install script.
 
The problem was because in vertica/network/SSH.py in nicInfoFromIfconfig in getNetworkProfiles the regexp for ifconfig is:
  
parsed = re.findall(r'^(\S+).*?inet addr:(\S+).*?Bcast:(\S+).*?Mask:(\S+)', ifconfig, re.S | re.M)
 
The ".*" between "inet addr" and "Bcast" causes it to match incorrectly on the loopback interface, this is because of module content "re.S" (DOTALL) which makes the "." special character match any character at all, including a newline.  Here is a reproducer and two ways to fix it:

import re # regular expressionsdef nicInfoFromIfconfig(host,ifconfig):
    parsed = re.findall(r'^(\S+).*?inet addr:(\S+).*?Bcast:(\S+).*?Mask:(\S+)', ifconfig, re.S | re.M)
    answer = None
    print "parsed=%s" % (parsed)
    for interface,addr,bcast,mask in parsed:
        print "interface=%s addr=%s bcast=%s mask=%s" % (interface,addr,bcast,mask)
        # pick an bcast if addr matches host addr, or bcast matches spec'd bcast addr
        if bcast == subnet or (not answer and addr == host):
            answer = [addr, bcast]
    return answermy_ifconfig = '''eth0       Link encap:Ethernet
          inet addr:15.216.151.36  Bcast:15.216.151.255  Mask:255.255.255.0lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0p3p2      Link encap:Ethernet  HWaddr 00:10:18:D3:FB:5D
          inet addr:192.168.20.20  Bcast:192.168.20.255  Mask:255.255.255.0
'''subnet='192.168.20.255'print nicInfoFromIfconfig('192.168.20.20',my_ifconfig)
# incorrectly returns '127.0.0.1', '192.168.20.255']def FixFornicInfoFromIfconfig(host,ifconfig):
    parsed = re.findall(r'^(\S+).*?inet addr:(\S+)[^\n]*?Bcast:(\S+).*?Mask:(\S+)', ifconfig, re.S | re.M)
    answer = None
    print "parsed=%s" % (parsed)
    for interface,addr,bcast,mask in parsed:
        print "interface=%s addr=%s bcast=%s mask=%s" % (interface,addr,bcast,mask)
        # pick an bcast if addr matches host addr, or bcast matches spec'd bcast addr
        if bcast == subnet or (not answer and addr == host):
            answer = [addr, bcast]
    return answerprint FixFornicInfoFromIfconfig('192.168.20.20',my_ifconfig)
# correctly returns '192.168.20.20', '192.168.20.255']def AltFixFornicInfoFromIfconfig(host,ifconfig):
    parsed = re.findall(r'inet addr:(\S+).*?Bcast:(\S+).*?Mask:(\S+)', ifconfig, re.M)
    answer = None
    print "parsed=%s" % (parsed)
    for addr,bcast,mask in parsed:
        print "addr=%s bcast=%s mask=%s" % (addr,bcast,mask)
        # pick an bcast if addr matches host addr, or bcast matches spec'd bcast addr
        if bcast == subnet or (not answer and addr == host):
            answer = [addr, bcast]
    return answerprint AltFixFornicInfoFromIfconfig('192.168.20.20',my_ifconfig)
# correctly returns '192.168.20.20', '192.168.20.255']
 Output when run with /opt/vertica/oss/python/bin/python
 
parsed=[('eth0', '15.216.151.36', '15.216.151.255', '255.255.255.0'), ('lo', '127.0.0.1', '192.168.20.255', '255.255.255.0')]
interface=eth0 addr=15.216.151.36 bcast=15.216.151.255 mask=255.255.255.0
interface=lo addr=127.0.0.1 bcast=192.168.20.255 mask=255.255.255.0
['127.0.0.1', '192.168.20.255']
parsed=[('eth0', '15.216.151.36', '15.216.151.255', '255.255.255.0'), ('lo', '192.168.20.20', '192.168.20.255', '255.255.255.0')]
interface=eth0 addr=15.216.151.36 bcast=15.216.151.255 mask=255.255.255.0
interface=lo addr=192.168.20.20 bcast=192.168.20.255 mask=255.255.255.0
['192.168.20.20', '192.168.20.255']
parsed=[('15.216.151.36', '15.216.151.255', '255.255.255.0'), ('192.168.20.20', '192.168.20.255', '255.255.255.0')]
addr=15.216.151.36 bcast=15.216.151.255 mask=255.255.255.0
addr=192.168.20.20 bcast=192.168.20.255 mask=255.255.255.0
['192.168.20.20', '192.168.20.255']
 
Cheers.

Comments

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file