本文整理汇总了Python中spinnaker.yaml_util.YamlBindings.import_dict方法的典型用法代码示例。如果您正苦于以下问题:Python YamlBindings.import_dict方法的具体用法?Python YamlBindings.import_dict怎么用?Python YamlBindings.import_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spinnaker.yaml_util.YamlBindings
的用法示例。
在下文中一共展示了YamlBindings.import_dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_key_not_found
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_load_key_not_found(self):
bindings = YamlBindings()
bindings.import_dict({'field': '${injected.value}', 'injected': {}})
with self.assertRaises(KeyError):
bindings['unknown']
self.assertEqual(None, bindings.get('unknown', None))
示例2: test_transform_ok
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_transform_ok(self):
bindings = YamlBindings()
bindings.import_dict({'a': {'b': { 'space': 'WithSpace',
'nospace': 'WithoutSpace',
'empty': 'Empty'}},
'x' : {'unique': True}})
template = """
a:
b:
space: {space}
nospace:{nospace}
empty:{empty}
unique:
b:
space: A
nospace:B
empty:
"""
source = template.format(space='SPACE', nospace='NOSPACE', empty='')
expect = template.format(space='WithSpace',
nospace=' WithoutSpace',
empty=' Empty')
got = source
for key in [ 'a.b.space', 'a.b.nospace', 'a.b.empty' ]:
got = bindings.transform_yaml_source(got, key)
self.assertEqual(expect, bindings.transform_yaml_source(expect, 'bogus'))
self.assertEqual(expect, got)
示例3: test_update_field_union_child
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_update_field_union_child(self):
bindings = YamlBindings()
bindings.import_dict({'parent1': {'a': 'A'}, 'parent2': {'x': 'X'}})
bindings.import_dict({'parent1': {'b': 'B'}})
self.assertEqual({'parent1': {'a': 'A', 'b': 'B'},
'parent2': {'x': 'X'}},
bindings.map)
示例4: test_true_false_not_resolved
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_true_false_not_resolved(self):
bindings = YamlBindings()
bindings.import_dict({'indirect': '${t}'})
validator = ValidateConfig(
configurator=Configurator(bindings=bindings))
self.assertFalse(validator.verify_true_false('indirect'))
self.assertEqual('Missing "indirect".', validator.errors[0])
示例5: test_load_transitive_indirect
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_load_transitive_indirect(self):
bindings = YamlBindings()
bindings.import_dict({'field': '${injected.value}', 'found': 'FOUND'})
bindings.import_dict({'injected': {'value': '${found}'}})
self.assertEqual('FOUND', bindings.get('field'))
self.assertEqual('FOUND', bindings['field'])
self.assertEqual('FOUND', bindings.get('field', None))
示例6: populate_google_yml
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def populate_google_yml(content):
credentials = {'project': '', 'jsonPath': ''}
google_dict = {'enabled': False,
'defaultRegion': 'us-central1',
'defaultZone': 'us-central1-f',}
google_dict['primaryCredentials'] = credentials
if is_google_instance():
zone = os.path.basename(
check_fetch(GOOGLE_INSTANCE_METADATA_URL + '/zone',
google=True).content)
google_dict['enabled'] = 'true'
google_dict['defaultRegion'] = zone[:-2]
google_dict['defaultZone'] = zone
credentials['project'] = check_fetch(
GOOGLE_METADATA_URL + '/project/project-id', google=True).content
bindings = YamlBindings()
bindings.import_dict({'providers': {'google': google_dict}})
content = bindings.transform_yaml_source(content, 'providers.google.enabled')
content = bindings.transform_yaml_source(
content, 'providers.google.defaultRegion')
content = bindings.transform_yaml_source(
content, 'providers.google.defaultZone')
content = bindings.transform_yaml_source(
content, 'providers.google.primaryCredentials.project')
content = bindings.transform_yaml_source(
content, 'providers.google.primaryCredentials.jsonPath')
return content
示例7: test_load_dict
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_load_dict(self):
expect = {'a': 'A',
'b': 0,
'c': ['A','B'],
'd': {'child': {'grandchild': 'x'}},
'e': None}
bindings = YamlBindings()
bindings.import_dict(expect)
self.assertEqual(expect, bindings.map)
示例8: test_true_false_good
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_true_false_good(self):
bindings = YamlBindings()
bindings.import_dict(
{'t': True, 'f':False, 'indirect':'${t}', 'default': '${x:true}'})
validator = ValidateConfig(
configurator=Configurator(bindings=bindings))
self.assertTrue(validator.verify_true_false('t'))
self.assertTrue(validator.verify_true_false('f'))
self.assertTrue(validator.verify_true_false('indirect'))
self.assertTrue(validator.verify_true_false('default'))
示例9: host_test_helper
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def host_test_helper(self, tests, valid, required=False):
bindings = YamlBindings()
bindings.import_dict(tests)
validator = ValidateConfig(
configurator=Configurator(bindings=bindings))
for key, value in tests.items():
msg = '"{key}" was {valid}'.format(
key=key, valid='invalid' if valid else 'valid')
self.assertEqual(valid, validator.verify_host(key, required), msg)
return validator
示例10: test_transform_fail
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_transform_fail(self):
bindings = YamlBindings()
bindings.import_dict({'a': {'b': { 'child': 'Hello, World!'}},
'x' : {'unique': True}})
yaml = """
a:
b:
child: Hello
"""
with self.assertRaises(ValueError):
bindings.transform_yaml_source(yaml, 'x.unique')
示例11: test_verify_at_least_one_provider_enabled_good
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_verify_at_least_one_provider_enabled_good(self):
bindings = YamlBindings()
bindings.import_dict({
'providers': {
'aws': { 'enabled': False },
'google': {'enabled': False },
'another': {'enabled': True }
},
})
validator = ValidateConfig(
configurator=Configurator(bindings=bindings))
self.assertTrue(validator.verify_at_least_one_provider_enabled())
示例12: baseUrl_test_helper
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def baseUrl_test_helper(self, tests, valid, scheme_optional):
bindings = YamlBindings()
bindings.import_dict(tests)
validator = ValidateConfig(
configurator=Configurator(bindings=bindings))
for key, value in tests.items():
msg = '"{key}" was {valid}'.format(
key=key, valid='invalid' if valid else 'valid')
self.assertEqual(
valid,
validator.verify_baseUrl(key, True,
scheme_optional=scheme_optional),
msg)
示例13: test_verify_at_least_one_provider_enabled_bad
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_verify_at_least_one_provider_enabled_bad(self):
bindings = YamlBindings()
bindings.import_dict({
'providers': {
'aws': { 'enabled': False },
'google': {'enabled': False }
},
'services': {'test': { 'enabled': True }}
})
validator = ValidateConfig(
configurator=Configurator(bindings=bindings))
self.assertFalse(validator.verify_at_least_one_provider_enabled())
self.assertEqual('None of the providers are enabled.',
validator.errors[0])
示例14: test_update_deck_settings
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_update_deck_settings(self):
temp_sourcedir = tempfile.mkdtemp()
temp_targetdir = tempfile.mkdtemp()
template = """
preamble
// BEGIN reconfigure_spinnaker
// var gateUrl = ${{services.gate.baseUrl}};
{gate_url_value}
// var bakeryBaseUrl = ${{services.bakery.baseUrl}};
{bakery_url_value}
// END reconfigure_spinnaker
// var gateUrl = ${{services.gate.baseUrl}};
stuff here is left along.
"""
# This was originally just a comment, which was preserved.
bakery_url_assignment = ("var bakeryBaseUrl = 'BAKERY_BASE_URL';"
"\n# comment")
# This was originally a different let statement that was removed.
gate_url_assignment = "var gateUrl = 'GATE_BASE_URL';"
bindings = YamlBindings()
bindings.import_dict({
'services': {
'gate': { 'baseUrl': 'GATE_BASE_URL' },
'bakery': { 'baseUrl': 'BAKERY_BASE_URL' },
}
})
installation = InstallationParameters
installation.INSTALLED_CONFIG_DIR = temp_sourcedir
installation.DECK_INSTALL_DIR = temp_targetdir
configurator = Configurator(installation_parameters=installation,
bindings=bindings)
try:
source_settings_path = os.path.join(temp_sourcedir, 'settings.js')
target_settings_path = os.path.join(temp_targetdir, 'settings.js')
with open(source_settings_path, 'w') as f:
f.write(template.format(gate_url_value="var gateUrl='old';",
bakery_url_value='# comment'))
configurator.update_deck_settings()
with open(target_settings_path, 'r') as f:
got = f.read()
expect = template.format(gate_url_value=gate_url_assignment,
bakery_url_value=bakery_url_assignment)
self.assertEqual(expect, got)
finally:
shutil.rmtree(temp_sourcedir)
shutil.rmtree(temp_targetdir)
示例15: test_load_default_bool
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_dict [as 别名]
def test_load_default_bool(self):
bindings = YamlBindings()
bindings.import_dict({'field': '${undefined:True}'})
self.assertEqual(True, bindings.get('field'))
bindings.import_dict({'field': '${undefined:true}'})
self.assertEqual(True, bindings.get('field'))
bindings.import_dict({'field': '${undefined:false}'})
self.assertEqual(False, bindings.get('field'))
bindings.import_dict({'field': '${undefined:False}'})
self.assertEqual(False, bindings.get('field'))