def test_release_url(self): self.assertIn( "4.6-s390x", rhcos.RHCOSBuildFinder(self.runtime, "4.6", "s390x").rhcos_release_url()) self.assertNotIn( "x86_64", rhcos.RHCOSBuildFinder(self.runtime, "4.6", "x86_64").rhcos_release_url()) self.assertIn( "4.9-aarch64", rhcos.RHCOSBuildFinder(self.runtime, "4.9", "aarch64").rhcos_release_url()) self.runtime.group_config.urls = Model( dict(rhcos_release_base=dict( aarch64="https//example.com/storage/releases/rhcos-4.x-aarch64" ))) self.assertIn( "4.x-aarch64", rhcos.RHCOSBuildFinder(self.runtime, "4.9", "aarch64").rhcos_release_url()) self.assertIn( "4.9-s390x", rhcos.RHCOSBuildFinder(self.runtime, "4.9", "s390x").rhcos_release_url())
def test_latest_container(self, meta_mock, id_mock): # "normal" lookup id_mock.return_value = "dummy" meta_mock.return_value = dict( oscontainer=dict(image="test", digest="sha256:1234abcd")) self.assertEqual(("dummy", "test@sha256:1234abcd"), rhcos.RHCOSBuildFinder(self.runtime, "4.4").latest_container()) # lookup when there is no build to look up id_mock.return_value = None self.assertEqual((None, None), rhcos.RHCOSBuildFinder(self.runtime, "4.4").latest_container()) # lookup when we have configured a different primary container self.runtime.group_config.rhcos = Model( dict(payload_tags=[ dict(name="spam"), dict(name="eggs", primary=True) ])) id_mock.return_value = "dummy" meta_mock.return_value = dict( oscontainer=dict(image="test", digest="sha256:1234abcdstandard"), altcontainer=dict(image="test", digest="sha256:abcd1234alt"), ) alt_container = dict(name="rhel-coreos-8", build_metadata_key="altcontainer", primary=True) self.runtime.group_config.rhcos = Model( dict(payload_tags=[alt_container])) self.assertEqual(("dummy", "test@sha256:abcd1234alt"), rhcos.RHCOSBuildFinder(self.runtime, "4.4").latest_container())
def test_build_id(self, mock_urlopen): _urlopen_json_cm(mock_urlopen, dict(builds=['id-1', 'id-2'])) self.assertEqual( 'id-1', rhcos.RHCOSBuildFinder(self.runtime, "4.4")._latest_rhcos_build_id()) self.assertIn('/rhcos-4.4/', mock_urlopen.call_args_list[0][0][0]) _urlopen_json_cm(mock_urlopen, dict(builds=[])) self.assertIsNone( rhcos.RHCOSBuildFinder(self.runtime, "4.2", "ppc64le")._latest_rhcos_build_id()) self.assertIn('/rhcos-4.2-ppc64le/', mock_urlopen.call_args_list[1][0][0])
def test_build_meta(self, meta_mock, id_mock): id_mock.return_value = "dummy" meta_mock.return_value = dict( oscontainer=dict(image="test", digest="sha256:1234abcd")) self.assertEqual( ("dummy", "test@sha256:1234abcd"), rhcos.RHCOSBuildFinder(self.runtime, "4.4").latest_machine_os_content()) id_mock.return_value = None self.assertEqual( (None, None), rhcos.RHCOSBuildFinder(self.runtime, "4.4").latest_machine_os_content())
def test_get_primary_container_conf(self): # default is same as it's always been self.assertEqual( "machine-os-content", rhcos.RHCOSBuildFinder( self.runtime, "4.6", "x86_64").get_primary_container_conf()["name"]) # but we can configure a different primary self.runtime.group_config.rhcos = Model( dict(payload_tags=[ dict(name="spam"), dict(name="eggs", primary=True) ])) self.assertEqual( "eggs", rhcos.RHCOSBuildFinder( self.runtime, "4.6", "x86_64").get_primary_container_conf()["name"])
def _latest_rhcos_build_id(runtime, version, arch, private) -> str: """wrapper to return None if anything goes wrong, which will be taken as no change""" try: return rhcos.RHCOSBuildFinder(runtime, version, arch, private).latest_rhcos_build_id() except rhcos.RHCOSNotFound as ex: # don't let flakiness in rhcos lookups prevent us from scanning regular builds; # if anything else changed it will sync anyway. runtime.logger.warning( f"could not determine RHCOS build for {version}-{arch}{'-priv' if private else ''}: {ex}" ) return None
def test_build_find_failure(self, mock_urlopen): mock_urlopen.side_effect = URLError("test") with self.assertRaises(rhcos.RHCOSNotFound): rhcos.RHCOSBuildFinder(self.runtime, "4.9")._latest_rhcos_build_id()