本文整理汇总了Python中rally.i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _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)
示例2: _initialize_testr
def _initialize_testr(self):
if not os.path.isdir(self.path(".testrepository")):
msg = _("Test Repository initialization.")
LOG.info(_("Starting: ") + msg)
subprocess.check_call("%s testr init" % self.venv_wrapper,
shell=True, cwd=self.path())
LOG.info(_("Completed: ") + msg)
示例3: 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()
示例4: 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()
示例5: 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
示例6: _initialize_testr
def _initialize_testr(self):
if not os.path.isdir(self.path(".testrepository")):
print(_("Test Repository initialization."))
try:
check_output("%s testr init" % self.venv_wrapper,
shell=True, cwd=self.path())
except subprocess.CalledProcessError:
if os.path.exists(self.path(".testrepository")):
shutil.rmtree(self.path(".testrepository"))
raise TempestSetupFailure(_("failed to initialize testr"))
示例7: _delete_single_resource
def _delete_single_resource(self, resource):
"""Safe resource deletion with retries and timeouts.
Send request to delete resource, in case of failures repeat it few
times. After that pull status of resource until it's deleted.
Writes in LOG warning with UUID of resource that wasn't deleted
:param resource: instance of resource manager initiated with resource
that should be deleted.
"""
msg_kw = {
"uuid": resource.id(),
"service": resource._service,
"resource": resource._resource
}
try:
rutils.retry(resource._max_attempts, resource.delete)
except Exception as e:
msg_kw["reason"] = e
LOG.warning(
_("Resource deletion failed, max retries exceeded for "
"%(service)s.%(resource)s: %(uuid)s. Reason: %(reason)s")
% msg_kw)
if CONF.debug:
LOG.exception(e)
else:
started = time.time()
failures_count = 0
while time.time() - started < resource._timeout:
try:
if resource.is_deleted():
return
except Exception as e:
LOG.warning(
_("Seems like %s.%s.is_deleted(self) method is broken "
"It shouldn't raise any exceptions.")
% (resource.__module__, type(resource).__name__))
LOG.exception(e)
# NOTE(boris-42): Avoid LOG spaming in case of bad
# is_deleted() method
failures_count += 1
if failures_count > resource._max_attempts:
break
finally:
time.sleep(resource._interval)
LOG.warning(_("Resource deletion failed, timeout occurred for "
"%(service)s.%(resource)s: %(uuid)s.")
% msg_kw)
示例8: generate_config_file
def generate_config_file(self):
"""Generate configuration file of tempest for current deployment."""
LOG.debug("Tempest config file: %s " % self.config_file)
if not self.is_configured():
msg = _("Creation of configuration file for tempest.")
LOG.info(_("Starting: ") + msg)
config.TempestConf(self.deploy_id).generate(self.config_file)
LOG.info(_("Completed: ") + msg)
else:
LOG.info("Tempest is already configured.")
示例9: required_services
def required_services(config, clients, task, *required_services):
"""Validator checks if specified OpenStack services are available.
:param *required_services: list of services names
"""
available_services = clients.services().values()
for service in required_services:
if service not in consts.Service:
return ValidationResult(False, _("Unknown service: %s") % service)
if service not in available_services:
return ValidationResult(
False, _("Service is not available: %s") % service)
return ValidationResult()
示例10: create_deploy
def create_deploy(config, name):
"""Create a deployment.
:param config: a dict with deployment configuration
:param name: a str represents a name of the deployment
"""
try:
deployment = objects.Deployment(name=name, config=config)
except exceptions.DeploymentNameExists as e:
if CONF.debug:
LOG.exception(e)
raise
deployer = deploy.EngineFactory.get_engine(deployment['config']['type'],
deployment)
try:
deployer.validate()
except jsonschema.ValidationError:
LOG.error(_('Deployment %(uuid)s: Schema validation error.') %
{'uuid': deployment['uuid']})
deployment.update_status(consts.DeployStatus.DEPLOY_FAILED)
raise
with deployer:
endpoints = deployer.make_deploy()
deployment.update_endpoints(endpoints)
return deployment
示例11: _consumer
def _consumer(consume, queue, is_published):
"""Infinity worker that consumes tasks from queue.
This finishes it's work only in case if is_published.isSet().
:param consume: method that consumes an object removed from the queue
:param queue: deque object to popleft() objects from
:param is_published: threading.Event that is used to stop the consumer
when the queue is empty
"""
cache = {}
while True:
if queue:
try:
consume(cache, queue.popleft())
except IndexError:
# NOTE(boris-42): queue is accessed from multiple threads so
# it's quite possible to have 2 queue accessing
# at the same point queue with only 1 element
pass
except Exception as e:
LOG.warning(_("Failed to consume a task from the queue: "
"%s") % e)
if CONF.debug:
LOG.exception(e)
elif is_published.isSet():
break
else:
time.sleep(0.1)
示例12: start
def start(self, task, deploy_id=None, tag=None, do_use=False):
"""Start benchmark task.
:param task: a file with yaml/json configration
:param deploy_id: a UUID of a deployment
:param tag: optional tag for this task
"""
task = os.path.expanduser(task)
with open(task, 'rb') as task_file:
config_dict = yaml.safe_load(task_file.read())
try:
task = api.create_task(deploy_id, tag)
print("=" * 80)
print(_("Task %(tag)s %(uuid)s is started")
% {"uuid": task["uuid"], "tag": task["tag"]})
print("-" * 80)
api.start_task(deploy_id, config_dict, task=task)
self.detailed(task_id=task['uuid'])
if do_use:
use.UseCommands().task(task['uuid'])
except exceptions.InvalidConfigException:
return(1)
except KeyboardInterrupt:
api.abort_task(task['uuid'])
raise
示例13: flavors
def flavors(self, deployment=None):
"""Display available flavors.
:param deployment: UUID or name of a deployment
"""
headers = ['ID', 'Name', 'vCPUs', 'RAM (MB)', 'Swap (MB)', 'Disk (GB)']
mixed_case_fields = ['ID', 'Name', 'vCPUs']
float_cols = ['RAM (MB)', 'Swap (MB)', 'Disk (GB)']
formatters = dict(zip(float_cols,
[cliutils.pretty_float_formatter(col)
for col in float_cols]))
table_rows = []
try:
for endpoint_dict in self._get_endpoints(deployment):
clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
nova_client = clients.nova()
for flavor in nova_client.flavors.list():
data = [flavor.id, flavor.name, flavor.vcpus,
flavor.ram, flavor.swap, flavor.disk]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
common_cliutils.print_list(table_rows,
fields=headers,
formatters=formatters,
mixed_case_fields=mixed_case_fields)
except exceptions.InvalidArgumentsException as e:
print(_("Authentication Issues: %s") % e)
return(1)
示例14: check
def check(criterion_value, result):
durations = [r["duration"] for r in result if not r.get("error")]
avg = putils.mean(durations)
success = avg < criterion_value
msg = (_("Maximum average duration per iteration %ss, found with %ss")
% (criterion_value, avg))
return SLAResult(success, msg)
示例15: images
def images(self, deployment=None):
"""Display available images.
:param deployment: UUID or name of a deployment
"""
headers = ['UUID', 'Name', 'Size (B)']
mixed_case_fields = ['UUID', 'Name']
float_cols = ["Size (B)"]
table_rows = []
formatters = dict(zip(float_cols,
[cliutils.pretty_float_formatter(col)
for col in float_cols]))
try:
for endpoint_dict in self._get_endpoints(deployment):
clients = osclients.Clients(endpoint.Endpoint(**endpoint_dict))
glance_client = clients.glance()
for image in glance_client.images.list():
data = [image.id, image.name, image.size]
table_rows.append(utils.Struct(**dict(zip(headers, data))))
common_cliutils.print_list(table_rows,
fields=headers,
formatters=formatters,
mixed_case_fields=mixed_case_fields)
except exceptions.InvalidArgumentsException as e:
print(_("Authentication Issues: %s") % e)
return(1)