Skip to content

Commit

Permalink
Prefer http over https for OpenQA
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Sep 4, 2023
1 parent 04e8df1 commit fd5413e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions ocw/lib/openqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_url(server: str) -> str:
server = server.rstrip('/').replace("_", ".")
if urlparse(server).scheme != "":
return server
for scheme in ("https", "http"):
for scheme in ("http", "https"):
try:
url = f"{scheme}://{server}"
got = requests.head(
Expand Down Expand Up @@ -55,7 +55,8 @@ def __new__(cls, **kwargs):
def __init__(self, **kwargs):
kwargs.pop("server")
self.__client = openqa_client.client.OpenQA_Client(server=self.server, **kwargs)
self.__client.session.verify = verify_tls(self.server)
if self.server.startswith("https://"):
self.__client.session.verify = verify_tls(self.server)

Check warning on line 59 in ocw/lib/openqa.py

View check run for this annotation

Codecov / codecov/patch

ocw/lib/openqa.py#L59

Added line #L59 was not covered by tests

def is_cancelled(self, job_id: str) -> bool:
if not job_id.isdigit():
Expand Down
12 changes: 6 additions & 6 deletions tests/test_openqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def openqa_client_mock():
def openqa_instance(openqa_client_mock):
with (
patch('openqa_client.client.OpenQA_Client', return_value=openqa_client_mock),
patch('ocw.lib.openqa.get_url', return_value=None),
patch('ocw.lib.openqa.get_url', return_value=""),
patch('ocw.lib.openqa.verify_tls', return_value=None),
):
yield OpenQA(server="myserver")
Expand Down Expand Up @@ -74,16 +74,16 @@ def test_singleton():

def test_get_url_cache():
with patch("requests.head") as mock_head:
url = get_url("https://openqa.suse.de/")
url2 = get_url("https://openqa.suse.de")
url = get_url("http://openqa.suse.de/")
url2 = get_url("http://openqa.suse.de")
url3 = get_url("openqa.suse.de")
assert url == url2 == url3
assert mock_head.call_count == 1


def test_get_url_with_valid_scheme():
url = get_url("https://openqa.suse.de")
assert url == "https://openqa.suse.de"
url = get_url("http://openqa.suse.de")
assert url == "http://openqa.suse.de"
get_url.cache_clear()


Expand All @@ -100,7 +100,7 @@ def test_get_url_with_valid_scheme_retry():
response_mock = mock_head.return_value
response_mock.raise_for_status.side_effect = [RequestException, None]
url = get_url("openqa.suse.de")
assert url == "http://openqa.suse.de"
assert url == "https://openqa.suse.de"
get_url.cache_clear()


Expand Down

0 comments on commit fd5413e

Please sign in to comment.