Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
scan-sources: use configured RHCOS container name
Browse files Browse the repository at this point in the history
  • Loading branch information
sosiouxme committed Jul 10, 2022
1 parent 7397423 commit 9e1a9ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions doozerlib/cli/scan_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,30 +265,30 @@ def _detect_rhcos_status(runtime, kubeconfig) -> list:
for arch in runtime.arches:
for private in (False, True):
name = f"{version}-{arch}{'-priv' if private else ''}"
tagged_mosc_id = _tagged_mosc_id(kubeconfig, version, arch, private)
tagged_rhcos_id = _tagged_rhcos_id(kubeconfig, rhcos.get_primary_container_name(runtime), version, arch, private)
latest_rhcos_id = _latest_rhcos_build_id(runtime, version, arch, private)
status = dict(name=name)
if not latest_rhcos_id:
status['changed'] = False
status['reason'] = "could not find an RHCOS build to sync"
elif tagged_mosc_id == latest_rhcos_id:
elif tagged_rhcos_id == latest_rhcos_id:
status['changed'] = False
status['reason'] = f"latest RHCOS build is still {latest_rhcos_id} -- no change from istag"
else:
status['changed'] = True
status['reason'] = f"latest RHCOS build is {latest_rhcos_id} which differs from istag {tagged_mosc_id}"
status['reason'] = f"latest RHCOS build is {latest_rhcos_id} which differs from istag {tagged_rhcos_id}"
statuses.append(status)

return statuses


def _tagged_mosc_id(kubeconfig, version, arch, private) -> str:
"""determine what the most recently tagged machine-os-content is in given imagestream"""
def _tagged_rhcos_id(kubeconfig, container_name, version, arch, private) -> str:
"""determine the most recently tagged RHCOS in given imagestream"""
base_name = rgp.default_imagestream_base_name(version)
base_namespace = rgp.default_imagestream_namespace_base_name()
name, namespace = rgp.payload_imagestream_name_and_namespace(base_name, base_namespace, arch, private)
stdout, _ = exectools.cmd_assert(
f"oc --kubeconfig '{kubeconfig}' --namespace '{namespace}' get istag '{name}:machine-os-content'"
f"oc --kubeconfig '{kubeconfig}' --namespace '{namespace}' get istag '{name}:{container_name}'"
" --template '{{.image.dockerImageMetadata.Config.Labels.version}}'",
retries=3,
pollrate=5,
Expand Down
9 changes: 5 additions & 4 deletions tests/cli/test_scan_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@
import yaml

from doozerlib.cli import scan_sources
from doozerlib.model import Model
from doozerlib import rhcos


class TestScanSourcesCli(TestCase):

@patch("doozerlib.exectools.cmd_assert")
def test_tagged_mosc_id(self, mock_cmd):
def test_tagged_rhcos_id(self, mock_cmd):
mock_cmd.return_value = ("id-1", "stderr")
self.assertEqual("id-1", scan_sources._tagged_mosc_id("kc.conf", "4.2", "s390x", True))
self.assertEqual("id-1", scan_sources._tagged_rhcos_id("kc.conf", "cname", "4.2", "s390x", True))
self.assertIn("--kubeconfig 'kc.conf'", mock_cmd.call_args_list[0][0][0])
self.assertIn("--namespace 'ocp-s390x-priv'", mock_cmd.call_args_list[0][0][0])
self.assertIn("istag '4.2-art-latest-s390x-priv", mock_cmd.call_args_list[0][0][0])

@patch("doozerlib.cli.scan_sources._tagged_mosc_id", autospec=True)
@patch("doozerlib.cli.scan_sources._tagged_rhcos_id", autospec=True)
@patch("doozerlib.cli.scan_sources._latest_rhcos_build_id", autospec=True)
def test_detect_rhcos_status(self, mock_latest, mock_tagged):
mock_tagged.return_value = "id-1"
mock_latest.return_value = "id-2"
runtime = MagicMock()
runtime = MagicMock(group_config=Model())
runtime.get_minor_version.return_value = "4.2"
runtime.arches = ['s390x']

Expand Down

0 comments on commit 9e1a9ef

Please sign in to comment.