diff --git a/buildman/component/buildcomponent.py b/buildman/component/buildcomponent.py index 8ebbeb92f..abe7072bc 100644 --- a/buildman/component/buildcomponent.py +++ b/buildman/component/buildcomponent.py @@ -11,6 +11,7 @@ from trollius import From, Return from buildman.server import BuildJobResult from buildman.component.basecomponent import BaseComponent +from buildman.component.buildparse import extract_current_step from buildman.jobutil.buildjob import BuildJobLoadException from buildman.jobutil.buildstatus import StatusHandler from buildman.jobutil.workererror import WorkerError @@ -269,9 +270,7 @@ class BuildComponent(BaseComponent): current_status_string = str(fully_unwrapped.encode('utf-8')) if current_status_string and phase == BUILD_PHASE.BUILDING: - step_increment = re.search(r'Step ([0-9]+) :', current_status_string) - if step_increment: - current_step = int(step_increment.group(1)) + current_step = extract_current_step(current_status_string) # Parse and update the phase and the status_dict. The status dictionary contains # the pull/push progress, as well as the current step index. diff --git a/buildman/component/buildparse.py b/buildman/component/buildparse.py new file mode 100644 index 000000000..3560c0861 --- /dev/null +++ b/buildman/component/buildparse.py @@ -0,0 +1,15 @@ +import re + +def extract_current_step(current_status_string): + """ Attempts to extract the current step numeric identifier from the given status string. Returns the step + number or None if none. + """ + # Older format: `Step 12 :` + # Newer format: `Step 4/13 :` + step_increment = re.search(r'Step ([0-9]+)/([0-9]+) :', current_status_string) + if step_increment: + return int(step_increment.group(1)) + + step_increment = re.search(r'Step ([0-9]+) :', current_status_string) + if step_increment: + return int(step_increment.group(1)) diff --git a/buildman/component/test/test_buildparse.py b/buildman/component/test/test_buildparse.py new file mode 100644 index 000000000..3bdb7295e --- /dev/null +++ b/buildman/component/test/test_buildparse.py @@ -0,0 +1,16 @@ +import pytest + +from buildman.component.buildparse import extract_current_step + + +@pytest.mark.parametrize('input,expected_step', [ + ("", None), + ("Step a :", None), + ("Step 1 :", 1), + ("Step 1 : ", 1), + ("Step 1/2 : ", 1), + ("Step 2/17 : ", 2), + ("Step 4/13 : ARG somearg=foo", 4), +]) +def test_extract_current_step(input, expected_step): + assert extract_current_step(input) == expected_step