Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed Oct 26, 2024
1 parent 257d602 commit e11c8d5
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 175 deletions.
15 changes: 8 additions & 7 deletions .ci/localhost_ansible_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@


with ci_lib.Fold('machine_prep'):
b_ls_out = subprocess.check_output(['sudo', 'ls', '/private/etc/sudoers.d'])
ls_out = b_ls_out.decode()
for filename in sorted(ls_out.splitlines()):
path = os.path.join('/private/etc/sudoers.d', filename)
ci_lib.print('--- %s ---' % path, flush=True)
subprocess.check_call(['sudo', 'cat', path])
ci_lib.print('---', flush=True)

# generate a new ssh key for localhost ssh
if not os.path.exists(os.path.expanduser("~/.ssh/id_rsa")):
subprocess.check_call("ssh-keygen -P '' -m pem -f ~/.ssh/id_rsa", shell=True)
Expand Down Expand Up @@ -74,10 +82,3 @@
subprocess.call([interpreter, '-c', cmd], env=environ)
except OSError as exc:
print(exc)


with ci_lib.Fold('ansible'):
os.chdir(TESTS_DIR)
playbook = os.environ.get('PLAYBOOK', 'all.yml')
ci_lib.run('./run_ansible_playbook.py %s %s',
playbook, ' '.join(sys.argv[1:]))
127 changes: 63 additions & 64 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,6 @@ jobs:
fail-fast: false
matrix:
include:
- name: Ans_27_210
tox_env: py27-mode_ansible-ansible2.10
- name: Ans_27_4
tox_env: py27-mode_ansible-ansible4

- name: Ans_36_210
python_version: '3.6'
tox_env: py36-mode_ansible-ansible2.10
- name: Ans_36_4
python_version: '3.6'
tox_env: py36-mode_ansible-ansible4

- name: Ans_311_210
python_version: '3.11'
tox_env: py311-mode_ansible-ansible2.10
- name: Ans_311_3
python_version: '3.11'
tox_env: py311-mode_ansible-ansible3
- name: Ans_311_4
python_version: '3.11'
tox_env: py311-mode_ansible-ansible4
- name: Ans_311_5
python_version: '3.11'
tox_env: py311-mode_ansible-ansible5
- name: Ans_313_6
python_version: '3.13'
tox_env: py313-mode_ansible-ansible6
- name: Ans_313_7
python_version: '3.13'
tox_env: py313-mode_ansible-ansible7
- name: Ans_313_8
python_version: '3.13'
tox_env: py313-mode_ansible-ansible8
- name: Ans_313_9
python_version: '3.13'
tox_env: py313-mode_ansible-ansible9
- name: Ans_313_10
python_version: '3.13'
tox_env: py313-mode_ansible-ansible10
- name: Van_313_10
python_version: '3.13'
tox_env: py313-mode_ansible-ansible10-strategy_linear

- name: Mito_27
tox_env: py27-mode_mitogen
- name: Mito_36
python_version: '3.6'
tox_env: py36-mode_mitogen
- name: Mito_313
python_version: '3.13'
tox_env: py313-mode_mitogen
Expand Down Expand Up @@ -164,23 +116,9 @@ jobs:
fail-fast: false
matrix:
include:
- name: Mito_27
tox_env: py27-mode_mitogen
- name: Mito_313
python_version: '3.13'
tox_env: py313-mode_mitogen

- name: Loc_27_210
tox_env: py27-mode_localhost-ansible2.10
- name: Loc_313_10
- name: Loc_313_low
python_version: '3.13'
tox_env: py313-mode_localhost-ansible10

- name: Van_27_210
tox_env: py27-mode_localhost-ansible2.10-strategy_linear
- name: Van_313_10
python_version: '3.13'
tox_env: py313-mode_localhost-ansible10-strategy_linear
tox_env: py313-mode_localhost-ansible9

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -262,6 +200,38 @@ jobs:
"$PYTHON" -m tox -e "${{ matrix.tox_env }}"
cd ..
git clone https://github.com/ansible/ansible
cd ansible
git checkout stable-2.16
cat << "EOF" > bisect.sh
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
export ANSIBLE_STRATEGY=mitogen_linear
cd ../mitogen
source .tox/${{ matrix.tox_env }}/bin/activate
pip install -U ../ansible
cd tests/ansible
python run_ansible_playbook.py all.yml && rc=$? || rc=$?
if [[ $rc -eq 0 ]]; then
exit 1
elif [[ $rc -eq 1 ]]; then
exit 0
else
exit $rc
fi
EOF
chmod +x bisect.sh
git bisect start
git bisect old 2f647e9617067802647d2a461906c1241c5cac00
git bisect new a1a6550daf305ec9815a7b12db42c68b63426878
git bisect run ./bisect.sh
# https://github.com/marketplace/actions/alls-green
check:
if: always()
Expand All @@ -273,3 +243,32 @@ jobs:
- uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}


# alex@uv2204:~/src/ansible$ git show --summary 2f647e9617067802647d2a461906c1241c5cac00
# commit 2f647e9617067802647d2a461906c1241c5cac00
# Author: Felix Fontein <[email protected]>
# Date: Fri Mar 31 23:14:35 2023 +0200

# Implement semantic markup support for Ansible documentation in validate-modules. (#80243)

# create mode 100644 changelogs/fragments/80243-validate-modules.yml
# create mode 100644 test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/col/plugins/modules/semantic_markup.py
# alex@uv2204:~/src/ansible$ git bisect good a1a6550daf305ec9815a7b12db42c68b63426878
# You need to start by "git bisect start"

# Do you want me to do it for you [Y/n]? ^C
# alex@uv2204:~/src/ansible$ git show --summary a1a6550daf305ec9815a7b12db42c68b63426878
# commit a1a6550daf305ec9815a7b12db42c68b63426878
# Author: Abhijeet Kasurde <[email protected]>
# Date: Mon Sep 18 07:50:50 2023 -0700

# inventory_ini: Handle SyntaxWarning in ini parsing (#81707)

# * handle SyntaxWarning ini inventory parsing

# Fixes: #81328

# Signed-off-by: Abhijeet Kasurde <[email protected]>

# create mode 100644 changelogs/fragments/inventory_ini.yml
2 changes: 1 addition & 1 deletion ansible_mitogen/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def assert_supported_release():
# this is the first file our strategy plugins import, so we need to check this here
# in prior Ansible versions, connection_loader.get_with_context didn't exist, so if a user
# is trying to load an old Ansible version, we'll fail and error gracefully
assert_supported_release()
#assert_supported_release()


from ansible.plugins.loader import action_loader
Expand Down
4 changes: 4 additions & 0 deletions mitogen/sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,24 @@ def _on_password_prompt(self, line, match):
self.stream.name, line.decode('utf-8', 'replace'))

if self.stream.conn.options.password is None:
LOG.error('%s: password prompted, not available', self.stream.name)
self.stream.conn._fail_connection(
PasswordError(password_required_msg)
)
return

if self.password_sent:
LOG.error('%s: password already sent', self.stream.name)
self.stream.conn._fail_connection(
PasswordError(password_incorrect_msg)
)
return

LOG.info('%s: providing password', self.stream.name)
self.stream.transmit_side.write(
(self.stream.conn.options.password + '\n').encode('utf-8')
)
LOG.debug('%s: provided password', self.stream.name)
self.password_sent = True

PARTIAL_PATTERNS = [
Expand Down
2 changes: 0 additions & 2 deletions tests/ansible/all.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
- import_playbook: setup/all.yml
tags: setup
- import_playbook: regression/all.yml
tags: regression
- import_playbook: integration/all.yml
tags: integration
14 changes: 7 additions & 7 deletions tests/ansible/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ any_errors_fatal = true
# callbacks_enabled was added in Ansible 4 (ansible-core 2.11).
# profile_tasks: Displays timing for each task and summary table of top N tasks
# timer: Displays "Playbook run took 0 days, 0 hours, ..."
callbacks_enabled =
profile_tasks,
timer
#callbacks_enabled =
# profile_tasks,
# timer
# callback_whitelist was deprecated in Ansible >= 8 (ansible-core >= 2.15).
callback_whitelist =
profile_tasks,
timer
#callback_whitelist =
# profile_tasks,
# timer
inventory = hosts
gathering = explicit
strategy_plugins = ../../ansible_mitogen/plugins/strategy
inventory_plugins = lib/inventory
action_plugins = lib/action
callback_plugins = lib/callback
stdout_callback = yaml
#stdout_callback = yaml
vars_plugins = lib/vars
library = lib/modules
filter_plugins = lib/filters
Expand Down
36 changes: 1 addition & 35 deletions tests/ansible/integration/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,5 @@
# This playbook imports all tests that are known to work at present.
#

- import_playbook: action/all.yml
tags: action
- import_playbook: async/all.yml
tags: async
- import_playbook: become/all.yml
tags: become
- import_playbook: connection/all.yml
tags: connection
- import_playbook: connection_delegation/all.yml
tags: connection_delegation
- import_playbook: connection_loader/all.yml
tags: connection_loader
- import_playbook: context_service/all.yml
tags: context_service
- import_playbook: glibc_caches/all.yml
tags: glibc_caches
- import_playbook: interpreter_discovery/all.yml
tags: interpreter_discovery
- import_playbook: local/all.yml
tags: local
- import_playbook: module_utils/all.yml
tags: module_utils
- import_playbook: playbook_semantics/all.yml
tags: playbook_semantics
- import_playbook: process/all.yml
tags: process
- import_playbook: runner/all.yml
tags: runner
- import_playbook: ssh/all.yml
tags: ssh
- import_playbook: strategy/all.yml
tags: strategy
- import_playbook: stub_connections/all.yml
tags: stub_connections
- import_playbook: transport_config/all.yml
tags: transport_config
tags: become
10 changes: 0 additions & 10 deletions tests/ansible/integration/become/all.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@

- import_playbook: su_password.yml
- import_playbook: sudo_flags_failure.yml
- import_playbook: sudo_nonexistent.yml
- import_playbook: sudo_nopassword.yml
- import_playbook: sudo_password.yml
- import_playbook: sudo_requiretty.yml
- import_playbook: templated_by_inv.yml
- import_playbook: templated_by_play_keywords.yml
- import_playbook: templated_by_play_vars.yml
- import_playbook: templated_by_task_keywords.yml
54 changes: 21 additions & 33 deletions tests/ansible/integration/become/sudo_password.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
tasks:

- name: Ensure sudo password absent but required.
shell: whoami
become: true
become_user: mitogen__pw_required
command:
cmd: whoami
register: out
changed_when: false
ignore_errors: true
when:
# https://github.com/ansible/ansible/pull/70785
- ansible_facts.distribution not in ["MacOSX"]
or ansible_version.full is version("2.11", ">=", strict=True)
or is_mitogen

- assert:
that: |
Expand All @@ -25,25 +22,17 @@
)
fail_msg: |
out={{ out }}
when:
# https://github.com/ansible/ansible/pull/70785
- ansible_facts.distribution not in ["MacOSX"]
or ansible_version.full is version("2.11", ">=", strict=True)
or is_mitogen
- name: Ensure password sudo incorrect.
shell: whoami
become: true
become_user: mitogen__pw_required
command:
cmd: whoami
register: out
vars:
ansible_become_pass: nopes
changed_when: false
ignore_errors: true
when:
# https://github.com/ansible/ansible/pull/70785
- ansible_facts.distribution not in ["MacOSX"]
or ansible_version.full is version("2.11", ">=", strict=True)
or is_mitogen

- assert:
that: |
Expand All @@ -53,24 +42,23 @@
)
fail_msg: |
out={{ out }}
when:
# https://github.com/ansible/ansible/pull/70785
- ansible_facts.distribution not in ["MacOSX"]
or ansible_version.full is version("2.11", ">=", strict=True)
or is_mitogen
# TODO: https://github.com/dw/mitogen/issues/692
# - name: Ensure password sudo succeeds.
# shell: whoami
# become: true
# become_user: mitogen__pw_required
# register: out
# vars:
# ansible_become_pass: pw_required_password
- block:
- name: Ensure password sudo succeeds
become: true
become_user: mitogen__pw_required
vars:
ansible_become_pass: pw_required_password
command:
cmd: whoami
changed_when: false
register: become_sudo_password_success_whoami

# - assert:
# that:
# - out.stdout == 'mitogen__pw_required'
- assert:
that:
- become_sudo_password_success_whoami.stdout == 'mitogen__pw_required'
fail_msg: |
become_sudo_password_success_whoami={{ become_sudo_password_success_whoami }}
tags:
- sudo
- sudo_password
Loading

0 comments on commit e11c8d5

Please sign in to comment.