Skip to content

Commit

Permalink
library: flake8 ceph-ansible modules
Browse files Browse the repository at this point in the history
This commit ensure all ceph-ansible modules pass flake8 properly.

Signed-off-by: Wong Hoi Sing Edison <hswong3i@pantarei-design.com>
(cherry picked from commit beda1fe)
  • Loading branch information
hswong3i authored and guits committed Aug 2, 2021
1 parent deac21c commit 5bf73d4
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 139 deletions.
76 changes: 38 additions & 38 deletions library/ceph_add_users_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
default: unlimited
bucketmaxobjects:
description:
- with bucket quota enabled specify maximum number of objects # noqa E501
- with bucket quota enabled specify maximum number of objects # noqa: E501
required: false
default: unlimited
buckets:
Expand Down Expand Up @@ -263,7 +263,7 @@
returned: always
type: list
sample: [
"test2: could not modify user: unable to modify user, cannot add duplicate email\n" # noqa E501
"test2: could not modify user: unable to modify user, cannot add duplicate email\n" # noqa: E501
]
failed_users:
Expand Down Expand Up @@ -334,52 +334,52 @@ def create_users(rgw, users, result):
if email:
if autogenkey:
try:
rgw.create_user(username, fullname, email=email, key_type='s3', # noqa E501
rgw.create_user(username, fullname, email=email, key_type='s3', # noqa: E501
generate_key=autogenkey,
max_buckets=maxbucket, suspended=suspend) # noqa E501
max_buckets=maxbucket, suspended=suspend) # noqa: E501
except radosgw.exception.RadosGWAdminError as e:
result['error_messages'].append(username + ' ' + e.get_code()) # noqa E501
result['error_messages'].append(username + ' ' + e.get_code()) # noqa: E501
fail_flag = True
else:
try:
rgw.create_user(username, fullname, email=email, key_type='s3', # noqa E501
access_key=accesskey, secret_key=secretkey, # noqa E501
max_buckets=maxbucket, suspended=suspend) # noqa E501
rgw.create_user(username, fullname, email=email, key_type='s3', # noqa: E501
access_key=accesskey, secret_key=secretkey, # noqa: E501
max_buckets=maxbucket, suspended=suspend) # noqa: E501
except radosgw.exception.RadosGWAdminError as e:
result['error_messages'].append(username + ' ' + e.get_code()) # noqa E501
result['error_messages'].append(username + ' ' + e.get_code()) # noqa: E501
fail_flag = True
else:
if autogenkey:
try:
rgw.create_user(username, fullname, key_type='s3',
generate_key=autogenkey,
max_buckets=maxbucket, suspended=suspend) # noqa E501
max_buckets=maxbucket, suspended=suspend) # noqa: E501
except radosgw.exception.RadosGWAdminError as e:
result['error_messages'].append(username + ' ' + e.get_code()) # noqa E501
result['error_messages'].append(username + ' ' + e.get_code()) # noqa: E501
fail_flag = True
else:
try:
rgw.create_user(username, fullname, key_type='s3',
access_key=accesskey, secret_key=secretkey, # noqa E501
max_buckets=maxbucket, suspended=suspend) # noqa E501
access_key=accesskey, secret_key=secretkey, # noqa: E501
max_buckets=maxbucket, suspended=suspend) # noqa: E501
except radosgw.exception.RadosGWAdminError as e:
result['error_messages'].append(username + ' ' + e.get_code()) # noqa E501
result['error_messages'].append(username + ' ' + e.get_code()) # noqa: E501
fail_flag = True

if not fail_flag and userquota:
try:
rgw.set_quota(username, 'user', max_objects=usermaxobjects,
max_size_kb=usermaxsize, enabled=True)
except radosgw.exception.RadosGWAdminError as e:
result['error_messages'].append(username + ' ' + e.get_code()) # noqa E501
result['error_messages'].append(username + ' ' + e.get_code()) # noqa: E501
fail_flag = True

if not fail_flag and bucketquota:
try:
rgw.set_quota(username, 'bucket', max_objects=bucketmaxobjects, # noqa E501
rgw.set_quota(username, 'bucket', max_objects=bucketmaxobjects, # noqa: E501
max_size_kb=bucketmaxsize, enabled=True)
except radosgw.exception.RadosGWAdminError as e:
result['error_messages'].append(username + ' ' + e.get_code()) # noqa E501
result['error_messages'].append(username + ' ' + e.get_code()) # noqa: E501
fail_flag = True

if fail_flag:
Expand Down Expand Up @@ -450,12 +450,12 @@ def create_buckets(rgw, buckets, result):
except radosgw.exception.RadosGWAdminError:
pass
failed_buckets.append(bucket)
result['error_messages'].append(bucket + ' could not be linked' + ', NoSuchUser ' + user) # noqa E501
result['error_messages'].append(bucket + ' could not be linked' + ', NoSuchUser ' + user) # noqa: E501

else:
# something went wrong
failed_buckets.append(bucket)
result['error_messages'].append(bucket + ' could not be created') # noqa E501
result['error_messages'].append(bucket + ' could not be created') # noqa: E501

result['added_buckets'] = ", ".join(added_buckets)
result['failed_buckets'] = ", ".join(failed_buckets)
Expand All @@ -467,7 +467,7 @@ def create_bucket(rgw, bucket):
host=rgw._connection[0],
port=rgw.port,
is_secure=rgw.is_secure,
calling_format=boto.s3.connection.OrdinaryCallingFormat(), # noqa E501
calling_format=boto.s3.connection.OrdinaryCallingFormat(), # noqa: E501
)

try:
Expand All @@ -489,23 +489,23 @@ def main():
admin_access_key=dict(type='str', required=True),
admin_secret_key=dict(type='str', required=True),
buckets=dict(type='list', required=False, elements='dict',
options=dict(bucket=dict(type='str', required=True), # noqa E501
user=dict(type='str', required=True))), # noqa E501
options=dict(bucket=dict(type='str', required=True), # noqa: E501
user=dict(type='str', required=True))), # noqa: E501
users=dict(type='list', required=False, elements='dict',
options=dict(username=dict(type='str', required=True), # noqa E501
fullname=dict(type='str', required=True), # noqa E501
email=dict(type='str', required=False), # noqa E501
maxbucket=dict(type='int', required=False, default=1000), # noqa E501
suspend=dict(type='bool', required=False, default=False), # noqa E501
autogenkey=dict(type='bool', required=False, default=True), # noqa E501
accesskey=dict(type='str', required=False), # noqa E501
secretkey=dict(type='str', required=False), # noqa E501
userquota=dict(type='bool', required=False, default=False), # noqa E501
usermaxsize=dict(type='str', required=False, default='-1'), # noqa E501
usermaxobjects=dict(type='int', required=False, default=-1), # noqa E501
bucketquota=dict(type='bool', required=False, default=False), # noqa E501
bucketmaxsize=dict(type='str', required=False, default='-1'), # noqa E501
bucketmaxobjects=dict(type='int', required=False, default=-1)))) # noqa E501
options=dict(username=dict(type='str', required=True), # noqa: E501
fullname=dict(type='str', required=True), # noqa: E501
email=dict(type='str', required=False), # noqa: E501
maxbucket=dict(type='int', required=False, default=1000), # noqa: E501
suspend=dict(type='bool', required=False, default=False), # noqa: E501
autogenkey=dict(type='bool', required=False, default=True), # noqa: E501
accesskey=dict(type='str', required=False), # noqa: E501
secretkey=dict(type='str', required=False), # noqa: E501
userquota=dict(type='bool', required=False, default=False), # noqa: E501
usermaxsize=dict(type='str', required=False, default='-1'), # noqa: E501
usermaxobjects=dict(type='int', required=False, default=-1), # noqa: E501
bucketquota=dict(type='bool', required=False, default=False), # noqa: E501
bucketmaxsize=dict(type='str', required=False, default='-1'), # noqa: E501
bucketmaxobjects=dict(type='int', required=False, default=-1)))) # noqa: E501

# the AnsibleModule object
module = AnsibleModule(argument_spec=fields,
Expand Down Expand Up @@ -533,8 +533,8 @@ def main():
# radosgw connection
rgw = radosgw.connection.RadosGWAdminConnection(host=rgw_host,
port=port,
access_key=admin_access_key, # noqa E501
secret_key=admin_secret_key, # noqa E501
access_key=admin_access_key, # noqa: E501
secret_key=admin_secret_key, # noqa: E501
aws_signature='AWS4',
is_secure=is_secure)

Expand Down
10 changes: 5 additions & 5 deletions library/ceph_crush.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def sort_osd_crush_location(location, module):
"region",
"root",
]
return sorted(location, key=lambda crush: crush_bucket_types.index(crush[0])) # noqa E501
return sorted(location, key=lambda crush: crush_bucket_types.index(crush[0])) # noqa: E501
except ValueError as error:
fatal("{} is not a valid CRUSH bucket, valid bucket types are {}".format(error.args[0].split()[0], crush_bucket_types), module) # noqa E501
fatal("{} is not a valid CRUSH bucket, valid bucket types are {}".format(error.args[0].split()[0], crush_bucket_types), module) # noqa: E501


def create_and_move_buckets_list(cluster, location, containerized=None):
Expand All @@ -128,10 +128,10 @@ def create_and_move_buckets_list(cluster, location, containerized=None):
for item in location:
bucket_type, bucket_name = item
# ceph osd crush add-bucket maroot root
cmd_list.append(generate_cmd(cluster, "add-bucket", bucket_name, bucket_type, containerized)) # noqa E501
cmd_list.append(generate_cmd(cluster, "add-bucket", bucket_name, bucket_type, containerized)) # noqa: E501
if previous_bucket:
# ceph osd crush move monrack root=maroot
cmd_list.append(generate_cmd(cluster, "move", previous_bucket, "%s=%s" % (bucket_type, bucket_name), containerized)) # noqa E501
cmd_list.append(generate_cmd(cluster, "move", previous_bucket, "%s=%s" % (bucket_type, bucket_name), containerized)) # noqa: E501
previous_bucket = item[1]
return cmd_list

Expand Down Expand Up @@ -178,7 +178,7 @@ def run_module():
startd = datetime.datetime.now()

# run the Ceph command to add buckets
rc, cmd, out, err = exec_commands(module, create_and_move_buckets_list(cluster, location, containerized)) # noqa E501
rc, cmd, out, err = exec_commands(module, create_and_move_buckets_list(cluster, location, containerized)) # noqa: E501

endd = datetime.datetime.now()
delta = endd - startd
Expand Down
Loading

0 comments on commit 5bf73d4

Please sign in to comment.