Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move isolate_timestamp_in_release() to artcommon #1141

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions artcommon/artcommonlib/release_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ def isolate_el_version_in_release(release: str) -> Optional[int]:
return None


def isolate_timestamp_in_release(release: str) -> Optional[str]:
"""
Given a release field, determines whether is contains
a timestamp. If it does, it returns the timestamp.
If it is not found, None is returned.
"""
match = re.search(r"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})", release) # yyyyMMddHHmm
if match:
year = int(match.group(1))
month = int(match.group(2))
day = int(match.group(3))
hour = int(match.group(4))
minute = int(match.group(5))
if year >= 2000 and month >= 1 and month <= 12 and day >= 1 and day <= 31 and hour <= 23 and minute <= 59:
return match.group(0)
return None


class SoftwareLifecyclePhase(Enum):
PRE_RELEASE = 0
SIGNING = 1
Expand Down
31 changes: 30 additions & 1 deletion artcommon/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import yaml

from artcommonlib import util, build_util, release_util
from artcommonlib.model import Model, MissingModel
from artcommonlib.model import Model
from artcommonlib.release_util import SoftwareLifecyclePhase
from artcommonlib.util import deep_merge, isolate_major_minor_in_group

Expand Down Expand Up @@ -226,3 +226,32 @@ def test_eq(self):
self.assertEqual(SoftwareLifecyclePhase.PRE_RELEASE, 0)
self.assertEqual(SoftwareLifecyclePhase.EOL.value, 100)
self.assertNotEqual(SoftwareLifecyclePhase.EOL.value, 101)

def test_isolate_timestamp_in_release(self):
actual = release_util.isolate_timestamp_in_release("foo-4.7.0-202107021813.p0.g01c9f3f.el8")
expected = "202107021813"
self.assertEqual(actual, expected)

actual = release_util.isolate_timestamp_in_release("foo-container-v4.7.0-202107021907.p0.g8b4b094")
expected = "202107021907"
self.assertEqual(actual, expected)

actual = release_util.isolate_timestamp_in_release("foo-container-v4.7.0-202107021907.p0.g8b4b094")
expected = "202107021907"
self.assertEqual(actual, expected)

actual = release_util.isolate_timestamp_in_release("foo-container-v4.8.0-202106152230.p0.g25122f5.assembly.stream")
expected = "202106152230"
self.assertEqual(actual, expected)

actual = release_util.isolate_timestamp_in_release("foo-container-v4.7.0-1.p0.g8b4b094")
expected = None
self.assertEqual(actual, expected)

actual = release_util.isolate_timestamp_in_release("foo-container-v4.7.0-202199999999.p0.g8b4b094")
expected = None
self.assertEqual(actual, expected)

actual = release_util.isolate_timestamp_in_release("")
expected = None
self.assertEqual(actual, expected)
8 changes: 4 additions & 4 deletions doozer/doozerlib/cli/scan_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from typing import List, Tuple, Optional

import artcommonlib.util
from artcommonlib import exectools
from artcommonlib import exectools, release_util
from artcommonlib.model import Missing
from artcommonlib.pushd import Dir
from artcommonlib.rhcos import get_primary_container_name
from doozerlib import brew, rhcos, util
from doozerlib import brew, rhcos
from doozerlib.cli import cli, pass_runtime, click_coroutine
from doozerlib.cli import release_gen_payload as rgp
from doozerlib.image import ImageMetadata
Expand Down Expand Up @@ -328,7 +328,7 @@ def find_oldest_newest(self, koji_api, build_info):
self.newest_image_event_ts = create_event_ts

def check_dependents(self, image_meta: ImageMetadata, build_info):
rebase_time = util.isolate_timestamp_in_release(build_info["release"])
rebase_time = release_util.isolate_timestamp_in_release(build_info["release"])
if not rebase_time: # no timestamp string in NVR?
return

Expand All @@ -354,7 +354,7 @@ def _check_dep(dep_key):
if not dep_info:
return

dep_rebase_time = util.isolate_timestamp_in_release(dep_info["release"])
dep_rebase_time = release_util.isolate_timestamp_in_release(dep_info["release"])
if not dep_rebase_time: # no timestamp string in NVR?
return

Expand Down
2 changes: 1 addition & 1 deletion doozer/doozerlib/cli/scan_sources_konflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from doozerlib.metadata import RebuildHint, RebuildHintCode, Metadata
from doozerlib.runtime import Runtime
from doozerlib.source_resolver import SourceResolver
from doozerlib.util import isolate_timestamp_in_release
from artcommonlib.release_util import isolate_timestamp_in_release

DEFAULT_THRESHOLD_HOURS = 6

Expand Down
18 changes: 0 additions & 18 deletions doozer/doozerlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,24 +357,6 @@ def strip_epoch(nvr: str):
return nvr.split(':')[0]


def isolate_timestamp_in_release(release: str) -> Optional[str]:
"""
Given a release field, determines whether is contains
a timestamp. If it does, it returns the timestamp.
If it is not found, None is returned.
"""
match = re.search(r"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})", release) # yyyyMMddHHmm
if match:
year = int(match.group(1))
month = int(match.group(2))
day = int(match.group(3))
hour = int(match.group(4))
minute = int(match.group(5))
if year >= 2000 and month >= 1 and month <= 12 and day >= 1 and day <= 31 and hour <= 23 and minute <= 59:
return match.group(0)
return None


def get_release_tag_datetime(release: str) -> Optional[str]:
match = re.search(r"(\d{4})-(\d{2})-(\d{2})-(\d{6})", release) # yyyy-MM-dd-HHmmss
if match:
Expand Down
29 changes: 0 additions & 29 deletions doozer/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,6 @@ def test_bogus_arch_xlate(self):
with self.assertRaises(Exception):
brew_arch_for_go_arch("bogus")

def test_isolate_timestamp_in_release(self):
actual = util.isolate_timestamp_in_release("foo-4.7.0-202107021813.p0.g01c9f3f.el8")
expected = "202107021813"
self.assertEqual(actual, expected)

actual = util.isolate_timestamp_in_release("foo-container-v4.7.0-202107021907.p0.g8b4b094")
expected = "202107021907"
self.assertEqual(actual, expected)

actual = util.isolate_timestamp_in_release("foo-container-v4.7.0-202107021907.p0.g8b4b094")
expected = "202107021907"
self.assertEqual(actual, expected)

actual = util.isolate_timestamp_in_release("foo-container-v4.8.0-202106152230.p0.g25122f5.assembly.stream")
expected = "202106152230"
self.assertEqual(actual, expected)

actual = util.isolate_timestamp_in_release("foo-container-v4.7.0-1.p0.g8b4b094")
expected = None
self.assertEqual(actual, expected)

actual = util.isolate_timestamp_in_release("foo-container-v4.7.0-202199999999.p0.g8b4b094")
expected = None
self.assertEqual(actual, expected)

actual = util.isolate_timestamp_in_release("")
expected = None
self.assertEqual(actual, expected)

def test_get_release_name_for_assembly(self):
releases_config = Model({
"releases": {
Expand Down