def test_load_from_pickle_file_empty_file(self): with TempDirectory() as temp_dir: pickle_file = temp_dir.path + '/test.pkl' open(pickle_file, 'a').close() pickle_wfr = WorkflowResult.load_from_pickle_file(pickle_file) expected_wfr = WorkflowResult() self.assertEqual( pickle_wfr._WorkflowResult__get_all_step_results_dict(), expected_wfr._WorkflowResult__get_all_step_results_dict())
def test_load_from_pickle_file_exception(self): with TempDirectory() as temp_dir: pickle_file_name = temp_dir.path + '/test.pkl' pickle_file = open(pickle_file_name, 'w+') pickle_file.write("This is not a Workflow Result.") pickle_file.close() with self.assertRaises(StepRunnerException): WorkflowResult.load_from_pickle_file(pickle_file)
def test_load_from_pickle_file_no_workflowresult(self): with TempDirectory() as temp_dir: pickle_file = temp_dir.path + '/test.pkl' not_wfr = {"step1": "value1", "step2": "value2"} with open(pickle_file, 'wb') as file: pickle.dump(not_wfr, file) with self.assertRaisesRegex( StepRunnerException, f'error {pickle_file} has invalid data'): WorkflowResult.load_from_pickle_file(pickle_file)
def create_given_step_implementer( self, step_implementer, step_config={}, step_name='', environment=None, implementer='', workflow_result=None, work_dir_path='', ): config = Config({ Config.CONFIG_KEY: { step_name: [{ 'implementer': implementer, 'config': step_config }] } }) step_config = config.get_step_config(step_name) sub_step_config = step_config.get_sub_step(implementer) if not workflow_result: workflow_result = WorkflowResult() step_implementer = step_implementer(workflow_result=workflow_result, work_dir_path=work_dir_path, config=sub_step_config, environment=environment) return step_implementer
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_result2 = StepResult('step1', 'sub2', 'implementer2') step_result2.add_artifact('artifact1', True) step_result2.add_artifact('artifact2', False) step_result2.add_artifact('artifact5', 'value5') wfr = WorkflowResult() wfr.add_step_result(step_result1) wfr.add_step_result(step_result2) return wfr
def workflow_result(self): """ Returns ------- WorkflowResult Object containing a list of dictionary of step results from previous steps. """ if not self.__workflow_result: self.__workflow_result = WorkflowResult.load_from_pickle_file( pickle_filename=self.workflow_result_pickle_file_path) return self.__workflow_result
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)
def _run_step_implementer_test(self, config, step, expected_step_results, test_dir, environment=None): working_dir_path = os.path.join(test_dir.path, 'step-runner-working') results_dir_path = os.path.join(test_dir.path, 'step-runner-results') factory = StepRunner(config, results_dir_path, 'step-runner-results.yml', working_dir_path) factory.run_step(step_name=step, environment=environment) pickle = f'{working_dir_path}/step-runner-results.pkl' workflow_results = WorkflowResult.load_from_pickle_file(pickle) step_result = workflow_results.get_step_result(step_name=step) self.assertEqual(expected_step_results, step_result.get_step_result_dict())
def __setup_get_value_with_env_test(self, test_dir, environment): step_config = {'test': 'hello world'} results_dir_path = os.path.join(test_dir.path, 'step-runner-results') results_file_name = 'step-runner-results.yml' 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(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', results_dir_path=results_dir_path, results_file_name=results_file_name, work_dir_path=work_dir_path, environment=environment)
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_result2 = StepResult('step2', 'sub2', 'implementer2') step_result2.add_artifact('artifact1', True) step_result2.add_artifact('artifact2', False) step_result2.add_artifact('artifact5', '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_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') 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 test_load_from_pickle_file_yes_workflow_result(self): with TempDirectory() as temp_dir: pickle_file = temp_dir.path + '/test.pkl' expected_wfr = setup_test() expected_wfr.write_to_pickle_file(pickle_file) pickle_wfr = WorkflowResult.load_from_pickle_file(pickle_file)
def test_load_from_pickle_file_no_file(self): pickle_wfr = WorkflowResult.load_from_pickle_file('test.pkl') expected_wfr = WorkflowResult() self.assertEqual( pickle_wfr._WorkflowResult__get_all_step_results_dict(), expected_wfr._WorkflowResult__get_all_step_results_dict())