From f5e77561e9a79f499cd8086abf7d49f7ccee96f7 Mon Sep 17 00:00:00 2001 From: Thomas Bechtold Date: Thu, 9 Jan 2020 08:27:37 +0100 Subject: [PATCH] qa: Fix problems detected by mypy This is a first step to enable mypy on the qa/ directory. Signed-off-by: Thomas Bechtold --- qa/tasks/cephfs/filesystem.py | 4 ++-- qa/tasks/cephfs/test_scrub_checks.py | 18 ++++++---------- qa/tasks/cephfs/test_snapshots.py | 6 +++--- qa/tasks/mds_thrash.py | 5 +++-- qa/tasks/mgr/test_insights.py | 2 +- qa/tasks/rbd.py | 6 +++--- qa/tasks/restart.py | 2 +- qa/tasks/rgw.py | 3 +-- qa/tasks/util/rgw.py | 4 ++-- qa/tasks/vstart_runner.py | 4 ++-- qa/tasks/workunit.py | 2 +- src/test/rgw/rgw_multi/tests.py | 9 -------- src/test/rgw/rgw_multi/tests_ps.py | 32 +++++++++++----------------- src/test/rgw/rgw_multi/zone_cloud.py | 8 ------- src/test/rgw/rgw_multi/zone_es.py | 7 ------ src/test/rgw/rgw_multi/zone_ps.py | 9 +------- 16 files changed, 39 insertions(+), 82 deletions(-) diff --git a/qa/tasks/cephfs/filesystem.py b/qa/tasks/cephfs/filesystem.py index 0110c9c22f474..7352f12c801be 100644 --- a/qa/tasks/cephfs/filesystem.py +++ b/qa/tasks/cephfs/filesystem.py @@ -610,8 +610,8 @@ class Filesystem(MDSCluster): if pool['pool_name'] == pool_name: if "application_metadata" in pool: if not "cephfs" in pool['application_metadata']: - raise RuntimeError("Pool %p does not name cephfs as application!".\ - format(pool_name)) + raise RuntimeError("Pool {pool_name} does not name cephfs as application!".\ + format(pool_name=pool_name)) def __del__(self): diff --git a/qa/tasks/cephfs/test_scrub_checks.py b/qa/tasks/cephfs/test_scrub_checks.py index c420936afdc82..e3f5609afe50c 100644 --- a/qa/tasks/cephfs/test_scrub_checks.py +++ b/qa/tasks/cephfs/test_scrub_checks.py @@ -169,10 +169,9 @@ class TestScrubChecks(CephFSTestCase): log.info("Cloning repo into place") repo_path = TestScrubChecks.clone_repo(self.mount_a, client_path) - log.info("Initiating mds_scrub_checks on mds.{id_}, " + - "test_path {path}, run_seq {seq}".format( - id_=mds_rank, path=abs_test_path, seq=run_seq) - ) + log.info("Initiating mds_scrub_checks on mds.{id_} test_path {path}, run_seq {seq}".format( + id_=mds_rank, path=abs_test_path, seq=run_seq) + ) success_validator = lambda j, r: self.json_validator(j, r, "return_code", 0) @@ -329,9 +328,8 @@ class TestScrubChecks(CephFSTestCase): else: jout = None - log.info("command '{command}' got response code " + - "'{rout}' and stdout '{sout}'".format( - command=command, rout=rout, sout=sout)) + log.info("command '{command}' got response code '{rout}' and stdout '{sout}'".format( + command=command, rout=rout, sout=sout)) success, errstring = validator(jout, rout) @@ -371,7 +369,5 @@ class AsokCommandFailedError(Exception): self.errstring = errstring def __str__(self): - return "Admin socket: {command} failed with rc={rc}," + \ - "json output={json}, because '{es}'".format( - command=self.command, rc=self.rc, - json=self.json, es=self.errstring) + return "Admin socket: {command} failed with rc={rc} json output={json}, because '{es}'".format( + command=self.command, rc=self.rc, json=self.json, es=self.errstring) diff --git a/qa/tasks/cephfs/test_snapshots.py b/qa/tasks/cephfs/test_snapshots.py index 067c7b1fb92d1..c3940897a7ba2 100644 --- a/qa/tasks/cephfs/test_snapshots.py +++ b/qa/tasks/cephfs/test_snapshots.py @@ -189,9 +189,9 @@ class TestSnapshots(CephFSTestCase): rank1 = self.fs.get_rank(rank=1, status=status) self.fs.rank_freeze(True, rank=0) self.fs.rank_freeze(True, rank=1) - self.fs.rank_asok(['config', 'set', "mds_kill_mdstable_at", "8".format(i)], rank=0, status=status) - self.fs.rank_asok(['config', 'set', "mds_kill_mdstable_at", "3".format(i)], rank=1, status=status) - proc = self.mount_a.run_shell(["mkdir", "d1/dir/.snap/s4".format(i)], wait=False) + self.fs.rank_asok(['config', 'set', "mds_kill_mdstable_at", "8"], rank=0, status=status) + self.fs.rank_asok(['config', 'set', "mds_kill_mdstable_at", "3"], rank=1, status=status) + proc = self.mount_a.run_shell(["mkdir", "d1/dir/.snap/s4"], wait=False) self.wait_until_true(lambda: "laggy_since" in self.fs.get_rank(rank=1), timeout=grace*2); self.delete_mds_coredump(rank1['name']); diff --git a/qa/tasks/mds_thrash.py b/qa/tasks/mds_thrash.py index d8c74250dd535..07ec039ed9cb8 100644 --- a/qa/tasks/mds_thrash.py +++ b/qa/tasks/mds_thrash.py @@ -203,7 +203,8 @@ class MDSThrasher(Thrasher, Greenlet): pass # no rank present if len(actives) >= max_mds: # no replacement can occur! - self.log("cluster has %d actives (max_mds is %d), no MDS can replace rank %d".format(len(actives), max_mds, rank)) + self.log("cluster has {actives} actives (max_mds is {max_mds}), no MDS can replace rank {rank}".format( + actives=len(actives), max_mds=max_mds, rank=rank)) return status else: if len(actives) == max_mds: @@ -303,7 +304,7 @@ class MDSThrasher(Thrasher, Greenlet): self.log( '{label} reported laggy/crashed since: {since}'.format(label=label, since=last_laggy_since)) else: - self.log('{label} down, removed from mdsmap'.format(label=label, since=last_laggy_since)) + self.log('{label} down, removed from mdsmap'.format(label=label)) # wait for a standby mds to takeover and become active status = self.wait_for_stable(rank, gid) diff --git a/qa/tasks/mgr/test_insights.py b/qa/tasks/mgr/test_insights.py index 3f5b9768bbeb0..c483e3abf76e0 100644 --- a/qa/tasks/mgr/test_insights.py +++ b/qa/tasks/mgr/test_insights.py @@ -117,7 +117,7 @@ class TestInsights(MgrTestCase): check_names.add(unique_check_name) # and also set the same health check to test deduplication - dupe_check_name = "insights_health_check".format(hours) + dupe_check_name = "insights_health_check" health_check = { dupe_check_name: { "severity": "warning", diff --git a/qa/tasks/rbd.py b/qa/tasks/rbd.py index 1962f583f2aeb..faa094dabebbd 100644 --- a/qa/tasks/rbd.py +++ b/qa/tasks/rbd.py @@ -65,7 +65,7 @@ def create_image(ctx, config): size=size)) args = [ 'adjust-ulimits', - 'ceph-coverage'.format(tdir=testdir), + 'ceph-coverage', '{tdir}/archive/coverage'.format(tdir=testdir), 'rbd', '-p', 'rbd', @@ -140,7 +140,7 @@ def clone_image(ctx, config): ('clone', parent_spec, name)]: args = [ 'adjust-ulimits', - 'ceph-coverage'.format(tdir=testdir), + 'ceph-coverage', '{tdir}/archive/coverage'.format(tdir=testdir), 'rbd', '-p', 'rbd' ] @@ -165,7 +165,7 @@ def clone_image(ctx, config): ('snap', 'rm', parent_spec)]: args = [ 'adjust-ulimits', - 'ceph-coverage'.format(tdir=testdir), + 'ceph-coverage', '{tdir}/archive/coverage'.format(tdir=testdir), 'rbd', '-p', 'rbd' ] diff --git a/qa/tasks/restart.py b/qa/tasks/restart.py index 52b685c9e360a..6e33677f002b1 100644 --- a/qa/tasks/restart.py +++ b/qa/tasks/restart.py @@ -61,7 +61,7 @@ def get_tests(ctx, config, role, remote, testdir): run.Raw('&&'), 'if', 'test', '-e', 'Makefile', run.Raw(';'), 'then', 'make', run.Raw(';'), 'fi', run.Raw('&&'), - 'find', '-executable', '-type', 'f', '-printf', r'%P\0'.format(srcdir=srcdir), + 'find', '-executable', '-type', 'f', '-printf', r'%P\0', run.Raw('>{tdir}/restarts.list'.format(tdir=testdir)), ], ) diff --git a/qa/tasks/rgw.py b/qa/tasks/rgw.py index aceef8894f8d3..df900d2c4505b 100644 --- a/qa/tasks/rgw.py +++ b/qa/tasks/rgw.py @@ -147,8 +147,7 @@ def start_rgw(ctx, config, clients): run.Raw('|'), 'sudo', 'tee', - '/var/log/ceph/rgw.{client_with_cluster}.stdout'.format(tdir=testdir, - client_with_cluster=client_with_cluster), + '/var/log/ceph/rgw.{client_with_cluster}.stdout'.format(client_with_cluster=client_with_cluster), run.Raw('2>&1'), ]) diff --git a/qa/tasks/util/rgw.py b/qa/tasks/util/rgw.py index d1ea39d1cd05c..91652198b8a6f 100644 --- a/qa/tasks/util/rgw.py +++ b/qa/tasks/util/rgw.py @@ -15,9 +15,9 @@ def rgwadmin(ctx, client, cmd, stdin=StringIO(), check_status=False, client_with_id = daemon_type + '.' + client_id pre = [ 'adjust-ulimits', - 'ceph-coverage'.format(tdir=testdir), + 'ceph-coverage', '{tdir}/archive/coverage'.format(tdir=testdir), - 'radosgw-admin'.format(tdir=testdir), + 'radosgw-admin', '--log-to-stderr', '--format', format, '-n', client_with_id, diff --git a/qa/tasks/vstart_runner.py b/qa/tasks/vstart_runner.py index ccc706b922b64..8d48152afd6f7 100644 --- a/qa/tasks/vstart_runner.py +++ b/qa/tasks/vstart_runner.py @@ -1476,11 +1476,11 @@ def exec_test(): if hasattr(fn, 'is_for_teuthology') and getattr(fn, 'is_for_teuthology') is True: drop_test = True - log.warn("Dropping test because long running: ".format(method.id())) + log.warn("Dropping test because long running: {method_id}".format(method_id=method.id())) if getattr(fn, "needs_trimming", False) is True: drop_test = (os.getuid() != 0) - log.warn("Dropping test because client trim unavailable: ".format(method.id())) + log.warn("Dropping test because client trim unavailable: {method_id}".format(method_id=method.id())) if drop_test: # Don't drop the test if it was explicitly requested in arguments diff --git a/qa/tasks/workunit.py b/qa/tasks/workunit.py index 6e555770063e5..46eeef41f2e08 100644 --- a/qa/tasks/workunit.py +++ b/qa/tasks/workunit.py @@ -358,7 +358,7 @@ def _run_tests(ctx, refspec, role, tests, env, basedir, run.Raw('&&'), 'if', 'test', '-e', 'Makefile', run.Raw(';'), 'then', 'make', run.Raw(';'), 'fi', run.Raw('&&'), - 'find', '-executable', '-type', 'f', '-printf', r'%P\0'.format(srcdir=srcdir), + 'find', '-executable', '-type', 'f', '-printf', r'%P\0', run.Raw('>{tdir}/workunits.list.{role}'.format(tdir=testdir, role=role)), ], ) diff --git a/src/test/rgw/rgw_multi/tests.py b/src/test/rgw/rgw_multi/tests.py index 2ddf88c6170e7..6cada052d3dfc 100644 --- a/src/test/rgw/rgw_multi/tests.py +++ b/src/test/rgw/rgw_multi/tests.py @@ -80,15 +80,6 @@ def mdlog_list(zone, period = None): mdlog_json = mdlog_json.decode('utf-8') return json.loads(mdlog_json) -def meta_sync_status(zone): - while True: - cmd = ['metadata', 'sync', 'status'] + zone.zone_args() - meta_sync_status_json, retcode = zone.cluster.admin(cmd, check_retcode=False, read_only=True) - if retcode == 0: - break - assert(retcode == 2) # ENOENT - time.sleep(5) - def mdlog_autotrim(zone): zone.cluster.admin(['mdlog', 'autotrim']) diff --git a/src/test/rgw/rgw_multi/tests_ps.py b/src/test/rgw/rgw_multi/tests_ps.py index 9dd037ba320c9..d827ed55f14ed 100644 --- a/src/test/rgw/rgw_multi/tests_ps.py +++ b/src/test/rgw/rgw_multi/tests_ps.py @@ -159,14 +159,6 @@ class StreamingHTTPServer: for worker in self.workers: worker.close() worker.join() - - def get_and_reset_events(self): - events = [] - for worker in self.workers: - events += worker.get_events() - worker.reset_events() - return events - # AMQP endpoint functions @@ -918,7 +910,7 @@ def test_ps_s3_topic_with_secret_on_master(): try: result = bad_topic_conf.set_config() except Exception as err: - print 'Error is expected: ' + str(err) + print('Error is expected: ' + str(err)) else: assert False, 'user password configuration set allowed only over HTTPS' @@ -1430,7 +1422,7 @@ def test_ps_s3_notification_push_amqp_on_master(): [thr.join() for thr in client_threads] time_diff = time.time() - start_time - print 'average time for deletion + amqp notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds' + print('average time for deletion + amqp notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds') print('wait for 5sec for the messages...') time.sleep(5) @@ -1589,9 +1581,9 @@ def test_ps_s3_notification_push_kafka_on_master(): [thr.join() for thr in client_threads] time_diff = time.time() - start_time - print 'average time for creation + kafka notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds' + print('average time for creation + kafka notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds') - print 'wait for 5sec for the messages...' + print('wait for 5sec for the messages...') time.sleep(5) keys = list(bucket.list()) receiver.verify_s3_events(keys, exact_match=True) @@ -1606,9 +1598,9 @@ def test_ps_s3_notification_push_kafka_on_master(): [thr.join() for thr in client_threads] time_diff = time.time() - start_time - print 'average time for deletion + kafka notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds' + print('average time for deletion + kafka notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds') - print 'wait for 5sec for the messages...' + print('wait for 5sec for the messages...') time.sleep(5) receiver.verify_s3_events(keys, exact_match=True, deletions=True) @@ -1684,10 +1676,10 @@ def kafka_security(security_type): [thr.join() for thr in client_threads] time_diff = time.time() - start_time - print 'average time for creation + kafka notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds' + print('average time for creation + kafka notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds') try: - print 'wait for 5sec for the messages...' + print('wait for 5sec for the messages...') time.sleep(5) keys = list(bucket.list()) receiver.verify_s3_events(keys, exact_match=True) @@ -1702,9 +1694,9 @@ def kafka_security(security_type): [thr.join() for thr in client_threads] time_diff = time.time() - start_time - print 'average time for deletion + kafka notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds' + print('average time for deletion + kafka notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds') - print 'wait for 5sec for the messages...' + print('wait for 5sec for the messages...') time.sleep(5) receiver.verify_s3_events(keys, exact_match=True, deletions=True) except Exception as err: @@ -1780,7 +1772,7 @@ def test_ps_s3_notification_multi_delete_on_master(): start_time = time.time() delete_all_objects(zones[0].conn, bucket_name) time_diff = time.time() - start_time - print 'average time for deletion + http notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds' + print('average time for deletion + http notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds') print('wait for 5sec for the messages...') time.sleep(5) @@ -1864,7 +1856,7 @@ def test_ps_s3_notification_push_http_on_master(): [thr.join() for thr in client_threads] time_diff = time.time() - start_time - print 'average time for deletion + http notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds' + print('average time for deletion + http notification is: ' + str(time_diff*1000/number_of_objects) + ' milliseconds') print('wait for 5sec for the messages...') time.sleep(5) diff --git a/src/test/rgw/rgw_multi/zone_cloud.py b/src/test/rgw/rgw_multi/zone_cloud.py index b9ff43ca96487..fdfca4f1eca12 100644 --- a/src/test/rgw/rgw_multi/zone_cloud.py +++ b/src/test/rgw/rgw_multi/zone_cloud.py @@ -140,14 +140,6 @@ class CloudKey: return r -def append_query_arg(s, n, v): - if not v: - return s - nv = '{n}={v}'.format(n=n, v=v) - if not s: - return nv - return '{s}&{nv}'.format(s=s, nv=nv) - class CloudZoneBucket: def __init__(self, zone_conn, target_path, name): diff --git a/src/test/rgw/rgw_multi/zone_es.py b/src/test/rgw/rgw_multi/zone_es.py index 55edae7292017..ec9b178fd1688 100644 --- a/src/test/rgw/rgw_multi/zone_es.py +++ b/src/test/rgw/rgw_multi/zone_es.py @@ -52,13 +52,6 @@ def make_request(conn, method, bucket, key, query_args, headers): raise boto.exception.S3ResponseError(result.status, result.reason, result.read()) return result -def append_query_arg(s, n, v): - if not v: - return s - nv = '{n}={v}'.format(n=n, v=v) - if not s: - return nv - return '{s}&{nv}'.format(s=s, nv=nv) class MDSearch: def __init__(self, conn, bucket_name, query, query_args = None, marker = None): diff --git a/src/test/rgw/rgw_multi/zone_ps.py b/src/test/rgw/rgw_multi/zone_ps.py index af1fb8464391e..e22200e2665ea 100644 --- a/src/test/rgw/rgw_multi/zone_ps.py +++ b/src/test/rgw/rgw_multi/zone_ps.py @@ -66,13 +66,6 @@ class PSZone(Zone): # pylint: disable=too-many-ancestors NO_HTTP_BODY = '' -def print_connection_info(conn): - """print connection details""" - print('Endpoint: ' + conn.host + ':' + str(conn.port)) - print('AWS Access Key:: ' + conn.aws_access_key_id) - print('AWS Secret Key:: ' + conn.aws_secret_access_key) - - def make_request(conn, method, resource, parameters=None, sign_parameters=False, extra_parameters=None): """generic request sending to pubsub radogw should cover: topics, notificatios and subscriptions @@ -171,7 +164,7 @@ def delete_all_s3_topics(zone, region): print('topic cleanup, deleting: ' + topic['TopicArn']) assert client.delete_topic(TopicArn=topic['TopicArn'])['ResponseMetadata']['HTTPStatusCode'] == 200 except Exception as err: - print 'failed to do topic cleanup: ' + str(err) + print('failed to do topic cleanup: ' + str(err)) def delete_all_objects(conn, bucket_name): -- 2.39.5