Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updaing Socket code to support Windows. #739

Merged
merged 3 commits into from
Sep 2, 2020

Conversation

Crash-GHaun
Copy link
Contributor

rqutil.py -- Lines 148 through 153 work on Linux and Windows, however fails on mac.
Since we can grab IP on Windows & Linux easily we should use that when RQD_USE_IP_AS_HOSTNAME = TRUE

Link the Issue(s) this Pull Request is related to.
#738

rqutil.py -- Lines 148 through 153 work on Linux and Windows, however
fail on mac.

Since we can grab IP on Windows & Linux easily we should use that when
RQD_USE_IP_AS_HOSTNAME = TRUE
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 30, 2020

CLA Check
The committers are authorized under a signed CLA.

@@ -145,7 +145,7 @@ def getHostIp():

def getHostname():
"""Returns the machine's fully qualified domain name"""
if platform.system() == "Linux":
if platform.system() in ("Linux", "Windows"):
if rqd.rqconstants.RQD_USE_IP_AS_HOSTNAME:
return getHostIp()
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think on Windows we need to handle the case if RQD_USE_IP_AS_HOSTNAME is false.
The socket.gethostbyaddr(socket.gethostname()) call fails for me on Windows and can simply be socket.gethostname().

Looking at the history here, I think there are some Linux environments that needed the gethostbyaddr line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What version of Python are you running? socket.gethostbyaddr(socket.gethostname()) works for me on the machines I've tested (two). I'm running Python3.7

The problem with using socket.gethostname() for me was it was providing the hostname but was unable to resolve it to an IP. This is why I needed it to use IP as the hostname.

See attached screenshot
socket

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on Python 3.8.5 and the issue is that socket.gethostbyaddr() is unable to find the host returned by socket.gethostname() ...
image

I'm wondering if this might be a local configuration problem on my box though?

Copy link
Contributor Author

@Crash-GHaun Crash-GHaun Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! That also makes me wonder if it's a configuration problem on my box as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also another question -- seems like this could potentially a tricky issue according to this. Would you feel adding a try/except here makes logical sense as a solution?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My local macOS machine also cannot resolve my machine's hostname:

>>> socket.gethostbyaddr(socket.gethostname())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
>>> socket.gethostbyname(socket.gethostname())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

I agree that this all seems highly dependent on the user's/host's particular configuration.

My vote here would be something like:

  • Drop the platform.system() check.
  • Always attempt to obey the RQD_USE_IP_AS_HOSTNAME setting.
  • As @Crash-GHaun suggested, wrap it all in a try/except block that falls back to using the hostname, and logs a warning to let the user know what's going on.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree with @bcipriano . Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated code to reflect our conversation. Tested on Windows. Please review. Thanks!

return socket.gethostbyaddr(socket.gethostname())[0].split('.')[0]
else:
except socket.herror:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On macOS this threw socket.gaierror, so we should probably catch that as well here.

rqd/rqd/rqutil.py Show resolved Hide resolved
@Crash-GHaun
Copy link
Contributor Author

Sorry for the delay on this change -- reimaged my machine last week and was unable to test my changes. Just got back up and running :)

Copy link
Collaborator

@bcipriano bcipriano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bcipriano bcipriano merged commit 953273c into AcademySoftwareFoundation:master Sep 2, 2020
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.

None yet

3 participants