def _register_policy(self, pack, policy): content = self._meta_loader.load(policy) pack_field = content.get("pack", None) if not pack_field: content["pack"] = pack pack_field = pack if pack_field != pack: raise Exception( 'Model is in pack "%s" but field "pack" is different: %s' % (pack, pack_field)) # Add in "metadata_file" attribute which stores path to the pack metadata file relative to # the pack directory metadata_file = content_utils.get_relative_path_to_pack_file( pack_ref=pack, file_path=policy, use_pack_cache=True) content["metadata_file"] = metadata_file policy_api = PolicyAPI(**content) policy_api = policy_api.validate() policy_db = PolicyAPI.to_model(policy_api) try: policy_db.id = Policy.get_by_name(policy_api.name).id except StackStormDBObjectNotFoundError: LOG.debug('Policy "%s" is not found. Creating new entry.', policy) try: policy_db = Policy.add_or_update(policy_db) extra = {"policy_db": policy_db} LOG.audit('Policy "%s" is updated.', policy_db.ref, extra=extra) except Exception: LOG.exception("Failed to create policy %s.", policy_api.name) raise
def _register_policy(self, pack, policy): content = self._meta_loader.load(policy) pack_field = content.get('pack', None) if not pack_field: content['pack'] = pack pack_field = pack if pack_field != pack: raise Exception('Model is in pack "%s" but field "pack" is different: %s' % (pack, pack_field)) policy_api = PolicyAPI(**content) policy_api.validate() policy_db = PolicyAPI.to_model(policy_api) try: policy_db.id = Policy.get_by_name(policy_api.name).id except ValueError: LOG.debug('Policy "%s" is not found. Creating new entry.', policy) try: policy_db = Policy.add_or_update(policy_db) extra = {'policy_db': policy_db} LOG.audit('Policy "%s" is updated.', policy_db.ref, extra=extra) except Exception: LOG.exception('Failed to create policy %s.', policy_api.name) raise
def _register_policy(self, pack, policy): content = self._meta_loader.load(policy) pack_field = content.get('pack', None) if not pack_field: content['pack'] = pack pack_field = pack if pack_field != pack: raise Exception('Model is in pack "%s" but field "pack" is different: %s' % (pack, pack_field)) # Add in "metadata_file" attribute which stores path to the pack metadata file relative to # the pack directory metadata_file = content_utils.get_relative_path_to_pack_file(pack_ref=pack, file_path=policy, use_pack_cache=True) content['metadata_file'] = metadata_file policy_api = PolicyAPI(**content) policy_api = policy_api.validate() policy_db = PolicyAPI.to_model(policy_api) try: policy_db.id = Policy.get_by_name(policy_api.name).id except StackStormDBObjectNotFoundError: LOG.debug('Policy "%s" is not found. Creating new entry.', policy) try: policy_db = Policy.add_or_update(policy_db) extra = {'policy_db': policy_db} LOG.audit('Policy "%s" is updated.', policy_db.ref, extra=extra) except Exception: LOG.exception('Failed to create policy %s.', policy_api.name) raise
def _register_policy(self, pack, policy): content = self._meta_loader.load(policy) pack_field = content.get('pack', None) if not pack_field: content['pack'] = pack pack_field = pack if pack_field != pack: raise Exception( 'Model is in pack "%s" but field "pack" is different: %s' % (pack, pack_field)) policy_api = PolicyAPI(**content) policy_api = policy_api.validate() policy_db = PolicyAPI.to_model(policy_api) try: policy_db.id = Policy.get_by_name(policy_api.name).id except StackStormDBObjectNotFoundError: LOG.debug('Policy "%s" is not found. Creating new entry.', policy) try: policy_db = Policy.add_or_update(policy_db) extra = {'policy_db': policy_db} LOG.audit('Policy "%s" is updated.', policy_db.ref, extra=extra) except Exception: LOG.exception('Failed to create policy %s.', policy_api.name) raise
def setUpClass(cls): super(PolicyControllerTest, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES['policytypes']): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policies']): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def setUpClass(cls): super(PolicyControllerTest, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES['policytypes']): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policies']): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def setUpClass(cls): super(PolicyControllerTestCase, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES["policytypes"]): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) cls.policy_dbs = [] for _, fixture in six.iteritems(FIXTURES["policies"]): instance = PolicyAPI(**fixture) policy_db = Policy.add_or_update(PolicyAPI.to_model(instance)) cls.policy_dbs.append(policy_db)
def setUpClass(cls): super(SchedulingPolicyTest, cls).setUpClass() # Register runners runners_registrar.register_runners() for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policytypes']): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policies']): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def setUpClass(cls): super(SchedulingPolicyTest, cls).setUpClass() # Register runners runners_registrar.register_runners() for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policytypes']): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policies']): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def setUpClass(cls): super(PolicyTest, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policytypes']): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policies']): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def setUpClass(cls): super(PolicyTest, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policytypes']): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policies']): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def setUp(self): EventletTestCase.setUpClass() DbTestCase.setUpClass() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policytypes']): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policies']): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def setUp(self): EventletTestCase.setUpClass() DbTestCase.setUpClass() for _, fixture in six.iteritems(FIXTURES["runners"]): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES["actions"]): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES["policytypes"]): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES["policies"]): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))