Handle log message interpolation by the logger in common/

According to OpenStack Guideline[1], logged string message should be
interpolated by the logger.
[1]: https://docs.openstack.org/oslo.i18n/latest/user/guidelines.html

Change-Id: I37af1aaf8163d3054ba92099f2d9244fa3bbe8a7
This commit is contained in:
rajat29 2017-08-09 12:50:15 +05:30 committed by Zhijiang Hu
parent 97c649a022
commit 4b286c742f
7 changed files with 77 additions and 77 deletions

View File

@ -185,7 +185,7 @@ def subprocess_call(command, file=None):
if file:
file.write(e.output.strip())
msg = "execute '%s' failed by subprocess call, "\
"error message: %s." % (command, e.output.strip())
"error message: %s.", (command, e.output.strip())
raise exception.SubprocessCmdFailed(message=msg)
@ -195,7 +195,7 @@ def check_file_whether_exist(file_name):
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
if e.returncode == 1:
msg = "%s does not exist" % file_name
msg = "%s does not exist", file_name
LOG.info(msg)
return False
else:
@ -212,7 +212,7 @@ def get_host_detail(req, host_id):
except exception.Invalid as e:
raise HTTPBadRequest(explanation=e.msg, request=req)
except exception.NotFound:
msg = "Host with identifier %s not found" % host_id
msg = "Host with identifier %s not found", host_id
LOG.debug(msg)
raise HTTPNotFound(msg)
return host_detail
@ -362,7 +362,7 @@ def _ping_hosts_test(ips):
)[0] for result in ping_result if result and
result.split()[2] != 'alive']
else:
msg = "ping failed beaceuse there is invlid ip in %s" % ips
msg = "ping failed beaceuse there is invlid ip in %s", ips
raise exception.InvalidIP(msg)
return unreachable_hosts
@ -373,7 +373,7 @@ def check_ping_hosts(ping_ips, max_ping_times):
return ping_ips
ping_count = 0
time_step = 5
LOG.info(_("begin ping test for %s" % ','.join(ping_ips)))
LOG.info(_("begin ping test for %s", ','.join(ping_ips)))
while True:
if ping_count == 0:
ips = _ping_hosts_test(ping_ips)
@ -383,14 +383,14 @@ def check_ping_hosts(ping_ips, max_ping_times):
ping_count += 1
if ips:
LOG.debug(
_("ping host %s for %s times" % (','.join(ips), ping_count)))
_("ping host %s for %s times", (','.join(ips), ping_count)))
if ping_count >= max_ping_times:
LOG.info(_("ping host %s timeout for %ss" %
LOG.info(_("ping host %s timeout for %ss",
(','.join(ips), ping_count * time_step)))
return ips
time.sleep(time_step)
else:
LOG.info(_("ping %s successfully" % ','.join(ping_ips)))
LOG.info(_("ping %s successfully", ','.join(ping_ips)))
return ips
@ -463,12 +463,12 @@ def cidr_to_netmask(cidr):
def get_rpm_package_by_name(path, rpm_name):
cmd = "ls %s | grep ^%s.*\.rpm" % (path, rpm_name)
cmd = "ls %s | grep ^%s.*\.rpm", (path, rpm_name)
try:
rpm_name = subprocess.check_output(
cmd, shell=True, stderr=subprocess.STDOUT).split('\n')[0]
except subprocess.CalledProcessError:
msg = _("Get rpm %s failed in %s!" % (rpm_name, path))
msg = _("Get rpm %s failed in %s!", (rpm_name, path))
raise exception.SubprocessCmdFailed(message=msg)
return rpm_name
@ -520,25 +520,25 @@ def trust_me(host_ips, root_passwd):
while count < try_times:
try:
trust_me_cmd = "/var/lib/daisy/trustme.sh\
%s %s" % (host_ip, root_passwd)
%s %s", (host_ip, root_passwd)
subprocess_call(trust_me_cmd)
except:
count += 1
LOG.info("Trying to trust '%s' for %s times" %
LOG.info("Trying to trust '%s' for %s times",
(host_ip, count))
time.sleep(2)
if count >= try_times:
message = "Setup trust for '%s' failed,"\
"see '/var/log/trustme.log' please" % (host_ip)
"see '/var/log/trustme.log' please", (host_ip)
raise exception.TrustMeFailed(message=message)
else:
message = "Setup trust to '%s' successfully" % (host_ip)
message = "Setup trust to '%s' successfully", (host_ip)
LOG.info(message)
break
def calc_host_iqn(min_mac):
cmd = "echo -n %s |openssl md5" % min_mac
cmd = "echo -n %s |openssl md5", min_mac
obj = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
@ -554,7 +554,7 @@ def calc_host_iqn(min_mac):
def _get_cluster_network(cluster_networks, network_name):
network = [cn for cn in cluster_networks if cn['name'] == network_name]
if not network or not network[0]:
msg = "network %s is not exist" % (network_name)
msg = "network %s is not exist", (network_name)
raise exception.InvalidNetworkConfig(msg)
else:
return network[0]
@ -571,7 +571,7 @@ def get_host_interface_by_network(host_detail, network_name):
interface = interface_list[0]
if not interface and 'MANAGEMENT' == network_name:
msg = "network %s of host %s is not exist" % (
msg = "network %s of host %s is not exist", (
network_name, host_detail_info['id'])
raise exception.InvalidNetworkConfig(msg)
@ -586,7 +586,7 @@ def get_host_network_ip(req, host_detail, cluster_networks, network_name):
return assigned_network.get('ip')
if not interface_network_ip and 'MANAGEMENT' == network_name:
msg = "%s network ip of host %s can't be empty" % (
msg = "%s network ip of host %s can't be empty", (
network_name, host_detail['id'])
raise exception.InvalidNetworkConfig(msg)
return interface_network_ip
@ -679,9 +679,9 @@ def _run_scrip(script, ip=None, password=None):
script = "\n".join(script)
_PIPE = subprocess.PIPE
if ip:
cmd = ["sshpass", "-p", "%s" % password,
cmd = ["sshpass", "-p", "%s", password,
"ssh", "-o StrictHostKeyChecking=no",
"%s" % ip, "bash -x"]
"%s", ip, "bash -x"]
else:
cmd = ["bash", "-x"]
environ = os.environ
@ -757,7 +757,7 @@ def update_db_host_status(req, host_id, host_status, version_id=None):
def get_local_deployment_ip(tecs_deployment_ips):
if not isinstance(tecs_deployment_ips, list):
msg = "%s must be converted to list" % tecs_deployment_ips
msg = "%s must be converted to list", tecs_deployment_ips
LOG.error(msg)
raise exception.InvalidIP(msg)
(status, output) = commands.getstatusoutput('ifconfig')
@ -969,7 +969,7 @@ def check_vlan_nic_and_join_vlan_network(req, cluster_id,
check_ip_if_valid = \
_checker_the_ip_or_hostname_valid(host_ip)
if not check_ip_if_valid:
msg = "Error:The %s is not the right ip!" % host_ip
msg = "Error:The %s is not the right ip!", host_ip
LOG.error(msg)
raise HTTPForbidden(explanation=msg)
nic_name_list = interface_info['name'].split('.')
@ -1007,22 +1007,22 @@ def check_vlan_nic_and_join_vlan_network(req, cluster_id,
append({'name': network['name'],
'ip': host_ip})
LOG.info("add the nic %s of the host "
"%s to assigned_network %s" %
(interface_info['name'],
host_id,
interface_info
['assigned_networks']))
"%s to assigned_network %s",
interface_info['name'],
host_id,
interface_info
['assigned_networks'])
elif vlan_id == network['vlan_id'] \
and not ip_in_cidr:
msg = "The vlan of nic %s is the same " \
"as network %s, but the ip of nic " \
"is not in the cidr range." % \
"is not in the cidr range.", \
(nic_name, network['name'])
LOG.error(msg)
raise HTTPForbidden(explanation=msg)
else:
msg = "There is no cidr in network " \
"%s" % network['name']
"%s", network['name']
LOG.error(msg)
raise HTTPForbidden(explanation=msg)
return father_vlan_list
@ -1092,15 +1092,15 @@ def check_bond_or_ether_nic_and_join_network(req,
'ip': host_info_ip})
LOG.info("add the nic %s of the "
"host %s to "
"assigned_network %s" %
(nic_name,
host_id,
interface_info
['assigned_networks']))
"assigned_network %s",
nic_name,
host_id,
interface_info
['assigned_networks'])
else:
msg = ("the nic %s of ip %s is in "
"the %s cidr range,but the "
"network vlan id is %s " %
"network vlan id is %s ",
(nic_name,
host_info_ip,
network['name'], vlan_id))
@ -1108,7 +1108,7 @@ def check_bond_or_ether_nic_and_join_network(req,
raise HTTPForbidden(explanation=msg)
else:
msg = "There is no cidr in network " \
"%s" % network['name']
"%s", network['name']
LOG.error(msg)
raise HTTPForbidden(explanation=msg)
@ -1120,8 +1120,8 @@ def check_bond_or_ether_nic_and_join_network(req,
host_id,
host_meta)
LOG.info("add the host %s join the cluster %s and"
" assigned_network successful" %
(host_id, cluster_id))
" assigned_network successful",
host_id, cluster_id)
def if_used_shared_storage(req, cluster_id):

View File

@ -119,7 +119,7 @@ def _ping_hosts_test(ips):
result in ping_result if
result and result.split()[2] != 'alive']
else:
msg = "ping failed beaceuse there is invlid ip in %s" % ips
msg = "ping failed beaceuse there is invlid ip in %s", ips
raise exception.InvalidIP(msg)
return unreachable_hosts
@ -130,7 +130,7 @@ def _check_ping_hosts(ping_ips, max_ping_times):
return ping_ips
ping_count = 0
time_step = 5
LOG.info(_("begin ping test for %s" % ','.join(ping_ips)))
LOG.info(_("begin ping test for %s", ','.join(ping_ips)))
while True:
if ping_count == 0:
ips = _ping_hosts_test(ping_ips)
@ -146,9 +146,9 @@ def _check_ping_hosts(ping_ips, max_ping_times):
return ips
time.sleep(time_step)
else:
LOG.info(_("ping host %s success" % ','.join(ping_ips)))
LOG.info(_("ping host %s success", ','.join(ping_ips)))
time.sleep(120)
LOG.info(_("120s after ping host %s success" % ','.join(ping_ips)))
LOG.info(_("120s after ping host %s success", ','.join(ping_ips)))
return ips
@ -194,7 +194,7 @@ def get_cluster_kolla_config(req, cluster_id):
kolla_openstack_version = line.strip()
openstack_version = kolla_openstack_version.split(
": ")[1].strip('\"')
LOG.info(_("openstack version is %s" % openstack_version))
LOG.info(_("openstack version is %s"), openstack_version)
docker_registry_ip = kolla_cmn._get_local_ip()
docker_registry = docker_registry_ip + ':4000'
LOG.info(_("get cluster network detail..."))
@ -473,12 +473,12 @@ def _thread_bin(req, cluster_id, host, root_passwd, fp, host_name_ip_list,
(host_ip, host_prepare_file, docker_registry_ip),
shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
message = "exec prepare.sh in %s failed!" % host_ip
message = "exec prepare.sh in %s failed!", host_ip
LOG.error(message + e)
fp.write(e.output.strip())
raise exception.InstallException(message)
else:
LOG.info(_("prepare for %s successfully!" % host_ip))
LOG.info(_("prepare for %s successfully!", host_ip))
fp.write(exc_result)
message = "Preparing for installation successful!"
update_host_progress_to_db(req, role_id_list, host,
@ -493,7 +493,7 @@ def thread_bin(req, cluster_id, host, root_passwd, fp, host_name_ip_list,
host_prepare_file, docker_registry_ip, role_id_list)
except Exception as e:
message = "Prepare for installation failed!"
LOG.error(message + e)
LOG.error(message, e)
update_host_progress_to_db(req, role_id_list, host,
kolla_state['INSTALL_FAILED'],
message)
@ -597,7 +597,7 @@ class KOLLAInstallTask(Thread):
t_net.join()
except:
LOG.error("join config network "
"thread %s failed!" % t_net)
"thread %s failed!", t_net)
time.sleep(20)
@ -627,7 +627,7 @@ class KOLLAInstallTask(Thread):
t.join()
except:
LOG.error("join kolla prepare installation "
"thread %s failed!" % t)
"thread %s failed!", t)
# check, load and multicast version
if cluster_data.get('tecs_version_id', None):

View File

@ -70,7 +70,7 @@ def pci_get_cpu_sets(numa_cpus, device_numa_node, clc_pci_list):
if not numa_cpus or not numa_cpus['numa_node0']:
msg = "The architecture of CPU isn't supported for CLC"
LOG.error(msg)
LOG.info("numa_cpus=%s" % numa_cpus)
LOG.info("numa_cpus=%s", numa_cpus)
return_code = 4
status['rc'] = return_code
status['msg'] = msg
@ -82,7 +82,7 @@ def pci_get_cpu_sets(numa_cpus, device_numa_node, clc_pci_list):
numa_node = device_numa_node['0000:' + clc_pci]
if numa_node < 0:
msg = "Invalid numa_node '%s' for CLC, maybe you "\
"need to upgrade BIOS version" % numa_node
"need to upgrade BIOS version", numa_node
LOG.error(msg)
return_code = 1
status['rc'] = return_code
@ -106,7 +106,7 @@ def pci_get_cpu_sets(numa_cpus, device_numa_node, clc_pci_list):
total_cpus = get_total_cpus_for_numa(numa_cpus)
high_pci_cpu_set['low'] =\
list(set(total_cpus) - set(high_pci_cpu_set['high']))
LOG.debug("high_pci_cpu_set:%s" % high_pci_cpu_set)
LOG.debug("high_pci_cpu_set:%s", high_pci_cpu_set)
return (status, high_pci_cpu_set)
@ -121,7 +121,7 @@ def get_numa_by_nic(nics_info, device_numa_node):
numa = list(set(numa))
numa_info = (-100 if len(numa) > 1 else numa[0])
except Exception as e:
LOG.error("Error, exception message: %s" % e.message)
LOG.error("Error, exception message: %s", e.message)
numa_info = -200
return numa_info
@ -143,7 +143,7 @@ def dvs_get_cpu_sets(dic_numas, nics_info, device_numa_node, cpu_num=6):
if not dic_numas or not dic_numas['numa_node0']:
msg = "The architecture of CPU isn't supported for DVS"
LOG.error(msg)
LOG.info("numa_cpus=%s" % dic_numas)
LOG.info("numa_cpus=%s", dic_numas)
return_code = 4
status['rc'] = return_code
status['msg'] = msg
@ -179,7 +179,7 @@ def dvs_get_cpu_sets(dic_numas, nics_info, device_numa_node, cpu_num=6):
'numa_node': -3}
else:
msg = "Invalid numa node '%s' for DVS, maybe you "\
"need to upgrade BIOS version" % numa_node
"need to upgrade BIOS version", numa_node
return_code = 1
cpu_set = {'high': [-1],
'low': [-1],
@ -209,7 +209,7 @@ def dvs_get_cpu_sets(dic_numas, nics_info, device_numa_node, cpu_num=6):
return (status, cpu_set)
if len(dic_numas[numa_key]) < (cpu_num + 1):
msg = "CPU on numa node '%s' is not enough for DVS" % numa_key
msg = "CPU on numa node '%s' is not enough for DVS", numa_key
LOG.error(msg)
return_code = 6
status['rc'] = return_code
@ -223,7 +223,7 @@ def dvs_get_cpu_sets(dic_numas, nics_info, device_numa_node, cpu_num=6):
return (status, cpu_set)
total_cpus = get_total_cpus_for_numa(dic_numas)
LOG.debug("total_cpu:%s" % total_cpus)
LOG.debug("total_cpu:%s", total_cpus)
cpu_total_num = len(dic_numas[numa_key])
half_total_num = divmod(cpu_total_num, 2)[0]
half_cpu_num = divmod(cpu_num, 2)[0]
@ -244,20 +244,20 @@ def dvs_get_cpu_sets(dic_numas, nics_info, device_numa_node, cpu_num=6):
set(dvsc_cpus) | set(dvsp_cpus) | set(dvsv_cpus)))))
low_cpu_set =\
list(set(total_cpus).difference(set(dic_numas[numa_key])))
LOG.debug("cpu used by dvs:%s" % dvs_cpu_set)
LOG.debug("low_cpu_set:%s" % low_cpu_set)
LOG.debug("high_cpu_set:%s" % high_cpu_set)
LOG.debug("cpu used by dvs:%s", dvs_cpu_set)
LOG.debug("low_cpu_set:%s", low_cpu_set)
LOG.debug("high_cpu_set:%s", high_cpu_set)
cpu_set['numa_node'] = numa_node
cpu_set['dvs'] = dvs_cpu_set
cpu_set['high'] = high_cpu_set
cpu_set['low'] = low_cpu_set
LOG.debug("cpu_set:%s" % cpu_set)
LOG.debug("cpu_set:%s", cpu_set)
msg = 'Success'
status['rc'] = return_code
status['msg'] = msg
LOG.debug("status:%s" % status)
LOG.debug("status:%s", status)
return (status, cpu_set)
@ -288,7 +288,7 @@ def get_dvs_cpusets(numa_cpus, host_detail, host_hw_info):
device_numa = {}
for device in host_hw_info['devices'].values():
device_numa.update(device)
LOG.info("DVS netcard info: '%s'" % nics_info)
LOG.info("DVS netcard info: '%s'", nics_info)
(status, dvs_cpusets) = \
dvs_get_cpu_sets(numa_cpus,
nics_info,
@ -306,7 +306,7 @@ def get_dvs_cpusets(numa_cpus, host_detail, host_hw_info):
'dvsp': [-7],
'dvsv': [-7]},
'numa_node': -7}
msg = "Can't get DVS nics for host %s" % host_detail['id']
msg = "Can't get DVS nics for host %s", host_detail['id']
LOG.error(msg)
return dvs_cpusets
@ -369,9 +369,9 @@ def allocate_clc_cpus(host_detail):
if not clc_pci_list:
return pci_cpu_sets
else:
LOG.info("CLC card pci number: '%s'" % clc_pci_list)
LOG.info("CLC card pci number: '%s'", clc_pci_list)
numa_cpus = utils.get_numa_node_cpus(host_hw_info.get('cpu', {}))
LOG.info("Get CLC cpusets of host '%s'" % host_id)
LOG.info("Get CLC cpusets of host '%s'", host_id)
device_numa = {}
for device in host_hw_info['devices'].values():
device_numa.update(device)
@ -406,7 +406,7 @@ def allocate_dvs_cpus(host_detail):
host_hw_info[f] = host_obj.get(f)
numa_cpus = utils.get_numa_node_cpus(host_hw_info.get('cpu', {}))
LOG.info("Get DVS cpusets of host '%s'" % host_id)
LOG.info("Get DVS cpusets of host '%s'", host_id)
dvs_cpu_sets = get_dvs_cpusets(numa_cpus,
host_detail,
host_hw_info)

View File

@ -61,7 +61,7 @@ class TestCommon(test.TestCase):
mock_do_subprocess_call.side_effect = mock_subprocess_call
mock_log.side_effect = self._log_handler.info
common.trust_me(ip, passwd)
self.assertIn("Setup trust to '127.0.0.1' successfully",
self.assertIn(("Setup trust to '%s' successfully", '127.0.0.1'),
self._log_messages['info'])
@mock.patch('daisy.registry.client.v1.api.'

View File

@ -108,7 +108,7 @@ def _get_endpoint_url(request, endpoint_type, catalog=None):
url = base.url_for(request,
service_type='identity',
endpoint_type=endpoint_type)
# LOG.info("service_catalog None url =%s." % url )
# LOG.info("service_catalog None url =%s.", url )
else:
auth_url = getattr(settings, 'OPENSTACK_KEYSTONE_URL')
url = request.session.get('region_endpoint', auth_url)
@ -117,7 +117,7 @@ def _get_endpoint_url(request, endpoint_type, catalog=None):
# in the endpoints this can be removed.
url = url.rstrip('/')
url = urlparse.urljoin(url, 'v%s' % VERSIONS.active)
# LOG.info("url =%s." % url)
# LOG.info("url =%s.", url)
return url
@ -144,7 +144,7 @@ def keystoneclient(request, admin=False):
request/response cycle don't have to be re-authenticated.
"""
user = request.user
# LOG.info("user = %s." % user)
# LOG.info("user = %s.", user)
if admin:
if not policy.check((("identity", "admin_required"),), request):
raise exceptions.NotAuthorized
@ -154,7 +154,7 @@ def keystoneclient(request, admin=False):
endpoint_type = getattr(settings,
'OPENSTACK_ENDPOINT_TYPE',
'internalURL')
# LOG.info("else endpoint_type =%s." % endpoint_type)
# LOG.info("else endpoint_type =%s.", endpoint_type)
api_version = VERSIONS.get_active_version()
@ -170,7 +170,7 @@ def keystoneclient(request, admin=False):
endpoint = _get_endpoint_url(request, endpoint_type)
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
LOG.debug("Creating a new keystoneclient connection to %s." % endpoint)
LOG.debug("Creating a new keystoneclient connection to %s.", endpoint)
remote_addr = request.environ.get('REMOTE_ADDR', '')
conn = api_version['client'].Client(token=user.token.id,
endpoint=endpoint,
@ -238,7 +238,7 @@ def get_default_domain(request):
domain = domain_get(request, domain_id)
domain_name = domain.name
except Exception:
LOG.warning("Unable to retrieve Domain: %s" % domain_id)
LOG.warning("Unable to retrieve Domain: %s", domain_id)
domain = base.APIDictWrapper({"id": domain_id,
"name": domain_name})
return domain

View File

@ -59,7 +59,7 @@ def read_cached_file(filename, force_reload=False):
cache_info = _FILE_CACHE.setdefault(filename, {})
if not cache_info or mtime > cache_info.get('mtime', 0):
LOG.debug("Reloading cached file %s" % filename)
LOG.debug("Reloading cached file %s", filename)
with open(filename) as fap:
cache_info['data'] = fap.read()
cache_info['mtime'] = mtime

View File

@ -46,11 +46,11 @@ def _get_enforcer():
enforcer.policy_path = os.path.join(_BASE_PATH,
policy_files[service])
if os.path.isfile(enforcer.policy_path):
LOG.debug("adding enforcer for service: %s" % service)
LOG.debug("adding enforcer for service: %s", service)
_ENFORCER[service] = enforcer
else:
LOG.warning("policy file for service: %s not found at %s" %
(service, enforcer.policy_path))
LOG.warning("policy file for service: %s not found at %s",
service, enforcer.policy_path)
return _ENFORCER