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_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_no_evn = StepResult(step_name='foo', sub_step_name='Mock', sub_step_implementer_name='Mock') step_result_no_evn.add_artifact(name='container-image-tag', value='localhost/mock:0.42.0-weird') workflow_result.add_step_result(step_result=step_result_no_evn) 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') step_result_deploy_test.add_artifact( name='container-image-tag', value='localhost/test/mock:0.42.0-weird') 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') step_result_deploy_test.add_artifact( name='container-image-tag', value='localhost/prod/mock:0.42.0-weird') 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)