Skip to content

Commit 8080979

Browse files
committed
[FIX] Use openshift install directly to obtain rhcos image
1 parent 4ce4404 commit 8080979

File tree

4 files changed

+110
-9
lines changed

4 files changed

+110
-9
lines changed

Diff for: osia/installer/clouds/ovirt.py

Whitespace-only changes.

Diff for: osia/installer/downloader/image.py

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""Module implements logic for rhcos image download"""
2+
import subprocess
23
from subprocess import Popen, PIPE
34
from shutil import copyfileobj
45
from pathlib import Path
56
from typing import Tuple
67
from tempfile import NamedTemporaryFile
78

9+
810
import gzip
911
import re
1012
import logging
@@ -16,7 +18,28 @@
1618
GITHUB_URL = "https://raw.githubusercontent.com/openshift/installer/{commit}/data/data/rhcos.json"
1719

1820

19-
def get_commit(installer: str) -> str:
21+
class CoreOsException(Exception):
22+
"""CoreOsException represents error while executing installer in older version
23+
"""
24+
def __init__(self, *args, **kwargs):
25+
super().__init__(self, *args, *kwargs)
26+
27+
28+
def _get_coreos_json(installer: str) -> str:
29+
json_data = {}
30+
with Popen([installer, "coreos", "print-stream-json"], stdout=PIPE,
31+
stderr=subprocess.DEVNULL, universal_newlines=True) as proc:
32+
proc.wait()
33+
if proc.returncode != 0:
34+
raise CoreOsException("Installer doesn't support coreos subcommand")
35+
json_data = json.loads(proc.stdout.read())
36+
json_part = json_data["architectures"]["x86_64"]["artifacts"]["openstack"]
37+
release_str = json_part["release"]
38+
json_part = json_part["formats"]["qcow2.gz"]
39+
return json_part.get("disk", json_part)["location"], release_str
40+
41+
42+
def get_commit(installer: str) -> Tuple[str, str]:
2043
"""Function extracts source commit from installer,
2144
in order to find associated rhcos image"""
2245
version_str = ""
@@ -28,16 +51,26 @@ def get_commit(installer: str) -> str:
2851
return commits[0]
2952

3053

31-
def get_url(installer: str) -> Tuple[str, str]:
32-
"""Function builds url to rhcos image and version of
33-
rhcos iamge."""
54+
def _get_old_url(installer: str) -> Tuple[str, str]:
3455
commit = get_commit(installer)
3556
gh_data_link = GITHUB_URL.format(commit=commit)
3657
rhcos_json = requests.get(gh_data_link, allow_redirects=True)
3758
rhcos_data = json.loads(rhcos_json.content)
3859
return rhcos_data['baseURI'] + rhcos_data['images']['openstack']['path'], rhcos_data['buildid']
3960

4061

62+
def get_url(installer: str) -> Tuple[str, str]:
63+
"""Function builds url to rhcos image and version of
64+
rhcos iamge."""
65+
url, version = None, None
66+
try:
67+
url, version = _get_coreos_json(installer)
68+
except CoreOsException as ex:
69+
logging.debug(ex)
70+
url, version = _get_old_url(installer)
71+
return url, version
72+
73+
4174
def _extract_gzip(buff: NamedTemporaryFile, target: str) -> Path:
4275
result = None
4376
with gzip.open(buff.name) as zip_file:

Diff for: poetry.lock

+72-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dynaconf = {extras = ["yaml"], version = "*"}
2929
gitpython = "*"
3030
beautifulsoup4 = "*"
3131
coloredlogs = "*"
32+
ovirt-engine-sdk-python = "^4.5.0"
3233

3334
[tool.poetry.dev-dependencies]
3435
flake8 = "*"

0 commit comments

Comments
 (0)