Skip to content

Commit

Permalink
automatic: Fix online detection with proxy (RhBz:2022440)
Browse files Browse the repository at this point in the history
In case the proxy is configured (either for a repo of globally) it is
used also for detecting whether the system is online.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2022440
  • Loading branch information
m-blaha authored and jan-kolarik committed Apr 20, 2023
1 parent de9c5c5 commit a798d23
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions dnf/automatic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def __init__(self):
self.add_option('network_online_timeout', libdnf.conf.OptionNumberInt32(60))
self.add_option('reboot', libdnf.conf.OptionEnumString('never',
libdnf.conf.VectorString(['never', 'when-changed', 'when-needed'])))
self.add_option('reboot_command', libdnf.conf.OptionString('shutdown -r +5 \'Rebooting after applying package updates\''))
self.add_option('reboot_command', libdnf.conf.OptionString(
'shutdown -r +5 \'Rebooting after applying package updates\''))

def imply(self):
if self.apply_updates:
Expand Down Expand Up @@ -255,21 +256,29 @@ def wait_for_network(repos, timeout):
'http': 80,
'https': 443,
'ftp': 21,
'socks': 1080,
'socks5': 1080,
}

def remote_address(url_list):
for url in url_list:
parsed_url = dnf.pycomp.urlparse.urlparse(url)
if parsed_url.hostname and parsed_url.scheme in remote_schemes:
yield (parsed_url.hostname,
parsed_url.port or remote_schemes[parsed_url.scheme])
if (not parsed_url.hostname) \
or (not parsed_url.port and parsed_url.scheme not in remote_schemes):
# skip urls without hostname or without recognized port
continue
yield (parsed_url.hostname,
parsed_url.port or remote_schemes[parsed_url.scheme])

# collect possible remote repositories urls
addresses = set()
for repo in repos.iter_enabled():
addresses.update(remote_address(repo.baseurl))
addresses.update(remote_address([repo.mirrorlist]))
addresses.update(remote_address([repo.metalink]))
if repo.proxy:
addresses.update(remote_address([repo.proxy]))
else:
addresses.update(remote_address(repo.baseurl))
addresses.update(remote_address([repo.mirrorlist]))
addresses.update(remote_address([repo.metalink]))

if not addresses:
# there is no remote repository enabled so network connection should not be needed
Expand Down

0 comments on commit a798d23

Please sign in to comment.