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

Fix HTTPS client host no domain issue #2432

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/cylc-cat-log
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import traceback

from cylc.option_parsers import CylcOptionParser as COP
from cylc.rundb import CylcSuiteDAO
from cylc.suite_host import is_remote
from cylc.hostuserutil import is_remote
from cylc.suite_logging import get_logs
from cylc.cfgspec.globalcfg import GLOBAL_CFG
from cylc.task_id import TaskID
Expand Down
5 changes: 2 additions & 3 deletions bin/cylc-documentation
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ from optparse import OptionParser
import cylc.flags
from cylc.cfgspec.globalcfg import GLOBAL_CFG
from cylc.run_get_stdout import run_get_stdout
from cylc.suite_host import get_hostname, get_user


def main():
Expand All @@ -73,13 +72,13 @@ def main():
"--user",
help="Other user account name. This results in "
"command reinvocation on the remote account.",
metavar="USER", default=get_user(), action="store", dest="owner")
metavar="USER", action="store", dest="owner")

parser.add_option(
"--host",
help="Other host name. This results in "
"command reinvocation on the remote account.",
metavar="HOST", action="store", default=get_hostname(), dest="host")
metavar="HOST", action="store", dest="host")

parser.add_option(
"--debug",
Expand Down
2 changes: 1 addition & 1 deletion bin/cylc-gscan
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ gtk.settings_get_default().set_long_property(
from cylc.cfgspec.globalcfg import GLOBAL_CFG
from cylc.gui.gscan import ScanApp
from cylc.option_parsers import CylcOptionParser as COP
from cylc.suite_host import get_user
from cylc.hostuserutil import get_user


def main():
Expand Down
6 changes: 3 additions & 3 deletions bin/cylc-scan
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ if "--use-ssh" in sys.argv[1:]:

import re

from cylc.cfgspec.globalcfg import GLOBAL_CFG
from cylc.hostuserutil import get_user
from cylc.network.port_scan import scan_many
from cylc.option_parsers import CylcOptionParser as COP
from cylc.cfgspec.globalcfg import GLOBAL_CFG
from cylc.suite_host import get_user
from cylc.suite_status import (
KEY_DESCRIPTION, KEY_META, KEY_NAME, KEY_OWNER, KEY_STATES,
KEY_TASKS_BY_STATE, KEY_TITLE, KEY_UPDATE_TIME)
KEY_TITLE, KEY_UPDATE_TIME)
from cylc.task_state import TASK_STATUSES_ORDERED
from cylc.task_state_prop import get_status_prop

Expand Down
2 changes: 1 addition & 1 deletion doc/src/cylc-user-guide/siterc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ \subsection{[suite host self-identification] }
other methods. For the {\em address} method, cylc attempts to use a
special external ``target address'' to determine the IP address of the
suite host as seen by remote task hosts (in-source documentation in
\lstinline=$CYLC_DIR/lib/cylc/suite_host.py= explains how this works).
\lstinline=$CYLC_DIR/lib/cylc/hostuserutil.py= explains how this works).
And finally, as a last resort, you can choose the {\em hardwired} method
and manually specify the host name or IP address of the suite host.

Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/cfgspec/globalcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from parsec.validate import coercers
from parsec import ParsecError
from parsec.upgrade import upgrader, converter
from cylc.suite_host import is_remote_user
from cylc.hostuserutil import is_remote_user
from cylc.envvar import expandvars
from cylc.mkdir_p import mkdir_p
import cylc.flags
Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/gui/app_gcylc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from uuid import uuid4
from isodatetime.parsers import TimePointParser

from cylc.suite_host import is_remote, is_remote_host, is_remote_user
from cylc.hostuserutil import is_remote, is_remote_host, is_remote_user
from cylc.gui.dbchooser import dbchooser
from cylc.gui.combo_logviewer import ComboLogViewer
from cylc.gui.warning_dialog import warning_dialog, info_dialog
Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/gui/dbchooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from cylc.network.port_scan import scan_many
from cylc.suite_srv_files_mgr import SuiteSrvFilesManager
from cylc.run_get_stdout import run_get_stdout
from cylc.suite_host import is_remote_host, is_remote_user
from cylc.hostuserutil import is_remote_host, is_remote_user


class db_updater(threading.Thread):
Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/gui/gpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from cylc.gui.scanutil import (KEY_PORT, get_gpanel_scan_menu,
update_suites_info)
from cylc.gui.util import get_icon, setup_icons
from cylc.suite_host import get_user
from cylc.hostuserutil import get_user
from cylc.suite_status import KEY_STATES
from cylc.task_state_prop import extract_group_state

Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/host_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import re
from cylc.cfgspec.globalcfg import GLOBAL_CFG
from cylc.run_get_stdout import run_get_stdout
from cylc.suite_host import is_remote_host
from cylc.hostuserutil import is_remote_host


REC_COMMAND = re.compile(r"(`|\$\()\s*(.*)\s*(`|\))$")
Expand Down
69 changes: 32 additions & 37 deletions lib/cylc/suite_host.py → lib/cylc/hostuserutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ def get_inst(cls, new=False, expire=None):

def __init__(self, expire):
self.expire_time = time() + expire
self._host_name = None
self._host_ip_address = None
self._host_name_pref = None
self._host = None # preferred name of localhost
self._host_exs = {} # host: socket.gethostbyname_ex(host), ...
self._remote_hosts = {} # host: is_remote, ...
self.user_pwent = None
self.remote_users = {}
Expand Down Expand Up @@ -112,43 +111,43 @@ def get_host_ip_by_name(target):
"""Return internal IP address of target."""
return socket.gethostbyname(target)

def get_hostname(self):
"""Return the fully qualified domain name for current host."""
if self._host_name is None:
self._host_name = socket.getfqdn()
return self._host_name

def _get_host_ip_address(self):
"""Return the external IP address for the current host."""
if self._host_ip_address is None:
self._host_ip_address = self.get_local_ip_address(
self._get_identification_cfg('target'))
return self._host_ip_address
def _get_host_info(self, target=None):
"""Return the extended info of the current host."""
if target not in self._host_exs:
if target is None:
target = socket.getfqdn()
self._host_exs[target] = socket.gethostbyname_ex(target)
return self._host_exs[target]

@staticmethod
def _get_identification_cfg(key):
"""Return the [suite host self-identification]key global conf."""
from cylc.cfgspec.globalcfg import GLOBAL_CFG
return GLOBAL_CFG.get(['suite host self-identification', key])

def get_suite_host(self):
def get_host(self):
"""Return the preferred identifier for the suite (or current) host.

As specified by the "suite host self-identification" settings in the
site/user global.rc files. This is mainly used for suite host
identification by task jobs.

"""
if self._host_name_pref is None:
if self._host is None:
hardwired = self._get_identification_cfg('host')
method = self._get_identification_cfg('method')
if method == 'address':
self._host_name_pref = self._get_host_ip_address()
self._host = self.get_local_ip_address(
self._get_identification_cfg('target'))
elif method == 'hardwired' and hardwired:
self._host_name_pref = hardwired
self._host = hardwired
else: # if method == 'name':
self._host_name_pref = self.get_hostname()
return self._host_name_pref
self._host = self._get_host_info()[0]
return self._host

def get_fqdn_by_host(self, target):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could fqdn be replaced by a more verbose name (or at least an expansion of the abbreviation in the docstring)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fully qualified domain name is probably too long? And fqdn matches socket.getfqdn, which is hopefully what this method is returning.

Copy link
Contributor

Choose a reason for hiding this comment

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

It could just go in the docstring then

"""Return the fully qualified domain name of the target host."""
return self._get_host_info(target)[0]

def get_user(self):
"""Return name of current user."""
Expand Down Expand Up @@ -178,15 +177,12 @@ def is_remote_host(self, name):
self._remote_hosts[name] = False
else:
try:
ipa = socket.gethostbyname(name)
host_info = self._get_host_info(name)
except IOError:
self._remote_hosts[name] = True
else:
host_ip_address = self._get_host_ip_address()
# local IP address of the suite host (e.g. 127.0.0.1)
my_ip_address = socket.gethostbyname(self.get_hostname())
self._remote_hosts[name] = (
ipa not in [host_ip_address, my_ip_address])
host_info != self._get_host_info())
return self._remote_hosts[name]

def is_remote_user(self, name):
Expand All @@ -210,24 +206,24 @@ def is_remote(self, host, owner):
return self.is_remote_host(host) or self.is_remote_user(owner)


def get_hostname():
"""Shorthand for HostUtil.get_inst().get_hostname()."""
return HostUtil.get_inst().get_hostname()
def get_host_ip_by_name(target):
"""Shorthand for HostUtil.get_inst().get_host_ip_by_name(target)."""
return HostUtil.get_inst().get_host_ip_by_name(target)


def get_local_ip_address(target):
"""Shorthand for HostUtil.get_inst().get_local_ip_address(target)."""
return HostUtil.get_inst().get_local_ip_address(target)


def get_host_ip_by_name(target):
"""Shorthand for HostUtil.get_inst().get_host_ip_by_name(target)."""
return HostUtil.get_inst().get_host_ip_by_name(target)
def get_host():
"""Shorthand for HostUtil.get_inst().get_host()."""
return HostUtil.get_inst().get_host()


def get_suite_host():
"""Shorthand for HostUtil.get_inst().get_suite_host()."""
return HostUtil.get_inst().get_suite_host()
def get_fqdn_by_host(target):
"""Shorthand for HostUtil.get_inst().get_fqdn_by_host(target)."""
return HostUtil.get_inst().get_fqdn_by_host(target)


def get_user():
Expand Down Expand Up @@ -266,7 +262,6 @@ def test_hosts(self):
self.assertFalse(is_remote_host(None))
self.assertFalse(is_remote_host('localhost'))
self.assertFalse(is_remote_host(os.getenv('HOSTNAME')))
self.assertFalse(is_remote_host(get_hostname()))
self.assertFalse(is_remote_host(get_suite_host()))
self.assertFalse(is_remote_host(get_host()))

unittest.main()
18 changes: 9 additions & 9 deletions lib/cylc/network/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from cylc.exceptions import CylcError
import cylc.flags
from cylc.network import NO_PASSPHRASE
from cylc.suite_host import get_suite_host, get_user
from cylc.hostuserutil import get_host, get_fqdn_by_host, get_user
from cylc.suite_srv_files_mgr import (
SuiteSrvFilesManager, SuiteServiceFileError)
from cylc.unicode_util import utf8_enforce
Expand Down Expand Up @@ -250,19 +250,19 @@ def _call_server_func(self, *func_dicts, **fargs):
self._load_contact_info()
except (IOError, ValueError, SuiteServiceFileError):
raise ClientInfoError(self.suite)
host = self.host
if host == 'localhost':
host = get_suite_host()

if self.host and self.host.split('.')[0] == 'localhost':
self.host = get_host()
elif self.host and '.' not in self.host: # Not IP and no domain
self.host = get_fqdn_by_host(self.host)
http_request_items = []
try:
# dictionary containing: url, payload, method
http_request_items.append(self._compile_url(
func_dict, host, self.comms_protocol))
func_dict, self.host, self.comms_protocol))
except (IndexError, ValueError, AttributeError):
for f_dict in func_dicts:
http_request_items.append(self._compile_url(
f_dict, host, self.comms_protocol))
f_dict, self.host, self.comms_protocol))
# Remove proxy settings from environment for now
environ = {}
for key in ("http_proxy", "https_proxy"):
Expand Down Expand Up @@ -480,7 +480,7 @@ def _get_headers(self):
CYLC_VERSION, self.prog_name, self.my_uuid
)
)
auth_info = "%s@%s" % (get_user(), get_suite_host())
auth_info = "%s@%s" % (get_user(), get_host())
return {"User-Agent": user_agent_string,
"From": auth_info}

Expand All @@ -494,7 +494,7 @@ def _load_contact_info(self):
return
if self.port:
# In case the contact file is corrupted, user can specify the port.
self.host = get_suite_host()
self.host = get_host()
return
data = self.srv_files_mgr.load_contact_file(
self.suite, self.owner, self.host)
Expand Down
4 changes: 2 additions & 2 deletions lib/cylc/network/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from cylc.network import (
NO_PASSPHRASE, PRIVILEGE_LEVELS, PRIV_IDENTITY, PRIV_DESCRIPTION,
PRIV_STATE_TOTALS, PRIV_FULL_READ, PRIV_SHUTDOWN, PRIV_FULL_CONTROL)
from cylc.suite_host import get_suite_host
from cylc.hostuserutil import get_host
from cylc.suite_logging import ERR, LOG
from cylc.suite_srv_files_mgr import (
SuiteSrvFilesManager, SuiteServiceFileError)
Expand Down Expand Up @@ -121,7 +121,7 @@ def start(self):
"""Start quick web service."""
# cherrypy.config["tools.encode.on"] = True
# cherrypy.config["tools.encode.encoding"] = "utf-8"
cherrypy.config["server.socket_host"] = get_suite_host()
cherrypy.config["server.socket_host"] = get_host()
cherrypy.config["engine.autoreload.on"] = False

if self.comms_method == "https":
Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/network/port_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
SuiteRuntimeServiceClient, ClientError, ClientTimeout)
from cylc.suite_srv_files_mgr import (
SuiteSrvFilesManager, SuiteServiceFileError)
from cylc.suite_host import is_remote_host, get_host_ip_by_name
from cylc.hostuserutil import is_remote_host, get_host_ip_by_name

CONNECT_TIMEOUT = 5.0
INACTIVITY_TIMEOUT = 10.0
Expand Down
4 changes: 1 addition & 3 deletions lib/cylc/option_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from optparse import OptionParser, OptionConflictError
import os
import cylc.flags
from cylc.suite_host import get_user


class CylcOptionParser(OptionParser):
Expand Down Expand Up @@ -115,8 +114,7 @@ def add_std_options(self):
"Other user account name. This results in "
"command reinvocation on the remote account."
),
metavar="USER", default=get_user(),
action="store", dest="owner")
metavar="USER", action="store", dest="owner")
self.add_std_option(
"--host",
help="Other host name. This results in "
Expand Down
2 changes: 1 addition & 1 deletion lib/cylc/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, argv=None):
if self.owner is None and self.host is None:
self.is_remote = False
else:
from cylc.suite_host import is_remote
from cylc.hostuserutil import is_remote
self.is_remote = is_remote(self.host, self.owner)

def execute(self, force_required=False, env=None, path=None,
Expand Down
4 changes: 2 additions & 2 deletions lib/cylc/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from cylc.suite_db_mgr import SuiteDatabaseManager
from cylc.suite_events import (
SuiteEventContext, SuiteEventError, SuiteEventHandler)
from cylc.suite_host import get_suite_host, get_user
from cylc.hostuserutil import get_host, get_user
from cylc.suite_logging import SuiteLog, ERR, LOG
from cylc.suite_srv_files_mgr import (
SuiteSrvFilesManager, SuiteServiceFileError)
Expand Down Expand Up @@ -149,7 +149,7 @@ def __init__(self, is_restart, options, args):
self.run_mode = self.options.run_mode

self.owner = get_user()
self.host = get_suite_host()
self.host = get_host()
self.port = None

self.is_stalled = False
Expand Down
4 changes: 2 additions & 2 deletions lib/cylc/suite_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from cylc.cfgspec.globalcfg import GLOBAL_CFG
from cylc.mp_pool import SuiteProcContext
from cylc.suite_host import get_suite_host, get_user
from cylc.hostuserutil import get_host, get_user
from cylc.suite_logging import LOG


Expand Down Expand Up @@ -106,7 +106,7 @@ def _run_event_mail(self, config, ctx):
'-s', subject,
'-r', self.get_events_conf(
config,
'mail from', 'notifications@' + get_suite_host()),
'mail from', 'notifications@' + get_host()),
self.get_events_conf(config, 'mail to', get_user()),
],
env=env,
Expand Down
Loading