本文整理汇总了Python中st2common.persistence.policy.Policy类的典型用法代码示例。如果您正苦于以下问题:Python Policy类的具体用法?Python Policy怎么用?Python Policy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Policy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _register_policy
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
开发者ID:emptywee,项目名称:st2,代码行数:26,代码来源:policiesregistrar.py
示例2: _register_policy
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
开发者ID:StackStorm,项目名称:st2,代码行数:33,代码来源:policiesregistrar.py
示例3: test_register_all_policies
def test_register_all_policies(self):
policies_dbs = Policy.get_all()
self.assertEqual(len(policies_dbs), 0)
packs_base_path = get_fixtures_packs_base_path()
count = policies_registrar.register_policies(packs_base_paths=[packs_base_path])
# Verify PolicyDB objects have been created
policies_dbs = Policy.get_all()
policies = {
policies_db.name: {
'pack': policies_db.pack,
'type': policies_db.policy_type,
'parameters': policies_db.parameters
}
for policies_db in policies_dbs
}
expected_policies = {
'test_policy_1': {
'pack': 'dummy_pack_1',
'type': 'action.concurrency',
'parameters': {
'action': 'delay',
'threshold': 3
}
},
'test_policy_3': {
'pack': 'dummy_pack_1',
'type': 'action.retry',
'parameters': {
'retry_on': 'timeout',
'max_retry_count': 5
}
},
'cancel_on_concurrency': {
'pack': 'mistral_tests',
'type': 'action.concurrency',
'parameters': {
'action': 'cancel',
'threshold': 3
}
},
'cancel_on_concurrency_by_attr': {
'pack': 'mistral_tests',
'type': 'action.concurrency.attr',
'parameters': {
'action': 'cancel',
'threshold': 1,
'attributes': ['friend']
}
}
}
self.assertEqual(len(expected_policies), count)
self.assertEqual(len(expected_policies), len(policies_dbs))
self.assertDictEqual(expected_policies, policies)
开发者ID:lyandut,项目名称:st2,代码行数:58,代码来源:test_policies_registrar.py
示例4: setUpClass
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))
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:10,代码来源:test_policies.py
示例5: test_run
def test_run(self):
pack = 'dummy_pack_1'
# Verify all the resources are there
pack_dbs = Pack.query(ref=pack)
action_dbs = Action.query(pack=pack)
alias_dbs = ActionAlias.query(pack=pack)
rule_dbs = Rule.query(pack=pack)
sensor_dbs = Sensor.query(pack=pack)
trigger_type_dbs = TriggerType.query(pack=pack)
policy_dbs = Policy.query(pack=pack)
config_schema_dbs = ConfigSchema.query(pack=pack)
config_dbs = Config.query(pack=pack)
self.assertEqual(len(pack_dbs), 1)
self.assertEqual(len(action_dbs), 1)
self.assertEqual(len(alias_dbs), 2)
self.assertEqual(len(rule_dbs), 1)
self.assertEqual(len(sensor_dbs), 3)
self.assertEqual(len(trigger_type_dbs), 4)
self.assertEqual(len(policy_dbs), 2)
self.assertEqual(len(config_schema_dbs), 1)
self.assertEqual(len(config_dbs), 1)
# Run action
action = self.get_action_instance()
action.run(packs=[pack])
# Make sure all resources have been removed from the db
pack_dbs = Pack.query(ref=pack)
action_dbs = Action.query(pack=pack)
alias_dbs = ActionAlias.query(pack=pack)
rule_dbs = Rule.query(pack=pack)
sensor_dbs = Sensor.query(pack=pack)
trigger_type_dbs = TriggerType.query(pack=pack)
policy_dbs = Policy.query(pack=pack)
config_schema_dbs = ConfigSchema.query(pack=pack)
config_dbs = Config.query(pack=pack)
self.assertEqual(len(pack_dbs), 0)
self.assertEqual(len(action_dbs), 0)
self.assertEqual(len(alias_dbs), 0)
self.assertEqual(len(rule_dbs), 0)
self.assertEqual(len(sensor_dbs), 0)
self.assertEqual(len(trigger_type_dbs), 0)
self.assertEqual(len(policy_dbs), 0)
self.assertEqual(len(config_schema_dbs), 0)
self.assertEqual(len(config_dbs), 0)
开发者ID:lyandut,项目名称:st2,代码行数:52,代码来源:test_action_unload.py
示例6: test_register_policies
def test_register_policies(self):
# Note: Only one policy should be registered since second one fails validation
pack_dir = os.path.join(fixturesloader.get_fixtures_base_path(), "dummy_pack_1")
self.assertEqual(register_policies(pack_dir=pack_dir), 1)
p1 = Policy.get_by_ref("dummy_pack_1.test_policy_1")
self.assertEqual(p1.name, "test_policy_1")
self.assertEqual(p1.pack, "dummy_pack_1")
self.assertEqual(p1.resource_ref, "dummy_pack_1.local")
self.assertEqual(p1.policy_type, "action.concurrency")
p2 = Policy.get_by_ref("dummy_pack_1.test_policy_2")
self.assertEqual(p2, None)
开发者ID:azamsheriff,项目名称:st2,代码行数:13,代码来源:test_policies.py
示例7: test_delete_sys_pack
def test_delete_sys_pack(self):
instance = self.__create_instance()
instance['pack'] = 'core'
post_resp = self.__do_post(instance)
self.assertEqual(post_resp.status_int, http_client.CREATED)
del_resp = self.__do_delete(self.__get_obj_id(post_resp))
self.assertEqual(del_resp.status_int, http_client.BAD_REQUEST)
self.assertEqual(del_resp.json['faultstring'],
"Resources belonging to system level packs can't be manipulated")
# Clean up manually since API won't delete object in sys pack.
Policy.delete(Policy.get_by_id(self.__get_obj_id(post_resp)))
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:14,代码来源:test_policies.py
示例8: test_register_policies_from_pack
def test_register_policies_from_pack(self):
pack_dir = os.path.join(get_fixtures_packs_base_path(), 'dummy_pack_1')
self.assertEqual(register_policies(pack_dir=pack_dir), 2)
p1 = Policy.get_by_ref('dummy_pack_1.test_policy_1')
self.assertEqual(p1.name, 'test_policy_1')
self.assertEqual(p1.pack, 'dummy_pack_1')
self.assertEqual(p1.resource_ref, 'dummy_pack_1.local')
self.assertEqual(p1.policy_type, 'action.concurrency')
# Verify that a default value for parameter "action" which isn't provided in the file is set
self.assertEqual(p1.parameters['action'], 'delay')
p2 = Policy.get_by_ref('dummy_pack_1.test_policy_2')
self.assertEqual(p2, None)
开发者ID:LindsayHill,项目名称:st2,代码行数:14,代码来源:test_policies_registrar.py
示例9: test_register_policies
def test_register_policies(self):
pack_dir = os.path.join(fixturesloader.get_fixtures_base_path(), 'dummy_pack_1')
self.assertEqual(register_policies(pack_dir=pack_dir), 2)
p1 = Policy.get_by_ref('dummy_pack_1.test_policy_1')
self.assertEqual(p1.name, 'test_policy_1')
self.assertEqual(p1.pack, 'dummy_pack_1')
self.assertEqual(p1.resource_ref, 'dummy_pack_1.local')
self.assertEqual(p1.policy_type, 'action.concurrency')
p2 = Policy.get_by_ref('dummy_pack_1.test_policy_2')
self.assertEqual(p2.name, 'test_policy_2')
self.assertEqual(p2.pack, 'dummy_pack_1')
self.assertEqual(p2.resource_ref, 'dummy_pack_1.local')
self.assertEqual(p2.policy_type, 'action.mock_policy_error')
self.assertEqual(p2.resource_ref, 'dummy_pack_1.local')
开发者ID:hejin,项目名称:st2,代码行数:16,代码来源:test_policies.py
示例10: test_over_threshold
def test_over_threshold(self):
policy_db = Policy.get_by_ref("wolfpack.action-1.concurrency.attr")
self.assertGreater(policy_db.parameters["threshold"], 0)
self.assertIn("actionstr", policy_db.parameters["attributes"])
for i in range(0, policy_db.parameters["threshold"]):
liveaction = LiveActionDB(action="wolfpack.action-1", parameters={"actionstr": "fu"})
action_service.request(liveaction)
scheduled = LiveAction.get_all()
self.assertEqual(len(scheduled), policy_db.parameters["threshold"])
for liveaction in scheduled:
self.assertIn(liveaction.status, SCHEDULED_STATES)
# Execution is expected to be delayed since concurrency threshold is reached.
liveaction = LiveActionDB(action="wolfpack.action-1", parameters={"actionstr": "fu"})
liveaction, _ = action_service.request(liveaction)
delayed = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(delayed.status, action_constants.LIVEACTION_STATUS_DELAYED)
# Execution is expected to be scheduled since concurrency threshold is not reached.
# The execution with actionstr "fu" is over the threshold but actionstr "bar" is not.
liveaction = LiveActionDB(action="wolfpack.action-1", parameters={"actionstr": "bar"})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
# Mark one of the execution as completed.
action_service.update_status(scheduled[0], action_constants.LIVEACTION_STATUS_SUCCEEDED, publish=True)
# Execution is expected to be rescheduled.
liveaction = LiveAction.get_by_id(str(delayed.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
开发者ID:ipv1337,项目名称:st2,代码行数:33,代码来源:test_concurrency_by_attr.py
示例11: test_over_threshold
def test_over_threshold(self):
policy_db = Policy.get_by_ref('wolfpack.action-1.concurrency')
self.assertGreater(policy_db.parameters['threshold'], 0)
for i in range(0, policy_db.parameters['threshold']):
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
action_service.request(liveaction)
scheduled = LiveAction.get_all()
self.assertEqual(len(scheduled), policy_db.parameters['threshold'])
for liveaction in scheduled:
self.assertIn(liveaction.status, SCHEDULED_STATES)
# Execution is expected to be delayed since concurrency threshold is reached.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_DELAYED)
# Mark one of the execution as completed.
action_service.update_status(
scheduled[0], action_constants.LIVEACTION_STATUS_SUCCEEDED, publish=True)
# Execution is expected to be rescheduled.
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
开发者ID:SamMarkowitz,项目名称:st2,代码行数:26,代码来源:test_concurrency.py
示例12: test_over_threshold_cancel_executions
def test_over_threshold_cancel_executions(self):
policy_db = Policy.get_by_ref('wolfpack.action-2.concurrency.cancel')
self.assertEqual(policy_db.parameters['action'], 'cancel')
self.assertGreater(policy_db.parameters['threshold'], 0)
for i in range(0, policy_db.parameters['threshold']):
liveaction = LiveActionDB(action='wolfpack.action-2', parameters={'actionstr': 'foo'})
action_service.request(liveaction)
scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES]
self.assertEqual(len(scheduled), policy_db.parameters['threshold'])
# duplicate executions caused by accidental publishing of state in the concurrency policies.
# num_state_changes = len(scheduled) * len(['requested', 'scheduled', 'running'])
expected_num_exec = len(scheduled)
expected_num_pubs = expected_num_exec * 3
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
# Execution is expected to be canceled since concurrency threshold is reached.
liveaction = LiveActionDB(action='wolfpack.action-2', parameters={'actionstr': 'foo'})
liveaction, _ = action_service.request(liveaction)
expected_num_exec += 0 # This request will not be scheduled for execution.
expected_num_pubs += 1 # Tally requested state.
# Assert the canceling state is being published.
calls = [call(liveaction, action_constants.LIVEACTION_STATUS_CANCELING)]
LiveActionPublisher.publish_state.assert_has_calls(calls)
expected_num_pubs += 2 # Tally canceling and canceled state changes.
# Assert the action is canceled.
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_CANCELED)
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
开发者ID:peak6,项目名称:st2,代码行数:35,代码来源:test_concurrency.py
示例13: test_disabled_policy_not_applied_on_pre_run
def test_disabled_policy_not_applied_on_pre_run(self, mock_policies):
scheduler_worker = scheduler.get_scheduler()
##########
# First test a scenario where policy is enabled
##########
self.assertTrue(self.policy_db.enabled)
# Post run hasn't been called yet, call count should be 0
self.assertEqual(mock_policies.get_driver.call_count, 0)
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
live_action_db, execution_db = action_service.request(liveaction)
scheduler_worker._apply_pre_run_policies(liveaction_db=live_action_db)
# Ony policy has been applied so call count should be 1
self.assertEqual(mock_policies.get_driver.call_count, 1)
##########
# Now a scenaro with disabled policy
##########
mock_policies.get_driver.call_count = 0
self.policy_db.enabled = False
self.policy_db = Policy.add_or_update(self.policy_db)
self.assertFalse(self.policy_db.enabled)
self.assertEqual(mock_policies.get_driver.call_count, 0)
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
live_action_db, execution_db = action_service.request(liveaction)
scheduler_worker._apply_pre_run_policies(liveaction_db=live_action_db)
# Policy is disabled so call_count should stay the same as before as no policies have been
# applied
self.assertEqual(mock_policies.get_driver.call_count, 0)
开发者ID:lyandut,项目名称:st2,代码行数:35,代码来源:test_base.py
示例14: test_over_threshold
def test_over_threshold(self):
policy_db = Policy.get_by_ref('wolfpack.action-1.concurrency')
self.assertGreater(policy_db.parameters['threshold'], 0)
for i in range(0, policy_db.parameters['threshold']):
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
eventlet.spawn(action_service.request, liveaction)
# Sleep here to let the threads above schedule the action execution.
eventlet.sleep(1)
scheduled = LiveAction.get_all()
self.assertEqual(len(scheduled), policy_db.parameters['threshold'])
for liveaction in scheduled:
self.assertIn(liveaction.status, SCHEDULED_STATES)
# Execution is expected to be delayed since concurrency threshold is reached.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_DELAYED)
# Sleep here to let the threads above complete the action execution.
eventlet.sleep(RUN_DELAY + 1)
# Execution is expected to be rescheduled.
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
开发者ID:Kailashkatheth1,项目名称:st2,代码行数:28,代码来源:test_concurrency.py
示例15: test_over_threshold_delay_executions
def test_over_threshold_delay_executions(self):
policy_db = Policy.get_by_ref('wolfpack.action-1.concurrency.attr')
self.assertGreater(policy_db.parameters['threshold'], 0)
self.assertIn('actionstr', policy_db.parameters['attributes'])
for i in range(0, policy_db.parameters['threshold']):
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'fu'})
action_service.request(liveaction)
scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES]
self.assertEqual(len(scheduled), policy_db.parameters['threshold'])
# Execution is expected to be delayed since concurrency threshold is reached.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'fu'})
liveaction, _ = action_service.request(liveaction)
delayed = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(delayed.status, action_constants.LIVEACTION_STATUS_DELAYED)
# Execution is expected to be scheduled since concurrency threshold is not reached.
# The execution with actionstr "fu" is over the threshold but actionstr "bar" is not.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'bar'})
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
# Mark one of the execution as completed.
action_service.update_status(
scheduled[0], action_constants.LIVEACTION_STATUS_SUCCEEDED, publish=True)
# Execution is expected to be rescheduled.
liveaction = LiveAction.get_by_id(str(delayed.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
开发者ID:Pulsant,项目名称:st2,代码行数:32,代码来源:test_concurrency_by_attr.py
示例16: test_on_cancellation
def test_on_cancellation(self):
policy_db = Policy.get_by_ref('wolfpack.action-1.concurrency')
self.assertGreater(policy_db.parameters['threshold'], 0)
# Launch action executions until the expected threshold is reached.
for i in range(0, policy_db.parameters['threshold']):
parameters = {'actionstr': 'foo-' + str(i)}
liveaction = LiveActionDB(action='wolfpack.action-1', parameters=parameters)
action_service.request(liveaction)
# Run the scheduler to schedule action executions.
self._process_scheduling_queue()
# Check the number of action executions in scheduled state.
scheduled = [item for item in LiveAction.get_all() if item.status in SCHEDULED_STATES]
self.assertEqual(len(scheduled), policy_db.parameters['threshold'])
# duplicate executions caused by accidental publishing of state in the concurrency policies.
# num_state_changes = len(scheduled) * len(['requested', 'scheduled', 'running'])
expected_num_exec = len(scheduled)
expected_num_pubs = expected_num_exec * 3
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
# Execution is expected to be delayed since concurrency threshold is reached.
liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'})
liveaction, _ = action_service.request(liveaction)
expected_num_pubs += 1 # Tally requested state.
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
# Run the scheduler to schedule action executions.
self._process_scheduling_queue()
# Since states are being processed async, wait for the liveaction to go into delayed state.
liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_DELAYED)
expected_num_exec += 0 # This request will not be scheduled for execution.
expected_num_pubs += 0 # The delayed status change should not be published.
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
# Cancel execution.
action_service.request_cancellation(scheduled[0], 'stanley')
expected_num_pubs += 2 # Tally the canceling and canceled states.
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
# Run the scheduler to schedule action executions.
self._process_scheduling_queue()
# Once capacity freed up, the delayed execution is published as requested again.
expected_num_exec += 1 # This request is expected to be executed.
expected_num_pubs += 2 # Tally scheduled and running state.
# Execution is expected to be rescheduled.
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertIn(liveaction.status, SCHEDULED_STATES)
self.assertEqual(expected_num_pubs, LiveActionPublisher.publish_state.call_count)
self.assertEqual(expected_num_exec, runner.MockActionRunner.run.call_count)
开发者ID:StackStorm,项目名称:st2,代码行数:59,代码来源:test_concurrency.py
示例17: test_get_driver
def test_get_driver(self):
policy_db = Policy.get_by_ref("wolfpack.action-1.concurrency")
policy = get_driver(policy_db.ref, policy_db.policy_type, **policy_db.parameters)
self.assertIsInstance(policy, ResourcePolicyApplicator)
self.assertEqual(policy._policy_ref, policy_db.ref)
self.assertEqual(policy._policy_type, policy_db.policy_type)
self.assertTrue(hasattr(policy, "threshold"))
self.assertEqual(policy.threshold, 3)
开发者ID:azamsheriff,项目名称:st2,代码行数:8,代码来源:test_policies.py
示例18: setUpClass
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))
开发者ID:StackStorm,项目名称:st2,代码行数:17,代码来源:test_policies.py
示例19: setUpClass
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))
开发者ID:hejin,项目名称:st2,代码行数:18,代码来源:test_policies.py
示例20: test_register_all_policies
def test_register_all_policies(self):
policies_dbs = Policy.get_all()
self.assertEqual(len(policies_dbs), 0)
packs_base_path = get_fixtures_packs_base_path()
count = policies_registrar.register_policies(packs_base_paths=[packs_base_path])
self.assertEqual(count, 2)
# Verify PolicyDB objects have been created
policies_dbs = Policy.get_all()
self.assertEqual(len(policies_dbs), 2)
self.assertEqual(policies_dbs[0].name, 'test_policy_1')
self.assertEqual(policies_dbs[0].policy_type, 'action.concurrency')
# Verify that a default value for parameter "action" which isn't provided in the file is set
self.assertEqual(policies_dbs[0].parameters['action'], 'delay')
self.assertEqual(policies_dbs[0].parameters['threshold'], 3)
开发者ID:LindsayHill,项目名称:st2,代码行数:18,代码来源:test_policies_registrar.py
注:本文中的st2common.persistence.policy.Policy类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论