Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def calculate_omp_num_threads(values_dict: dict) -> int:
"""
Calculates correct value of OMP_NUM_THREADS according to CPU resources requested in template's values.yaml.
:param values_dict: Dictionary containing template's values,yaml file
:return: Calculated OMP_NUM_THREADS value
:raises ValueError, TypeError, KeyError
"""
if values_dict.get("cpu") and values_dict.get("cpu") != "null":
cpu_limit = values_dict.get("cpu")
elif values_dict.get("resources"):
cpu_limit = dutil.get(values_dict, "resources.limits.cpu", separator='.')
elif values_dict.get("worker_resources"):
cpu_limit = dutil.get(values_dict, "worker_resources.limits.cpu", separator='.')
else:
raise ValueError('Unable to find requested CPUs count.')
# We need to handle cases when CPU is provided either as absolute value, or in millicpu format.
# Convert_k8s_cpu_resource returns cpu request in millicpus, so we divide it by 1000 to get absolute
# value of cpus, and we make sure that there will be at least one thread.
return int(max(convert_k8s_cpu_resource(cpu_limit) // 1000, 1))
def calculate_omp_num_threads(values_dict: dict) -> int:
"""
Calculates correct value of OMP_NUM_THREADS according to CPU resources requested in template's values.yaml.
:param values_dict: Dictionary containing template's values,yaml file
:return: Calculated OMP_NUM_THREADS value
:raises ValueError, TypeError, KeyError
"""
if values_dict.get("cpu") and values_dict.get("cpu") != "null":
cpu_limit = values_dict.get("cpu")
elif values_dict.get("resources"):
cpu_limit = dutil.get(values_dict, "resources.limits.cpu", separator='.')
elif values_dict.get("worker_resources"):
cpu_limit = dutil.get(values_dict, "worker_resources.limits.cpu", separator='.')
else:
raise ValueError('Unable to find requested CPUs count.')
# We need to handle cases when CPU is provided either as absolute value, or in millicpu format.
# Convert_k8s_cpu_resource returns cpu request in millicpus, so we divide it by 1000 to get absolute
# value of cpus, and we make sure that there will be at least one thread.
return int(max(convert_k8s_cpu_resource(cpu_limit) // 1000, 1))
def test_types_get_glob_multiple():
ehash = TestMapping({
"a": TestMapping({
"b": TestMapping({
"c": TestMapping({
"d": 0
}),
"e": TestMapping({
"d": 0
})
})
})
})
assert_raises(ValueError, dpath.util.get, ehash, '/a/b/*/d')
assert_raises(ValueError, dpath.util.get, ehash, ['a', 'b', '*', 'd'])
def nova_ceph(env):
data = env.get_settings_data()
if dpath.util.get(data, '*/storage/**/ephemeral_ceph/value'):
pytest.skip("Nova Ceph RBD should be disabled")
def test_get_explicit_single():
ehash = {
"a": {
"b": {
"c": {
"d": 0,
"e": 1,
"f": 2
}
}
}
}
assert(dpath.util.get(ehash, '/a/b/c/f') == 2)
assert(dpath.util.get(ehash, ['a', 'b', 'c', 'f']) == 2)
def test_get_glob_single():
ehash = {
"a": {
"b": {
"c": {
"d": 0,
"e": 1,
"f": 2
}
}
}
}
assert(dpath.util.get(ehash, '/a/b/*/f') == 2)
assert(dpath.util.get(ehash, ['a', 'b', '*', 'f']) == 2)
def test_unicode_search():
a = {'中': ['zhong']}
results = [[x[0], x[1]] for x in dpath.util.search(a, '*', yielded=True)]
print(results)
assert(len(results) == 1)
assert(results[0][0] == '中')
assert(results[0][1] == ['zhong'])
def ssl_config(self):
return dpath.util.get(self.get_settings_data(), '*/public_ssl')
"d": 0,
"e": 1,
"f": 2
}
}
}
}
paths = [
'a',
'a;b',
'a;b;c',
'a;b;c;d',
'a;b;c;e',
'a;b;c;f'
]
for (path, value) in dpath.util.search(dict, '/**', yielded=True, separator=";"):
assert(path in paths)
for (path, value) in dpath.util.search(dict, ['**'], yielded=True, separator=";"):
assert(path in paths)
def test_search_list_key_with_separator():
tdict = {
"a": {
"b": {
"d": 'failure'
},
"/b/d": 'success'
}
}
res = dpath.util.search(tdict, ['a', '/b/d'])
assert(not 'b' in res['a'])
assert(res['a']['/b/d'] == 'success')