本文整理汇总了Python中st2tests.fixturesloader.get_fixtures_packs_base_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_fixtures_packs_base_path函数的具体用法?Python get_fixtures_packs_base_path怎么用?Python get_fixtures_packs_base_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_fixtures_packs_base_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_register_from_pack_action_metadata_fails_validation
def test_register_from_pack_action_metadata_fails_validation(self):
# No fail on failure flag, should succeed
pack_dir = os.path.join(get_fixtures_packs_base_path(), 'dummy_pack_4')
runner_dirs = os.path.join(get_fixtures_packs_base_path(), 'runners')
opts = [
'--register-pack=%s' % (pack_dir),
'--register-no-fail-on-failure',
'--register-runner-dir=%s' % (runner_dirs),
]
cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
exit_code, _, stderr = run_command(cmd=cmd)
self.assertTrue('Registered 0 actions.' in stderr)
self.assertEqual(exit_code, 0)
# Fail on failure, should fail
pack_dir = os.path.join(get_fixtures_packs_base_path(), 'dummy_pack_4')
opts = [
'--register-pack=%s' % (pack_dir),
'--register-fail-on-failure',
'--register-runner-dir=%s' % (runner_dirs),
]
cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
exit_code, _, stderr = run_command(cmd=cmd)
self.assertTrue('object has no attribute \'get\'' in stderr)
self.assertEqual(exit_code, 1)
示例2: test_get_pack_resource_file_abs_path
def test_get_pack_resource_file_abs_path(self):
# Mock the packs path to point to the fixtures directory
cfg.CONF.content.packs_base_paths = get_fixtures_packs_base_path()
# Invalid resource type
expected_msg = 'Invalid resource type: fooo'
self.assertRaisesRegexp(ValueError, expected_msg, get_pack_resource_file_abs_path,
pack_ref='dummy_pack_1',
resource_type='fooo',
file_path='test.py')
# Invalid paths (directory traversal and absolute paths)
file_paths = ['/tmp/foo.py', '../foo.py', '/etc/passwd', '../../foo.py']
for file_path in file_paths:
expected_msg = 'Invalid file path: .*%s' % (file_path)
self.assertRaisesRegexp(ValueError, expected_msg, get_pack_resource_file_abs_path,
pack_ref='dummy_pack_1',
resource_type='action',
file_path=file_path)
# Valid paths
file_paths = ['foo.py', 'a/foo.py', 'a/b/foo.py']
for file_path in file_paths:
expected = os.path.join(get_fixtures_packs_base_path(),
'dummy_pack_1/actions', file_path)
result = get_pack_resource_file_abs_path(pack_ref='dummy_pack_1',
resource_type='action',
file_path=file_path)
self.assertEqual(result, expected)
示例3: test_register_from_pack_success
def test_register_from_pack_success(self):
pack_dir = os.path.join(get_fixtures_packs_base_path(), 'dummy_pack_1')
runner_dirs = os.path.join(get_fixtures_packs_base_path(), 'runners')
opts = [
'--register-pack=%s' % (pack_dir),
'--register-runner-dir=%s' % (runner_dirs),
]
cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + opts
exit_code, _, stderr = run_command(cmd=cmd)
self.assertTrue('Registered 1 actions.' in stderr)
self.assertEqual(exit_code, 0)
示例4: test_get_pack_resource_file_abs_path
def test_get_pack_resource_file_abs_path(self):
# Mock the packs path to point to the fixtures directory
cfg.CONF.content.packs_base_paths = get_fixtures_packs_base_path()
# Invalid resource type
expected_msg = 'Invalid resource type: fooo'
self.assertRaisesRegexp(ValueError, expected_msg, get_pack_resource_file_abs_path,
pack_ref='dummy_pack_1',
resource_type='fooo',
file_path='test.py')
# Invalid paths (directory traversal and absolute paths)
file_paths = ['/tmp/foo.py', '../foo.py', '/etc/passwd', '../../foo.py',
'/opt/stackstorm/packs/invalid_pack/actions/my_action.py',
'../../foo.py']
for file_path in file_paths:
# action resource_type
expected_msg = (r'Invalid file path: ".*%s"\. File path needs to be relative to the '
r'pack actions directory (.*). For example "my_action.py"\.' %
(file_path))
self.assertRaisesRegexp(ValueError, expected_msg, get_pack_resource_file_abs_path,
pack_ref='dummy_pack_1',
resource_type='action',
file_path=file_path)
# sensor resource_type
expected_msg = (r'Invalid file path: ".*%s"\. File path needs to be relative to the '
r'pack sensors directory (.*). For example "my_sensor.py"\.' %
(file_path))
self.assertRaisesRegexp(ValueError, expected_msg, get_pack_resource_file_abs_path,
pack_ref='dummy_pack_1',
resource_type='sensor',
file_path=file_path)
# no resource type
expected_msg = (r'Invalid file path: ".*%s"\. File path needs to be relative to the '
r'pack directory (.*). For example "my_action.py"\.' %
(file_path))
self.assertRaisesRegexp(ValueError, expected_msg, get_pack_file_abs_path,
pack_ref='dummy_pack_1',
file_path=file_path)
# Valid paths
file_paths = ['foo.py', 'a/foo.py', 'a/b/foo.py']
for file_path in file_paths:
expected = os.path.join(get_fixtures_packs_base_path(),
'dummy_pack_1/actions', file_path)
result = get_pack_resource_file_abs_path(pack_ref='dummy_pack_1',
resource_type='action',
file_path=file_path)
self.assertEqual(result, expected)
示例5: test_register_triggers_from_pack
def test_register_triggers_from_pack(self):
base_path = get_fixtures_packs_base_path()
pack_dir = os.path.join(base_path, 'dummy_pack_1')
trigger_type_dbs = TriggerType.get_all()
self.assertEqual(len(trigger_type_dbs), 0)
count = triggers_registrar.register_triggers(pack_dir=pack_dir)
self.assertEqual(count, 2)
# Verify TriggerTypeDB and corresponding TriggerDB objects have been created
trigger_type_dbs = TriggerType.get_all()
trigger_dbs = Trigger.get_all()
self.assertEqual(len(trigger_type_dbs), 2)
self.assertEqual(len(trigger_dbs), 2)
self.assertEqual(trigger_type_dbs[0].name, 'event_handler')
self.assertEqual(trigger_type_dbs[0].pack, 'dummy_pack_1')
self.assertEqual(trigger_dbs[0].name, 'event_handler')
self.assertEqual(trigger_dbs[0].pack, 'dummy_pack_1')
self.assertEqual(trigger_dbs[0].type, 'dummy_pack_1.event_handler')
self.assertEqual(trigger_type_dbs[1].name, 'head_sha_monitor')
self.assertEqual(trigger_type_dbs[1].pack, 'dummy_pack_1')
self.assertEqual(trigger_type_dbs[1].payload_schema['type'], 'object')
示例6: 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)
示例7: _override_common_opts
def _override_common_opts():
packs_base_path = get_fixtures_packs_base_path()
CONF.set_override(name='base_path', override=packs_base_path, group='system')
CONF.set_override(name='system_packs_base_path', override=packs_base_path, group='content')
CONF.set_override(name='packs_base_paths', override=packs_base_path, group='content')
CONF.set_override(name='api_url', override='http://127.0.0.1', group='auth')
CONF.set_override(name='mask_secrets', override=True, group='log')
CONF.set_override(name='url', override='zake://', group='coordination')
CONF.set_override(name='lock_timeout', override=1, group='coordination')
示例8: test_register_policy_invalid_policy_type_references
def test_register_policy_invalid_policy_type_references(self):
# Policy references an invalid (inexistent) policy type
registrar = PolicyRegistrar()
policy_path = os.path.join(get_fixtures_packs_base_path(),
'dummy_pack_1/policies/policy_2.yaml')
expected_msg = 'Referenced policy_type "action.mock_policy_error" doesnt exist'
self.assertRaisesRegexp(ValueError, expected_msg, registrar._register_policy,
pack='dummy_pack_1', policy=policy_path)
示例9: test_make_sure_policy_parameters_are_validated_during_register
def test_make_sure_policy_parameters_are_validated_during_register(self):
# Policy where specified parameters fail schema validation
registrar = PolicyRegistrar()
policy_path = os.path.join(get_fixtures_packs_base_path(),
'dummy_pack_2/policies/policy_3.yaml')
expected_msg = '100 is greater than the maximum of 5'
self.assertRaisesRegexp(jsonschema.ValidationError, expected_msg,
registrar._register_policy, pack='dummy_pack_2',
policy=policy_path)
示例10: test_register_setup_virtualenvs
def test_register_setup_virtualenvs(self):
# Single pack
pack_dir = os.path.join(get_fixtures_packs_base_path(), 'dummy_pack_1')
cmd = BASE_CMD_ARGS + ['--register-pack=%s' % (pack_dir), '--register-setup-virtualenvs',
'--register-no-fail-on-failure']
exit_code, stdout, stderr = run_command(cmd=cmd)
self.assertTrue('Setting up virtualenv for pack "dummy_pack_1"' in stderr)
self.assertTrue('Setup virtualenv for 1 pack(s)' in stderr)
self.assertEqual(exit_code, 0)
示例11: _override_common_opts
def _override_common_opts():
packs_base_path = get_fixtures_packs_base_path()
CONF.set_override(name='base_path', override=packs_base_path, group='system')
CONF.set_override(name='validate_output_schema', override=True, group='system')
CONF.set_override(name='system_packs_base_path', override=packs_base_path, group='content')
CONF.set_override(name='packs_base_paths', override=packs_base_path, group='content')
CONF.set_override(name='api_url', override='http://127.0.0.1', group='auth')
CONF.set_override(name='mask_secrets', override=True, group='log')
CONF.set_override(name='jitter_interval', override=0, group='mistral')
CONF.set_override(name='query_interval', override=0.1, group='resultstracker')
CONF.set_override(name='stream_output', override=False, group='actionrunner')
示例12: test_register_all_triggers
def test_register_all_triggers(self):
trigger_type_dbs = TriggerType.get_all()
self.assertEqual(len(trigger_type_dbs), 0)
packs_base_path = get_fixtures_packs_base_path()
count = triggers_registrar.register_triggers(packs_base_paths=[packs_base_path])
self.assertEqual(count, 2)
# Verify TriggerTypeDB and corresponding TriggerDB objects have been created
trigger_type_dbs = TriggerType.get_all()
trigger_dbs = Trigger.get_all()
self.assertEqual(len(trigger_type_dbs), 2)
self.assertEqual(len(trigger_dbs), 2)
示例13: 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_packs_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)
示例14: 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)
示例15: test_register_all_and_register_setup_virtualenvs
def test_register_all_and_register_setup_virtualenvs(self):
# Verify that --register-all works in combinations with --register-setup-virtualenvs
# Single pack
pack_dir = os.path.join(get_fixtures_packs_base_path(), 'dummy_pack_1')
cmd = BASE_CMD_ARGS + [
'--register-pack=%s' % (pack_dir),
'--register-all',
'--register-setup-virtualenvs',
'--register-no-fail-on-failure'
]
exit_code, stdout, stderr = run_command(cmd=cmd)
self.assertTrue('Registering actions' in stderr, 'Actual stderr: %s' % (stderr))
self.assertTrue('Registering rules' in stderr)
self.assertTrue('Setup virtualenv for %s pack(s)' % ('1') in stderr)
self.assertEqual(exit_code, 0)