本文整理汇总了Python中rally.openstack.common.gettextutils._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: image_valid_on_flavor_validator
def image_valid_on_flavor_validator(config, clients, task):
flavor_id = types.FlavorResourceType.transform(
clients=clients,
resource_config=config.get("args", {}).get(flavor_name))
try:
flavor = clients.nova().flavors.get(flavor=flavor_id)
except nova_exc.NotFound:
message = _("Flavor with id '%s' not found") % flavor_id
return ValidationResult(False, message)
image_id = types.ImageResourceType.transform(
clients=clients,
resource_config=config.get("args", {}).get(image_name))
try:
image = clients.glance().images.get(image=image_id)
except glance_exc.HTTPNotFound:
message = _("Image with id '%s' not found") % image_id
return ValidationResult(False, message)
if flavor.ram < (image.min_ram or 0):
message = _("The memory size for flavor '%s' is too small "
"for requested image '%s'") % (flavor_id, image_id)
return ValidationResult(False, message)
if flavor.disk:
if (image.size or 0) > flavor.disk * (1024 ** 3):
message = _("The disk size for flavor '%s' is too small "
"for requested image '%s'") % (flavor_id, image_id)
return ValidationResult(False, message)
if (image.min_disk or 0) > flavor.disk:
message = _("The disk size for flavor '%s' is too small "
"for requested image '%s'") % (flavor_id, image_id)
return ValidationResult(False, message)
return ValidationResult()
示例2: to_bytes
def to_bytes(text, default=0):
"""Converts a string into an integer of bytes.
Looks at the last characters of the text to determine
what conversion is needed to turn the input text into a byte number.
Supports "B, K(B), M(B), G(B), and T(B)". (case insensitive)
:param text: String input for bytes size conversion.
:param default: Default return value when text is blank.
"""
match = BYTE_REGEX.search(text)
if match:
magnitude = int(match.group(1))
mult_key_org = match.group(2)
if not mult_key_org:
return magnitude
elif text:
msg = _("Invalid string format: %s") % text
raise TypeError(msg)
else:
return default
mult_key = mult_key_org.lower().replace("b", "", 1)
multiplier = BYTE_MULTIPLIERS.get(mult_key)
if multiplier is None:
msg = _("Unknown byte multiplier: %s") % mult_key_org
raise TypeError(msg)
return magnitude * multiplier
示例3: wrapper
def wrapper(self, *args, **kwargs):
params = {"msg": msg % kw, "obj_name": obj.title(),
"uuid": getattr(self, obj)["uuid"]}
log(_("%(obj_name)s %(uuid)s | Starting: %(msg)s") % params)
result = f(self, *args, **kwargs)
log(_("%(obj_name)s %(uuid)s | Completed: %(msg)s") % params)
return result
示例4: _load_img
def _load_img(self):
cirros_url = ('http://download.cirros-cloud.net/%s/%s' %
(CONF.image.cirros_version,
CONF.image.cirros_image))
try:
response = requests.get(cirros_url, stream=True)
except requests.ConnectionError as err:
msg = _('Error on downloading cirros image, possibly'
' no connection to Internet with message %s') % str(err)
raise TempestConfigCreationFailure(msg)
if response.status_code == 200:
with open(self.img_path + '.tmp', 'wb') as img_file:
for chunk in response.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
img_file.write(chunk)
img_file.flush()
os.rename(self.img_path + '.tmp', self.img_path)
else:
if response.status_code == 404:
msg = _('Error on downloading cirros image, possibly'
'invalid cirros_version or cirros_image in rally.conf')
else:
msg = _('Error on downloading cirros image, '
'HTTP error code %s') % response.getcode()
raise TempestConfigCreationFailure(msg)
示例5: _validate_test_config
def _validate_test_config(self, test_config):
"""Checks whether the given test config is valid and can be used during
verification and benchmarking tests.
:param test_config: Dictionary in the same format as for the __init__
method.
:raises: Exception if the test config is not valid
"""
task_uuid = self.task['uuid']
# Perform schema validation
try:
jsonschema.validate(test_config, config.test_config_schema)
except jsonschema.ValidationError as e:
LOG.exception(_('Task %s: Error: %s') % (task_uuid, e.message))
raise exceptions.InvalidConfigException(message=e.message)
# Check for verification test names
for test in test_config['verify']:
if test not in self.verification_tests:
LOG.exception(_('Task %s: Error: the specified '
'verification test does not exist: %s') %
(task_uuid, test))
raise exceptions.NoSuchVerificationTest(test_name=test)
# Check for benchmark scenario names
benchmark_scenarios_set = set(self.benchmark_scenarios)
for scenario in test_config['benchmark']:
if scenario not in benchmark_scenarios_set:
LOG.exception(_('Task %s: Error: the specified '
'benchmark scenario does not exist: %s') %
(task_uuid, scenario))
raise exceptions.NoSuchScenario(name=scenario)
示例6: _cleanup_users_resources
def _cleanup_users_resources(self):
for user in self.users:
clients = osclients.Clients(user)
admin_clients = osclients.Clients(self.admin)
cleanup_methods = {
"nova": functools.partial(utils.delete_nova_resources,
clients.nova()),
"glance": functools.partial(utils.delete_glance_resources,
clients.glance(),
clients.keystone().tenant_id),
"cinder": functools.partial(utils.delete_cinder_resources,
clients.cinder()),
"quotas": functools.partial(utils.delete_quotas,
admin_clients,
clients.keystone().tenant_id)
}
for service in self.config:
try:
cleanup_methods[service]()
except Exception as e:
LOG.debug(_("Not all resources were cleaned."),
exc_info=sys.exc_info())
LOG.warning(_('Unable to fully cleanup the cloud: %s') %
(e.message))
示例7: setup
def setup(self):
self.verifier = tempest.Tempest(self.task.task.deployment_uuid)
self.verifier.log_file = "/dev/null"
try:
if not self.verifier.is_installed():
self.verifier.install()
if not self.verifier.is_configured():
self.verifier.generate_config_file()
except exceptions.TempestSetupFailure:
msg = _("Failing to install tempest.")
LOG.error(msg)
raise exceptions.BenchmarkSetupFailure(msg)
except exceptions.TempestConfigCreationFailure:
msg = _("Failing to configure tempest.")
LOG.error(msg)
raise exceptions.BenchmarkSetupFailure(msg)
self.context["verifier"] = self.verifier
# Create temporary directory for xml-results.
self.results_dir = os.path.join(
tempfile.gettempdir(), "%s-results" % self.task.task.uuid)
os.mkdir(self.results_dir)
self.context["tmp_results_dir"] = self.results_dir
示例8: get_image_uuid
def get_image_uuid(self):
"""Get image uuid. Download image if necessary."""
image_uuid = self.config['image'].get('uuid', None)
if image_uuid:
return image_uuid
for image in self.glance.images.list():
if image.checksum == self.config['image']['checksum']:
LOG.info(_('Found image with appropriate checksum. Using it.'))
return image.id
LOG.info(_('Downloading new image %s') % self.config['image']['url'])
image = self.glance.images.create(name=self.config['image']['name'])
try:
image.update(data=urllib2.urlopen(self.config['image']['url']),
disk_format=self.config['image']['format'],
container_format='bare')
except urllib2.URLError:
LOG.error(_('Unable to retrieve %s') % self.config['image']['url'])
raise
image.get()
if image.checksum != self.config['image']['checksum']:
raise exceptions.ChecksumMismatch(url=self.config['image']['url'])
return image.id
示例9: inner
def inner(*args, **kwargs):
try:
with lock(name, lock_file_prefix, external, lock_path):
LOG.debug(_('Got semaphore / lock "%(function)s"'), {"function": f.__name__})
return f(*args, **kwargs)
finally:
LOG.debug(_('Semaphore / lock released "%(function)s"'), {"function": f.__name__})
示例10: _cleanup_users_resources
def _cleanup_users_resources(self):
def _init_services_to_cleanup(cleanup_methods):
scenario_name = self.context.get('scenario_name')
if scenario_name:
cls_name, method_name = scenario_name.split(".", 1)
scenario = scenario_base.Scenario.get_by_name(cls_name)()
scenario_method = getattr(scenario, method_name)
if hasattr(scenario_method, "cleanup_services"):
return getattr(scenario_method, "cleanup_services")
return cleanup_methods.keys()
if not self.users:
return
for user in self.users:
clients = osclients.Clients(user)
cleanup_methods = {
"nova": functools.partial(utils.delete_nova_resources,
clients.nova()),
"glance": functools.partial(utils.delete_glance_resources,
clients.glance(),
clients.keystone()),
"cinder": functools.partial(utils.delete_cinder_resources,
clients.cinder())
}
for service in _init_services_to_cleanup(cleanup_methods):
try:
cleanup_methods[service]()
except Exception as e:
LOG.debug(_("Not all resources were cleaned."),
exc_info=sys.exc_info())
LOG.warning(_('Unable to fully cleanup the cloud: %s') %
(e.message))
示例11: required_openstack
def required_openstack(config, clients, task, admin=False, users=False):
"""Validator that requires OpenStack admin or (and) users.
This allows us to create 4 kind of benchmarks:
1) not OpenStack related (validator is not specified)
2) requires OpenStack admin
3) requires OpenStack admin + users
4) requires OpenStack users
:param admin: requires OpenStack admin
:param users: requires OpenStack users
"""
if not (admin or users):
return ValidationResult(False, _("You should specify admin=True or users=True or both."))
deployment = objects.Deployment.get(task["deployment_uuid"])
if deployment["admin"] and deployment["users"]:
return ValidationResult()
if deployment["admin"]:
if users and not config.get("context", {}).get("users"):
return ValidationResult(False, _("You should specify 'users' context"))
return ValidationResult()
if deployment["users"] and admin:
return ValidationResult(False, _("Admin credentials required"))
return ValidationResult()
示例12: image_valid_on_flavor
def image_valid_on_flavor(config, clients, task, flavor_name, image_name):
"""Returns validator for image could be used for current flavor
:param flavor_name: defines which variable should be used
to get flavor id value.
:param image_name: defines which variable should be used
to get image id value.
"""
valid_result, flavor = _get_validated_flavor(config, clients, flavor_name)
if not valid_result.is_valid:
return valid_result
valid_result, image = _get_validated_image(config, clients, image_name)
if not valid_result.is_valid:
return valid_result
if flavor.ram < (image.min_ram or 0):
message = _("The memory size for flavor '%s' is too small "
"for requested image '%s'") % (flavor.id, image.id)
return ValidationResult(False, message)
if flavor.disk:
if (image.size or 0) > flavor.disk * (1024 ** 3):
message = _("The disk size for flavor '%s' is too small "
"for requested image '%s'") % (flavor.id, image.id)
return ValidationResult(False, message)
if (image.min_disk or 0) > flavor.disk:
message = _("The disk size for flavor '%s' is too small "
"for requested image '%s'") % (flavor.id, image.id)
return ValidationResult(False, message)
return ValidationResult()
示例13: _initialize_testr
def _initialize_testr(self):
if not os.path.isdir(os.path.join(self.tempest_path,
".testrepository")):
msg = _("Test Repository initialization.")
LOG.info(_("Starting: ") + msg)
subprocess.check_call("%s testr init" % self.venv_wrapper,
shell=True, cwd=self.tempest_path)
LOG.info(_("Completed: ") + msg)
示例14: _cleanup_admin_resources
def _cleanup_admin_resources(self):
try:
admin = osclients.Clients(self.admin)
utils.delete_keystone_resources(admin.keystone())
except Exception as e:
LOG.debug(_("Not all resources were cleaned."),
exc_info=sys.exc_info())
LOG.warning(_('Unable to fully cleanup keystone service: %s') %
(e.message))
示例15: wrapper
def wrapper(*args, **kwargs):
try:
path = lock_path or os.environ.get("RALLY_LOCK_PATH")
lock = lockfile.FileLock(os.path.join(path, lock_prefix))
with lock:
LOG.debug(_('Got lock "%s"') % f.__name__)
return f(*args, **kwargs)
finally:
LOG.debug(_('Lock released "%s"') % f.__name__)