def test_load_playbook_file_bad_permissions(self):
     test_permissions = {'a': 42}
     filepath = os.path.join(test_data_path, 'test.json')
     with open(filepath, 'w') as file_out:
         file_out.write(json.dumps(test_permissions))
     os.chmod(filepath, 0o444)
     self.assertIsNone(Loader.load_playbook(filepath))
Esempio n. 2
0
def load_playbook(playbook_name):
    execution_db = ExecutionDatabase.instance
    playbook = JsonPlaybookLoader.load_playbook(
        os.path.join(walkoff.config.Config.WORKFLOWS_PATH, playbook_name + '.playbook'))
    execution_db.session.add(playbook)
    execution_db.session.commit()
    return playbook
Esempio n. 3
0
def load_playbook(playbook_name):
    execution_db = ExecutionDatabase.instance
    playbook = JsonPlaybookLoader.load_playbook(
        os.path.join(walkoff.config.Config.WORKFLOWS_PATH, playbook_name + '.playbook'))
    execution_db.session.add(playbook)
    execution_db.session.commit()
    return playbook
 def test_load_playbook(self):
     workflows = [Workflow('something'), Workflow('something2')]
     playbook = Playbook('test', workflows=workflows)
     filepath = os.path.join(test_data_path, 'test.json')
     with open(filepath, 'w') as file_out:
         file_out.write(json.dumps(playbook.read()))
     loaded = Loader.load_playbook(filepath)
     self.assertIsInstance(loaded, Playbook)
     self.assertEqual(loaded.name, 'test')
Esempio n. 5
0
def import_workflows(app):
    playbook_name = [playbook.id for playbook in app.running_context.execution_db.session.query(Playbook).all()]
    if os.path.exists(walkoff.config.Config.WORKFLOWS_PATH):
        logger.info('Importing any workflows not currently in database')
        for p in os.listdir(walkoff.config.Config.WORKFLOWS_PATH):
            full_path = os.path.join(walkoff.config.Config.WORKFLOWS_PATH, p)
            if os.path.isfile(full_path):
                playbook = JsonPlaybookLoader.load_playbook(full_path)
                if playbook.name not in playbook_name:
                    app.running_context.execution_db.session.add(playbook)
        app.running_context.execution_db.session.commit()
 def test_load_playbook_invalid_app(self):
     workflow_json = {
         "name": "test_workflow",
         "start": "start",
         "actions": [{"action": "invalid",
                      "app": "Invalid",
                      "name": "start",
                      "branches": []}]}
     playbook_json = {'name': 'test_playbook', 'workflows': [workflow_json]}
     filepath = os.path.join(test_data_path, 'test.json')
     with open(filepath, 'w') as file_out:
         file_out.write(json.dumps(playbook_json))
     self.assertIsNone(Loader.load_playbook(filepath))
Esempio n. 7
0
def load_workflow(playbook_name, workflow_name):
    playbook = JsonPlaybookLoader.load_playbook(
        os.path.join(test_workflows_path, playbook_name + '.playbook'))
    executiondb.execution_db.session.add(playbook)
    executiondb.execution_db.session.commit()

    workflow = None
    for wf in playbook.workflows:
        if wf.name == workflow_name:
            workflow = wf
            break

    return workflow
Esempio n. 8
0
def import_workflows(app):
    playbook_name = [
        playbook.id for playbook in
        app.running_context.execution_db.session.query(Playbook).all()
    ]
    if os.path.exists(walkoff.config.Config.WORKFLOWS_PATH):
        logger.info('Importing any workflows not currently in database')
        for p in os.listdir(walkoff.config.Config.WORKFLOWS_PATH):
            full_path = os.path.join(walkoff.config.Config.WORKFLOWS_PATH, p)
            if os.path.isfile(full_path):
                playbook = JsonPlaybookLoader.load_playbook(full_path)
                if playbook.name not in playbook_name:
                    app.running_context.execution_db.session.add(playbook)
        app.running_context.execution_db.session.commit()
Esempio n. 9
0
def load_workflow(playbook_name, workflow_name):
    execution_db = ExecutionDatabase.instance
    playbook = JsonPlaybookLoader.load_playbook(
        os.path.join(walkoff.config.Config.WORKFLOWS_PATH, playbook_name + '.playbook'))
    execution_db.session.add(playbook)
    execution_db.session.commit()

    workflow = None
    for wf in playbook.workflows:
        if wf.name == workflow_name:
            workflow = wf
            break

    return workflow
Esempio n. 10
0
def load_workflow(playbook_name, workflow_name):
    execution_db = ExecutionDatabase.instance
    playbook = JsonPlaybookLoader.load_playbook(
        os.path.join(walkoff.config.Config.WORKFLOWS_PATH, playbook_name + '.playbook'))
    execution_db.session.add(playbook)
    execution_db.session.commit()

    workflow = None
    for wf in playbook.workflows:
        if wf.name == workflow_name:
            workflow = wf
            break

    return workflow
 def test_load_playbook_invalid_json_format(self):
     test_invalid_json = 'something not json'
     filepath = os.path.join(test_data_path, 'test.json')
     with open(filepath, 'w') as file_out:
         file_out.write(test_invalid_json)
     self.assertIsNone(Loader.load_playbook(filepath))
 def test_load_playbook_file_dne(self):
     self.assertIsNone(Loader.load_playbook('/some/invalid/workflow.invalid'))
Esempio n. 13
0
def load_playbook(playbook_name):
    playbook = JsonPlaybookLoader.load_playbook(
        os.path.join(test_workflows_path, playbook_name + '.playbook'))
    executiondb.execution_db.session.add(playbook)
    executiondb.execution_db.session.commit()
    return playbook