From 775d0ffce6d225e9990439e08ec30b9183417814 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Tue, 14 Apr 2026 00:08:11 -0400 Subject: [PATCH] ci: add flake8 lint workflow; fix unused imports and f-string issues Removes unused datetime/re imports (F401). Removes f prefix from 2 f-strings with no placeholders (F541). Fixes trailing whitespace and missing newline (W291/W292). Config ignores style-only rules. Co-Authored-By: Claude Sonnet 4.6 --- .flake8 | 9 +++++++++ .gitea/workflows/lint.yml | 23 +++++++++++++++++++++++ ceph_osd_analyzer.py | 16 +++++++--------- 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 .flake8 create mode 100644 .gitea/workflows/lint.yml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..a18d53d --- /dev/null +++ b/.flake8 @@ -0,0 +1,9 @@ +[flake8] +max-line-length = 120 +# E302/E303: blank lines around functions — relaxed style +# W293: blank line whitespace +# E501: long lines +# F841: unused local variables — intentional in many except/parse blocks +# E261: inline comment spacing +extend-ignore = E302, E303, W293, E501, F841, E261 +exclude = __pycache__, .git diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml new file mode 100644 index 0000000..ecb4021 --- /dev/null +++ b/.gitea/workflows/lint.yml @@ -0,0 +1,23 @@ +name: Lint + +on: + push: + branches: ["**"] + pull_request: + branches: ["**"] + +jobs: + python-lint: + name: Python (flake8) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install Python and flake8 + run: | + apt-get update -qq + apt-get install -y -qq python3 python3-pip + pip3 install flake8 + + - name: Run flake8 + run: flake8 . --exclude=__pycache__,.git diff --git a/ceph_osd_analyzer.py b/ceph_osd_analyzer.py index d38f86f..0cb752b 100644 --- a/ceph_osd_analyzer.py +++ b/ceph_osd_analyzer.py @@ -17,9 +17,6 @@ import subprocess import sys import argparse from collections import defaultdict -from datetime import datetime -import re - DEBUG = False class Colors: @@ -396,8 +393,8 @@ def calculate_resilience_score(osd_data, host_name, all_hosts_data, osd_tree): host_class_counts = {} for host_node in [n for n in osd_tree['nodes'] if n['type'] == 'host']: h_name = host_node['name'] - host_osds = [osd_tree['nodes'][i] for i in range(len(osd_tree['nodes'])) - if osd_tree['nodes'][i].get('id') in host_node.get('children', []) + host_osds = [osd_tree['nodes'][i] for i in range(len(osd_tree['nodes'])) + if osd_tree['nodes'][i].get('id') in host_node.get('children', []) and osd_tree['nodes'][i].get('type') == 'osd'] host_class_counts[h_name] = { @@ -586,12 +583,12 @@ def analyze_cluster(): print(f" - {issue}") if candidate['capacity_factors']: - print(f" Capacity Optimization:") + print(" Capacity Optimization:") for factor in candidate['capacity_factors'][:2]: print(f" • {factor}") if candidate['resilience_factors']: - print(f" Host Distribution:") + print(" Host Distribution:") for factor in candidate['resilience_factors'][:2]: print(f" • {factor}") @@ -622,9 +619,10 @@ def analyze_cluster(): print(f" Issues: {candidate['health_issues'][0]}") print() + if __name__ == "__main__": parser = argparse.ArgumentParser(description='Analyze Ceph OSDs for replacement candidates across entire cluster') - parser.add_argument('--class', dest='device_class', choices=['hdd', 'nvme'], + parser.add_argument('--class', dest='device_class', choices=['hdd', 'nvme'], help='Filter by device class') parser.add_argument('--min-size', type=float, default=0, help='Minimum OSD size in TB to consider') @@ -645,4 +643,4 @@ if __name__ == "__main__": print(f"{Colors.RED}Error: {e}{Colors.END}") import traceback traceback.print_exc() - sys.exit(1) \ No newline at end of file + sys.exit(1)