def test_flow_scope_job(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j1', max_fails=0, expect_invocations=0, expect_order=None) api.job('j2', max_fails=0, expect_invocations=0, expect_order=None) with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: pass ctrl1.invoke('j1') with raises(FlowScopeException): with parallel(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: pass ctrl1.invoke('j1') with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: with ctrl1.parallel() as ctrl2: pass ctrl2.invoke('j2') with raises(FlowScopeException): with parallel(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: with ctrl1.serial() as ctrl2: ctrl2.invoke('j1') ctrl2.invoke('j2')
def test_flow_scope_serial(): with mock_api.api(__file__) as api: api.flow_job() with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: pass with ctrl1.serial(1): pass with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: pass with ctrl1.parallel(1): pass with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: with ctrl1.serial() as ctrl2: ctrl2.serial(1) ctrl2.serial(1) with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: with ctrl1.serial() as ctrl2: ctrl1.serial(1)
def test_flow_scope_serial(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: pass with ctrl1.serial(1): pass with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: pass with ctrl1.parallel(1): pass with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: with ctrl1.serial() as ctrl2: ctrl2.serial(1) ctrl2.serial(1) with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: with ctrl1.serial() as ctrl2: ctrl1.serial(1)
def test_reporting_queued(api_type, capsys): # TODO skip_apis = (ApiType.SCRIPT, ApiType.MOCK) with api_select.api(__file__, api_type, login=True) as api: api.flow_job() exp_invocations = 2 if api.api_type not in skip_apis else 1 unknown_result = False if api.api_type not in skip_apis else True api.job('j1', exec_time=10, max_fails=0, expect_invocations=exp_invocations, expect_order=None, unknown_result=unknown_result) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke_unchecked('j1') print(api.api_type, type(api.api_type)) if api.api_type in skip_apis: return with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, require_idle=False) as ctrl1: ctrl1.invoke('j1') sout, _ = capsys.readouterr() assert_lines_in( api_type, sout, "^Invoking Job (1/1,1/1): http://x.x/job/jenkinsflow_test__reporting_queued__j1", build_queued_msg(api, "jenkinsflow_test__reporting_queued__j1", 1), build_started_msg(api, "jenkinsflow_test__reporting_queued__j1", 2), )
def test_flow_scope_job(): with mock_api.api(__file__) as api: api.flow_job() api.job("j1", 0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job("j2", 0.01, max_fails=0, expect_invocations=0, expect_order=None) with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: pass ctrl1.invoke("j1") with raises(FlowScopeException): with parallel(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: pass ctrl1.invoke("j1") with raises(FlowScopeException): with serial(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: with ctrl1.parallel() as ctrl2: pass ctrl2.invoke("j2") with raises(FlowScopeException): with parallel(api, 10, job_name_prefix=api.job_name_prefix) as ctrl1: with ctrl1.serial() as ctrl2: ctrl2.invoke("j1") ctrl2.invoke("j2")
def test_no_running_jobs_jobs_allowed(api_type): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() exp_invocations = 2 if api.api_type != ApiType.MOCK else 1 unknown_result = False if api.api_type != ApiType.MOCK else True api.job('j1', max_fails=0, expect_invocations=exp_invocations, expect_order=None, exec_time=20, invocation_delay=0, unknown_result=unknown_result) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke_unchecked('j1') api.sleep(1) # TODO if api.api_type != ApiType.MOCK: with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, require_idle=False) as ctrl1: ctrl1.invoke('j1')
def test_no_running_jobs_unchecked(api_type, capsys): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() api.job('j1', max_fails=0, expect_invocations=1, expect_order=None, exec_time=50, invocation_delay=0, unknown_result=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke_unchecked('j1') sout, _ = capsys.readouterr() assert lines_in( api_type, sout, "unchecked job: 'jenkinsflow_test__no_running_jobs_unchecked__j1' UNKNOWN - RUNNING" ) api.sleep(1) with raises(JobNotIdleException) as exinfo: with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke_unchecked('j1') assert "unchecked job: 'jenkinsflow_test__no_running_jobs_unchecked__j1' is in state RUNNING. It must be IDLE." in str( exinfo.value)
def test_missing_jobs_not_allowed(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j1', max_fails=0, expect_invocations=0, expect_order=None) api.job('j2', max_fails=0, expect_invocations=0, expect_order=None) with raises(MissingJobsException) as exinfo: with serial(api, 20, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j1') ctrl1.invoke('missingA') ctrl1.invoke('j2') assert lines_in( api_type, str(exinfo.value), re.compile("^Job not found: .*jenkinsflow_test__missing_jobs_not_allowed__missingA") ) with raises(MissingJobsException): with serial(api, 20, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j1') ctrl1.invoke('missingA') with ctrl1.parallel() as ctrl2: ctrl2.invoke('missingB') ctrl2.invoke('j2') ctrl1.invoke('missingC')
def test_missing_jobs_not_allowed(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j1', 0.01, max_fails=0, expect_invocations=0, expect_order=None) api.job('j2', 0.01, max_fails=0, expect_invocations=0, expect_order=None) with raises(MissingJobsException) as exinfo: with serial(api, 20, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j1') ctrl1.invoke('missingA') ctrl1.invoke('j2') assert_lines_in( api_type, str(exinfo.value), re.compile("^Job not found: .*jenkinsflow_test__missing_jobs_not_allowed__missingA") ) with raises(MissingJobsException): with serial(api, 20, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j1') ctrl1.invoke('missingA') with ctrl1.parallel() as ctrl2: ctrl2.invoke('missingB') ctrl2.invoke('j2') ctrl1.invoke('missingC')
def test_multiple_invocations_new_flow(): with mock_api.api(__file__) as api: api.flow_job() _params = (('password', '', 'Some password'), ('s1', '', 'Some string argument')) api.job('j1', exec_time=0.01, max_fails=0, expect_invocations=2, expect_order=1, params=_params) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('j1', password='******', s1='b') with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('j1', password='******', s1='asdasdasdasdad')
def test_multiple_invocations_new_flow_same_args(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() _params = (('password', '', 'Some password'), ('s1', '', 'Some string argument')) api.job('j1', max_fails=0, expect_invocations=2, expect_order=1, params=_params) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('j1', password='******', s1='b') with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('j1', password='******', s1='b')
def test_no_running_jobs_jobs_allowed(): with mock_api.api(__file__) as api: api.flow_job() exp_invocations = 2 if not is_mocked else 1 api.job('j1', exec_time=20, max_fails=0, expect_invocations=exp_invocations, expect_order=None, unknown_result=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke_unchecked('j1') # TODO if not is_mocked: with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, require_idle=False) as ctrl1: ctrl1.invoke('j1')
def test_no_running_jobs(): with mock_api.api(__file__) as api: api.flow_job() api.job('j1', exec_time=50, max_fails=0, expect_invocations=1, expect_order=None, unknown_result=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke_unchecked('j1') with raises(JobNotIdleException) as exinfo: with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j1') assert "Job: jenkinsflow_test__no_running_jobs__j1 is in state RUNNING. It must be IDLE." in exinfo.value.message
def test_retry_parallel_through_outer_level(api_type, capsys): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=1, expect_order=1) api.job('j21', max_fails=0, expect_invocations=1, expect_order=2, serial=True) api.job('j31', max_fails=0, expect_invocations=1, expect_order=3, serial=True) api.job('j41_fail', max_fails=2, expect_invocations=3, expect_order=3) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j11') with ctrl1.serial(timeout=70, max_tries=2) as ctrl2: ctrl2.invoke('j21') with ctrl2.parallel(timeout=70) as ctrl3: ctrl3.invoke('j31') with ctrl3.parallel(timeout=70, max_tries=2) as ctrl4: ctrl4.invoke('j41_fail') sout, _ = capsys.readouterr() sout = utils.replace_host_port(api_type, sout) assert "RETRY: job: 'jenkinsflow_test__retry_parallel_through_outer_level__j41_fail' failed but will be retried. Up to 1 more times in current flow" in sout, 'SOUT:' + sout assert "RETRY: job: 'jenkinsflow_test__retry_parallel_through_outer_level__j41_fail' failed but will be retried. Up to 2 more times through outer flow" in sout, 'SOUT:' + sout
def test_retry_serial_through_parent_serial_level(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=1, expect_order=1) api.job('j21', max_fails=0, expect_invocations=2, expect_order=2, serial=True) api.job('j31_fail', max_fails=2, expect_invocations=3, expect_order=3, serial=True) api.job('j32', max_fails=0, expect_invocations=1, expect_order=4, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j11') with ctrl1.serial(timeout=70, max_tries=2) as ctrl2: ctrl2.invoke('j21') with ctrl2.serial(timeout=70, max_tries=2) as ctrl3: ctrl3.invoke('j31_fail') ctrl3.invoke('j32')
def test_single_level_errors_serial(api_type): with api_select.api(__file__, api_type) as api: api.job('quick', max_fails=0, expect_invocations=1, expect_order=1, params=(('s1', '', 'desc'), ('c1', 'false', 'desc'))) api.job('quick_fail', max_fails=1, expect_invocations=1, expect_order=2, serial=True) api.job('wait5', max_fails=0, expect_invocations=0, expect_order=None, exec_time=5) with raises(FailedChildJobException): with serial(api, timeout=20, job_name_prefix=api.job_name_prefix, report_interval=3) as ctrl: ctrl.invoke('quick', s1='', c1=False) ctrl.invoke('quick_fail') ctrl.invoke('wait5')
def test_direct_url_is_public_url(api_type, capsys): with api_select.api(__file__, api_type) as api: api.job('j1', max_fails=0, expect_invocations=1, expect_order=1, params=(('s1', 'Hi', 'desc'), ('c1', ('true', 'maybe', 'false'), 'desc'))) api.job('j2', max_fails=0, expect_invocations=1, expect_order=2, serial=True) with serial(api, timeout=40, job_name_prefix=api.job_name_prefix, report_interval=1, direct_url=api.public_uri) as ctrl: ctrl.invoke('j1', s1='HELLO', c1=True) ctrl.invoke('j2') sout, _ = capsys.readouterr() assert '//job' not in sout assert '/job/' in sout
def test_set_build_description_cli_no_env_url(api_type, env_no_base_url, cli_runner): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() job_name = 'j1' api.job(job_name, max_fails=0, expect_invocations=1, expect_order=1) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke(job_name, password='******', s1='b') # Need to read the build number job = api.get_job(api.job_name_prefix + job_name) _, _, build_num = job.job_status() cli_args = [ 'set_build_description', '--job-name', job.name, '--build-number', repr(build_num), '--description', 'BBB1'] print("cli args:", cli_args) result = cli_runner.invoke(cli, cli_args) print(result.output) assert result.exception assert "Could not get env variable JENKINS_URL or HUDSON_URL" in str(result.exception) assert "You must specify 'direct-url'" in result.output
def test_reporting_job_status_unchecked(capsys): with mock_api.api(__file__) as api: api.flow_job() api.job('j11', 0.1, max_fails=0, expect_invocations=1, expect_order=1) api.job('j21_unchecked', 50, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=None, unknown_result=True, serial=True) api.job('j22', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=2) api.job('j31', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=3) api.job('j32_unchecked', 1.5, max_fails=1, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=3) api.job('j41', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=3) api.job('j42_unchecked', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=3, serial=True) api.job('j23', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=4) api.job('j12', 5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=5) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=0.5/_hyperspeed_speedup) as ctrl1: ctrl1.invoke('j11') with ctrl1.serial() as ctrl2: ctrl2.invoke_unchecked('j21_unchecked') ctrl2.invoke('j22') with ctrl2.parallel() as ctrl3: ctrl3.invoke('j31') ctrl3.invoke_unchecked('j32_unchecked') with ctrl3.serial() as ctrl4: ctrl4.invoke('j41') ctrl4.invoke_unchecked('j42_unchecked') ctrl2.invoke('j23') ctrl1.invoke('j12') sout, _ = capsys.readouterr()
def test_invoke_unchecked_mix_no_fails(api_type): with api_select.api(__file__, api_type, login=True) as api: api.job('j31_unchecked', max_fails=0, expect_invocations=1, expect_order=1, exec_time=30, unknown_result=True) api.job('j32_unchecked', max_fails=0, expect_invocations=1, expect_order=1, exec_time=30, unknown_result=True) api.job('j11', max_fails=0, expect_invocations=1, expect_order=2) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke_unchecked('j31_unchecked') with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke_unchecked('j32_unchecked') ctrl1.invoke('j11')
def test_reporting_result_unchecked(capsys): with mock_api.api(__file__) as api: api.flow_job() api.job('j11', 0.1, max_fails=0, expect_invocations=1, expect_order=1) api.job('j21_unchecked', 50, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=None, unknown_result=True, serial=True) api.job('j22', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=2) api.job('j31', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=3) api.job('j32_unchecked_fail', 1.5, max_fails=1, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=3) api.job('j41', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=3) api.job('j42_unchecked', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=3, serial=True) api.job('j23', 1.5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=4) api.job('j12', 5, max_fails=0, expect_invocations=1, invocation_delay=0.0001, initial_buildno=7, expect_order=5) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=0.5/hyperspeed.speedup) as ctrl1: ctrl1.invoke('j11') with ctrl1.serial() as ctrl2: ctrl2.invoke_unchecked('j21_unchecked') ctrl2.invoke('j22') with ctrl2.parallel() as ctrl3: ctrl3.invoke('j31') ctrl3.invoke_unchecked('j32_unchecked_fail') with ctrl3.serial() as ctrl4: ctrl4.invoke('j41') ctrl4.invoke_unchecked('j42_unchecked') ctrl2.invoke('j23') ctrl1.invoke('j12') sout, _ = capsys.readouterr() assert_lines_in( sout, "^UNCHECKED FAILURE: 'jenkinsflow_test__reporting_result_unchecked__j32_unchecked_fail' - build: http://x.x/job/jenkinsflow_test__reporting_result_unchecked__j32_unchecked_fail/", "^UNCHECKED SUCCESS: 'jenkinsflow_test__reporting_result_unchecked__j42_unchecked' - build: http://x.x/job/jenkinsflow_test__reporting_result_unchecked__j42_unchecked/" + num_console(8, api) )
def test_set_build_description_util(api_type): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() job_name = "job-1" api.job(job_name, exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) # Need to read the build number if api.api_type == ApiType.SCRIPT: # TODO: This can't be called here for Jenkins API. Why? job = api.get_job(api.job_name_prefix + job_name) _clear_description(api, job) with serial( api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1, description="AAA" ) as ctrl1: ctrl1.invoke(job_name, password="******", s1="b") if api.api_type != ApiType.SCRIPT: job = api.get_job(api.job_name_prefix + job_name) _, _, build_num = job.job_status() api.set_build_description(job.name, build_num, "BBB1") api.set_build_description(job.name, build_num, "BBB2", replace=False) _verify_description(api, job, build_num, "AAA\nBBB1\nBBB2") api.set_build_description(job.name, build_num, "BBB3", replace=True) api.set_build_description(job.name, build_num, "BBB4", replace=False, separator="#") api.set_build_description(job.name, build_num, "BBB5", separator="!!") _verify_description(api, job, build_num, "BBB3#BBB4!!BBB5")
def test_set_build_description_flow_set(api_type): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() _params = (("password", "", "Some password"), ("s1", "", "Some string argument")) api.job("job-1", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1, params=_params) api.job("job-2", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=2, params=_params, serial=True) api.job("job-3", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job("job-4", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job("job-5", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job("job-6", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=4, params=_params) api.job("job-7", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=5, params=_params, serial=True) with serial( api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1, description="AAA" ) as ctrl1: ctrl1.invoke("job-1", password="******", s1="b") ctrl1.invoke("job-2", password="******", s1="b") with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke("job-3", password="******", s1="b") ctrl3a.invoke("job-6", password="******", s1="b") with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke("job-4", password="******", s1="b") ctrl3b.invoke("job-5", password="******", s1="b") ctrl1.invoke("job-7", password="******", s1="b")
def test_set_build_description_cli_no_env_url(api_type, env_no_base_url, cli_runner): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() job_name = "j1" api.job(job_name, exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke(job_name, password="******", s1="b") # Need to read the build number job = api.get_job(api.job_name_prefix + job_name) _, _, build_num = job.job_status() cli_args = [ "set_build_description", "--job-name", job.name, "--build-number", repr(build_num), "--description", "BBB1", ] print("cli args:", cli_args) result = cli_runner.invoke(cli, cli_args) print(result.output) assert result.exception assert "Could not get env variable JENKINS_URL or HUDSON_URL" in str(result.exception) assert "You must specify '--direct-url'" in result.output
def test_retry_serial_inner(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=1, expect_order=1) api.job('j21', max_fails=0, expect_invocations=2, expect_order=2, serial=True) api.job('j22_fail', max_fails=1, expect_invocations=2, expect_order=3, serial=True) api.job('j23', max_fails=0, expect_invocations=1, expect_order=4, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j11') with ctrl1.serial(max_tries=2) as ctrl2: ctrl2.invoke('j21') ctrl2.invoke('j22_fail') ctrl2.invoke('j23')
def test_messages_on_job(api_type, capsys): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j21', max_fails=0, expect_invocations=1, invocation_delay=1.0, expect_order=1, serial=True) api.job('j12', max_fails=0, expect_invocations=1, invocation_delay=1.0, expect_order=2, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: with ctrl1.serial() as sctrl2: with sctrl2.invoke('j21') as j21: j21.message("*** Calling j21 ***") ctrl1.invoke('j12') sout, _ = capsys.readouterr() print(sout) assert lines_in( api_type, sout, "^--- Starting flow ---", "^Flow Invocation (1/1,1/1): [['jenkinsflow_test__messages_on_job__j21'], 'jenkinsflow_test__messages_on_job__j12'", "^Flow Invocation (1/1,1/1): ['jenkinsflow_test__messages_on_job__j21']", "^*** Calling j21 ***", "^Job Invocation (1/1,1/1): http://x.x/job/jenkinsflow_test__messages_on_job__j21", "^SUCCESS: " + result_msg(api, "jenkinsflow_test__messages_on_job__j21"), "^Flow SUCCESS ['jenkinsflow_test__messages_on_job__j21'] after: ", "^Job Invocation (1/1,1/1): http://x.x/job/jenkinsflow_test__messages_on_job__j12", "^SUCCESS: " + result_msg(api, "jenkinsflow_test__messages_on_job__j12"), )
def test_multi_level_mixed(): with mock_api.api(__file__) as api: api.flow_job() _params = (("password", "", "Some password"), ("s1", "", "Some string argument")) api.job("job-1", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1, params=_params) api.job("job-2", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=2, params=_params, serial=True) api.job("job-3", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job("job-4", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job("job-5", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job("job-6", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=4, params=_params) api.job("job-7", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=5, params=_params, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke("job-1", password="******", s1="b") ctrl1.invoke("job-2", password="******", s1="b") with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke("job-3", password="******", s1="b") ctrl3a.invoke("job-6", password="******", s1="b") with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke("job-4", password="******", s1="b") ctrl3b.invoke("job-5", password="******", s1="b") ctrl1.invoke("job-7", password="******", s1="b")
def test_messages_redefined(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=0, invocation_delay=1.0, expect_order=None) api.job('j21', max_fails=0, expect_invocations=0, invocation_delay=1.0, expect_order=None) with raises(MessageRedefinedException) as exinfo: with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j11') with ctrl1.serial() as sctrl2: sctrl2.message("**** Message 1 ****") sctrl2.invoke('j21') sctrl2.message("New message") ctrl1.invoke('j12') assert str( exinfo.value ) == "Existing message: '**** Message 1 ****', new message: 'New message'"
def test_propagation_warn_only_nested_serial_parallel(api_type): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=1, expect_order=1) api.job('j21', max_fails=0, expect_invocations=1, expect_order=2, serial=True) api.job('j22_fail', max_fails=1, expect_invocations=1, expect_order=2) api.job('j23', max_fails=0, expect_invocations=1, expect_order=2) with raises(FinalResultException) as exinfo: with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=3) as ctrl1: ctrl1.invoke('j11') with ctrl1.parallel( propagation=Propagation.FAILURE_TO_UNSTABLE) as ctrl2: ctrl2.invoke('j21') ctrl2.invoke('j22_fail') ctrl2.invoke('j23') assert exinfo.value.result == BuildResult.UNSTABLE return 77
def main(api): with serial(api, timeout=70, securitytoken=security.securitytoken, job_name_prefix='jenkinsflow_demo__errors__', report_interval=3) as ctrl1: ctrl1.invoke('wait1-1') with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke('wait2') ctrl3a.invoke('quick_fail-1', force_result='FAILURE', password='******', s1='WORLD', c1='be') # Never invoked ctrl3a.invoke('quick', password='******', s1='WORLD', c1='maybe') with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke('wait5-2a') ctrl3b.invoke('quick_fail-2', force_result='FAILURE', password='******', s1='WORLD', c1='maybe') ctrl3b.invoke('wait5-2b') ctrl3b.invoke('wait5-2c') # Never invoked ctrl1.invoke('wait1-2')
def test_set_build_description_api(api_type): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() job_name = 'job-1' api.job(job_name, max_fails=0, expect_invocations=1, expect_order=1) # Need to read the build number if api.api_type == ApiType.SCRIPT: # TODO: This can't be called here for Jenkins API. Why? job = api.get_job(api.job_name_prefix + job_name) _clear_description(api, job) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1, description="AAA") as ctrl1: ctrl1.invoke(job_name, password='******', s1='b') if api.api_type != ApiType.SCRIPT: job = api.get_job(api.job_name_prefix + job_name) _, _, build_num = job.job_status() api.set_build_description('BBB1', job_name=job.name, build_number=build_num) api.set_build_description('BBB2', False, job_name=job.name, build_number=build_num) assert _get_description(api, job, build_num) == 'AAA\nBBB1\nBBB2' api.set_build_description('BBB3', replace=True, job_name=job.name, build_number=build_num) api.set_build_description('BBB4', replace=False, separator='#', job_name=job.name, build_number=build_num) api.set_build_description('BBB5', separator='!!', job_name=job.name, build_number=build_num) assert _get_description(api, job, build_num) == 'BBB3#BBB4!!BBB5'
def test_propagate_unstable_parallel_inner_raise_if_unsuccessful_true( api_type): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=1, expect_order=1) api.job('j21', max_fails=0, expect_invocations=1, expect_order=2, serial=True) api.job('j22_unstable', max_fails=0, expect_invocations=1, expect_order=2, final_result='unstable') api.job('j23', max_fails=0, expect_invocations=1, expect_order=2) with raises(FinalResultException) as exinfo: with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j11') with ctrl1.parallel() as ctrl2: ctrl2.invoke('j21') ctrl2.invoke('j22_unstable') ctrl2.invoke('j23') assert exinfo.value.result == BuildResult.UNSTABLE assert ctrl2.result == BuildResult.UNSTABLE assert ctrl1.result == BuildResult.UNSTABLE return 77
def test_timeout_inner_level_parallel(api_type): with api_select.api(__file__, api_type, login=True) as api: api.job('quick11', max_fails=0, expect_invocations=1, expect_order=None) api.job('quick21', max_fails=0, expect_invocations=1, expect_order=None) api.job('wait20', max_fails=0, expect_invocations=1, expect_order=None, exec_time=30, unknown_result=True) with raises(FlowTimeoutException) as exinfo: with serial(api, timeout=3000, job_name_prefix=api.job_name_prefix, report_interval=3) as ctrl1: ctrl1.invoke('quick11') with ctrl1.parallel(timeout=8) as ctrl2: ctrl2.invoke('quick21') ctrl2.invoke('wait20') assert "Timeout after:" in str(exinfo.value) assert ", in flow ('jenkinsflow_test__timeout_inner_level_parallel__quick21', 'jenkinsflow_test__timeout_inner_level_parallel__wait20'). Unfinished jobs:['jenkinsflow_test__timeout_inner_level_parallel__wait20']" in str( exinfo.value)
def test_prefix(api_type, capsys): with api_select.api(__file__, api_type) as api: def job(name): api.job(name, exec_time=0.5, max_fails=0, expect_invocations=0, expect_order=None, params=None) api.flow_job() job('quick1') index = 0 for index in 1, 2, 3: job('x_quick2-' + str(index)) job('quick3') job('y_z_quick4') job('y_quick5') with serial(api, timeout=70, report_interval=3, job_name_prefix='top_', just_dump=True) as ctrl1: ctrl1.invoke('quick1') for index in 1, 2, 3: with ctrl1.serial(timeout=20, report_interval=3, job_name_prefix='x_') as ctrl2: ctrl2.invoke('quick2-' + str(index)) ctrl1.invoke('quick3') with ctrl1.parallel(timeout=40, report_interval=3, job_name_prefix='y_') as ctrl2: with ctrl2.serial(timeout=40, report_interval=3, job_name_prefix='z_') as ctrl3a: ctrl3a.invoke('quick4a') # Reset prefix with ctrl2.serial(timeout=40, report_interval=3, job_name_prefix=None) as ctrl3b: ctrl3b.invoke('quick4b') ctrl2.invoke('quick5') sout, _ = capsys.readouterr() assert prefixed_jobs.strip() in sout
def test_invoke_unchecked_mix_fails(): with api_select.api(__file__, login=True) as api: api.flow_job() api.job('j11_unchecked', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=None) api.job('j12', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=2) api.job('j31', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) # Make sure result is available during first invocation of _check, only way to hit error handling code in unchecked job vfast = 0.00000000000000000000000000000000001 api.job('j32_fail_unchecked', exec_time=vfast, max_fails=1, expect_invocations=1, expect_order=3, invocation_delay=0) api.job('j33_slow_unchecked', exec_time=100, max_fails=0, expect_invocations=1, expect_order=None, unknown_result=True) api.job('j34', exec_time=5, max_fails=0, expect_invocations=1, expect_order=3) api.job('j35_fail_unchecked', exec_time=0.01, max_fails=1, expect_invocations=1, expect_order=3) api.job('j13', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=4) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke_unchecked('j11_unchecked') ctrl1.invoke('j12') with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke('j31') ctrl3a.invoke_unchecked('j32_fail_unchecked') with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke_unchecked('j33_slow_unchecked') ctrl3b.invoke('j34') ctrl3b.invoke_unchecked('j35_fail_unchecked') ctrl1.invoke('j13')
def test_retry_unchecked_quick_serial_toplevel(api_type): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() api.job('j11_unchecked', max_fails=1, expect_invocations=2, expect_order=1) api.job('j12_fail', max_fails=1, expect_invocations=2, expect_order=2, exec_time=1) api.job('j13', max_fails=0, expect_invocations=1, expect_order=3, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, max_tries=2) as ctrl1: ctrl1.invoke_unchecked('j11_unchecked') ctrl1.invoke('j12_fail') ctrl1.invoke('j13')
def test_invoke_unchecked_serial(api_type): with api_select.api(__file__, api_type, login=True) as api: api.job('j11_unchecked', max_fails=0, expect_invocations=1, expect_order=None, exec_time=30, unknown_result=True) api.job('j12', max_fails=0, expect_invocations=1, expect_order=1, exec_time=5) api.job('j13_unchecked', max_fails=0, expect_invocations=1, expect_order=2, exec_time=30, invocation_delay=0, unknown_result=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke_unchecked('j11_unchecked') ctrl1.invoke('j12') ctrl1.invoke_unchecked('j13_unchecked')
def test_cause_no_build_number(api_type, env_job_name): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j1', max_fails=0, expect_invocations=1, expect_order=1) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('j1')
def _flow(api, strip_prefix, json_dir): if not os.path.exists(json_dir): os.makedirs(json_dir) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1, json_dir=json_dir, json_strip_top_level_prefix=strip_prefix) as ctrl1: ctrl1.invoke('j1') ctrl1.invoke('j2') with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke('j3') ctrl3a.invoke('j6') ctrl3a.invoke_unchecked('j7_unchecked') with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke('j4') ctrl3b.invoke('j5') ctrl3b.invoke_unchecked('j8_unchecked') ctrl1.invoke('j9') return ctrl1
def test_multi_level_mixed(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() _params = (('password', '', 'Some password'), ('s1', '', 'Some string argument')) api.job('job-1', max_fails=0, expect_invocations=1, expect_order=1, params=_params) api.job('job-2', max_fails=0, expect_invocations=1, expect_order=2, params=_params, serial=True) api.job('job-3', max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job('job-4', max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job('job-5', max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job('job-6', max_fails=0, expect_invocations=1, expect_order=4, params=_params) api.job('job-7', max_fails=0, expect_invocations=1, expect_order=5, params=_params, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('job-1', password='******', s1='b') ctrl1.invoke('job-2', password='******', s1='b') with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke('job-3', password='******', s1='b') ctrl3a.invoke('job-6', password='******', s1='b') with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke('job-4', password='******', s1='b') ctrl3b.invoke('job-5', password='******', s1='b') ctrl1.invoke('job-7', password='******', s1='b')
def test_no_running_jobs(): with api_select.api(__file__) as api: api.flow_job() api.job('j1', exec_time=50, max_fails=0, expect_invocations=1, expect_order=None, unknown_result=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke_unchecked('j1') # Make sure job has actually started nefore entering new flow hyperspeed.sleep(1) with raises(JobNotIdleException) as exinfo: with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j1') assert "job: 'jenkinsflow_test__no_running_jobs__j1' is in state RUNNING. It must be IDLE." in exinfo.value.message
def test_no_running_jobs_jobs_allowed(): with api_select.api(__file__) as api: api.flow_job() exp_invocations = 2 if api.api_type != ApiType.MOCK else 1 unknown_result = False if api.api_type != ApiType.MOCK else True api.job('j1', exec_time=20, max_fails=0, expect_invocations=exp_invocations, expect_order=None, unknown_result=unknown_result) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke_unchecked('j1') hyperspeed.sleep(1) # TODO if api.api_type != ApiType.MOCK: with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, require_idle=False) as ctrl1: ctrl1.invoke('j1')
def main(api): with serial( api, timeout=70, securitytoken=security.securitytoken, job_name_prefix="jenkinsflow_demo__errors__", report_interval=3, ) as ctrl1: ctrl1.invoke("wait1-1") with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke("wait2") ctrl3a.invoke("quick_fail-1", force_result="FAILURE", password="******", s1="WORLD", c1="be") # Never invoked ctrl3a.invoke("quick", password="******", s1="WORLD", c1="maybe") with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke("wait5-2a") ctrl3b.invoke("quick_fail-2", force_result="FAILURE", password="******", s1="WORLD", c1="maybe") ctrl3b.invoke("wait5-2b") ctrl3b.invoke("wait5-2c") # Never invoked ctrl1.invoke("wait1-2")
def test_reporting_result_unchecked(api_type, capsys): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=1, expect_order=1) api.job('j21_unchecked', max_fails=0, expect_invocations=1, invocation_delay=0, exec_time=50, initial_buildno=7, expect_order=None, unknown_result=True, serial=True) api.job('j22', max_fails=0, expect_invocations=1, invocation_delay=0, exec_time=1.5, initial_buildno=7, expect_order=2) api.job('j31', max_fails=0, expect_invocations=1, invocation_delay=0, exec_time=1.5, initial_buildno=7, expect_order=3) api.job('j32_unchecked_fail', max_fails=1, expect_invocations=1, invocation_delay=0, exec_time=1.5, initial_buildno=7, expect_order=3) api.job('j41', max_fails=0, expect_invocations=1, invocation_delay=0, exec_time=1.5, initial_buildno=7, expect_order=3) api.job('j42_unchecked', max_fails=0, expect_invocations=1, invocation_delay=0, exec_time=1.5, initial_buildno=7, expect_order=3, serial=True) api.job('j23', max_fails=0, expect_invocations=1, invocation_delay=0, exec_time=1.5, initial_buildno=7, expect_order=4) api.job('j12', max_fails=0, expect_invocations=1, invocation_delay=0, exec_time=5, initial_buildno=7, expect_order=5) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=0.5/api.speedup) as ctrl1: ctrl1.invoke('j11') with ctrl1.serial() as ctrl2: ctrl2.invoke_unchecked('j21_unchecked') ctrl2.invoke('j22') with ctrl2.parallel() as ctrl3: ctrl3.invoke('j31') ctrl3.invoke_unchecked('j32_unchecked_fail') with ctrl3.serial() as ctrl4: ctrl4.invoke('j41') ctrl4.invoke_unchecked('j42_unchecked') ctrl2.invoke('j23') ctrl1.invoke('j12') sout, _ = capsys.readouterr() assert lines_in( api_type, sout, "^UNCHECKED FAILURE: " + result_msg(api, "jenkinsflow_test__reporting_result_unchecked__j32_unchecked_fail"), "^UNCHECKED SUCCESS: " + result_msg(api, "jenkinsflow_test__reporting_result_unchecked__j42_unchecked", 8), )
def test_empty_flow_mix(): with mock_api.api(__file__) as api: api.flow_job() api.job("j11", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job("j31", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=2) api.job("j32", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, serial=True) api.job("j12", exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=4, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke("j11") with ctrl1.parallel(): pass with ctrl1.serial(): pass with ctrl1.parallel() as ctrl2: with ctrl2.serial() as ctrl3a: ctrl3a.invoke("j31") ctrl3a.invoke("j32") with ctrl2.parallel(): pass ctrl1.invoke("j12")
def test_reporting_multiple_invocations(api_type, capsys): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=3, expect_order=None) api.job('j12', max_fails=0, expect_invocations=1, invocation_delay=1.0, exec_time=1.5, initial_buildno=7, expect_order=4, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=0.5/api.speedup) as ctrl1: ctrl1.invoke('j11') ctrl1.invoke('j11') ctrl1.invoke('j11') ctrl1.invoke('j12') sout, _ = capsys.readouterr() empty_re = re.compile("^$") assert lines_in( api_type, sout, "^Defined Invocation-1 http://x.x/job/jenkinsflow_test__reporting_multiple_invocations__j11", "^Defined Invocation-2 http://x.x/job/jenkinsflow_test__reporting_multiple_invocations__j11", "^Defined Invocation-3 http://x.x/job/jenkinsflow_test__reporting_multiple_invocations__j11", "^Defined Invocation http://x.x/job/jenkinsflow_test__reporting_multiple_invocations__j12", empty_re, "--- Starting flow ---", empty_re, "^Flow Invocation (1/1,1/1): ['jenkinsflow_test__reporting_multiple_invocations__j11', 'jenkinsflow_test__reporting_multiple_invocations__j11', 'jenkinsflow_test__reporting_multiple_invocations__j11', 'jenkinsflow_test__reporting_multiple_invocations__j12']", "^Job Invocation-1 (1/1,1/1): http://x.x/job/jenkinsflow_test__reporting_multiple_invocations__j11", build_started_msg(api, "jenkinsflow_test__reporting_multiple_invocations__j11", 1, invocation_number=1), "^Job Invocation (1/1,1/1): http://x.x/job/jenkinsflow_test__reporting_multiple_invocations__j12", build_started_msg(api, "jenkinsflow_test__reporting_multiple_invocations__j12", 8), )
def test_propagate_unstable_serial_toplevel(api_type): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=1, expect_order=1) api.job('j12_unstable', max_fails=0, expect_invocations=1, expect_order=2, final_result='unstable', serial=True) api.job('j13', max_fails=0, expect_invocations=1, expect_order=3, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, raise_if_unsuccessful=False) as ctrl1: ctrl1.invoke('j11') ctrl1.invoke('j12_unstable') ctrl1.invoke('j13') assert ctrl1.result == BuildResult.UNSTABLE return 77
def test_set_build_description_cli_env_url(api_type, env_base_url, cli_runner): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() job_name = 'j1' api.job(job_name, max_fails=0, expect_invocations=1, expect_order=1) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke(job_name, password='******', s1='b') # Need to read the build number job = api.get_job(api.job_name_prefix + job_name) _, _, build_num = job.job_status() _clear_description(api, job) cli_args = [ 'set_build_description', '--job-name', job.name, '--build-number', repr(build_num), '--description', 'BBB1', '--separator', '\n', '--username', username, '--password', password] print("cli args:", cli_args) result = cli_runner.invoke(cli, cli_args) print(result.output) assert not result.exception assert _get_description(api, job, build_num) == 'BBB1'
def test_retry_mix(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j11_fail', max_fails=1, expect_invocations=2, expect_order=1) api.job('j12', max_fails=0, expect_invocations=1, expect_order=2, serial=True) api.job('j21', max_fails=0, expect_invocations=1, expect_order=3, serial=True) api.job('j22_fail', max_fails=2, expect_invocations=3, expect_order=3) api.job('j31_fail', max_fails=3, expect_invocations=4, expect_order=3) api.job('j32', max_fails=0, expect_invocations=1, expect_order=3, serial=True) api.job('j23', max_fails=0, expect_invocations=1, expect_order=3) api.job('j13', max_fails=0, expect_invocations=1, expect_order=4, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, max_tries=2) as ctrl1: ctrl1.invoke('j11_fail') ctrl1.invoke('j12') with ctrl1.parallel(timeout=70, max_tries=3) as ctrl2: ctrl2.invoke('j21') ctrl2.invoke('j22_fail') with ctrl2.serial(timeout=70, max_tries=2) as ctrl3: ctrl3.invoke('j31_fail') ctrl3.invoke('j32') ctrl2.invoke('j23') ctrl1.invoke('j13')
def main(api): with serial(api, timeout=70, securitytoken=security.securitytoken, job_name_prefix='jenkinsflow_demo__hide_password__', report_interval=3, secret_params='.*PASS.*|.*pass.*') as ctrl: # NOTE: In order to ensure that passwords are not displayed in a stacktrace you must never put a literal password # In the last line in the with statement, or in any statement that may raise an exception. You shold not really # put clear text paswords in you code anyway :) p1, p2, p3 = 'SECRET', 'sec', 'not_security' ctrl.invoke('passwd_args', password=p1, s1='no-secret', passwd=p2, PASS=p3)
def test_no_args(): with mock_api.api(__file__) as api: api.flow_job() api.job('job-1', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('job-1')
def test_retry_unchecked_alone_serial_toplevel(): with api_select.api(__file__) as api: api.flow_job() api.job('j11_unchecked', 20, max_fails=1, expect_invocations=1, expect_order=1, invocation_delay=0.000000000000001, unknown_result=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, max_tries=2) as ctrl1: ctrl1.invoke_unchecked('j11_unchecked')
def test_reporting_defined_job_parameters(api_type, capsys): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j1', max_fails=0, expect_invocations=1, invocation_delay=1.0, exec_time=1.5, initial_buildno=7, expect_order=1, serial=True, params=(('s1', '', 'desc'), ('c1', 'what', 'desc'), ('i1', 1, 'integer'), ('b1', False, 'boolean'))) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=0.5 / api.speedup) as ctrl1: ctrl1.invoke('j1', s1="hi", c1='why?', i1=2, b1=True) sout, _ = capsys.readouterr() assert lines_in( api_type, sout, "^Defined Invocation http://x.x/job/jenkinsflow_test__reporting_defined_job_parameters__j1 - parameters:", " i1 = '2'", ) assert " s1 = 'hi'" in sout assert " c1 = 'why?'" in sout assert " b1 = 'true'" in sout
def test_empty_flow_mix(api_type): with api_select.api(__file__, api_type) as api: api.flow_job() api.job('j11', max_fails=0, expect_invocations=1, expect_order=1) api.job('j31', max_fails=0, expect_invocations=1, expect_order=2) api.job('j32', max_fails=0, expect_invocations=1, expect_order=3, serial=True) api.job('j12', max_fails=0, expect_invocations=1, expect_order=4, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('j11') with ctrl1.parallel(): pass with ctrl1.serial(): pass with ctrl1.parallel() as ctrl2: with ctrl2.serial() as ctrl3a: ctrl3a.invoke('j31') ctrl3a.invoke('j32') with ctrl2.parallel(): pass ctrl1.invoke('j12')
def test_json_unchecked_only_in_flows(): with mock_api.api(__file__) as api: flow_name = api.flow_job() api.job('j1_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j2_unchecked', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=None) api.job('j3_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j4_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j5_unchecked', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=None) api.job('j6', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job('j7', exec_time=5, max_fails=0, expect_invocations=1, expect_order=2) json_dir = flow_graph_dir(flow_name) if not os.path.exists(json_dir): os.makedirs(json_dir) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1, json_dir=json_dir) as ctrl1: ctrl1.invoke_unchecked('j1_unchecked') with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke_unchecked('j2_unchecked') ctrl3a.invoke_unchecked('j3_unchecked') with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke_unchecked('j4_unchecked') ctrl3b.invoke_unchecked('j5_unchecked') ctrl1.invoke('j6') ctrl1.invoke('j7') # Test default compact json with open(ctrl1.json_file) as got_jf, open(jp(here, "json_test_unchecked_compact.json")) as expected_jf: _assert_json(got_jf.read().strip(), expected_jf.read().strip())
def test_unicode_auth_latin1(api_type): with api_select.api(__file__, api_type, username="******", password=r'abcæøåÆØÅ') as api: api.flow_job() api.job('j11', 0.01, max_fails=0, expect_invocations=1, invocation_delay=1.0, expect_order=1) with flow.serial(api, timeout=70, job_name_prefix=api.job_name_prefix) as ctrl1: ctrl1.invoke('j11')
def test_multi_level_mixed(): with api_select.api(__file__) as api: api.flow_job() _params = (('password', '', 'Some password'), ('s1', '', 'Some string argument')) api.job('job-1', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1, params=_params) api.job('job-2', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=2, params=_params, serial=True) api.job('job-3', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job('job-4', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job('job-5', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3, params=_params) api.job('job-6', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=4, params=_params) api.job('job-7', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=5, params=_params, serial=True) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('job-1', password='******', s1='b') ctrl1.invoke('job-2', password='******', s1='b') with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3a: ctrl3a.invoke('job-3', password='******', s1='b') ctrl3a.invoke('job-6', password='******', s1='b') with ctrl2.parallel(timeout=40, report_interval=3) as ctrl3b: ctrl3b.invoke('job-4', password='******', s1='b') ctrl3b.invoke('job-5', password='******', s1='b') ctrl1.invoke('job-7', password='******', s1='b')
def test_unicode_params_call(api_type): with api_select.api(__file__, api_type, login=True) as api: api.flow_job() _params = (('password', '', 'Description'),) api.job('job-1', max_fails=0, expect_invocations=1, expect_order=1, params=_params) with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1) as ctrl1: ctrl1.invoke('job-1', password='******')
def flow(api, kill_all, allow_missing_jobs): with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, allow_missing_jobs=allow_missing_jobs, kill_all=kill_all) as ctrl1: with ctrl1.parallel() as ctrl2: ctrl2.invoke_unchecked('j1') ctrl2.invoke_unchecked('j2') with ctrl1.parallel() as ctrl3: ctrl3.invoke('j3') ctrl3.invoke('j4') ctrl3.invoke('j5')