Skip to content

Commit 20da8e1

Browse files
gthiemongejohnsom
authored andcommitted
Fix pylint checks
pylint 2.10.2 introduced new checkers. Fixed redundant-u-string-prefix, use-dict-literal, use-list-literal, and unspecified-encoding warnings Change-Id: Ifdb1acb7e53ca2acfbef8c34dbb360d738117439
1 parent 5c8f606 commit 20da8e1

File tree

14 files changed

+47
-37
lines changed

14 files changed

+47
-37
lines changed

octavia/amphorae/backends/agent/api_server/amphora_info.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def _get_extend_body_from_lvs_driver(self, extend_lvs_driver):
127127

128128
def _get_meminfo(self):
129129
re_parser = re.compile(r'^(?P<key>\S*):\s*(?P<value>\d*)\s*kB')
130-
result = dict()
131-
with open('/proc/meminfo', 'r') as meminfo:
130+
result = {}
131+
with open('/proc/meminfo', 'r', encoding='utf-8') as meminfo:
132132
for line in meminfo:
133133
match = re_parser.match(line)
134134
if not match:
@@ -138,7 +138,7 @@ def _get_meminfo(self):
138138
return result
139139

140140
def _cpu(self):
141-
with open('/proc/stat') as f:
141+
with open('/proc/stat', encoding='utf-8') as f:
142142
cpu = f.readline()
143143
vals = cpu.split(' ')
144144
return {
@@ -153,13 +153,13 @@ def _cpu(self):
153153
}
154154

155155
def _load(self):
156-
with open('/proc/loadavg') as f:
156+
with open('/proc/loadavg', encoding='utf-8') as f:
157157
load = f.readline()
158158
vals = load.split(' ')
159159
return vals[:3]
160160

161161
def _get_networks(self):
162-
networks = dict()
162+
networks = {}
163163
with pyroute2.NetNS(consts.AMPHORA_NAMESPACE) as netns:
164164
for interface in netns.get_links():
165165
interface_name = None

octavia/amphorae/backends/agent/api_server/keepalived.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ def manager_keepalived_service(self, action):
146146
keepalived_pid_path = util.keepalived_pid_path()
147147
try:
148148
# Is there a pid file for keepalived?
149-
with open(keepalived_pid_path, 'r') as pid_file:
149+
with open(keepalived_pid_path,
150+
'r', encoding='utf-8') as pid_file:
150151
pid = int(pid_file.readline())
151152
os.kill(pid, 0)
152153

octavia/amphorae/backends/agent/api_server/keepalivedlvs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ def get_lvs_listener_config(self, listener_id):
189189
:param listener_id: the id of the listener
190190
"""
191191
self._check_lvs_listener_exists(listener_id)
192-
with open(util.keepalived_lvs_cfg_path(listener_id), 'r') as file:
192+
with open(util.keepalived_lvs_cfg_path(listener_id),
193+
'r', encoding='utf-8') as file:
193194
cfg = file.read()
194195
resp = webob.Response(cfg, content_type='text/plain')
195196
return resp
@@ -242,7 +243,7 @@ def _check_lvs_listener_status(self, listener_id):
242243
'/proc', util.get_keepalivedlvs_pid(listener_id))):
243244
# Check if the listener is disabled
244245
with open(util.keepalived_lvs_cfg_path(listener_id),
245-
'r') as file:
246+
'r', encoding='utf-8') as file:
246247
cfg = file.read()
247248
m = re.search('virtual_server', cfg)
248249
if m:
@@ -256,7 +257,7 @@ def get_all_lvs_listeners_status(self):
256257
257258
Gets the status of all UDP listeners on the amphora.
258259
"""
259-
listeners = list()
260+
listeners = []
260261

261262
for lvs_listener in util.get_lvs_listeners():
262263
status = self._check_lvs_listener_status(lvs_listener)

octavia/amphorae/backends/agent/api_server/loadbalancer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def get_haproxy_config(self, lb_id):
8282
:param listener_id: the id of the listener
8383
"""
8484
self._check_lb_exists(lb_id)
85-
with open(util.config_path(lb_id), 'r') as file:
85+
with open(util.config_path(lb_id), 'r', encoding='utf-8') as file:
8686
cfg = file.read()
8787
resp = webob.Response(cfg, content_type='text/plain')
8888
resp.headers['ETag'] = (
@@ -365,7 +365,7 @@ def get_all_listeners_status(self, other_listeners=None):
365365
366366
Currently type==SSL is also not detected
367367
"""
368-
listeners = list()
368+
listeners = []
369369

370370
for lb in util.get_loadbalancers():
371371
stats_socket, listeners_on_lb = util.parse_haproxy_file(lb)
@@ -414,7 +414,7 @@ def get_certificate_md5(self, lb_id, filename):
414414
details="No certificate with filename: {f}".format(
415415
f=filename)), status=404)
416416

417-
with open(cert_path, 'r') as crt_file:
417+
with open(cert_path, 'r', encoding='utf-8') as crt_file:
418418
cert = crt_file.read()
419419
md5sum = md5(octavia_utils.b(cert),
420420
usedforsecurity=False).hexdigest() # nosec
@@ -433,7 +433,8 @@ def _get_listeners_on_lb(self, lb_id):
433433
if os.path.exists(
434434
os.path.join('/proc', util.get_haproxy_pid(lb_id))):
435435
# Check if the listener is disabled
436-
with open(util.config_path(lb_id), 'r') as file:
436+
with open(util.config_path(lb_id),
437+
'r', encoding='utf-8') as file:
437438
cfg = file.read()
438439
m = re.findall('^frontend (.*)$', cfg, re.MULTILINE)
439440
return m or []

octavia/amphorae/backends/agent/api_server/util.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ def config_path(lb_id):
116116

117117

118118
def get_haproxy_pid(lb_id):
119-
with open(pid_path(lb_id), 'r') as f:
119+
with open(pid_path(lb_id), 'r', encoding='utf-8') as f:
120120
return f.readline().rstrip()
121121

122122

123123
def get_keepalivedlvs_pid(listener_id):
124124
pid_file = keepalived_lvs_pids_path(listener_id)[0]
125-
with open(pid_file, 'r') as f:
125+
with open(pid_file, 'r', encoding='utf-8') as f:
126126
return f.readline().rstrip()
127127

128128

@@ -224,7 +224,8 @@ def is_lvs_listener_running(listener_id):
224224

225225
def get_os_init_system():
226226
if os.path.exists(consts.INIT_PROC_COMM_PATH):
227-
with open(consts.INIT_PROC_COMM_PATH, 'r') as init_comm:
227+
with open(consts.INIT_PROC_COMM_PATH,
228+
'r', encoding='utf-8') as init_comm:
228229
init_proc_name = init_comm.read().rstrip('\n')
229230
if init_proc_name == consts.INIT_SYSTEMD:
230231
return consts.INIT_SYSTEMD
@@ -293,7 +294,7 @@ def get_backend_for_lb_object(object_id):
293294

294295

295296
def parse_haproxy_file(lb_id):
296-
with open(config_path(lb_id), 'r') as file:
297+
with open(config_path(lb_id), 'r', encoding='utf-8') as file:
297298
cfg = file.read()
298299

299300
listeners = {}
@@ -345,7 +346,8 @@ def vrrp_check_script_update(lb_id, action):
345346
# If no LBs are found, so make sure keepalived thinks haproxy is down.
346347
if not lb_ids:
347348
if not lvs_ids:
348-
with open(haproxy_check_script_path(), 'w') as text_file:
349+
with open(haproxy_check_script_path(),
350+
'w', encoding='utf-8') as text_file:
349351
text_file.write('exit 1')
350352
else:
351353
try:
@@ -362,7 +364,7 @@ def vrrp_check_script_update(lb_id, action):
362364
args.append(haproxy_sock_path(lbid))
363365

364366
cmd = 'haproxy-vrrp-check {args}; exit $?'.format(args=' '.join(args))
365-
with open(haproxy_check_script_path(), 'w') as text_file:
367+
with open(haproxy_check_script_path(), 'w', encoding='utf-8') as text_file:
366368
text_file.write(cmd)
367369

368370

@@ -373,7 +375,7 @@ def get_haproxy_vip_addresses(lb_id):
373375
:returns: List of VIP addresses (IPv4 and IPv6)
374376
"""
375377
vips = []
376-
with open(config_path(lb_id), 'r') as file:
378+
with open(config_path(lb_id), 'r', encoding='utf-8') as file:
377379
for line in file:
378380
current_line = line.strip()
379381
if current_line.startswith('bind'):

octavia/amphorae/backends/health_daemon/health_daemon.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def run_sender(cmd_queue):
118118
# heartbeat
119119
if os.path.isfile(keepalived_cfg_path):
120120
# Is there a pid file for keepalived?
121-
with open(keepalived_pid_path, 'r') as pid_file:
121+
with open(keepalived_pid_path,
122+
'r', encoding='utf-8') as pid_file:
122123
pid = int(pid_file.readline())
123124
os.kill(pid, 0)
124125

@@ -251,7 +252,7 @@ def build_stats_message():
251252
pool_status = (
252253
keepalivedlvs_query.get_lvs_listener_pool_status(
253254
listener_id))
254-
lvs_listener_dict = dict()
255+
lvs_listener_dict = {}
255256
lvs_listener_dict['status'] = listener_stats['status']
256257
lvs_listener_dict['stats'] = {
257258
'tx': delta_values['bout'],

octavia/amphorae/backends/utils/haproxy_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _query(self, query):
5353

5454
try:
5555
sock.send(octavia_utils.b(query + '\n'))
56-
data = u''
56+
data = ''
5757
while True:
5858
x = sock.recv(1024)
5959
if not x:
@@ -68,7 +68,7 @@ def show_info(self):
6868
"""Get and parse output from 'show info' command."""
6969
results = self._query('show info')
7070

71-
dict_results = dict()
71+
dict_results = {}
7272
for r in results.split('\n'):
7373
vals = r.split(":", 1)
7474
dict_results[vals[0].strip()] = vals[1].strip()

octavia/amphorae/backends/utils/keepalivedlvs_query.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def get_lvs_listener_resource_ipports_nsname(listener_id):
147147
# 'ipport': ipport}],
148148
# 'HealthMonitor': {'id': healthmonitor-id}}
149149
resource_ipport_mapping = {}
150-
with open(util.keepalived_lvs_cfg_path(listener_id), 'r') as f:
150+
with open(util.keepalived_lvs_cfg_path(listener_id),
151+
'r', encoding='utf-8') as f:
151152
cfg = f.read()
152153
ns_name = NS_REGEX.findall(cfg)[0]
153154
listener_ip_port = V4_VS_REGEX.findall(cfg)
@@ -255,7 +256,8 @@ def get_lvs_listener_pool_status(listener_id):
255256
# updating to a recent keepalived release.
256257
restarting = config_stat.st_mtime > check_pid_stat.st_mtime
257258

258-
with open(util.keepalived_lvs_cfg_path(listener_id), 'r') as f:
259+
with open(util.keepalived_lvs_cfg_path(listener_id),
260+
'r', encoding='utf-8') as f:
259261
cfg = f.read()
260262
hm_enabled = len(CHECKER_REGEX.findall(cfg)) > 0
261263

@@ -323,7 +325,7 @@ def get_ipvsadm_info(ns_name, is_stats_cmd=False):
323325
# mapping = {'listeneripport': {'Linstener': vs_values,
324326
# 'members': [rs_values1, rs_values2]}}
325327
last_key = None
326-
value_mapping = dict()
328+
value_mapping = {}
327329
output_line_num = len(output)
328330

329331
def split_line(line):
@@ -382,8 +384,8 @@ def get_lvs_listeners_stats():
382384
need_check_listener_ids = [
383385
listener_id for listener_id in lvs_listener_ids
384386
if util.is_lvs_listener_running(listener_id)]
385-
ipport_mapping = dict()
386-
listener_stats_res = dict()
387+
ipport_mapping = {}
388+
listener_stats_res = {}
387389
for check_listener_id in need_check_listener_ids:
388390
# resource_ipport_mapping = {'Listener': {'id': listener-id,
389391
# 'ipport': ipport},

octavia/amphorae/backends/utils/network_namespace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def __init__(self, netns):
4141
def __enter__(self):
4242
# Save the current network namespace
4343
# pylint: disable=consider-using-with
44-
self.current_netns_fd = open(self.current_netns)
45-
with open(self.target_netns) as fd:
44+
self.current_netns_fd = open(self.current_netns, encoding='utf-8')
45+
with open(self.target_netns, encoding='utf-8') as fd:
4646
self.set_netns(fd.fileno(), self.CLONE_NEWNET)
4747

4848
def __exit__(self, *args):

octavia/amphorae/drivers/haproxy/rest_api_driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def _process_listener_pool_certs(self, listener, amphora, obj_id):
513513
# 'client_cert': client_full_filename,
514514
# 'ca_cert': ca_cert_full_filename,
515515
# 'crl': crl_full_filename}}
516-
pool_certs_dict = dict()
516+
pool_certs_dict = {}
517517
for pool in listener.pools:
518518
if pool.id not in pool_certs_dict:
519519
pool_certs_dict[pool.id] = self._process_pool_certs(
@@ -527,7 +527,7 @@ def _process_listener_pool_certs(self, listener, amphora, obj_id):
527527
return pool_certs_dict
528528

529529
def _process_pool_certs(self, listener, pool, amphora, obj_id):
530-
pool_cert_dict = dict()
530+
pool_cert_dict = {}
531531

532532
# Handle the client cert(s) and key
533533
if pool.tls_certificate_id:

octavia/certificates/manager/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_cert(context, cert_ref, **kwargs):
111111
filename_intermediates = "{0}.int".format(filename_base)
112112
filename_pkp = "{0}.pass".format(filename_base)
113113

114-
cert_data = dict()
114+
cert_data = {}
115115

116116
flags = os.O_RDONLY
117117
try:

octavia/cmd/health_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def sctp_health_check(ip_address, port, timeout=2):
224224
if send_abort:
225225
has_sctp_support = False
226226

227-
with open("/proc/net/protocols") as fp:
227+
with open("/proc/net/protocols", encoding='utf-8') as fp:
228228
for line in fp:
229229
if line.startswith('SCTP'):
230230
has_sctp_support = True

octavia/controller/worker/v1/tasks/compute_tasks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def execute(self, amphora_id, server_pem, server_group_id,
158158
"""
159159

160160
# load client certificate
161-
with open(CONF.controller_worker.client_ca, 'r') as client_ca:
161+
with open(CONF.controller_worker.client_ca,
162+
'r', encoding='utf-8') as client_ca:
162163
ca = client_ca.read()
163164

164165
key = utils.get_compatible_server_certs_key_passphrase()

octavia/controller/worker/v2/tasks/compute_tasks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ def execute(self, amphora_id, server_pem, server_group_id,
165165
"""
166166

167167
# load client certificate
168-
with open(CONF.controller_worker.client_ca, 'r') as client_ca:
168+
with open(CONF.controller_worker.client_ca,
169+
'r', encoding='utf-8') as client_ca:
169170
ca = client_ca.read()
170171

171172
key = utils.get_compatible_server_certs_key_passphrase()

0 commit comments

Comments
 (0)