mirror of
https://github.com/openshift/community.okd.git
synced 2026-03-26 19:03:14 +00:00
* Upgrade Ansible and OKD versions for CI * Use ubi9 and fix sanity * Use correct pip install * Try using quotes * Ensure python3.9 * Upgrade ansible and molecule versions * Remove DeploymentConfig DeploymentConfigs are deprecated and seem to now be causing idempotence problems. Replacing them with Deployments fixes it. * Attempt to fix ldap integration tests Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Move sanity and unit tests to GH actions Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Firt round of sanity fixes Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Add kubernetes.core collection as sanity requirement Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Add ignore-2.16.txt Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Attempt to fix units Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Add ignore-2.17 Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Attempt to fix unit tests Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Add pytest-ansible to test-requirements.txt Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Add changelog fragment Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Add workflow for ansible-lint Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Apply black Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Fix linters Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Add # fmt: skip Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Yet another round of linting Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Yet another round of linting Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Remove setup.cfg Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Revert #fmt Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Use ansible-core 2.14 Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Cleanup ansible-lint ignores Signed-off-by: Alina Buzachis <abuzachis@redhat.com> * Try using service instead of pod IP * Fix typo * Actually use the correct port * See if NetworkPolicy is preventing connection * using Pod internal IP * fix adm prune auth roles syntax * adding some retry steps * fix: openshift_builds target * add flag --force-with-deps when building downstream collection * Remove yamllint from tox linters, bump minimum python supported version to 3.9, Remove support for ansible-core < 2.14 --------- Signed-off-by: Alina Buzachis <abuzachis@redhat.com> Co-authored-by: Mike Graves <mgraves@redhat.com> Co-authored-by: Alina Buzachis <abuzachis@redhat.com>
109 lines
3.4 KiB
Python
109 lines
3.4 KiB
Python
#!/usr/bin/env python
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
import re
|
|
|
|
|
|
def convert_storage_to_bytes(value):
|
|
keys = {
|
|
"Ki": 1024,
|
|
"Mi": 1024 * 1024,
|
|
"Gi": 1024 * 1024 * 1024,
|
|
"Ti": 1024 * 1024 * 1024 * 1024,
|
|
"Pi": 1024 * 1024 * 1024 * 1024 * 1024,
|
|
"Ei": 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
|
|
}
|
|
for k in keys:
|
|
if value.endswith(k) or value.endswith(k[0]):
|
|
idx = value.find(k[0])
|
|
return keys.get(k) * int(value[:idx])
|
|
return int(value)
|
|
|
|
|
|
def is_valid_digest(digest):
|
|
digest_algorithm_size = dict(
|
|
sha256=64,
|
|
sha384=96,
|
|
sha512=128,
|
|
)
|
|
|
|
m = re.match(r"[a-zA-Z0-9-_+.]+:[a-fA-F0-9]+", digest)
|
|
if not m:
|
|
return "Docker digest does not match expected format %s" % digest
|
|
|
|
idx = digest.find(":")
|
|
# case: "sha256:" with no hex.
|
|
if idx < 0 or idx == (len(digest) - 1):
|
|
return "Invalid docker digest %s, no hex value define" % digest
|
|
|
|
algorithm = digest[:idx]
|
|
if algorithm not in digest_algorithm_size:
|
|
return "Unsupported digest algorithm value %s for digest %s" % (
|
|
algorithm,
|
|
digest,
|
|
)
|
|
|
|
hex_value = digest[idx + 1:] # fmt: skip
|
|
if len(hex_value) != digest_algorithm_size.get(algorithm):
|
|
return "Invalid length for digest hex expected %d found %d (digest is %s)" % (
|
|
digest_algorithm_size.get(algorithm),
|
|
len(hex_value),
|
|
digest,
|
|
)
|
|
|
|
|
|
def parse_docker_image_ref(image_ref, module=None):
|
|
"""
|
|
Docker Grammar Reference
|
|
Reference => name [ ":" tag ] [ "@" digest ]
|
|
name => [hostname '/'] component ['/' component]*
|
|
hostname => hostcomponent ['.' hostcomponent]* [':' port-number]
|
|
hostcomponent => /([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])/
|
|
port-number => /[0-9]+/
|
|
component => alpha-numeric [separator alpha-numeric]*
|
|
alpha-numeric => /[a-z0-9]+/
|
|
separator => /[_.]|__|[-]*/
|
|
"""
|
|
idx = image_ref.find("/")
|
|
|
|
def _contains_any(src, values):
|
|
return any(x in src for x in values)
|
|
|
|
result = {"tag": None, "digest": None}
|
|
default_domain = "docker.io"
|
|
if idx < 0 or (
|
|
not _contains_any(image_ref[:idx], ":.") and image_ref[:idx] != "localhost"
|
|
):
|
|
result["hostname"], remainder = default_domain, image_ref
|
|
else:
|
|
result["hostname"], remainder = image_ref[:idx], image_ref[idx + 1:] # fmt: skip
|
|
|
|
# Parse remainder information
|
|
idx = remainder.find("@")
|
|
if idx > 0 and len(remainder) > (idx + 1):
|
|
# docker image reference with digest
|
|
component, result["digest"] = remainder[:idx], remainder[idx + 1:] # fmt: skip
|
|
err = is_valid_digest(result["digest"])
|
|
if err:
|
|
if module:
|
|
module.fail_json(msg=err)
|
|
return None, err
|
|
else:
|
|
idx = remainder.find(":")
|
|
if idx > 0 and len(remainder) > (idx + 1):
|
|
# docker image reference with tag
|
|
component, result["tag"] = remainder[:idx], remainder[idx + 1:] # fmt: skip
|
|
else:
|
|
# name only
|
|
component = remainder
|
|
v = component.split("/")
|
|
namespace = None
|
|
if len(v) > 1:
|
|
namespace = v[0]
|
|
result.update({"namespace": namespace, "name": v[-1]})
|
|
|
|
return result, None
|