本文整理汇总了Python中nailgun.logger.logger.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_file_content
def get_file_content(self, path):
try:
with open(path, "r") as f:
return f.read().strip()
except Exception as e:
logger.error("Error while reading file: %s. %s",
path, six.text_type(e))
示例2: update_task_status
def update_task_status(cls, uuid, status, progress, msg="", result=None):
# verify_networks - task is expecting to receive result with
# some data if connectivity_verification fails
logger.debug("Updating task: %s", uuid)
task = db().query(Task).filter_by(uuid=uuid).first()
if not task:
logger.error("Can't set status='%s', message='%s':no task \
with UUID %s found!", status, msg, uuid)
return
previous_status = task.status
data = {'status': status, 'progress': progress,
'message': msg, 'result': result}
for key, value in data.iteritems():
if value is not None:
setattr(task, key, value)
logger.info(
u"Task {0} ({1}) {2} is set to {3}".format(
task.uuid,
task.name,
key,
value
)
)
db().add(task)
db().commit()
if previous_status != status and task.cluster_id:
logger.debug("Updating cluster status: "
"cluster_id: %s status: %s",
task.cluster_id, status)
cls.update_cluster_status(uuid)
if task.parent:
logger.debug("Updating parent task: %s.", task.parent.uuid)
cls.update_parent_task(task.parent.uuid)
示例3: stats_user_resp
def stats_user_resp(cls, **kwargs):
logger.info("RPC method stats_user_resp received: %s",
jsonutils.dumps(kwargs))
task_uuid = kwargs.get('task_uuid')
nodes = kwargs.get('nodes', [])
status = kwargs.get('status')
error = kwargs.get('error')
message = kwargs.get('msg')
task = objects.Task.get_by_uuid(
task_uuid, fail_if_not_found=True, lock_for_update=True)
if status not in (consts.TASK_STATUSES.ready,
consts.TASK_STATUSES.error):
logger.debug("Task %s, id: %s in status: %s",
task.name, task.id, task.status)
return
data = {'status': status, 'progress': 100, 'message': message}
if status == consts.TASK_STATUSES.error:
logger.error("Task %s, id: %s failed: %s",
task.name, task.id, error)
data['message'] = error
objects.Task.update(task, data)
cls._update_action_log_entry(status, task.name, task_uuid, nodes)
logger.info("RPC method stats_user_resp processed")
示例4: get_network_roles
def get_network_roles(cls, cluster, merge_policy):
"""Returns the network roles from plugins.
The roles cluster and plugins will be mixed
according to merge policy.
"""
instance_roles = cluster.release.network_roles_metadata
all_roles = dict((role['id'], role) for role in instance_roles)
conflict_roles = dict()
for plugin in cluster.plugins:
for role in plugin.network_roles_metadata:
role_id = role['id']
if role_id in all_roles:
try:
merge_policy.apply_patch(
all_roles[role_id],
role
)
except errors.UnresolvableConflict as e:
logger.error("cannot merge plugin {0}: {1}"
.format(plugin.name, e))
conflict_roles[role_id] = plugin.name
else:
all_roles[role_id] = role
if conflict_roles:
raise errors.NetworkRoleConflict(
"Cannot override existing network roles: '{0}' in "
"plugins: '{1}'".format(
', '.join(conflict_roles),
', '.join(set(conflict_roles.values()))))
return list(all_roles.values())
示例5: update_verify_networks
def update_verify_networks(cls, uuid, status,
progress, msg, result):
#TODO(dshulyak) move network tests into ostf
task = db().query(Task).filter_by(uuid=uuid).first()
if not task:
logger.error("Can't set status='%s', message='%s': No task \
with UUID %s found!", status, msg, uuid)
return
previous_status = task.status
statuses = [sub.status for sub in task.subtasks]
messages = [sub.message for sub in task.subtasks]
messages.append(msg)
statuses.append(status)
if any(st == 'error' for st in statuses):
task.status = 'error'
else:
task.status = status or task.status
task.progress = progress or task.progress
task.result = result or task.result
# join messages if not None or ""
task.message = '\n'.join([m for m in messages if m])
db().commit()
if previous_status != task.status and task.cluster_id:
logger.debug("Updating cluster status: "
"cluster_id: %s status: %s",
task.cluster_id, status)
cls.update_cluster_status(uuid)
示例6: send_log_serialized
def send_log_serialized(self, records, ids):
if records:
logger.info("Send %d action logs records", len(records))
resp = self.send_data_to_url(
url=self.build_collector_url("COLLECTOR_ACTION_LOGS_URL"),
data={"action_logs": records}
)
resp_dict = resp.json()
if self.is_status_acceptable(resp.status_code,
resp_dict["status"]):
records_resp = resp_dict["action_logs"]
saved_ids = set()
failed_ids = set()
for record in records_resp:
if record["status"] == \
consts.LOG_RECORD_SEND_STATUS.failed:
failed_ids.add(record["external_id"])
else:
saved_ids.add(record["external_id"])
sent_saved_ids = set(saved_ids) & set(ids)
logger.info("Action logs records saved: %s, failed: %s",
six.text_type(list(sent_saved_ids)),
six.text_type(list(failed_ids)))
db().query(models.ActionLog).filter(
models.ActionLog.id.in_(sent_saved_ids)
).update(
{"is_sent": True}, synchronize_session=False
)
db().commit()
else:
logger.error("Unexpected collector answer: %s",
six.text_type(resp.text))
示例7: launch_verify
def launch_verify(self, cluster):
try:
data = self.validator.validate_networks_update(web.data())
except web.webapi.badrequest as exc:
task = Task(name='check_networks', cluster=cluster)
db().add(task)
db().commit()
TaskHelper.set_error(task.uuid, exc.data)
logger.error(traceback.format_exc())
json_task = build_json_response(TaskHandler.render(task))
raise web.accepted(data=json_task)
data["networks"] = [
n for n in data["networks"] if n.get("name") != "fuelweb_admin"
]
vlan_ids = [{
'name': n['name'],
'vlans': cluster.network_manager.generate_vlan_ids_list(
data, cluster, n)
} for n in data['networks']]
task_manager = VerifyNetworksTaskManager(cluster_id=cluster.id)
try:
task = task_manager.execute(data, vlan_ids)
except errors.CantRemoveOldVerificationTask:
raise web.badrequest("You cannot delete running task manually")
return TaskHandler.render(task)
示例8: PUT
def PUT(self, cluster_id):
cluster = self.get_object_or_404(
Cluster,
cluster_id,
log_404=(
"warning",
"Error: there is no cluster "
"with id '{0}' in DB.".format(cluster_id)
)
)
if not cluster.attributes:
logger.error('ClusterAttributesDefaultsHandler: no attributes'
' found for cluster_id %s' % cluster_id)
raise web.internalerror("No attributes found!")
cluster.attributes.editable = cluster.release.attributes_metadata.get(
"editable"
)
self.db.commit()
cluster.add_pending_changes("attributes")
logger.debug('ClusterAttributesDefaultsHandler:'
' editable attributes for cluster_id %s were reset'
' to default' % cluster_id)
return {"editable": cluster.attributes.editable}
示例9: PUT
def PUT(self, cluster_id):
"""
:IMPORTANT: this method should be rewritten to be more RESTful
:returns: JSONized Task object.
:http: * 202 (network checking task failed)
* 200 (network verification task started)
* 404 (cluster not found in db)
"""
cluster = self.get_object_or_404(Cluster, cluster_id)
try:
data = self.validator.validate_networks_update(web.data())
except web.webapi.badrequest as exc:
task = Task(name='check_networks', cluster=cluster)
db().add(task)
db().commit()
TaskHelper.set_error(task.uuid, exc.data)
logger.error(traceback.format_exc())
json_task = build_json_response(TaskHandler.render(task))
raise web.accepted(data=json_task)
vlan_ids = [{
'name': n['name'],
'vlans': NetworkGroup.generate_vlan_ids_list(n)
} for n in data['networks']]
task_manager = VerifyNetworksTaskManager(cluster_id=cluster.id)
task = task_manager.execute(data, vlan_ids)
return TaskHandler.render(task)
示例10: PUT
def PUT(self, cluster_id):
""":returns: JSONized Task object.
:http: * 202 (network checking task created)
* 404 (cluster not found in db)
"""
data = jsonutils.loads(web.data())
if data.get("networks"):
data["networks"] = [n for n in data["networks"] if n.get("name") != "fuelweb_admin"]
cluster = self.get_object_or_404(objects.Cluster, cluster_id)
self.check_net_provider(cluster)
self.check_if_network_configuration_locked(cluster)
task_manager = CheckNetworksTaskManager(cluster_id=cluster.id)
task = task_manager.execute(data)
if task.status != consts.TASK_STATUSES.error:
try:
if "networks" in data:
self.validator.validate_networks_update(jsonutils.dumps(data))
if "dns_nameservers" in data:
self.validator.validate_dns_servers_update(jsonutils.dumps(data))
objects.Cluster.get_network_manager(cluster).update(cluster, data)
except Exception as exc:
# set task status to error and update its corresponding data
data = {"status": consts.TASK_STATUSES.error, "progress": 100, "message": six.text_type(exc)}
objects.Task.update(task, data)
logger.error(traceback.format_exc())
raise self.http(202, objects.Task.to_json(task))
示例11: calculate_fault_tolerance
def calculate_fault_tolerance(cls, percentage_or_value, total):
"""Calculates actual fault tolerance value.
:param percentage_or_value: the fault tolerance as percent of nodes
that can fail or actual number of nodes,
the negative number means the number of nodes
which have to deploy successfully.
:param total: the total number of nodes in group
:return: the actual number of nodes that can fail
"""
if percentage_or_value is None:
# unattainable number
return total + 1
if isinstance(percentage_or_value, six.string_types):
percentage_or_value = percentage_or_value.strip()
try:
if (isinstance(percentage_or_value, six.string_types) and
percentage_or_value[-1] == '%'):
value = (int(percentage_or_value[:-1]) * total) // 100
else:
value = int(percentage_or_value)
if value < 0:
# convert negative value to number of nodes which may fail
value = max(0, total + value)
return value
except ValueError as e:
logger.error(
"Failed to handle fault_tolerance: '%s': %s. it is ignored",
percentage_or_value, e
)
# unattainable number
return total + 1
示例12: __init__
def __init__(self):
settings_files = []
logger.debug("Looking for settings.yaml package config " "using old style __file__")
project_path = os.path.dirname(__file__)
project_settings_file = os.path.join(project_path, "settings.yaml")
settings_files.append(project_settings_file)
settings_files.append("/etc/nailgun/settings.yaml")
version_paths = ["/etc/fuel/version.yaml", "/etc/fuel/nailgun/version.yaml", "/etc/nailgun/version.yaml"]
for path in version_paths:
if os.access(path, os.R_OK):
settings_files.append(path)
break
else:
logger.error("'version.yaml' config file is not found")
self.config = {}
for sf in settings_files:
try:
logger.debug("Trying to read config file %s" % sf)
self.update_from_file(sf)
except Exception as e:
logger.error("Error while reading config file %s: %s" % (sf, str(e)))
if int(self.config.get("DEVELOPMENT")):
logger.info("DEVELOPMENT MODE ON:")
here = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
self.config.update(
{"STATIC_DIR": os.path.join(here, "static"), "TEMPLATE_DIR": os.path.join(here, "static")}
)
logger.info("Static dir is %s" % self.config.get("STATIC_DIR"))
logger.info("Template dir is %s" % self.config.get("TEMPLATE_DIR"))
示例13: get_metadata
def get_metadata(self):
"""Get plugin data tree.
:return: All plugin metadata
:rtype: dict
"""
data_tree, report = self.loader.load()
if report.is_failed():
logger.error(report.render())
logger.error('Problem with loading plugin {0}'.format(
self.plugin_path))
return data_tree
for field in data_tree:
if field in self.attributes_processors:
data_tree[field] = \
self.attributes_processors[field](data_tree.get(field))
data_tree = {
k: v
for k, v in six.iteritems(data_tree)
if v is not None
}
return data_tree
示例14: update_action_log
def update_action_log(cls, task, al_instance=None):
from nailgun.objects import ActionLog
try:
if not al_instance:
al_instance = ActionLog.get_by_kwargs(task_uuid=task.uuid,
action_name=task.name)
# this is needed as status for check_networks task is not set to
# "ready" in case of success (it is left in status "running") so
# we do it here manually, there is no such issue with "error"
# status though.
set_to_ready_cond = (
task.name == consts.TASK_NAMES.check_networks
and task.status == consts.TASK_STATUSES.running
)
task_status = consts.TASK_STATUSES.ready if set_to_ready_cond \
else task.status
if al_instance:
task_cache = cls.get_task_cache(task)
update_data = {
"end_timestamp": datetime.datetime.utcnow(),
"additional_info": {
"ended_with_status": task_status,
"message": "",
"output": cls.sanitize_task_output(task_cache,
al_instance)
}
}
ActionLog.update(al_instance, update_data)
except Exception as e:
logger.error("update_action_log failed: %s", six.text_type(e))
示例15: _success_start_action
def _success_start_action(cls, task, status, progress):
# check if all nodes are ready
if any(map(lambda n: n.status == 'error',
task.cluster.nodes)):
cls._error_start_action(task, 'error', 100)
return
task_name = task.name.title()
task_cache=cls.get_task_cache(task)
try:
message = (
u"The Role {0} of cluster '{1}' is success {2}"
).format(
task_cache["role"],
task.cluster.name,
task_cache[task_cache["role"].lower()]["action"]
)
except Exception as exc:
logger.error(": ".join([
str(exc),
traceback.format_exc()
]))
message = u"{0} of environment '{1}' is done".format(
task_name,
task.cluster.name
)
notifier.notify(
"done",
message,
task.cluster_id
)
data = {'status': status, 'progress': progress, 'message': message,'timestamp':datetime.datetime.now()}
objects.Task.update(task, data)