Skip to content

Commit 397f49c

Browse files
committed
Bump hacking
hacking was indirectly capped by pycodestyle. This bumps hacking to apply the rules recently added. Also remove the note about pip's behavior, which is no longer valid for recent versions. notes: - T117 test is now disabled. There are a lot of lines violating this rule and we have to decide if we really want to enforce it. - Once this is merged, we have to update bump hacking in some plugins which import hacking extensions from tempest. Change-Id: I5ee5e152418079f9f2720eb97c3a5361edba2695
1 parent 22022cc commit 397f49c

File tree

11 files changed

+93
-89
lines changed

11 files changed

+93
-89
lines changed

requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# The order of packages is significant, because pip processes them in the order
2-
# of appearance. Changing the order has an impact on the overall integration
3-
# process, which may cause wedges in the gate later.
41
pbr!=2.1.0,>=2.0.0 # Apache-2.0
52
cliff!=2.9.0,>=2.8.0 # Apache-2.0
63
jsonschema>=3.2.0 # MIT

tempest/api/identity/admin/v3/test_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_list_user_groups(self):
128128
for g in user_groups:
129129
if 'membership_expires_at' in g:
130130
self.assertIsNone(g['membership_expires_at'])
131-
del(g['membership_expires_at'])
131+
del g['membership_expires_at']
132132
self.assertEqual(sorted(groups, key=lambda k: k['name']),
133133
sorted(user_groups, key=lambda k: k['name']))
134134
self.assertEqual(2, len(user_groups))

tempest/common/utils/linux/remote_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ def get_disks(self):
5959
output = self.exec_command(command)
6060
selected = []
6161
pos = None
62-
for l in output.splitlines():
63-
if pos is None and l.find("TYPE") > 0:
64-
pos = l.find("TYPE")
62+
for line in output.splitlines():
63+
if pos is None and line.find("TYPE") > 0:
64+
pos = line.find("TYPE")
6565
# Show header line too
66-
selected.append(l)
66+
selected.append(line)
6767
# lsblk lists disk type in a column right-aligned with TYPE
68-
elif pos is not None and pos > 0 and l[pos:pos + 4] == "disk":
69-
selected.append(l)
68+
elif pos is not None and pos > 0 and line[pos:pos + 4] == "disk":
69+
selected.append(line)
7070

7171
if selected:
7272
return "\n".join(selected)
@@ -121,9 +121,9 @@ def get_nic_ip_addresses(self, nic_name, ip_version=None):
121121
def _get_dns_servers(self):
122122
cmd = 'cat /etc/resolv.conf'
123123
resolve_file = self.exec_command(cmd).strip().split('\n')
124-
entries = (l.split() for l in resolve_file)
125-
dns_servers = [l[1] for l in entries
126-
if len(l) and l[0] == 'nameserver']
124+
entries = (line.split() for line in resolve_file)
125+
dns_servers = [line[1] for line in entries
126+
if len(line) and line[0] == 'nameserver']
127127
return dns_servers
128128

129129
def get_dns_servers(self, timeout=5):

tempest/common/utils/net_downtime.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,29 @@
5050

5151

5252
class NetDowntimeMeter(fixtures.Fixture):
53-
def __init__(self, dest_ip, interval='0.2'):
53+
def __init__(self, dest_ip, interval=0.2):
5454
self.dest_ip = dest_ip
5555
# Note: for intervals lower than 0.2 ping requires root privileges
56-
self.interval = interval
56+
self.interval = float(interval)
5757
self.ping_process = None
5858

5959
def _setUp(self):
6060
self.start_background_pinger()
6161

6262
def start_background_pinger(self):
6363
cmd = ['ping', '-q', '-s1']
64-
cmd.append('-i{}'.format(self.interval))
64+
cmd.append('-i%g' % self.interval)
6565
cmd.append(self.dest_ip)
66-
LOG.debug("Starting background pinger to '{}' with interval {}".format(
67-
self.dest_ip, self.interval))
66+
LOG.debug("Starting background pinger to '%s' with interval %g",
67+
self.dest_ip, self.interval)
6868
self.ping_process = subprocess.Popen(
6969
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
7070
self.addCleanup(self.cleanup)
7171

7272
def cleanup(self):
7373
if self.ping_process and self.ping_process.poll() is None:
74-
LOG.debug('Terminating background pinger with pid {}'.format(
75-
self.ping_process.pid))
74+
LOG.debug('Terminating background pinger with pid %d',
75+
self.ping_process.pid)
7676
self.ping_process.terminate()
7777
self.ping_process = None
7878

@@ -83,7 +83,7 @@ def get_downtime(self):
8383
output = self.ping_process.stderr.readline().strip().decode('utf-8')
8484
if output and len(output.split()[0].split('/')) == 2:
8585
succ, total = output.split()[0].split('/')
86-
return (int(total) - int(succ)) * float(self.interval)
86+
return (int(total) - int(succ)) * self.interval
8787
else:
8888
LOG.warning('Unexpected output obtained from the pinger: %s',
8989
output)
@@ -115,8 +115,9 @@ def upload_metadata_script(self):
115115
chmod_cmd = 'chmod +x {}'.format(self.script_path)
116116
self.ssh_client.exec_command(';'.join((echo_cmd, chmod_cmd)))
117117
LOG.debug('script created: %s', self.script_path)
118-
LOG.debug(self.ssh_client.exec_command(
119-
'cat {}'.format(self.script_path)))
118+
output = self.ssh_client.exec_command(
119+
'cat {}'.format(self.script_path))
120+
LOG.debug('script content: %s', output)
120121

121122
def run_metadata_script(self):
122123
self.ssh_client.exec_command('{} > {} &'.format(self.script_path,

tempest/common/waiters.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ def wait_for_image_deleted_from_store(client, image, available_stores,
327327
# Check if image have last store location
328328
if len(available_stores) == 1:
329329
exc_cls = lib_exc.OtherRestClientException
330-
message = ('Delete from last store location not allowed'
331-
% (image, image_store_deleted))
330+
message = 'Delete from last store location not allowed'
332331
raise exc_cls(message)
333332
start = int(time.time())
334333
while int(time.time()) - start < client.build_timeout:
@@ -548,7 +547,7 @@ def wait_for_interface_status(client, server_id, port_id, status):
548547
interface_status = body['port_state']
549548
start = int(time.time())
550549

551-
while(interface_status != status):
550+
while interface_status != status:
552551
time.sleep(client.build_interval)
553552
body = (client.show_interface(server_id, port_id)
554553
['interfaceAttachment'])

tempest/hacking/checks.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import re
1717

1818
from hacking import core
19-
import pycodestyle
2019

2120

2221
PYTHON_CLIENTS = ['cinder', 'glance', 'keystone', 'nova', 'swift', 'neutron',
@@ -40,51 +39,51 @@
4039

4140

4241
@core.flake8ext
43-
def import_no_clients_in_api_and_scenario_tests(physical_line, filename):
42+
def import_no_clients_in_api_and_scenario_tests(logical_line, filename):
4443
"""Check for client imports from tempest/api & tempest/scenario tests
4544
4645
T102: Cannot import OpenStack python clients
4746
"""
4847

4948
if "tempest/api" in filename or "tempest/scenario" in filename:
50-
res = PYTHON_CLIENT_RE.match(physical_line)
49+
res = PYTHON_CLIENT_RE.match(logical_line)
5150
if res:
52-
return (physical_line.find(res.group(1)),
51+
return (logical_line.find(res.group(1)),
5352
("T102: python clients import not allowed"
5453
" in tempest/api/* or tempest/scenario/* tests"))
5554

5655

5756
@core.flake8ext
58-
def scenario_tests_need_service_tags(physical_line, filename,
57+
def scenario_tests_need_service_tags(logical_line, filename,
5958
previous_logical):
6059
"""Check that scenario tests have service tags
6160
6261
T104: Scenario tests require a services decorator
6362
"""
6463

6564
if 'tempest/scenario/' in filename and '/test_' in filename:
66-
if TEST_DEFINITION.match(physical_line):
65+
if TEST_DEFINITION.match(logical_line):
6766
if not SCENARIO_DECORATOR.match(previous_logical):
68-
return (physical_line.find('def'),
67+
return (logical_line.find('def'),
6968
"T104: Scenario tests require a service decorator")
7069

7170

7271
@core.flake8ext
73-
def no_setup_teardown_class_for_tests(physical_line, filename):
72+
def no_setup_teardown_class_for_tests(logical_line, filename, noqa):
7473

75-
if pycodestyle.noqa(physical_line):
74+
if noqa:
7675
return
7776

7877
if 'tempest/test.py' in filename or 'tempest/lib/' in filename:
7978
return
8079

81-
if SETUP_TEARDOWN_CLASS_DEFINITION.match(physical_line):
82-
return (physical_line.find('def'),
80+
if SETUP_TEARDOWN_CLASS_DEFINITION.match(logical_line):
81+
return (logical_line.find('def'),
8382
"T105: (setUp|tearDown)Class can not be used in tests")
8483

8584

8685
@core.flake8ext
87-
def service_tags_not_in_module_path(physical_line, filename):
86+
def service_tags_not_in_module_path(logical_line, filename):
8887
"""Check that a service tag isn't in the module path
8988
9089
A service tag should only be added if the service name isn't already in
@@ -96,14 +95,14 @@ def service_tags_not_in_module_path(physical_line, filename):
9695
# created for services like heat which would cause false negatives for
9796
# those tests, so just exclude the scenario tests.
9897
if 'tempest/scenario' not in filename:
99-
matches = SCENARIO_DECORATOR.match(physical_line)
98+
matches = SCENARIO_DECORATOR.match(logical_line)
10099
if matches:
101100
services = matches.group(1).split(',')
102101
for service in services:
103102
service_name = service.strip().strip("'")
104103
modulepath = os.path.split(filename)[0]
105104
if service_name in modulepath:
106-
return (physical_line.find(service_name),
105+
return (logical_line.find(service_name),
107106
"T107: service tag should not be in path")
108107

109108

@@ -140,28 +139,27 @@ def no_testtools_skip_decorator(logical_line):
140139
"decorators.skip_because from tempest.lib")
141140

142141

143-
def _common_service_clients_check(logical_line, physical_line, filename):
144-
if not re.match('tempest/(lib/)?services/.*', filename):
142+
def _common_service_clients_check(logical_line, filename, noqa):
143+
if noqa:
145144
return False
146145

147-
if not METHOD.match(physical_line):
146+
if not re.match('tempest/(lib/)?services/.*', filename):
148147
return False
149148

150-
if pycodestyle.noqa(physical_line):
149+
if not METHOD.match(logical_line):
151150
return False
152151

153152
return True
154153

155154

156155
@core.flake8ext
157-
def get_resources_on_service_clients(physical_line, logical_line, filename,
158-
line_number, lines):
156+
def get_resources_on_service_clients(logical_line, filename,
157+
line_number, lines, noqa):
159158
"""Check that service client names of GET should be consistent
160159
161160
T110
162161
"""
163-
if not _common_service_clients_check(logical_line, physical_line,
164-
filename):
162+
if not _common_service_clients_check(logical_line, filename, noqa):
165163
return
166164

167165
for line in lines[line_number:]:
@@ -182,14 +180,13 @@ def get_resources_on_service_clients(physical_line, logical_line, filename,
182180

183181

184182
@core.flake8ext
185-
def delete_resources_on_service_clients(physical_line, logical_line, filename,
186-
line_number, lines):
183+
def delete_resources_on_service_clients(logical_line, filename,
184+
line_number, lines, noqa):
187185
"""Check that service client names of DELETE should be consistent
188186
189187
T111
190188
"""
191-
if not _common_service_clients_check(logical_line, physical_line,
192-
filename):
189+
if not _common_service_clients_check(logical_line, filename, noqa):
193190
return
194191

195192
for line in lines[line_number:]:
@@ -262,7 +259,7 @@ def dont_use_config_in_tempest_lib(logical_line, filename):
262259
'oslo_config' in logical_line):
263260
msg = ('T114: tempest.lib can not have any dependency on tempest '
264261
'config.')
265-
yield(0, msg)
262+
yield (0, msg)
266263

267264

268265
@core.flake8ext
@@ -281,7 +278,7 @@ def dont_put_admin_tests_on_nonadmin_path(logical_line,
281278

282279
if not re.match(r'.\/tempest\/api\/.*\/admin\/.*', filename):
283280
msg = 'T115: All admin tests should exist under admin path.'
284-
yield(0, msg)
281+
yield (0, msg)
285282

286283

287284
@core.flake8ext
@@ -293,11 +290,11 @@ def unsupported_exception_attribute_PY3(logical_line):
293290
result = EX_ATTRIBUTE.search(logical_line)
294291
msg = ("[T116] Unsupported 'message' Exception attribute in PY3")
295292
if result:
296-
yield(0, msg)
293+
yield (0, msg)
297294

298295

299296
@core.flake8ext
300-
def negative_test_attribute_always_applied_to_negative_tests(physical_line,
297+
def negative_test_attribute_always_applied_to_negative_tests(logical_line,
301298
filename):
302299
"""Check ``@decorators.attr(type=['negative'])`` applied to negative tests.
303300
@@ -307,13 +304,13 @@ def negative_test_attribute_always_applied_to_negative_tests(physical_line,
307304

308305
if re.match(r'.\/tempest\/api\/.*_negative.*', filename):
309306

310-
if NEGATIVE_TEST_DECORATOR.match(physical_line):
307+
if NEGATIVE_TEST_DECORATOR.match(logical_line):
311308
_HAVE_NEGATIVE_DECORATOR = True
312309
return
313310

314-
if TEST_DEFINITION.match(physical_line):
311+
if TEST_DEFINITION.match(logical_line):
315312
if not _HAVE_NEGATIVE_DECORATOR:
316-
return (
313+
yield (
317314
0, "T117: Must apply `@decorators.attr(type=['negative'])`"
318315
" to all negative API tests"
319316
)

tempest/scenario/manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ def image_create(self, name='scenario-img', **kwargs):
851851
kernel_img_path = os.path.join(extract_dir, fname)
852852
elif re.search(r'(.*-initrd.*|ari-.*/image$)', fname):
853853
ramdisk_img_path = os.path.join(extract_dir, fname)
854-
elif re.search(f'(.*\\.img$|ami-.*/image$)', fname):
854+
elif re.search(r'(.*\\.img$|ami-.*/image$)', fname):
855855
img_path = os.path.join(extract_dir, fname)
856856
# Create the kernel image.
857857
kparams = {
@@ -1561,8 +1561,8 @@ def refresh():
15611561
floating_ip = (self.floating_ips_client.
15621562
show_floatingip(floatingip_id)['floatingip'])
15631563
if status == floating_ip['status']:
1564-
LOG.info("FloatingIP: {fp} is at status: {st}"
1565-
.format(fp=floating_ip, st=status))
1564+
LOG.info("FloatingIP: %s is at status: %s",
1565+
floating_ip, status)
15661566
return status == floating_ip['status']
15671567

15681568
if not test_utils.call_until_true(refresh,

0 commit comments

Comments
 (0)