def register_policy_types(module): registered_count = 0 mod_path = os.path.dirname(os.path.realpath(sys.modules[module.__name__].__file__)) path = '%s/policies/meta' % mod_path files = [] for ext in ALLOWED_EXTS: exp = '%s/*%s' % (path, ext) files += glob.glob(exp) for f in files: try: LOG.debug('Loading policy type from "%s".', f) content = loader.load_meta_file(f) policy_type_api = PolicyTypeAPI(**content) policy_type_db = PolicyTypeAPI.to_model(policy_type_api) try: existing_entry = PolicyType.get_by_ref(policy_type_db.ref) if existing_entry: policy_type_db.id = existing_entry.id except ValueError: LOG.debug('Policy type "%s" is not found. Creating new entry.', policy_type_db.ref) policy_type_db = PolicyType.add_or_update(policy_type_db) extra = {'policy_type_db': policy_type_db} LOG.audit('Policy type "%s" is updated.', policy_type_db.ref, extra=extra) registered_count += 1 except: LOG.exception('Unable to register policy type from "%s".', f) return registered_count
def register_policy_types(module): registered_count = 0 mod_path = os.path.dirname(os.path.realpath(sys.modules[module.__name__].__file__)) path = os.path.join(mod_path, 'policies/meta') files = [] for ext in ALLOWED_EXTS: exp = '%s/*%s' % (path, ext) files += glob.glob(exp) for f in files: try: LOG.debug('Loading policy type from "%s".', f) content = loader.load_meta_file(f) policy_type_api = PolicyTypeAPI(**content) policy_type_db = PolicyTypeAPI.to_model(policy_type_api) try: existing_entry = PolicyType.get_by_ref(policy_type_db.ref) if existing_entry: policy_type_db.id = existing_entry.id except StackStormDBObjectNotFoundError: LOG.debug('Policy type "%s" is not found. Creating new entry.', policy_type_db.ref) policy_type_db = PolicyType.add_or_update(policy_type_db) extra = {'policy_type_db': policy_type_db} LOG.audit('Policy type "%s" is updated.', policy_type_db.ref, extra=extra) registered_count += 1 except: LOG.exception('Unable to register policy type from "%s".', f) return registered_count
def get_wf_fixture_meta_data(self, fixture_pack_path, wf_meta_file_name): wf_meta_file_path = fixture_pack_path + '/actions/' + wf_meta_file_name wf_meta_content = loader.load_meta_file(wf_meta_file_path) wf_name = wf_meta_content['pack'] + '.' + wf_meta_content['name'] return { 'file_name': wf_meta_file_name, 'file_path': wf_meta_file_path, 'content': wf_meta_content, 'name': wf_name }
def get_wf_fixture_meta_data(fixture_pack_path, wf_meta_file_name): wf_meta_file_path = fixture_pack_path + '/actions/' + wf_meta_file_name wf_meta_content = loader.load_meta_file(wf_meta_file_path) wf_name = wf_meta_content['pack'] + '.' + wf_meta_content['name'] return { 'file_name': wf_meta_file_name, 'file_path': wf_meta_file_path, 'content': wf_meta_content, 'name': wf_name }
def get_wf_fixture_meta_data(fixture_pack_path, wf_meta_file_name): wf_meta_file_path = fixture_pack_path + "/actions/" + wf_meta_file_name wf_meta_content = loader.load_meta_file(wf_meta_file_path) wf_name = wf_meta_content["pack"] + "." + wf_meta_content["name"] return { "file_name": wf_meta_file_name, "file_path": wf_meta_file_path, "content": wf_meta_content, "name": wf_name, }
TEST_PACK = 'mistral_tests' TEST_PACK_PATH = fixturesloader.get_fixtures_packs_base_path() + '/' + TEST_PACK PACKS = [ TEST_PACK_PATH, fixturesloader.get_fixtures_packs_base_path() + '/core' ] # Action executions requirements ACTION_PARAMS = {'friend': 'Rocky'} NON_EMPTY_RESULT = 'non-empty' # Non-workbook with a single workflow WF1_META_FILE_NAME = 'workflow_v2.yaml' WF1_META_FILE_PATH = TEST_PACK_PATH + '/actions/' + WF1_META_FILE_NAME WF1_META_CONTENT = loader.load_meta_file(WF1_META_FILE_PATH) WF1_NAME = WF1_META_CONTENT['pack'] + '.' + WF1_META_CONTENT['name'] WF1_ENTRY_POINT = TEST_PACK_PATH + '/actions/' + WF1_META_CONTENT['entry_point'] WF1_ENTRY_POINT_X = WF1_ENTRY_POINT.replace(WF1_META_FILE_NAME, 'xformed_' + WF1_META_FILE_NAME) WF1_SPEC = yaml.safe_load(MistralRunner.get_workflow_definition(WF1_ENTRY_POINT_X)) WF1_YAML = yaml.safe_dump(WF1_SPEC, default_flow_style=False) WF1 = workflows.Workflow(None, {'name': WF1_NAME, 'definition': WF1_YAML}) WF1_OLD = workflows.Workflow(None, {'name': WF1_NAME, 'definition': ''}) WF1_EXEC = {'id': str(uuid.uuid4()), 'state': 'RUNNING', 'workflow_name': WF1_NAME} WF1_EXEC_CANCELLED = copy.deepcopy(WF1_EXEC) WF1_EXEC_CANCELLED['state'] = 'CANCELLED' # Workflow with a subworkflow action WF2_META_FILE_NAME = 'workflow_v2_call_workflow_action.yaml' WF2_META_FILE_PATH = TEST_PACK_PATH + '/actions/' + WF2_META_FILE_NAME WF2_META_CONTENT = loader.load_meta_file(WF2_META_FILE_PATH)
TEST_PACK_PATH = fixturesloader.get_fixtures_packs_base_path( ) + '/' + TEST_PACK PACKS = [ TEST_PACK_PATH, fixturesloader.get_fixtures_packs_base_path() + '/core' ] # Action executions requirements ACTION_PARAMS = {'friend': 'Rocky'} NON_EMPTY_RESULT = 'non-empty' # Non-workbook with a single workflow WF1_META_FILE_NAME = 'workflow_v2.yaml' WF1_META_FILE_PATH = TEST_PACK_PATH + '/actions/' + WF1_META_FILE_NAME WF1_META_CONTENT = loader.load_meta_file(WF1_META_FILE_PATH) WF1_NAME = WF1_META_CONTENT['pack'] + '.' + WF1_META_CONTENT['name'] WF1_ENTRY_POINT = TEST_PACK_PATH + '/actions/' + WF1_META_CONTENT['entry_point'] WF1_ENTRY_POINT_X = WF1_ENTRY_POINT.replace(WF1_META_FILE_NAME, 'xformed_' + WF1_META_FILE_NAME) WF1_SPEC = yaml.safe_load( MistralRunner.get_workflow_definition(WF1_ENTRY_POINT_X)) WF1_YAML = yaml.safe_dump(WF1_SPEC, default_flow_style=False) WF1 = workflows.Workflow(None, {'name': WF1_NAME, 'definition': WF1_YAML}) WF1_OLD = workflows.Workflow(None, {'name': WF1_NAME, 'definition': ''}) WF1_EXEC = { 'id': str(uuid.uuid4()), 'state': 'RUNNING', 'workflow_name': WF1_NAME } WF1_EXEC_CANCELLED = copy.deepcopy(WF1_EXEC)