Skip to content

Commit

Permalink
Use getopts
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Jul 30, 2021
1 parent e8e8fa1 commit 7a9d005
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
34 changes: 28 additions & 6 deletions roles/ansible-test-splitter/files/split_targets.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
#!/usr/bin/env python3

from pathlib import PosixPath
import sys
import getopt
import json
import sys

try:
opts, args = getopt.getopt(sys.argv,"ht:j:p:")
except getopt.GetoptError:
print('split_targets.py -t <targets> -j <total_jobs> -p <job_prefix>')
sys.exit(2)

job_prefix = sys.argv[1]
if len(sys.argv) == 3:
targets_from_cli = sys.argv[2].split(" ")
targets = ""
job_prefix = "job"
job_count = 10

for opt, arg in opts:
if opt == '-h':
print('split_targets.py -t <targets> -j <total_jobs> -p <job_prefix>')
sys.exit(0)
if opt == '-p':
job_prefix = arg
if opt == '-t':
targets_from_cli = arg
if opt == '-c':
job_count = int(arg)

if targets:
targets_from_cli = targets.split(" ")
else:
targets_from_cli = []
jobs = [f"{job_prefix}{i}" for i in range(10)]
total_jobs = 10

jobs = [f"{job_prefix}{i}" for i in range(job_count)]
total_jobs = job_count
slow_targets = []
regular_targets = []

Expand Down
6 changes: 5 additions & 1 deletion roles/ansible-test-splitter/tasks/split_targets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
mode: '0700'

- name: Split the workload
command: python3 /tmp/split_targets.py "{{ ansible_test_splitter__children_prefix }}" "{{ ansible_test_splitter__targets_to_test|default('') }}"
command: >-
python3 /tmp/split_targets.py
-p "{{ ansible_test_splitter__children_prefix }}"
-t "{{ ansible_test_splitter__targets_to_test|default('') }}"
-c 10
args:
chdir: "{{ ansible_test_location }}"
register: _result
Expand Down

0 comments on commit 7a9d005

Please sign in to comment.