def test_json_strip_prefix(): with mock_api.api(__file__) as api: flow_name = api.flow_job() api.job('j1', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job('j2', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=2) api.job('j3', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j4', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j5', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j6', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j7_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j8_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j9', exec_time=5, max_fails=0, expect_invocations=1, expect_order=4) ctrl1 = _flow(api, True, flow_graph_dir(flow_name)) # Test pretty printing json_file = jp(flow_graph_dir(flow_name), "pretty.json") ctrl1.json(json_file, indent=4) with open(json_file) as jf: _assert_json(jf.read().strip(), _pretty_json) # Test default compact json with open(ctrl1.json_file) as jf: _assert_json(jf.read().strip(), _compact_json) # Test return json json = ctrl1.json(None) _assert_json(json, _compact_json)
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 main(api): logging.basicConfig() logging.getLogger("").setLevel(logging.WARNING) print("Doing stuff before flow ...") demo_name = "jenkinsflow_demo__calculated_flow" graph_output_dir = flow_graph_dir(demo_name) if not os.path.exists(graph_output_dir): os.makedirs(graph_output_dir) g1_components = range(1) g2_components = range(2) g3_components = range(2) component_groups = OrderedDict((("g1", g1_components), ("g2", g2_components), ("g3", g3_components))) # Flow with serial( api, timeout=70, securitytoken=security.securitytoken, job_name_prefix=demo_name + "__", report_interval=3, # Write json flow graph to display in browser, see INSTALL.md json_dir=graph_output_dir, json_indent=4, ) as ctrl1: ctrl1.invoke("prepare") with ctrl1.parallel(timeout=0, report_interval=3) as ctrl2: for gname, group in component_groups.items(): with ctrl2.serial(timeout=0, report_interval=3) as ctrl3: for component in group: ctrl3.invoke("deploy_component_" + gname + "_" + str(component)) with ctrl1.parallel(timeout=0, report_interval=3) as ctrl2: ctrl2.invoke("report_deploy") ctrl2.invoke("prepare_tests") with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3: ctrl3.invoke("test_ui") with ctrl3.parallel(timeout=0, report_interval=3) as ctrl4: for gname, group in component_groups.items(): for component in group: ctrl4.invoke("test_component_" + gname + "_" + str(component)) ctrl2.invoke("test_x") ctrl1.invoke("report", password="******", s1="tst_regression", c1="complete") ctrl1.invoke("promote") print("Doing stuff after flow ...")
def test_json_no_strip_prefix(): with mock_api.api(__file__) as api: flow_name = api.flow_job() api.job('j1', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=1) api.job('j2', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=2) api.job('j3', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j4', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j5', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j6', exec_time=0.01, max_fails=0, expect_invocations=1, expect_order=3) api.job('j7_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j8_unchecked', exec_time=40, max_fails=0, expect_invocations=1, invocation_delay=0.0000000000001, expect_order=None, unknown_result=True) api.job('j9', exec_time=5, max_fails=0, expect_invocations=1, expect_order=4) ctrl1 = _flow(api, False, flow_graph_dir(flow_name)) # Test pretty printing with no stripping of top level prefix json_file = jp(flow_graph_dir(flow_name), "verbose_pretty.json") ctrl1.json(json_file, indent=4) with open(json_file) as jf: got_json = jf.read().strip() expect_json = _pretty_json.replace('strip_prefix', 'no_strip_prefix').replace('name": "', 'name": "jenkinsflow_test__json_no_strip_prefix__') _assert_json(got_json, expect_json)
def test_just_dump_with_json(): with mock_api.api(__file__) as api: flow_name = api.flow_job() api.job('j1', exec_time=0.01, max_fails=0, expect_invocations=0, expect_order=None) api.job('j2', exec_time=0.01, max_fails=0, expect_invocations=0, expect_order=None) api.job('j3_unchecked', exec_time=40, max_fails=0, expect_invocations=0, expect_order=None) api.job('j4', exec_time=5, max_fails=0, expect_invocations=0, expect_order=None) api.job('j5', exec_time=5, max_fails=0, expect_invocations=0, expect_order=None) fgd = flow_graph_dir(flow_name) ctrl1 = _flow(api, fgd) # Test json json = ctrl1.json(None) _assert_json(json, _compact_json)
def main(api): logging.basicConfig() logging.getLogger("").setLevel(logging.WARNING) print("Doing stuff before flow ...") demo_name = 'jenkinsflow_demo__basic' graph_output_dir = flow_graph_dir(demo_name) if not os.path.exists(graph_output_dir): os.makedirs(graph_output_dir) g1_components = range(1) g2_components = range(2) g3_components = range(2) component_groups = OrderedDict((('g1', g1_components), ('g2', g2_components), ('g3', g3_components))) # Flow with serial(api, timeout=70, securitytoken=security.securitytoken, job_name_prefix=demo_name + '__', report_interval=3, # Write json flow graph to display in browser, see INSTALL.md json_dir=graph_output_dir, json_indent=4) as ctrl1: ctrl1.invoke('prepare') with ctrl1.parallel(timeout=0, report_interval=3) as ctrl2: for gname, group in component_groups.items(): with ctrl2.serial(timeout=0, report_interval=3) as ctrl3: for component in group: ctrl3.invoke('deploy_component_' + gname + '_' + str(component)) with ctrl1.parallel(timeout=0, report_interval=3) as ctrl2: ctrl2.invoke('report_deploy') ctrl2.invoke('prepare_tests') with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2: with ctrl2.serial(timeout=40, report_interval=3) as ctrl3: ctrl3.invoke('test_ui') with ctrl3.parallel(timeout=0, report_interval=3) as ctrl4: for gname, group in component_groups.items(): for component in group: ctrl4.invoke('test_component_' + gname + '_' + str(component)) ctrl2.invoke('test_x') ctrl1.invoke('report', password='******', s1='tst_regression', c1='complete') ctrl1.invoke('promote') print("Doing stuff after flow ...")