tests: add flake8 to tox.ini

this:
- adds flake8 to tox.ini
- addresses all flake8 errors

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
pull/7474/head
Guillaume Abrioux 2024-02-12 21:04:12 +01:00
parent 1a97696d9b
commit e4eb268a56
5 changed files with 29 additions and 31 deletions

View File

@ -4,23 +4,18 @@ __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
try: try:
from ansible.module_utils.ca_common import container_exec, \ from ansible.module_utils.ca_common import container_exec, \
is_containerized, \ is_containerized
fatal
except ImportError: except ImportError:
from module_utils.ca_common import container_exec, \ from module_utils.ca_common import container_exec, \
is_containerized, \ is_containerized
fatal
import datetime import datetime
import json
import os import os
import struct
import time
import base64
import socket
class KeyringExists(Exception): class KeyringExists(Exception):
pass pass
def build_cmd(create_keyring=False, def build_cmd(create_keyring=False,
gen_key=False, gen_key=False,
add_key=False, add_key=False,
@ -39,7 +34,6 @@ def build_cmd(create_keyring=False,
else: else:
c = [auth_tool_binary] c = [auth_tool_binary]
if name: if name:
c.extend(['-n', name]) c.extend(['-n', name])
if create_keyring: if create_keyring:
@ -59,6 +53,7 @@ def build_cmd(create_keyring=False,
return c return c
def run_module(): def run_module():
module_args = dict( module_args = dict(
name=dict(type='str', required=False), name=dict(type='str', required=False),
@ -76,9 +71,6 @@ def run_module():
add_file_common_args=True, add_file_common_args=True,
) )
cmd = [] cmd = []
changed = False changed = False
@ -130,8 +122,10 @@ def run_module():
# module.set_fs_attributes_if_different(file_args, False) # module.set_fs_attributes_if_different(file_args, False)
module.exit_json(**result) module.exit_json(**result)
def main(): def main():
run_module() run_module()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -3,7 +3,6 @@
# Author: Guillaume Abrioux <gabrioux@redhat.com> # Author: Guillaume Abrioux <gabrioux@redhat.com>
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
from typing import List, Tuple
__metaclass__ = type __metaclass__ = type
from ansible.module_utils.basic import AnsibleModule # type: ignore from ansible.module_utils.basic import AnsibleModule # type: ignore
@ -167,7 +166,7 @@ def main() -> None:
if action == 'set': if action == 'set':
if value.lower() == current_value: if value.lower() == current_value:
out = 'who={} option={} value={} already set. Skipping.'.format(who, option, value, container_image=container_image) out = 'who={} option={} value={} already set. Skipping.'.format(who, option, value)
else: else:
rc, cmd, out, err = set_option(module, who, option, value, container_image=container_image) rc, cmd, out, err = set_option(module, who, option, value, container_image=container_image)
changed = True changed = True

View File

@ -1,5 +1,4 @@
import pytest import pytest
import re
class TestMons(object): class TestMons(object):
@ -28,4 +27,3 @@ class TestMons(object):
cmd = "sudo ceph --cluster={} --connect-timeout 5 -s".format(setup["cluster_name"]) # noqa E501 cmd = "sudo ceph --cluster={} --connect-timeout 5 -s".format(setup["cluster_name"]) # noqa E501
output = host.check_output(cmd) output = host.check_output(cmd)
assert output.strip().startswith("cluster") assert output.strip().startswith("cluster")

View File

@ -17,18 +17,6 @@ fake_keyring = '/etc/ceph/{}.{}.keyring'.format(fake_cluster, fake_user)
class TestCephCrushRuleModule(object): class TestCephCrushRuleModule(object):
@patch('ansible.module_utils.basic.AnsibleModule.fail_json')
def test_without_parameters(self, m_fail_json):
ca_test_common.set_module_args({})
m_fail_json.side_effect = ca_test_common.fail_json
with pytest.raises(ca_test_common.AnsibleFailJson) as result:
ceph_crush_rule.main()
result = result.value.args[0]
assert result['msg'] == 'missing required arguments: name'
@patch('ansible.module_utils.basic.AnsibleModule.fail_json') @patch('ansible.module_utils.basic.AnsibleModule.fail_json')
def test_with_name_only(self, m_fail_json): def test_with_name_only(self, m_fail_json):
ca_test_common.set_module_args({ ca_test_common.set_module_args({

19
tox.ini
View File

@ -3,6 +3,7 @@ envlist = centos-{container,non_container}-{all_daemons,all_daemons_ipv6,colloca
centos-non_container-{switch_to_containers} centos-non_container-{switch_to_containers}
infra_lv_create infra_lv_create
migrate_ceph_disk_to_ceph_volume migrate_ceph_disk_to_ceph_volume
flake8
skipsdist = True skipsdist = True
@ -419,3 +420,21 @@ commands=
cephadm_adopt: {[cephadm-adopt]commands} cephadm_adopt: {[cephadm-adopt]commands}
vagrant destroy --force vagrant destroy --force
[testenv:flake8]
max-line-length = 100
ignore =
E501,
W503,
exclude =
.tox \
.vagrant \
__pycache__ \
*.pyc \
templates \
.eggs
statistics = True
deps =
flake8
commands =
flake8 --max-line-length=160 ./library ./module_utils/ ./tests/library/ ./tests/module_utils/ ./tests/functional/tests/ {posargs}