Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: followup for recent ansible-lint related changes #179

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ kinds:
skip_list:
- fqcn-builtins
- var-naming[no-role-prefix]
- sanity[cannot-ignore]
- sanity[cannot-ignore] # wokeignore:rule=sanity
exclude_paths:
- tests/roles/
- .github/
Expand Down
33 changes: 23 additions & 10 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ variables:
- cluster_basic
- cluster_destroy
- default
- include_vars_from_parent
- qdevice_all_options
- qdevice_minimal
- qdevice_tls_kaptb_options
Expand Down Expand Up @@ -104,6 +103,17 @@ variables:
- if [ "x$PYTHON_VER" != "x3.9" ]; then pushd .; cd "${PYENV_PACKAGES}"; rename --verbose "3.9" "$PYTHON_VER" pcs-*.egg-info; popd; fi
- ls -l "$PYENV_PACKAGES"

.convert_role_to_collection: &convert_role_to_collection
- MY_DIR="$(basename $(pwd))"
- if [ "x$MY_DIR" != "xha_cluster" ]; then ln -s "$MY_DIR" ../ha_cluster; fi
- LSR_INFO=true python /usr/local/lib/lsr-auto-maintenance/lsr_role2collection.py --dest-path ../ --src-path ../ --src-owner tomjelinek --role ha_cluster
- coll_dir="../ansible_collections/fedora/linux_system_roles/"
- ignore_dir="$coll_dir/tests/sanity" # wokeignore:rule=sanity
- mkdir -pv "$ignore_dir"
- for file in .sanity-ansible-ignore-*.txt; do if [ -f "$file" ]; then cp "$file" "$ignore_dir/${file//*.sanity-ansible-}"; fi; done # wokeignore:rule=sanity
- cd "$coll_dir"
- rm -f .pandoc_template-ha_cluster.html5 # remove irrelevant files

default:
before_script:
- source "${PYENV_ROOT}/bin/activate"
Expand All @@ -114,6 +124,17 @@ stages:
- tier1

# tier0 - non-python
check_tier1_test_list:
extends: .job_generic_linter
stage: tier0
script:
- TESTS_DIR=$(find tests/tests_*.yml)
- TESTS_CI=$(python -c 'import yaml; f=open(".gitlab-ci.yml"); d=yaml.safe_load(f); print("\n".join([f"tests/tests_{test}.yml" for test in d[".tier1_tests"]]))')
- echo -e "Tests found:\n$TESTS_DIR"
- echo -e "\nTests defined:\n$TESTS_CI"
- echo -e "\nDiff tests found vs tests defined:"
- diff <(echo -e "$TESTS_DIR") <(echo -e "$TESTS_CI")

ansible_lint:
extends: .job_ansible_check
stage: tier0
Expand All @@ -125,15 +146,7 @@ ansible_test:
extends: .job_ansible_check
stage: tier0
script:
- MY_DIR="$(basename $(pwd))"
- if [ "x$MY_DIR" != "xha_cluster" ]; then ln -s "$MY_DIR" ../ha_cluster; fi
- LSR_INFO=true python /usr/local/lib/lsr-auto-maintenance/lsr_role2collection.py --dest-path ../ --src-path ../ --src-owner tomjelinek --role ha_cluster
- coll_dir="../ansible_collections/fedora/linux_system_roles/"
- ignore_dir="$coll_dir/tests/sanity" # wokeignore:rule=sanity
- mkdir -pv "$ignore_dir"
- for file in .sanity-ansible-ignore-*.txt; do if [ -f "$file" ]; then cp "$file" "$ignore_dir/${file//*.sanity-ansible-}"; fi; done # wokeignore:rule=sanity
- cd "$coll_dir"
- rm -f .pandoc_template-ha_cluster.html5 # remove irrelevant files
- *convert_role_to_collection
- ansible-test --version
- ansible-test sanity -v --color=yes --truncate=0 --no-redact --coverage --docker # wokeignore:rule=sanity

Expand Down
18 changes: 12 additions & 6 deletions library/pcs_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,31 @@
returned: when the command is valid and accepted by API
"""

import traceback
from typing import Optional

from ansible.module_utils.basic import AnsibleModule

# pylint: disable=no-name-in-module
from ansible.module_utils.ha_cluster_lsr import pcs_api_v2_utils as api_utils

import traceback

# pylint: enable=no-name-in-module
try:
from pcs.common.async_tasks.dto import CommandDto, CommandOptionsDto
except ImportError:
HAS_PCS = False
PCS_IMPORT_ERROR = traceback.format_exc()
PCS_IMPORT_ERROR: Optional[str] = traceback.format_exc()

Check warning on line 132 in library/pcs_api_v2.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_api_v2.py#L132

Added line #L132 was not covered by tests

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'PCS_IMPORT_ERROR' is not used.

# These classes need to be available and imported above to do linting
# properly, linters can be safely silenced for these stubs.

class CommandOptionsDto(object):
def __init__(self, **kwargs):
# pylint: disable=missing-class-docstring
# pylint: disable=too-few-public-methods
class CommandOptionsDto: # type: ignore
def __init__(self, **kwargs): # type: ignore

Check warning on line 140 in library/pcs_api_v2.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_api_v2.py#L139-L140

Added lines #L139 - L140 were not covered by tests
pass

class CommandDto(object):
class CommandDto: # type: ignore

Check warning on line 143 in library/pcs_api_v2.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_api_v2.py#L143

Added line #L143 was not covered by tests
pass

else:
Expand Down
18 changes: 12 additions & 6 deletions library/pcs_qdevice_certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,31 @@
returned: when the command is valid and accepted by API
"""

import traceback
from typing import Optional

from ansible.module_utils.basic import AnsibleModule

# pylint: disable=no-name-in-module
from ansible.module_utils.ha_cluster_lsr import pcs_api_v2_utils as api_utils

import traceback

# pylint: enable=no-name-in-module
try:
from pcs.common.async_tasks.dto import CommandDto, CommandOptionsDto
except ImportError:
HAS_PCS = False
PCS_IMPORT_ERROR = traceback.format_exc()
PCS_IMPORT_ERROR: Optional[str] = traceback.format_exc()

Check warning on line 124 in library/pcs_qdevice_certs.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_qdevice_certs.py#L124

Added line #L124 was not covered by tests

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'PCS_IMPORT_ERROR' is not used.

# These classes need to be available and imported above to do linting
# properly, linters can be safely silenced for these stubs.

class CommandOptionsDto(object):
def __init__(self, **kwargs):
# pylint: disable=missing-class-docstring
# pylint: disable=too-few-public-methods
class CommandOptionsDto: # type: ignore
def __init__(self, **kwargs): # type: ignore

Check warning on line 132 in library/pcs_qdevice_certs.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_qdevice_certs.py#L131-L132

Added lines #L131 - L132 were not covered by tests
pass

class CommandDto(object):
class CommandDto: # type: ignore

Check warning on line 135 in library/pcs_qdevice_certs.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_qdevice_certs.py#L135

Added line #L135 was not covered by tests
pass

else:
Expand Down
22 changes: 13 additions & 9 deletions module_utils/ha_cluster_lsr/pcs_api_v2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
import sys
import traceback


# Add paths to pcs bundled libraries to make Dacite available
sys.path.insert(0, "/usr/lib64/pcs/pcs_bundled/packages/")
sys.path.insert(0, "/usr/lib/pcs/pcs_bundled/packages/")

from http.client import HTTPResponse
from json import JSONDecodeError
from typing import Any, Mapping, Union
from typing import Any, Mapping, Optional, Union

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
Expand All @@ -31,7 +30,7 @@
from dacite import DaciteError
except ImportError:
HAS_DACITE = False
DACITE_IMPORT_ERROR = traceback.format_exc()
DACITE_IMPORT_ERROR: Optional[str] = traceback.format_exc()
else:
HAS_DACITE = True
DACITE_IMPORT_ERROR = None
Expand All @@ -47,19 +46,24 @@
from pcs.common.reports import ReportItemDto, ReportItemSeverity
except ImportError:
HAS_PCS = False
PCS_IMPORT_ERROR = traceback.format_exc()
PCS_IMPORT_ERROR: Optional[str] = traceback.format_exc()

# These classes need to be available and imported above to do linting
# properly, linters can be safely silenced for these stubs.

class CommandOptionsDto(object):
def __init__(self, **kwargs):
# pylint: disable=missing-class-docstring
# pylint: disable=too-few-public-methods
class CommandOptionsDto: # type: ignore
def __init__(self, **kwargs): # type: ignore
pass

class ReportItemDto(object):
class ReportItemDto: # type: ignore
pass

class TaskResultDto(object):
class TaskResultDto: # type: ignore
pass

class CommandDto(object):
class CommandDto: # type: ignore
pass

else:
Expand Down
Loading