本文整理汇总了Python中st2common.persistence.keyvalue.KeyValuePair.add_or_update方法的典型用法代码示例。如果您正苦于以下问题:Python KeyValuePair.add_or_update方法的具体用法?Python KeyValuePair.add_or_update怎么用?Python KeyValuePair.add_or_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.keyvalue.KeyValuePair
的用法示例。
在下文中一共展示了KeyValuePair.add_or_update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_lookup_cast
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_lookup_cast(self):
KeyValuePair.add_or_update(KeyValuePairDB(name='count', value='5.5'))
lookup = KeyValueLookup(scope=FULL_SYSTEM_SCOPE)
self.assertEqual(str(lookup.count), '5.5')
self.assertEqual(float(lookup.count), 5.5)
self.assertEqual(int(lookup.count), 5)
示例2: test_get_config_dynamic_config_item_list
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_get_config_dynamic_config_item_list(self):
pack_name = 'dummy_pack_schema_with_nested_object_7'
loader = ContentPackConfigLoader(pack_name=pack_name)
KeyValuePair.add_or_update(KeyValuePairDB(name='k0', value='v0'))
KeyValuePair.add_or_update(KeyValuePairDB(name='k1', value='v1'))
####################
# values in list
values = {
'level0_key': [
'a',
'{{st2kv.system.k0}}',
'b',
'{{st2kv.system.k1}}',
]
}
config_db = ConfigDB(pack=pack_name, values=values)
config_db = Config.add_or_update(config_db)
config_rendered = loader.get_config()
self.assertEquals(config_rendered,
{
'level0_key': [
'a',
'v0',
'b',
'v1'
]
})
config_db.delete()
示例3: test_get_finalized_params_system_values
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_get_finalized_params_system_values(self):
KeyValuePair.add_or_update(KeyValuePairDB(name='actionstr', value='foo'))
KeyValuePair.add_or_update(KeyValuePairDB(name='actionnumber', value='1.0'))
params = {
'runnerint': 555
}
liveaction_db = self._get_liveaction_model(params)
runner_params, action_params = param_utils.get_finalized_params(
ParamsUtilsTest.runnertype_db.runner_parameters,
ParamsUtilsTest.action_system_default_db.parameters,
liveaction_db.parameters,
liveaction_db.context)
# Asserts for runner params.
# Assert that default values for runner params are resolved.
self.assertEqual(runner_params.get('runnerstr'), 'defaultfoo')
# Assert that a runner param from action exec is picked up.
self.assertEqual(runner_params.get('runnerint'), 555)
# Assert that an immutable param cannot be overridden by action param or execution param.
self.assertEqual(runner_params.get('runnerimmutable'), 'runnerimmutable')
# Asserts for action params.
self.assertEqual(action_params.get('actionstr'), 'foo')
self.assertEqual(action_params.get('actionnumber'), 1.0)
示例4: test_system_transform
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_system_transform(self):
rule = self.models['rules']['rule_action_default_value_render_fail.yaml']
runner_type_db = mock.Mock()
runner_type_db.runner_parameters = {}
action_db = mock.Mock()
action_db.parameters = {}
k5 = KeyValuePair.add_or_update(KeyValuePairDB(name='k5', value='v5'))
k6 = KeyValuePair.add_or_update(KeyValuePairDB(name='k6', value='v6'))
k7 = KeyValuePair.add_or_update(KeyValuePairDB(name='k7', value='v7'))
k8 = KeyValuePair.add_or_update(KeyValuePairDB(name='k8', value='v8',
scope=FULL_SYSTEM_SCOPE))
params = {'ip5': '{{trigger.k2}}-static',
'ip6': '{{st2kv.system.k6}}-static',
'ip7': '{{st2kv.system.k7}}-static'}
expected_params = {'ip5': 'v2-static',
'ip6': 'v6-static',
'ip7': 'v7-static'}
try:
self.assertResolvedParamsMatchExpected(rule=rule,
trigger_instance=MOCK_TRIGGER_INSTANCE_4,
params=params,
expected_params=expected_params)
finally:
KeyValuePair.delete(k5)
KeyValuePair.delete(k6)
KeyValuePair.delete(k7)
KeyValuePair.delete(k8)
示例5: test_user_scope_lookups_user_sep_in_name
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_user_scope_lookups_user_sep_in_name(self):
KeyValuePair.add_or_update(KeyValuePairDB(name='stanley:r:i:p', value='v4',
scope=FULL_USER_SCOPE))
lookup = UserKeyValueLookup(scope=FULL_USER_SCOPE, user='stanley')
# This is the only way to lookup because USER_SEPARATOR (':') cannot be a part of
# variable name in Python.
self.assertEquals(str(lookup['r:i:p']), 'v4')
示例6: test_non_hierarchical_lookup
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_non_hierarchical_lookup(self):
k1 = KeyValuePair.add_or_update(KeyValuePairDB(name='k1', value='v1'))
k2 = KeyValuePair.add_or_update(KeyValuePairDB(name='k2', value='v2'))
k3 = KeyValuePair.add_or_update(KeyValuePairDB(name='k3', value='v3'))
lookup = KeyValueLookup()
self.assertEquals(str(lookup.k1), k1.value)
self.assertEquals(str(lookup.k2), k2.value)
self.assertEquals(str(lookup.k3), k3.value)
示例7: test_hierarchical_lookup_dict
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_hierarchical_lookup_dict(self):
k1 = KeyValuePair.add_or_update(KeyValuePairDB(name='a.b', value='v1'))
k2 = KeyValuePair.add_or_update(KeyValuePairDB(name='a.b.c', value='v2'))
k3 = KeyValuePair.add_or_update(KeyValuePairDB(name='b.c', value='v3'))
lookup = KeyValueLookup()
self.assertEquals(str(lookup['a']['b']), k1.value)
self.assertEquals(str(lookup['a']['b']['c']), k2.value)
self.assertEquals(str(lookup['b']['c']), k3.value)
self.assertEquals(str(lookup['a']), '')
示例8: test_lookups_older_scope_names_backward_compatibility
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_lookups_older_scope_names_backward_compatibility(self):
k1 = KeyValuePair.add_or_update(KeyValuePairDB(name='a.b', value='v1',
scope=FULL_SYSTEM_SCOPE))
lookup = KeyValueLookup(scope=SYSTEM_SCOPE)
self.assertEquals(str(lookup['a']['b']), k1.value)
k2 = KeyValuePair.add_or_update(KeyValuePairDB(name='stanley:r.i.p', value='v4',
scope=FULL_USER_SCOPE))
user_lookup = UserKeyValueLookup(scope=USER_SCOPE, user='stanley')
self.assertEquals(str(user_lookup['r']['i']['p']), k2.value)
示例9: setUp
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def setUp(self):
super(KeyValuesControllerRBACTestCase, self).setUp()
self.kvps = {}
# Insert mock users
user_1_db = UserDB(name='user1')
user_1_db = User.add_or_update(user_1_db)
self.users['user_1'] = user_1_db
user_2_db = UserDB(name='user2')
user_2_db = User.add_or_update(user_2_db)
self.users['user_2'] = user_2_db
# Insert mock kvp objects
kvp_api = KeyValuePairSetAPI(name='test_system_scope', value='value1',
scope=FULL_SYSTEM_SCOPE)
kvp_db = KeyValuePairSetAPI.to_model(kvp_api)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps['kvp_1'] = kvp_db
kvp_api = KeyValuePairSetAPI(name='test_system_scope_secret', value='value_secret',
scope=FULL_SYSTEM_SCOPE, secret=True)
kvp_db = KeyValuePairSetAPI.to_model(kvp_api)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps['kvp_2'] = kvp_db
name = get_key_reference(scope=FULL_USER_SCOPE, name='test_user_scope_1', user='user1')
kvp_db = KeyValuePairDB(name=name, value='valueu12', scope=FULL_USER_SCOPE)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps['kvp_3'] = kvp_db
name = get_key_reference(scope=FULL_USER_SCOPE, name='test_user_scope_2', user='user1')
kvp_api = KeyValuePairSetAPI(name=name, value='user_secret', scope=FULL_USER_SCOPE,
secret=True)
kvp_db = KeyValuePairSetAPI.to_model(kvp_api)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps['kvp_4'] = kvp_db
name = get_key_reference(scope=FULL_USER_SCOPE, name='test_user_scope_3', user='user2')
kvp_db = KeyValuePairDB(name=name, value='valueu21', scope=FULL_USER_SCOPE)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps['kvp_5'] = kvp_db
self.system_scoped_items_count = 2
self.user_scoped_items_count = 3
self.user_scoped_items_per_user_count = {
'user1': 2,
'user2': 1
}
示例10: test_lookup_with_key_prefix
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_lookup_with_key_prefix(self):
KeyValuePair.add_or_update(KeyValuePairDB(name='some:prefix:stanley:k5', value='v5',
scope=FULL_USER_SCOPE))
# No prefix provided, should return None
lookup = UserKeyValueLookup(user='stanley', scope=FULL_USER_SCOPE)
self.assertEqual(str(lookup.k5), '')
# Prefix provided
lookup = UserKeyValueLookup(prefix='some:prefix', user='stanley', scope=FULL_USER_SCOPE)
self.assertEqual(str(lookup.k5), 'v5')
示例11: test_secret_lookup
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_secret_lookup(self):
secret_value = '0055A2D9A09E1071931925933744965EEA7E23DCF59A8D1D7A3' + \
'64338294916D37E83C4796283C584751750E39844E2FD97A3727DB5D553F638'
k1 = KeyValuePair.add_or_update(KeyValuePairDB(
name='k1', value=secret_value,
secret=True, encrypted=True)
)
k2 = KeyValuePair.add_or_update(KeyValuePairDB(name='k2', value='v2'))
lookup = KeyValueLookup()
self.assertEquals(str(lookup.k1), k1.value)
self.assertEquals(str(lookup.k2), k2.value)
示例12: setUp
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def setUp(self):
super(KeyValuesControllerRBACTestCase, self).setUp()
self.kvps = {}
# Insert mock users
user_1_db = UserDB(name="user1")
user_1_db = User.add_or_update(user_1_db)
self.users["user_1"] = user_1_db
user_2_db = UserDB(name="user2")
user_2_db = User.add_or_update(user_2_db)
self.users["user_2"] = user_2_db
# Insert mock kvp objects
kvp_api = KeyValuePairSetAPI(name="test_system_scope", value="value1", scope=FULL_SYSTEM_SCOPE)
kvp_db = KeyValuePairSetAPI.to_model(kvp_api)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps["kvp_1"] = kvp_db
kvp_api = KeyValuePairSetAPI(
name="test_system_scope_secret", value="value_secret", scope=FULL_SYSTEM_SCOPE, secret=True
)
kvp_db = KeyValuePairSetAPI.to_model(kvp_api)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps["kvp_2"] = kvp_db
name = get_key_reference(scope=FULL_USER_SCOPE, name="test_user_scope_1", user="user1")
kvp_db = KeyValuePairDB(name=name, value="valueu12", scope=FULL_USER_SCOPE)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps["kvp_3"] = kvp_db
name = get_key_reference(scope=FULL_USER_SCOPE, name="test_user_scope_2", user="user1")
kvp_api = KeyValuePairSetAPI(name=name, value="user_secret", scope=FULL_USER_SCOPE, secret=True)
kvp_db = KeyValuePairSetAPI.to_model(kvp_api)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps["kvp_4"] = kvp_db
name = get_key_reference(scope=FULL_USER_SCOPE, name="test_user_scope_3", user="user2")
kvp_db = KeyValuePairDB(name=name, value="valueu21", scope=FULL_USER_SCOPE)
kvp_db = KeyValuePair.add_or_update(kvp_db)
kvp_db = KeyValuePairAPI.from_model(kvp_db)
self.kvps["kvp_5"] = kvp_db
self.system_scoped_items_count = 2
self.user_scoped_items_count = 3
self.user_scoped_items_per_user_count = {"user1": 2, "user2": 1}
示例13: test_system_transform
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_system_transform(self):
k5 = KeyValuePair.add_or_update(KeyValuePairDB(name="k5", value="v5"))
k6 = KeyValuePair.add_or_update(KeyValuePairDB(name="k6", value="v6"))
k7 = KeyValuePair.add_or_update(KeyValuePairDB(name="k7", value="v7"))
try:
transformer = datatransform.get_transformer(PAYLOAD)
mapping = {"ip5": "{{trigger.k2}}-static", "ip6": "{{system.k6}}-static", "ip7": "{{system.k7}}-static"}
result = transformer(mapping)
expected = {"ip5": "v2-static", "ip6": "v6-static", "ip7": "v7-static"}
self.assertEqual(result, expected)
finally:
KeyValuePair.delete(k5)
KeyValuePair.delete(k6)
KeyValuePair.delete(k7)
示例14: setUp
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def setUp(self):
super(TemplatingUtilsTestCase, self).setUp()
# Insert mock DB objects
kvp_1_db = KeyValuePairDB(name='key1', value='valuea')
kvp_1_db = KeyValuePair.add_or_update(kvp_1_db)
kvp_2_db = KeyValuePairDB(name='key2', value='valueb')
kvp_2_db = KeyValuePair.add_or_update(kvp_2_db)
kvp_3_db = KeyValuePairDB(name='stanley:key1', value='valuestanley1', scope=USER_SCOPE)
kvp_3_db = KeyValuePair.add_or_update(kvp_3_db)
kvp_4_db = KeyValuePairDB(name='joe:key1', value='valuejoe1', scope=USER_SCOPE)
kvp_4_db = KeyValuePair.add_or_update(kvp_4_db)
示例15: test_filter_decrypt_kv
# 需要导入模块: from st2common.persistence.keyvalue import KeyValuePair [as 别名]
# 或者: from st2common.persistence.keyvalue.KeyValuePair import add_or_update [as 别名]
def test_filter_decrypt_kv(self):
KeyValuePair.add_or_update(KeyValuePairDB(name='k8', value=self.secret_value,
scope=FULL_SYSTEM_SCOPE,
secret=True))
context = {}
context.update({SYSTEM_SCOPE: KeyValueLookup(scope=SYSTEM_SCOPE)})
context.update({
DATASTORE_PARENT_SCOPE: {
SYSTEM_SCOPE: KeyValueLookup(scope=FULL_SYSTEM_SCOPE)
}
})
template = '{{st2kv.system.k8 | decrypt_kv}}'
actual = self.env.from_string(template).render(context)
self.assertEqual(actual, self.secret)