Skip to content

Fixed invalid host causing 'reference to variable before assignment' - #31153

Merged
cachedout merged 1 commit into
saltstack:2015.8from
edencrane:fix-network-connect-invalid-hostname
Feb 12, 2016
Merged

cachedout merged 1 commit into
saltstack:2015.8from
edencrane:fix-network-connect-invalid-hostname

Conversation

@edencrane

Copy link
Copy Markdown

The current version of exception handling for network.connect references variable '_address', but '_address' can be undefined if a call to socket.getaddrinfo failed in the same try block.

eg.
salt 'minion' network.connect junkdomain 80

The minion function caused an exception: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/minion.py", line 1071, in _thread_return
return_data = func(_args, *_kwargs)
File "/usr/lib/python2.7/site-packages/salt/modules/network.py", line 1104, in connect
ret['comment'] = 'Unable to connect to {0} ({1}) on {2} port {3}'.format(host, _address[0], proto, port)
UnboundLocalError: local variable '_address' referenced before assignment

This patch catches socket.getaddrinfo execption socket.gaierror and returns with a friendly fail message.

The current version of exception handling for network.connect references variable '_address', but '_address' is not defined if a call to socket.getaddrinfo failed in the same try block.

eg.
>salt '<minion>' network.connect junkdomain 80
    The minion function caused an exception: Traceback (most recent call last):
      File "/usr/lib/python2.7/site-packages/salt/minion.py", line 1071, in _thread_return
        return_data = func(*args, **kwargs)
      File "/usr/lib/python2.7/site-packages/salt/modules/network.py", line 1104, in connect
        ret['comment'] = 'Unable to connect to {0} ({1}) on {2} port {3}'.format(host, _address[0], proto, port)
    UnboundLocalError: local variable '_address' referenced before assignment

This patch catches socket.getaddrinfo execption socket.gaierror and returns with a friendly fail message.
cachedout pushed a commit that referenced this pull request Feb 12, 2016
…hostname

Fixed invalid host causing 'reference to variable before assignment'
@cachedout
cachedout merged commit 7986b9e into saltstack:2015.8 Feb 12, 2016
@cachedout

Copy link
Copy Markdown
Contributor

Nice catch! Thank you, @edencrane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants