本文整理汇总了Python中rally.common.i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_img
def _load_img(self):
cirros_url = ("%s/%s/%s" %
(CONF.image.cirros_base_url,
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: required_openstack
def required_openstack(config, clients, deployment, 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."))
if deployment["admin"] and deployment["users"]:
return ValidationResult(True)
if deployment["admin"]:
if users and not config.get("context", {}).get("users"):
return ValidationResult(False,
_("You should specify 'users' context"))
return ValidationResult(True)
if deployment["users"] and admin:
return ValidationResult(False, _("Admin credentials required"))
示例3: details
def details(self):
strs = [_("Action: '%s'. %.2fs <= %.2fs") %
(atom, self.avg_by_action[atom], val)
for atom, val in self.criterion_items]
head = _("Average duration of one iteration for atomic actions:")
end = _("Status: %s") % self.status()
return "\n".join([head] + strs + [end])
示例4: _check_tempest_tree_existence
def _check_tempest_tree_existence(verifier):
if not os.path.exists(verifier.path()):
msg = _("Tempest tree for "
"deployment '%s' not found! ") % verifier.deployment
LOG.error(
msg + _("Use `rally verify install` for Tempest installation"))
raise exceptions.NotFoundException(message=msg)
示例5: create
def create(self, name, fromenv=False, filename=None, do_use=False):
"""Create new deployment.
This command will create a new deployment record in rally
database. In the case of ExistingCloud deployment engine it
will use the cloud represented in the configuration. If the
cloud doesn't exist, Rally can deploy a new one for you with
Devstack or Fuel. Different deployment engines exist for these
cases.
If you use the ExistingCloud deployment engine you can pass
a deployment config by environment variables with ``--fromenv``:
OS_USERNAME
OS_PASSWORD
OS_AUTH_URL
OS_TENANT_NAME
OS_ENDPOINT_TYPE or OS_INTERFACE
OS_ENDPOINT
OS_REGION_NAME
OS_CACERT
OS_INSECURE
All other deployment engines need more complex configuration
data, so it should be stored in a configuration file.
You can use physical servers, LXC containers, KVM virtual
machines or virtual machines in OpenStack for deploying the
cloud. Except physical servers, Rally can create cluster nodes
for you. Interaction with virtualization software, OpenStack
cloud or physical servers is provided by server providers.
:param fromenv: boolean, read environment instead of config file
:param filename: path to the configuration file
:param name: name of the deployment
"""
if fromenv:
config = {"type": "ExistingCloud"}
config.update(envutils.get_creds_from_env_vars())
else:
if not filename:
print("Either --filename or --fromenv is required.")
return(1)
filename = os.path.expanduser(filename)
with open(filename, "rb") as deploy_file:
config = yaml.safe_load(deploy_file.read())
try:
deployment = api.Deployment.create(config, name)
except jsonschema.ValidationError:
print(_("Config schema validation error: %s.") % sys.exc_info()[1])
return(1)
except exceptions.DeploymentNameExists:
print(_("Error: %s") % sys.exc_info()[1])
return(1)
self.list(deployment_list=[deployment])
if do_use:
self.use(deployment["uuid"])
示例6: show
def show(self, verification=None, sort_by="name", detailed=False):
"""Display results table of a verification.
:param verification: UUID of a verification
:param sort_by: Sort results by 'name' or 'duration'
:param detailed: Display detailed errors of failed tests
"""
try:
verification = api.Verification.get(verification)
tests = verification.get_results()
except exceptions.NotFoundException as e:
print(six.text_type(e))
return 1
print(_("Total results of verification:\n"))
total_fields = ["UUID", "Deployment UUID", "Set name", "Tests", "Failures", "Created at", "Status"]
cliutils.print_list([verification], fields=total_fields)
print(_("\nTests:\n"))
fields = ["name", "time", "status"]
results = tests["test_cases"]
values = [utils.Struct(**results[test_name]) for test_name in results]
sortby_index = ("name", "duration").index(sort_by)
cliutils.print_list(values, fields, sortby_index=sortby_index)
if detailed:
for test in six.itervalues(tests["test_cases"]):
if test["status"] == "fail":
header = cliutils.make_header(
"FAIL: %(name)s\n" "Time: %(time)s" % {"name": test["name"], "time": test["time"]}
)
formatted_test = "%(header)s%(log)s\n" % {"header": header, "log": test["traceback"]}
print(formatted_test)
示例7: _install_venv
def _install_venv(self):
path_to_venv = self.path(".venv")
if not os.path.isdir(path_to_venv):
LOG.debug("No virtual environment for Tempest found.")
LOG.info(_("Installing the virtual environment for Tempest."))
LOG.debug("Virtual environment directory: %s" % path_to_venv)
try:
check_output(["virtualenv", "-p", sys.executable, ".venv"],
cwd=self.path())
# NOTE(kun): Using develop mode installation is for run
# multiple tempest instance. However, dependency
# from tempest(os-testr) has issues here, before
# https://review.openstack.org/#/c/207691/ being
# merged, we have to install dependency manually and
# run setup.py with -N(install package without
# dependency)
check_output([self.venv_wrapper, "pip", "install", "-r",
"requirements.txt", "-r",
"test-requirements.txt"], cwd=self.path())
check_output([self.venv_wrapper, "pip", "install",
"-e", "./"], cwd=self.path())
except subprocess.CalledProcessError:
if os.path.exists(self.path(".venv")):
shutil.rmtree(self.path(".venv"))
raise TempestSetupFailure(_("failed to install virtualenv"))
示例8: start
def start(self, deployment=None, set_name="", regex=None,
tests_file=None, tempest_config=None, xfails_file=None,
do_use=True, system_wide=False, concur=0):
"""Start verification (run Tempest tests).
:param deployment: UUID or name of a deployment
:param set_name: Name of a Tempest test set
:param regex: Regular expression of test
:param tests_file: Path to a file with a list of Tempest tests
:param tempest_config: User specified Tempest config file location
:param xfails_file: Path to a file in YAML format with a list of
Tempest tests that are expected to fail
:param do_use: Use new task as default for future operations
:param system_wide: Whether or not to create a virtual env when
installing Tempest; whether or not to use
the local env instead of the Tempest virtual
env when running the tests
:param concur: How many processes to use to run Tempest tests.
The default value (0) auto-detects CPU count
"""
msg = _("Arguments '%s' and '%s' are not compatible. "
"You can use only one of the mentioned arguments.")
if regex and set_name:
print(msg % ("regex", "set"))
return 1
if tests_file and set_name:
print(msg % ("tests_file", "set"))
return 1
if tests_file and regex:
print(msg % ("tests_file", "regex"))
return 1
if not (regex or set_name or tests_file):
set_name = "full"
if set_name and set_name not in AVAILABLE_SETS:
print(_("Tempest test set '%s' not found "
"in available test sets. Available sets are %s.")
% (set_name, ", ".join(AVAILABLE_SETS)))
return 1
if tests_file and not os.path.exists(tests_file):
print(_("File '%s' not found.") % tests_file)
return 1
expected_failures = None
if xfails_file:
if os.path.exists(xfails_file):
with open(os.path.abspath(xfails_file), "rb") as f:
expected_failures = yaml.load(f)
else:
print(_("File '%s' not found.") % xfails_file)
return 1
verification = api.Verification.verify(
deployment, set_name=set_name, regex=regex, tests_file=tests_file,
tempest_config=tempest_config, expected_failures=expected_failures,
system_wide=system_wide, concur=concur)
if do_use:
self.use(verification["uuid"])
示例9: _install_venv
def _install_venv(self):
path_to_venv = self.path(".venv")
if not os.path.isdir(path_to_venv):
print("No virtual environment found...Install the virtualenv.")
LOG.debug("Virtual environment directory: %s" % path_to_venv)
required_vers = (2, 7)
if sys.version_info[:2] != required_vers:
# NOTE(andreykurilin): let's try to find a suitable python
# interpreter for Tempest
python_interpreter = costilius.get_interpreter(required_vers)
if not python_interpreter:
raise exceptions.IncompatiblePythonVersion(
version=sys.version, required_version=required_vers)
LOG.info(
_("Tempest requires Python %(required)s, '%(found)s' was "
"found in your system and it will be used for installing"
" virtual environment.") % {"required": required_vers,
"found": python_interpreter})
else:
python_interpreter = sys.executable
try:
check_output("%s ./tools/install_venv.py" % python_interpreter,
shell=True, cwd=self.path())
check_output("%s python setup.py install" % self.venv_wrapper,
shell=True, cwd=self.path())
except subprocess.CalledProcessError:
if os.path.exists(self.path(".venv")):
shutil.rmtree(self.path(".venv"))
raise TempestSetupFailure(_("failed to install virtualenv"))
示例10: _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(),
"name": resource.name() or "",
"service": resource._service,
"resource": resource._resource,
}
LOG.debug("Deleting %(service)s %(resource)s object %(name)s (%(uuid)s)" % msg_kw)
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 logging.is_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 spamming 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
)
示例11: 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
else:
if not self.glance:
raise exceptions.InvalidConfigException(
"If glance is not available in the service catalog"
" obtained by the openstack server provider, then"
" images cannot be uploaded so the uuid of an"
" existing image must be specified in the"
" deployment config."
)
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"],
copy_from=self.config["image"]["url"],
disk_format=self.config["image"]["format"],
container_format="bare")
image.get()
if image.checksum != self.config["image"]["checksum"]:
raise exceptions.ChecksumMismatch(url=self.config["image"]["url"])
return image.id
示例12: create
def create(self, name, filename, do_use=False):
"""Create new deployment.
This command will create a new deployment record in rally ovs
database.
"""
filename = os.path.expanduser(filename)
print("file:" + filename)
with open(filename, "rb") as deploy_file:
config = yaml.safe_load(deploy_file.read())
try:
deployment = api.Deployment.create(config, name)
except jsonschema.ValidationError:
print(_("Config schema validation error: %s.") % sys.exc_info()[1])
return(1)
except exceptions.DeploymentNameExists:
print(_("Error: %s") % sys.exc_info()[1])
return(1)
self.list(deployment_list=[deployment])
if do_use:
self.use(deployment["uuid"])
示例13: setup
def setup(self):
# FIXME(andreykurilin): move all checks to validate method.
# do not use admin, if we have users...
user = random.choice(self.context.get("users",
[self.context["admin"]]))
clients = osclients.Clients(user["endpoint"])
services = clients.services()
for client_name, conf in six.iteritems(self.config):
if "service_type" in conf and conf["service_type"] not in services:
raise exceptions.ValidationError(_(
"There is no service with '%s' type in your environment.")
% conf["service_type"])
elif "service_name" in conf:
if conf["service_name"] not in services.values():
raise exceptions.ValidationError(
_("There is no '%s' service in your environment") %
conf["service_name"])
service_types = [
key for key in services
if services[key] == conf["service_name"]]
if len(service_types) > 1:
# NOTE(andreykurilin): does it possible??
raise exceptions.ValidationError(
_("There are several services with name '%s'. Try to "
"specify service_type property instead.") %
conf["service_name"])
self.context["config"]["api_versions"][client_name][
"service_type"] = service_types[0]
示例14: _download_image
def _download_image(image_path, image=None):
if image:
LOG.debug("Downloading image '%s' "
"from Glance to %s" % (image.name, image_path))
with open(image_path, "wb") as image_file:
for chunk in image.data():
image_file.write(chunk)
else:
LOG.debug("Downloading image from %s "
"to %s" % (CONF.tempest.img_url, image_path))
try:
response = requests.get(CONF.tempest.img_url, stream=True)
except requests.ConnectionError as err:
msg = _("Failed to download image. "
"Possibly there is no connection to Internet. "
"Error: %s.") % (str(err) or "unknown")
raise exceptions.TempestConfigCreationFailure(msg)
if response.status_code == 200:
with open(image_path, "wb") as image_file:
for chunk in response.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
image_file.write(chunk)
image_file.flush()
else:
if response.status_code == 404:
msg = _("Failed to download image. Image was not found.")
else:
msg = _("Failed to download image. "
"HTTP error code %d.") % response.status_code
raise exceptions.TempestConfigCreationFailure(msg)
LOG.debug("The image has been successfully downloaded!")
示例15: _get_validated_image
def _get_validated_image(config, clients, param_name):
image_context = config.get("context", {}).get("images", {})
image_args = config.get("args", {}).get(param_name)
image_ctx_name = image_context.get("image_name")
if not image_args:
msg = _("Parameter %s is not specified.") % param_name
return (ValidationResult(False, msg), None)
if "image_name" in image_context:
# NOTE(rvasilets) check string is "exactly equal to" a regex
# or image name from context equal to image name from args
if "regex" in image_args:
match = re.match(image_args.get("regex"), image_ctx_name)
if image_ctx_name == image_args.get("name") or (
"regex" in image_args and match):
image = {
"size": image_context.get("min_disk", 0),
"min_ram": image_context.get("min_ram", 0),
"min_disk": image_context.get("min_disk", 0)
}
return (ValidationResult(True), image)
try:
image_id = types.ImageResourceType.transform(
clients=clients, resource_config=image_args)
image = clients.glance().images.get(image=image_id).to_dict()
return (ValidationResult(True), image)
except (glance_exc.HTTPNotFound, exceptions.InvalidScenarioArgument):
message = _("Image '%s' not found") % image_args
return (ValidationResult(False, message), None)