def test_accumulated_risk_with_error(self): workflow = Workflow(name='workflow') step1 = Step(name="step_one", app='HelloWorld', action='Buggy', risk=1) step2 = Step(name="step_two", app='HelloWorld', action='Buggy', risk=2) step3 = Step(name="step_three", app='HelloWorld', action='Buggy', risk=3.5) workflow.steps = { 'step_one': step1, 'step_two': step2, 'step_three': step3 } workflow.total_risk = 6.5 instance = Instance.create(app_name='HelloWorld', device_name='test_device_name') workflow._Workflow__execute_step(workflow.steps["step_one"], instance) self.assertAlmostEqual(workflow.accumulated_risk, 1.0 / 6.5) workflow._Workflow__execute_step(workflow.steps["step_two"], instance) self.assertAlmostEqual(workflow.accumulated_risk, (1.0 / 6.5) + (2.0 / 6.5)) workflow._Workflow__execute_step(workflow.steps["step_three"], instance) self.assertAlmostEqual(workflow.accumulated_risk, 1.0)
def test_name_parent_step_rename(self): workflow = Workflow(parent_name='workflow_parent', name='workflow') step = Step(name="test_step", action='helloWorld', app='HelloWorld', ancestry=workflow.ancestry) workflow.steps["test_step"] = step new_ancestry = ["workflow_parent_update"] workflow.reconstruct_ancestry(new_ancestry) new_ancestry.append("workflow") new_ancestry.append("test_step") self.assertListEqual(new_ancestry, workflow.steps["test_step"].ancestry)
def test_simple_risk(self): workflow = Workflow(name='workflow') workflow.create_step(name="stepOne", action='helloWorld', app='HelloWorld', risk=1) workflow.create_step(name="stepTwo", action='helloWorld', app='HelloWorld', risk=2) workflow.create_step(name="stepThree", action='helloWorld', app='HelloWorld', risk=3) self.assertEqual(workflow.total_risk, 6)
def run_workflow(workflow_name): config = get_config() workflow_path = config['paths']['workflows_path'] + workflow_name workflow = Workflow(workflow_path) workflow_valid = workflow.validate() if workflow_valid: components = verify_components(workflow) if not components: logger.error('components declared in workflow are missing') exit(1) #requirements = generate_workflow_requirements(workflow) #virtual_environment = setup_virtual_environment(requirements, workflow_name) state = execute_workflow(workflow.steps) if state is True: logger.info('workflow executed') else: logger.info('failed to execute workflow') print('\n') else: logger.error('invalid workflow') exit(1)
def test_name_parent_rename(self): workflow = Workflow(parent_name='workflow_parent', name='workflow') new_ancestry = ['workflow_parent_update'] workflow.reconstruct_ancestry(new_ancestry) new_ancestry.append('workflow') self.assertListEqual(new_ancestry, workflow.ancestry)