def setup_test_sub_steps(): step_result1 = StepResult('step1', 'sub1', 'implementer1') step_result1.add_artifact('artifact1', 'value1', 'description1') step_result1.add_artifact('artifact2', 'value2', 'description2') step_result1.add_artifact('artifact3', 'value3') step_result1.add_artifact('artifact4', False) step_result1.add_evidence('evidence1', 'value1', 'description1') step_result1.add_evidence('evidence2', 'value2', 'description2') step_result1.add_evidence('evidence3', 'value3') step_result1.add_evidence('evidence4', False) step_result2 = StepResult('step1', 'sub2', 'implementer2') step_result2.add_artifact('artifact1', True) step_result2.add_artifact('artifact2', False) step_result2.add_artifact('artifact5', 'value5') step_result2.add_evidence('evidence1', True) step_result2.add_evidence('evidence2', False) step_result2.add_evidence('evidence5', 'value5') wfr = WorkflowResult() wfr.add_step_result(step_result1) wfr.add_step_result(step_result2) return wfr
def setup_previous_result(self, work_dir_path, artifact_config={}): step_result = StepResult( step_name='test-step', sub_step_name='test-sub-step-name', sub_step_implementer_name='test-step-implementer-name') for key1, val1 in artifact_config.items(): description = '' value = '' for key2, val2 in val1.items(): if key2 == 'description': description = val2 elif key2 == 'value': value = val2 else: raise StepRunnerException( f'Given field is not apart of an artifact: {key2}') step_result.add_artifact( name=key1, value=value, description=description, ) workflow_result = WorkflowResult() workflow_result.add_step_result(step_result=step_result) pickle_filename = os.path.join(work_dir_path, 'step-runner-results.pkl') workflow_result.write_to_pickle_file(pickle_filename=pickle_filename) return workflow_result
def setup_test(): step_result1 = StepResult('step1', 'sub1', 'implementer1') step_result1.add_artifact('artifact1', 'value1', 'description1') step_result1.add_artifact('artifact2', 'value2', 'description2') step_result1.add_artifact('artifact3', 'value3') step_result1.add_artifact('artifact4', False) step_result1.add_artifact('same-artifact-all-env-and-no-env', 'result1') step_result1.add_evidence('evidence1', 'value1', 'description1') step_result1.add_evidence('evidence2', 'value2', 'description2') step_result1.add_evidence('evidence3', 'value3') step_result1.add_evidence('evidence4', False) step_result1.add_evidence('same-evidence-all-env-and-no-env', 'result1') step_result2 = StepResult('step2', 'sub2', 'implementer2') step_result2.add_artifact('artifact1', True) step_result2.add_artifact('artifact2', False) step_result2.add_artifact('artifact5', 'value5') step_result2.add_evidence('evidence1', True) step_result2.add_evidence('evidence2', False) step_result2.add_evidence('evidence5', 'value5') step_result3 = StepResult('deploy', 'deploy-sub', 'helm', 'dev') step_result3.add_artifact('same-artifact-diff-env', 'value-dev-env') step_result3.add_artifact('unique-artifact-to-step-and-environment-1', 'value1-dev-env') step_result3.add_artifact('same-artifact-all-env-and-no-env', 'result3-dev-env') step_result3.add_evidence('same-evidence-diff-env', 'value-dev-env') step_result3.add_evidence('unique-evidence-to-step-and-environment-1', 'value1-dev-env') step_result3.add_evidence('same-evidence-all-env-and-no-env', 'result3-dev-env') step_result4 = StepResult('deploy', 'deploy-sub', 'helm', 'test') step_result4.add_artifact('artifact1', True) step_result4.add_artifact('artifact2', False) step_result4.add_artifact('artifact5', 'value5') step_result4.add_artifact('same-artifact-diff-env', 'value-test-env') step_result4.add_artifact('unique-artifact-to-step-and-environment-2', 'value2-test-env') step_result4.add_artifact('same-artifact-all-env-and-no-env', 'result4-test-env') step_result4.add_evidence('evidence1', True) step_result4.add_evidence('evidence2', False) step_result4.add_evidence('evidence5', 'value5') step_result4.add_evidence('same-evidence-diff-env', 'value-test-env') step_result4.add_evidence('unique-evidence-to-step-and-environment-2', 'value2-test-env') step_result4.add_evidence('same-evidence-all-env-and-no-env', 'result4-test-env') wfr = WorkflowResult() wfr.add_step_result(step_result1) wfr.add_step_result(step_result2) wfr.add_step_result(step_result3) wfr.add_step_result(step_result4) return wfr
def _setup_get_value_with_env_test(self, test_dir, environment): step_config = { 'test': 'hello world', 'old-param-name': 'foo42', 'new-param-name': 'bar42' } parent_work_dir_path = os.path.join(test_dir.path, 'working') workflow_result = WorkflowResult() step_result_deploy_test = StepResult( step_name='deploy', sub_step_name='ArgoCD', sub_step_implementer_name='ArgoCD', environment='TEST' ) step_result_deploy_test.add_artifact( name='deployed-host-urls', value='https://awesome-app.test.ploigos.xyz' ) workflow_result.add_step_result(step_result=step_result_deploy_test) step_result_deploy_prod = StepResult( step_name='deploy', sub_step_name='ArgoCD', sub_step_implementer_name='ArgoCD', environment='PROD' ) step_result_deploy_prod.add_artifact( name='deployed-host-urls', value='https://awesome-app.prod.ploigos.xyz' ) workflow_result.add_step_result(step_result=step_result_deploy_prod) pickle_filename = os.path.join(parent_work_dir_path, 'step-runner-results.pkl') workflow_result.write_to_pickle_file(pickle_filename=pickle_filename) return self.create_given_step_implementer( step_implementer=FooStepImplementer, step_config=step_config, step_name='foo', implementer='FooStepImplementer', workflow_result=workflow_result, parent_work_dir_path=parent_work_dir_path, environment=environment )
def test_merge_matching_stepresults_on_pickle(self): """When we pickle to disk, make sure we merge the artifacts and evidence from in-memory StepResult instances with those on disk. Whatever is in memory wins. """ with TempDirectory() as temp_dir: pickle_file = temp_dir.path + '/test.pkl' expected_wfr = setup_test() expected_wfr.write_to_pickle_file(pickle_file) # now adjust our expected WorkflowResult to include the # amended evidence/artifacts we expect to see. All other # StepResults and their artifacts/evidence are left the same. expected_sr_no_env = expected_wfr.get_step_result('step1', 'sub1') expected_sr_no_env.add_artifact('artifact1', 'changed-value1', 'description1') expected_sr_no_env.add_evidence('evidence1', 'changed-value1', 'description1') expected_sr_env = expected_wfr.get_step_result( 'deploy', 'deploy-sub', 'dev') expected_sr_env.add_artifact('artifact1', 'changed-value1') expected_sr_env.add_evidence('evidence1', 'changed-value1', 'description1') # now build our 'in memory' WFR that we're going to write # to disk. this has the amended evidence/artifacts. # one StepResult with environment, one without. in_mem_wfr = WorkflowResult() sr_no_env = StepResult('step1', 'sub1', 'implementer1') sr_no_env.add_artifact('artifact1', 'changed-value1', 'description1') sr_no_env.add_evidence('evidence1', 'changed-value1', 'description1') sr_env = StepResult('deploy', 'deploy-sub', 'helm', 'dev') sr_env.add_artifact('artifact1', 'changed-value1') sr_env.add_evidence('evidence1', 'changed-value1', 'description1') in_mem_wfr.add_step_result(sr_no_env) in_mem_wfr.add_step_result(sr_env) # write in-memory to disk post-merging in_mem_wfr.merge_with_pickle_file(pickle_file) in_mem_wfr.write_to_pickle_file(pickle_file) resulting_wfr = WorkflowResult.load_from_pickle_file(pickle_file) resulting_workflow_list = resulting_wfr.workflow_list for expected_result in expected_wfr.workflow_list: merged_result = resulting_wfr.get_step_result( step_name=expected_result.step_name, sub_step_name=expected_result.sub_step_name, environment=expected_result.environment) self.assertEqual(expected_result, merged_result) resulting_workflow_list.remove(expected_result) # nothing duplicate or extra should be in the result self.assertEqual(len(resulting_workflow_list), 0)