WIP3
This commit is contained in:
2
roles/linux-system-roles.network/tests/.gitignore
vendored
Normal file
2
roles/linux-system-roles.network/tests/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/*.retry
|
||||
/inventory
|
||||
@@ -0,0 +1 @@
|
||||
roles/linux-system-roles.network/library/network_connections.py
|
||||
16
roles/linux-system-roles.network/tests/covstats
Executable file
16
roles/linux-system-roles.network/tests/covstats
Executable file
@@ -0,0 +1,16 @@
|
||||
#! /bin/bash
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
if [ "$#" -lt 1 ]
|
||||
then
|
||||
echo "USAGE: ${0} coverage_data_file..."
|
||||
echo "Show Statistics for each coverage data file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for coverage_file in "${@}"
|
||||
do
|
||||
echo "coverage statistics for: ${coverage_file}:"
|
||||
COVERAGE_FILE="${coverage_file}" coverage report
|
||||
echo
|
||||
done
|
||||
10
roles/linux-system-roles.network/tests/down-profile.yml
Normal file
10
roles/linux-system-roles.network/tests/down-profile.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Set {{ profile }} down
|
||||
hosts: all
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ profile }}"
|
||||
state: down
|
||||
roles:
|
||||
- linux-system-roles.network
|
||||
109
roles/linux-system-roles.network/tests/ensure_non_running_provider.py
Executable file
109
roles/linux-system-roles.network/tests/ensure_non_running_provider.py
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
""" Check that there is a playbook to run all role tests with the non-default
|
||||
provider as well """
|
||||
# vim: fileencoding=utf8
|
||||
|
||||
import glob
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
import yaml
|
||||
|
||||
OTHER_PROVIDER_SUFFIX = "_other_provider.yml"
|
||||
|
||||
IGNORE = [
|
||||
"tests_helpers-and-asserts.yml",
|
||||
"tests_states.yml",
|
||||
"tests_unit.yml",
|
||||
"tests_vlan_mtu_initscripts.yml",
|
||||
"tests_vlan_mtu_nm.yml",
|
||||
"tests_ethtool_features_initscripts.yml",
|
||||
"tests_ethtool_features_nm.yml",
|
||||
]
|
||||
|
||||
OTHER_PLAYBOOK = """
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Run playbook '{tests_playbook}' with non-default provider
|
||||
hosts: all
|
||||
vars:
|
||||
network_provider_current:
|
||||
tasks:
|
||||
# required for the code to set network_provider_current
|
||||
- name: Get service facts
|
||||
service_facts:
|
||||
- name: Set network provider
|
||||
set_fact:
|
||||
network_provider: '{{{{ "initscripts" if network_provider_current == "nm"
|
||||
else "nm" }}}}'
|
||||
|
||||
- import_playbook: "{tests_playbook}"
|
||||
when:
|
||||
- ansible_distribution_major_version != '6'
|
||||
""" # noqa: E501 # ignore that the line is too long
|
||||
|
||||
|
||||
def get_current_provider_code():
|
||||
with open("../defaults/main.yml") as defaults:
|
||||
yaml_defaults = yaml.safe_load(defaults)
|
||||
current_provider = yaml_defaults["network_provider_current"]
|
||||
return current_provider
|
||||
|
||||
|
||||
def generate_nominal_other_playbook(tests_playbook):
|
||||
nominal_other_testfile_data = OTHER_PLAYBOOK.format(tests_playbook=tests_playbook)
|
||||
nominal = yaml.safe_load(nominal_other_testfile_data)
|
||||
nominal[0]["vars"]["network_provider_current"] = get_current_provider_code()
|
||||
return yaml.dump(nominal, default_flow_style=False, explicit_start=True, width=80)
|
||||
|
||||
|
||||
def main():
|
||||
testsfiles = glob.glob("tests_*.yml")
|
||||
missing = []
|
||||
returncode = 0
|
||||
|
||||
# Generate files when specified
|
||||
generate = bool(len(sys.argv) > 1 and sys.argv[1] == "generate")
|
||||
|
||||
if not testsfiles:
|
||||
print("ERROR: No tests found")
|
||||
returncode = 1
|
||||
|
||||
for filename in testsfiles:
|
||||
if filename.endswith(OTHER_PROVIDER_SUFFIX):
|
||||
continue
|
||||
|
||||
if filename in IGNORE:
|
||||
continue
|
||||
|
||||
fileroot = os.path.splitext(filename)[0]
|
||||
other_testfile = fileroot + OTHER_PROVIDER_SUFFIX
|
||||
nominal_other_testfile_data = generate_nominal_other_playbook(filename)
|
||||
|
||||
if generate:
|
||||
with open(other_testfile, "w") as ofile:
|
||||
ofile.write(nominal_other_testfile_data)
|
||||
|
||||
if other_testfile not in testsfiles and not generate:
|
||||
missing.append(filename)
|
||||
else:
|
||||
with open(other_testfile) as ifile:
|
||||
testdata = ifile.read()
|
||||
if testdata != nominal_other_testfile_data:
|
||||
print(
|
||||
"ERROR: Playbook does not match nominal value " + other_testfile
|
||||
)
|
||||
returncode = 1
|
||||
|
||||
if missing:
|
||||
print("ERROR: No tests for other provider found for:\n" + ", \n".join(missing))
|
||||
print("Try to generate them with '{} generate'".format(sys.argv[0]))
|
||||
returncode = 1
|
||||
|
||||
return returncode
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
68
roles/linux-system-roles.network/tests/get-coverage.sh
Executable file
68
roles/linux-system-roles.network/tests/get-coverage.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#! /bin/bash
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
if [ -n "${DEBUG}" ]
|
||||
then
|
||||
set -x
|
||||
fi
|
||||
set -e
|
||||
|
||||
if [ "$#" -lt 2 ]
|
||||
then
|
||||
echo "USAGE: ${0} host playbook"
|
||||
echo "Get coverage info from host for playbook"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
host="${1}"
|
||||
shift
|
||||
playbook="${1}"
|
||||
|
||||
coverage_data="remote-coveragedata-${host}-${playbook%.yml}"
|
||||
coverage="/root/.local/bin/coverage"
|
||||
|
||||
echo "Getting coverage for ${playbook} on ${host}" >&2
|
||||
|
||||
call_ansible() {
|
||||
local module="${1}"
|
||||
shift
|
||||
local args="${1}"
|
||||
shift
|
||||
ansible -m "${module}" -i "${host}", -a "${args}" all "${@}"
|
||||
}
|
||||
|
||||
remote_coverage_dir="$(mktemp -d /tmp/remote_coverage-XXXXXX)"
|
||||
trap "rm -rf '${remote_coverage_dir}'" EXIT
|
||||
ansible-playbook -i "${host}", get-coverage.yml -e "test_playbook=${playbook} destdir=${remote_coverage_dir}"
|
||||
|
||||
#COVERAGE_FILE=remote-coverage coverage combine remote-coverage/tests_*/*/root/.coverage
|
||||
./merge-coverage.sh coverage "${coverage_data}"-tmp $(find "${remote_coverage_dir}" -type f | tr , _)
|
||||
|
||||
# When https://github.com/nedbat/coveragepy/pull/49 is merged, this can be simplified:
|
||||
if false
|
||||
then
|
||||
cat > tmp_merge_coveragerc <<EOF
|
||||
[paths]
|
||||
source =
|
||||
.
|
||||
/tmp/ansible_*/
|
||||
EOF
|
||||
else
|
||||
cat > tmp_merge_coveragerc <<EOF
|
||||
[paths]
|
||||
source =
|
||||
.
|
||||
EOF
|
||||
for file in $(COVERAGE_FILE="${coverage_data}"-tmp coverage report | grep -o "/tmp/ansible_[^/]*" | sort -u)
|
||||
do
|
||||
echo " ${file}" >> tmp_merge_coveragerc
|
||||
done
|
||||
fi
|
||||
|
||||
COVERAGE_FILE="${coverage_data}" coverage combine --rcfile tmp_merge_coveragerc "${coverage_data}"-tmp
|
||||
rm tmp_merge_coveragerc
|
||||
|
||||
COVERAGE_FILE="${coverage_data}" coverage report ||:
|
||||
COVERAGE_FILE="${coverage_data}" coverage html --directory "htmlcov-${coverage_data}" ||:
|
||||
|
||||
echo "Coverage collected in: ${coverage_data}"
|
||||
66
roles/linux-system-roles.network/tests/get-coverage.yml
Normal file
66
roles/linux-system-roles.network/tests/get-coverage.yml
Normal file
@@ -0,0 +1,66 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
# This expects the variable test_playbook to be set from the outside
|
||||
- name: Prepare for coverage extraction
|
||||
hosts: all
|
||||
tasks:
|
||||
# Use set_fact to set variables to make them available in all plays
|
||||
# 'vars:' Would only set variables for the current play
|
||||
- name: set facts
|
||||
set_fact:
|
||||
coverage_module: network_connections
|
||||
coverage: /root/.local/bin/coverage
|
||||
destdir: "remote_coverage/{{ test_playbook }}"
|
||||
|
||||
# This uses variables from the other set_fact task, therefore it needs to
|
||||
# be its own task
|
||||
- name: set more facts
|
||||
set_fact:
|
||||
coverage_file: ansible-coverage-{{ coverage_module }}-{{ test_playbook|replace('.yml', '') }}
|
||||
|
||||
- name: debug info
|
||||
debug:
|
||||
msg: Getting coverage for '{{ coverage_module }}' with '{{ test_playbook }}'
|
||||
|
||||
# combine data in case old data is left there
|
||||
- command: "{{ coverage }} combine"
|
||||
environment:
|
||||
COVERAGE_FILE: "{{ coverage_file }}"
|
||||
ignore_errors: yes
|
||||
|
||||
- name: remove old data
|
||||
file:
|
||||
state: absent
|
||||
path: "{{ coverage_file }}"
|
||||
|
||||
- name: remove old data
|
||||
shell: rm -f .coverage.*
|
||||
|
||||
- name: copy coveragerc
|
||||
copy:
|
||||
content: "[run]\ndisable_warnings = no-data-collected\n"
|
||||
dest: .coveragerc
|
||||
|
||||
- name: install latest pip
|
||||
pip:
|
||||
name: coverage
|
||||
extra_args: --user --upgrade
|
||||
|
||||
- import_playbook: "{{ test_playbook }}"
|
||||
vars:
|
||||
ansible_python_interpreter: "{{ coverage }} run -p --include *ansible_module_{{ coverage_module }}.py"
|
||||
|
||||
- name: Gather coverage data
|
||||
hosts: all
|
||||
tasks:
|
||||
- shell: "{{ coverage }} combine .coverage.*"
|
||||
environment:
|
||||
COVERAGE_FILE: "{{ coverage_file }}"
|
||||
|
||||
- name: Get coverage data
|
||||
hosts: all
|
||||
tasks:
|
||||
- fetch:
|
||||
src: "{{ coverage_file }}"
|
||||
dest: "{{ destdir }}"
|
||||
flat: no
|
||||
34
roles/linux-system-roles.network/tests/get-total-coverage.sh
Executable file
34
roles/linux-system-roles.network/tests/get-total-coverage.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#! /bin/bash
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
set -e
|
||||
coverage_data=total-coveragedata
|
||||
testhost="${1}"
|
||||
|
||||
if [ "$#" -lt 1 ]
|
||||
then
|
||||
echo "USAGE: ${0} host"
|
||||
echo "Get local and all remote coverage data for host"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f remote-coveragedata* "${coveragedata}"
|
||||
|
||||
|
||||
# collect pytest coverage
|
||||
tox -e py26,py27,py36,py37 -- --cov-append
|
||||
|
||||
for test_playbook in tests_*.yml
|
||||
do
|
||||
./get-coverage.sh "${testhost}" "${test_playbook}"
|
||||
done
|
||||
|
||||
./merge-coverage.sh coverage "total-remote-coveragedata" remote-coveragedata-*
|
||||
./covstats .coverage remote-coveragedata-* "total-remote-coveragedata"
|
||||
|
||||
./merge-coverage.sh coverage "${coverage_data}" .coverage remote-coveragedata-*
|
||||
echo "Total coverage:"
|
||||
COVERAGE_FILE="${coverage_data}" coverage report ||:
|
||||
COVERAGE_FILE="${coverage_data}" coverage html --directory "htmlcov-${coverage_data}" ||:
|
||||
echo "Open HTML report with:"
|
||||
echo "xdg-open htmlcov-${coverage_data}/index.html"
|
||||
35
roles/linux-system-roles.network/tests/merge-coverage.sh
Executable file
35
roles/linux-system-roles.network/tests/merge-coverage.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#! /bin/bash
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
if [ -n "${DEBUG}" ]
|
||||
then
|
||||
set -x
|
||||
fi
|
||||
set -e
|
||||
|
||||
if [ "$#" -lt 3 ]
|
||||
then
|
||||
echo "USAGE: ${0} path_to_coverage_binary output_file input_files..."
|
||||
echo "Merges all input_files into output file without removing input_files"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# path to coverage binary
|
||||
coverage="${1}"
|
||||
shift
|
||||
|
||||
# read by coverage binary
|
||||
export COVERAGE_FILE="${1}"
|
||||
shift
|
||||
|
||||
tempdir="$(mktemp -d /tmp/coverage_merge-XXXXXX)"
|
||||
trap "rm -rf '${tempdir}'" EXIT
|
||||
|
||||
cp --backup=numbered -- "${@}" "${tempdir}"
|
||||
# FIXME: Would not work if coverage files are not hidden but they are by
|
||||
# default
|
||||
shopt -s dotglob
|
||||
"${coverage}" combine "${tempdir}/"*
|
||||
|
||||
echo "Merged data into ${COVERAGE_FILE}"
|
||||
./covstats "${COVERAGE_FILE}"
|
||||
1
roles/linux-system-roles.network/tests/playbooks/roles
Symbolic link
1
roles/linux-system-roles.network/tests/playbooks/roles
Symbolic link
@@ -0,0 +1 @@
|
||||
../roles/
|
||||
1
roles/linux-system-roles.network/tests/playbooks/tasks
Symbolic link
1
roles/linux-system-roles.network/tests/playbooks/tasks
Symbolic link
@@ -0,0 +1 @@
|
||||
../tasks/
|
||||
@@ -0,0 +1,111 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
interface: lsrfeat1
|
||||
type: veth
|
||||
tasks:
|
||||
- name: "INIT: Ethtool feeatures tests"
|
||||
debug:
|
||||
msg: "##################################################"
|
||||
- include_tasks: tasks/show-interfaces.yml
|
||||
- include_tasks: tasks/manage-test-interface.yml
|
||||
vars:
|
||||
state: present
|
||||
- include_tasks: tasks/assert-device_present.yml
|
||||
- name: Install ethtool (test dependency)
|
||||
package:
|
||||
name: ethtool
|
||||
state: present
|
||||
- block:
|
||||
- name: "TEST: I can create a profile without changing the ethtool features."
|
||||
debug:
|
||||
msg: "##################################################"
|
||||
- name: Get current device features
|
||||
command: "ethtool --show-features {{ interface }}"
|
||||
register: original_ethtool_features
|
||||
- import_role:
|
||||
name: linux-system-roles.network
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ interface }}"
|
||||
state: up
|
||||
type: ethernet
|
||||
ip:
|
||||
dhcp4: "no"
|
||||
auto6: "no"
|
||||
- name: Get current device features
|
||||
command: "ethtool --show-features {{ interface }}"
|
||||
register: ethtool_features
|
||||
- name: "ASSERT: The profile does not change the ethtool features"
|
||||
assert:
|
||||
that:
|
||||
- original_ethtool_features.stdout == ethtool_features.stdout
|
||||
- name: "TEST: I can disable gro and tx-tcp-segmentation and enable gso."
|
||||
debug:
|
||||
msg: "##################################################"
|
||||
- import_role:
|
||||
name: linux-system-roles.network
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ interface }}"
|
||||
state: up
|
||||
type: ethernet
|
||||
ip:
|
||||
dhcp4: "no"
|
||||
auto6: "no"
|
||||
ethtool:
|
||||
features:
|
||||
gro: "no"
|
||||
gso: "yes"
|
||||
tx-tcp-segmentation: "no"
|
||||
- name: Get current device features
|
||||
command: "ethtool --show-features {{ interface }}"
|
||||
register: ethtool_features
|
||||
- name:
|
||||
debug:
|
||||
var: ethtool_features.stdout_lines
|
||||
- name: Assert device features
|
||||
assert:
|
||||
that:
|
||||
- "'generic-receive-offload: off' in ethtool_features.stdout_lines"
|
||||
- "'generic-segmentation-offload: on' in ethtool_features.stdout_lines"
|
||||
- "'tx-tcp-segmentation: off' in ethtool_features.stdout_lines | map('trim')"
|
||||
- name: "TEST: I can reset features to their original value."
|
||||
debug:
|
||||
msg: "##################################################"
|
||||
- import_role:
|
||||
name: linux-system-roles.network
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ interface }}"
|
||||
state: up
|
||||
type: ethernet
|
||||
ip:
|
||||
dhcp4: "no"
|
||||
auto6: "no"
|
||||
- name: Get current device features
|
||||
command: "ethtool --show-features {{ interface }}"
|
||||
register: ethtool_features
|
||||
# Resetting the ethtools only works with NetworkManager
|
||||
- name: "ASSERT: The profile does not change the ethtool features"
|
||||
assert:
|
||||
that:
|
||||
- original_ethtool_features.stdout == ethtool_features.stdout
|
||||
when:
|
||||
network_provider == 'nm'
|
||||
always:
|
||||
- block:
|
||||
- import_role:
|
||||
name: linux-system-roles.network
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ interface }}"
|
||||
persistent_state: absent
|
||||
state: down
|
||||
ignore_errors: true
|
||||
- include_tasks: tasks/manage-test-interface.yml
|
||||
vars:
|
||||
state: absent
|
||||
tags:
|
||||
- "tests::cleanup"
|
||||
@@ -0,0 +1,49 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
interface: statebr
|
||||
profile: "{{ interface }}"
|
||||
network_provider: nm
|
||||
tasks:
|
||||
- debug:
|
||||
msg: Inside states tests
|
||||
- include_tasks: tasks/show-interfaces.yml
|
||||
- include_tasks: tasks/assert-device_absent.yml
|
||||
|
||||
# create test profile
|
||||
- include_role:
|
||||
name: linux-system-roles.network
|
||||
vars:
|
||||
network_connections:
|
||||
- name: statebr
|
||||
state: up
|
||||
type: bridge
|
||||
ip:
|
||||
dhcp4: false
|
||||
auto6: false
|
||||
- include_tasks: tasks/assert-device_present.yml
|
||||
- include_tasks: tasks/assert-profile_present.yml
|
||||
|
||||
# test case (remove profile but keep it up)
|
||||
# I can remove a profile but keep the configuration active.
|
||||
- include_role:
|
||||
name: linux-system-roles.network
|
||||
vars:
|
||||
network_connections:
|
||||
- name: statebr
|
||||
persistent_state: absent
|
||||
- include_tasks: tasks/assert-device_present.yml
|
||||
- include_tasks: tasks/assert-profile_absent.yml
|
||||
|
||||
# test case
|
||||
# I can set a profile down that is up and absent.
|
||||
- name: Set down
|
||||
include_role:
|
||||
name: linux-system-roles.network
|
||||
vars:
|
||||
network_connections:
|
||||
- name: statebr
|
||||
state: down
|
||||
- include_tasks: tasks/assert-device_absent.yml
|
||||
- include_tasks: tasks/assert-profile_absent.yml
|
||||
@@ -0,0 +1,66 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- hosts: all
|
||||
vars:
|
||||
type: veth
|
||||
interface: lsr101
|
||||
vlan_interface: lsr101.90
|
||||
tasks:
|
||||
- include_tasks: tasks/show-interfaces.yml
|
||||
- include_tasks: tasks/manage-test-interface.yml
|
||||
vars:
|
||||
state: present
|
||||
- include_tasks: tasks/assert-device_present.yml
|
||||
- name: "TEST: I can configure the MTU for a vlan interface without autoconnect."
|
||||
debug:
|
||||
msg: "##################################################"
|
||||
- import_role:
|
||||
name: linux-system-roles.network
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ interface }}"
|
||||
type: ethernet
|
||||
state: up
|
||||
mtu: 1492
|
||||
autoconnect: false
|
||||
ip:
|
||||
dhcp4: false
|
||||
auto6: false
|
||||
|
||||
- name: "{{ vlan_interface }}"
|
||||
parent: "{{ interface }}"
|
||||
type: vlan
|
||||
vlan_id: 90
|
||||
mtu: 1280
|
||||
state: up
|
||||
autoconnect: false
|
||||
ip:
|
||||
dhcp4: false
|
||||
auto6: false
|
||||
- include_tasks: tasks/assert-device_present.yml
|
||||
vars:
|
||||
interface: "{{ vlan_interface }}"
|
||||
- include_tasks: tasks/assert-profile_present.yml
|
||||
vars:
|
||||
profile: "{{ item }}"
|
||||
loop:
|
||||
- "{{ interface }}"
|
||||
- "{{ vlan_interface }}"
|
||||
|
||||
- name: "TEARDOWN: remove profiles."
|
||||
debug:
|
||||
msg: "##################################################"
|
||||
- import_role:
|
||||
name: linux-system-roles.network
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ interface }}"
|
||||
persistent_state: absent
|
||||
state: down
|
||||
- name: "{{ vlan_interface }}"
|
||||
persistent_state: absent
|
||||
state: down
|
||||
ignore_errors: true
|
||||
- include_tasks: tasks/manage-test-interface.yml
|
||||
vars:
|
||||
state: absent
|
||||
10
roles/linux-system-roles.network/tests/remove-profile.yml
Normal file
10
roles/linux-system-roles.network/tests/remove-profile.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Remove {{ profile }}
|
||||
hosts: all
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ profile }}"
|
||||
persistent_state: absent
|
||||
roles:
|
||||
- linux-system-roles.network
|
||||
@@ -0,0 +1 @@
|
||||
../../../defaults/
|
||||
@@ -0,0 +1 @@
|
||||
../../../library/
|
||||
@@ -0,0 +1 @@
|
||||
../../../meta/
|
||||
@@ -0,0 +1 @@
|
||||
../../../module_utils/
|
||||
@@ -0,0 +1 @@
|
||||
../../../tasks/
|
||||
6
roles/linux-system-roles.network/tests/run-tasks.yml
Normal file
6
roles/linux-system-roles.network/tests/run-tasks.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Run the tasklist {{ task }}
|
||||
hosts: all
|
||||
tasks:
|
||||
- include_tasks: "{{ task }}"
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-interface_stat.yml
|
||||
- name: "assert that interface {{ interface }} is absent"
|
||||
assert:
|
||||
that: not interface_stat.stat.exists
|
||||
msg: "{{ interface }} exists"
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-interface_stat.yml
|
||||
- name: "assert that interface {{ interface }} is present"
|
||||
assert:
|
||||
that: interface_stat.stat.exists
|
||||
msg: "{{ interface }} does not exist"
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-profile_stat.yml
|
||||
- name: "assert that profile '{{ profile }}' is absent"
|
||||
assert:
|
||||
that: not profile_stat.stat.exists
|
||||
msg: "profile {{ profile_path }} does exist"
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-profile_stat.yml
|
||||
- name: "assert that profile '{{ profile }}' is present"
|
||||
assert:
|
||||
that: profile_stat.stat.exists
|
||||
msg: "profile {{ profile_path }} does not exist"
|
||||
@@ -0,0 +1,20 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: manage-test-interface.yml
|
||||
vars:
|
||||
state: absent
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: assert-device_absent.yml
|
||||
|
||||
- include_tasks: manage-test-interface.yml
|
||||
vars:
|
||||
state: present
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: assert-device_present.yml
|
||||
|
||||
- include_tasks: manage-test-interface.yml
|
||||
vars:
|
||||
state: absent
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: assert-device_absent.yml
|
||||
@@ -0,0 +1,8 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- command: ls -1
|
||||
args:
|
||||
chdir: /sys/class/net
|
||||
register: _current_interfaces
|
||||
- set_fact:
|
||||
current_interfaces: "{{ _current_interfaces.stdout_lines }}"
|
||||
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: "Get stat for interface {{ interface }}"
|
||||
stat:
|
||||
get_attributes: false
|
||||
get_checksum: false
|
||||
get_mime: false
|
||||
path: "/sys/class/net/{{ interface }}"
|
||||
register: interface_stat
|
||||
@@ -0,0 +1,26 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: "Get stat for network-scripts"
|
||||
stat:
|
||||
get_attributes: false
|
||||
get_checksum: false
|
||||
get_mime: false
|
||||
path: "/etc/sysconfig/network-scripts"
|
||||
register: network_scripts_stat
|
||||
- name: Set profile path (network-scripts)
|
||||
set_fact:
|
||||
profile_path: /etc/sysconfig/network-scripts/ifcfg-{{ profile }}
|
||||
when:
|
||||
- network_scripts_stat.stat.exists
|
||||
- name: Set profile path (NetworkManager system-connections)
|
||||
set_fact:
|
||||
profile_path: /etc/NetworkManager/system-connections/{{ profile }}
|
||||
when:
|
||||
- not network_scripts_stat.stat.exists
|
||||
- name: stat profile file
|
||||
stat:
|
||||
get_attributes: false
|
||||
get_checksum: false
|
||||
get_mime: false
|
||||
path: "{{ profile_path }}"
|
||||
register: profile_stat
|
||||
@@ -0,0 +1,50 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- fail:
|
||||
msg: "state needs to be present or absent, not '{{ state }}'"
|
||||
when: state not in ["present", "absent"]
|
||||
|
||||
- fail:
|
||||
msg: "type needs to be dummy, tap or veth, not '{{ type }}'"
|
||||
when: type not in ["dummy", "tap", "veth"]
|
||||
|
||||
# - include: get-current_interfaces.yml
|
||||
- include: show-interfaces.yml
|
||||
|
||||
- name: Install iproute
|
||||
package:
|
||||
name: iproute
|
||||
state: present
|
||||
|
||||
# veth
|
||||
- name: Create veth interface {{ interface }}
|
||||
shell: ip link add {{ interface }} type veth peer name peer{{ interface }}
|
||||
when: "type == 'veth' and state == 'present' and
|
||||
interface not in current_interfaces"
|
||||
|
||||
- name: Delete veth interface {{ interface }}
|
||||
shell: ip link del {{ interface }} type veth
|
||||
when: "type == 'veth' and state == 'absent' and
|
||||
interface in current_interfaces"
|
||||
|
||||
# dummy
|
||||
- name: Create dummy interface {{ interface }}
|
||||
shell: ip link add "{{ interface }}" type dummy
|
||||
when: "type == 'dummy' and state == 'present' and
|
||||
interface not in current_interfaces"
|
||||
|
||||
- name: Delete dummy interface {{ interface }}
|
||||
shell: ip link del "{{ interface }}" type dummy
|
||||
when: "type == 'dummy' and state == 'absent' and
|
||||
interface in current_interfaces"
|
||||
|
||||
# tap
|
||||
- name: Create tap interface {{ interface }}
|
||||
shell: ip tuntap add dev {{ interface }} mode tap
|
||||
when: "type == 'tap' and state == 'present'
|
||||
and interface not in current_interfaces"
|
||||
|
||||
- name: Delete tap interface {{ interface }}
|
||||
shell: ip tuntap del dev {{ interface }} mode tap
|
||||
when: "type == 'tap' and state == 'absent' and
|
||||
interface in current_interfaces"
|
||||
@@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-current_interfaces.yml
|
||||
- debug:
|
||||
msg: "current_interfaces: {{ current_interfaces }}"
|
||||
55
roles/linux-system-roles.network/tests/tests_bridge.yml
Normal file
55
roles/linux-system-roles.network/tests/tests_bridge.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Test configuring bridges
|
||||
hosts: all
|
||||
vars:
|
||||
interface: LSR-TST-br31
|
||||
|
||||
tasks:
|
||||
- name: "set interface={{ interface }}"
|
||||
set_fact:
|
||||
interface: "{{ interface }}"
|
||||
- include_tasks: tasks/show-interfaces.yml
|
||||
- include_tasks: tasks/assert-device_absent.yml
|
||||
|
||||
- name: Add test bridge
|
||||
hosts: all
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ interface }}"
|
||||
interface_name: "{{ interface }}"
|
||||
state: up
|
||||
type: bridge
|
||||
ip:
|
||||
dhcp4: no
|
||||
auto6: yes
|
||||
roles:
|
||||
- linux-system-roles.network
|
||||
|
||||
- import_playbook: run-tasks.yml
|
||||
vars:
|
||||
task: tasks/assert-device_present.yml
|
||||
|
||||
- import_playbook: run-tasks.yml
|
||||
vars:
|
||||
profile: "{{ interface }}"
|
||||
task: tasks/assert-profile_present.yml
|
||||
|
||||
- import_playbook: down-profile.yml
|
||||
vars:
|
||||
profile: "{{ interface }}"
|
||||
# FIXME: assert profile/device down
|
||||
|
||||
- import_playbook: remove-profile.yml
|
||||
vars:
|
||||
profile: "{{ interface }}"
|
||||
|
||||
- import_playbook: run-tasks.yml
|
||||
vars:
|
||||
profile: "{{ interface }}"
|
||||
task: tasks/assert-profile_absent.yml
|
||||
|
||||
# FIXME: Devices might still be left when profile is absent
|
||||
#- import_playbook: run-tasks.yml
|
||||
# vars:
|
||||
# task: tasks/assert-device_absent.yml
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- hosts: all
|
||||
name: Run playbook 'tests_bridge.yml' with non-default provider
|
||||
tasks:
|
||||
- name: Get service facts
|
||||
service_facts: null
|
||||
- name: Set network provider
|
||||
set_fact:
|
||||
network_provider: '{{ "initscripts" if network_provider_current == "nm" else
|
||||
"nm" }}'
|
||||
vars:
|
||||
network_provider_current: '{{ ''nm'' if ''NetworkManager.service'' in ansible_facts.services
|
||||
and ansible_facts.services[''NetworkManager.service''][''state''] == ''running''
|
||||
else ''initscripts'' }}'
|
||||
- import_playbook: tests_bridge.yml
|
||||
when:
|
||||
- ansible_distribution_major_version != '6'
|
||||
6
roles/linux-system-roles.network/tests/tests_default.yml
Normal file
6
roles/linux-system-roles.network/tests/tests_default.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Test executing the role with default parameters
|
||||
hosts: all
|
||||
roles:
|
||||
- linux-system-roles.network
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- hosts: all
|
||||
name: Run playbook 'tests_default.yml' with non-default provider
|
||||
tasks:
|
||||
- name: Get service facts
|
||||
service_facts: null
|
||||
- name: Set network provider
|
||||
set_fact:
|
||||
network_provider: '{{ "initscripts" if network_provider_current == "nm" else
|
||||
"nm" }}'
|
||||
vars:
|
||||
network_provider_current: '{{ ''nm'' if ''NetworkManager.service'' in ansible_facts.services
|
||||
and ansible_facts.services[''NetworkManager.service''][''state''] == ''running''
|
||||
else ''initscripts'' }}'
|
||||
- import_playbook: tests_default.yml
|
||||
when:
|
||||
- ansible_distribution_major_version != '6'
|
||||
62
roles/linux-system-roles.network/tests/tests_ethernet.yml
Normal file
62
roles/linux-system-roles.network/tests/tests_ethernet.yml
Normal file
@@ -0,0 +1,62 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- hosts: all
|
||||
tasks:
|
||||
- debug:
|
||||
msg: Inside ethernet tests
|
||||
- debug:
|
||||
var: network_provider
|
||||
|
||||
- name: Test configuring ethernet devices
|
||||
hosts: all
|
||||
vars:
|
||||
type: veth
|
||||
interface: lsr27
|
||||
|
||||
tasks:
|
||||
- name: "set type={{ type }} and interface={{ interface }}"
|
||||
set_fact:
|
||||
type: "{{ type }}"
|
||||
interface: "{{ interface }}"
|
||||
- include_tasks: tasks/show-interfaces.yml
|
||||
- include_tasks: tasks/manage-test-interface.yml
|
||||
vars:
|
||||
state: present
|
||||
- include_tasks: tasks/assert-device_present.yml
|
||||
|
||||
- name: Test static interface up
|
||||
hosts: all
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ interface }}"
|
||||
interface_name: "{{ interface }}"
|
||||
state: up
|
||||
type: ethernet
|
||||
autoconnect: yes
|
||||
ip:
|
||||
address: 192.0.2.1/24
|
||||
roles:
|
||||
- linux-system-roles.network
|
||||
|
||||
- hosts: all
|
||||
tasks:
|
||||
- debug:
|
||||
var: network_provider
|
||||
|
||||
# FIXME: assert profile present
|
||||
# FIXME: assert profile/device up + IP address
|
||||
- import_playbook: down-profile.yml
|
||||
vars:
|
||||
profile: "{{ interface }}"
|
||||
# FIXME: assert profile/device down
|
||||
- import_playbook: remove-profile.yml
|
||||
vars:
|
||||
profile: "{{ interface }}"
|
||||
# FIXME: assert profile away
|
||||
- name: Remove interfaces
|
||||
hosts: all
|
||||
tasks:
|
||||
- include_tasks: tasks/manage-test-interface.yml
|
||||
vars:
|
||||
state: absent
|
||||
- include_tasks: tasks/assert-device_absent.yml
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- hosts: all
|
||||
name: Run playbook 'tests_ethernet.yml' with non-default provider
|
||||
tasks:
|
||||
- name: Get service facts
|
||||
service_facts: null
|
||||
- name: Set network provider
|
||||
set_fact:
|
||||
network_provider: '{{ "initscripts" if network_provider_current == "nm" else
|
||||
"nm" }}'
|
||||
vars:
|
||||
network_provider_current: '{{ ''nm'' if ''NetworkManager.service'' in ansible_facts.services
|
||||
and ansible_facts.services[''NetworkManager.service''][''state''] == ''running''
|
||||
else ''initscripts'' }}'
|
||||
- import_playbook: tests_ethernet.yml
|
||||
when:
|
||||
- ansible_distribution_major_version != '6'
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
# set network provider and gather facts
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: Set network provider to 'initscripts'
|
||||
set_fact:
|
||||
network_provider: initscripts
|
||||
|
||||
# workaround for: https://github.com/ansible/ansible/issues/27973
|
||||
# There is no way in Ansible to abort a playbook hosts with specific OS
|
||||
# releases Therefore we include the playbook with the tests only if the hosts
|
||||
# would support it.
|
||||
- import_playbook: playbooks/tests_ethtool_features.yml
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
# set network provider and gather facts
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: Set network provider to 'nm'
|
||||
set_fact:
|
||||
network_provider: nm
|
||||
- name: Install NetworkManager
|
||||
package:
|
||||
name: NetworkManager
|
||||
state: present
|
||||
- name: Get NetworkManager version
|
||||
command: rpm -q --qf "%{version}" NetworkManager
|
||||
args:
|
||||
warn: "no"
|
||||
when: true
|
||||
register: NetworkManager_version
|
||||
|
||||
# workaround for: https://github.com/ansible/ansible/issues/27973
|
||||
# There is no way in Ansible to abort a playbook hosts with specific OS
|
||||
# releases Therefore we include the playbook with the tests only if the hosts
|
||||
# would support it.
|
||||
# The test should run with NetworkManager, therefore it cannot run on RHEL 6 or CentOS 6.
|
||||
- import_playbook: playbooks/tests_ethtool_features.yml
|
||||
when:
|
||||
- ansible_distribution_major_version != '6'
|
||||
# NetworkManager 1.20.0 introduced ethtool settings support
|
||||
- NetworkManager_version.stdout is version('1.20.0', '>=')
|
||||
@@ -0,0 +1,27 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Check that creating and removing test devices and assertions work
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: test veth interface management
|
||||
include_tasks: tasks/create-and-remove-interface.yml
|
||||
vars:
|
||||
type: veth
|
||||
interface: veth1298
|
||||
|
||||
- name: test veth interface management
|
||||
include_tasks: tasks/create-and-remove-interface.yml
|
||||
vars:
|
||||
type: dummy
|
||||
interface: dummy1298
|
||||
|
||||
# FIXME: when: does not seem to work with include_tasks, therefore this cannot be safely tested for now
|
||||
# - name: test tap interfaces
|
||||
# include_tasks: tasks/create-and-remove-interface.yml
|
||||
# vars:
|
||||
# - type: tap
|
||||
# - interface: tap1298
|
||||
# when: ansible_distribution_major_version > 6
|
||||
# # ip tuntap does not exist on RHEL6
|
||||
# # FIXME: Maybe use some other tool to manage devices, openvpn can do this,
|
||||
# # but it is in EPEL
|
||||
11
roles/linux-system-roles.network/tests/tests_states.yml
Normal file
11
roles/linux-system-roles.network/tests/tests_states.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
# empty playbook to gather facts for import_playbook when clause
|
||||
- hosts: all
|
||||
|
||||
# workaround for: https://github.com/ansible/ansible/issues/27973
|
||||
# There is no way in Ansible to abort a playbook hosts with specific OS
|
||||
# releases Therefore we include the playbook with the tests only if the hosts
|
||||
# would support it.
|
||||
# The test requires NetworkManager, therefore it cannot run on RHEL 6 or CentOS 6.
|
||||
- import_playbook: playbooks/tests_states.yml
|
||||
when: ansible_distribution_major_version != '6'
|
||||
89
roles/linux-system-roles.network/tests/tests_unit.yml
Normal file
89
roles/linux-system-roles.network/tests/tests_unit.yml
Normal file
@@ -0,0 +1,89 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- hosts: all
|
||||
name: Setup for test running
|
||||
tasks:
|
||||
- name: Install EPEL on enterprise Linux for python2-mock
|
||||
command: yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm
|
||||
args:
|
||||
warn: false
|
||||
creates: /etc/yum.repos.d/epel.repo
|
||||
when:
|
||||
- ansible_distribution in ['RedHat', 'CentOS']
|
||||
- ansible_distribution_major_version in ['6', '7']
|
||||
|
||||
- name: Install dependencies
|
||||
package:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
# Ignore error because some package names might not be available
|
||||
ignore_errors: true
|
||||
loop:
|
||||
- NetworkManager-libnm
|
||||
- python2-gobject-base
|
||||
- python3-gobject-base
|
||||
- python-gobject-base
|
||||
- python2-mock
|
||||
|
||||
- hosts: all
|
||||
name: execute python unit tests
|
||||
tasks:
|
||||
- name: Copy python modules
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /tmp/test-unit-1/
|
||||
local_follow: false
|
||||
loop:
|
||||
- ../library/network_connections.py
|
||||
- unit/test_network_connections.py
|
||||
- ../module_utils/network_lsr
|
||||
|
||||
- name: Create helpers directory
|
||||
file:
|
||||
state: directory
|
||||
dest: /tmp/test-unit-1/helpers
|
||||
|
||||
- name: Copy helpers
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: /tmp/test-unit-1/helpers
|
||||
mode: 0755
|
||||
with_fileglob:
|
||||
- unit/helpers/*
|
||||
|
||||
- name: Check if python2 is available
|
||||
command: python2 --version
|
||||
ignore_errors: true
|
||||
register: python2_available
|
||||
when: true
|
||||
|
||||
- name: Run python2 unit tests
|
||||
command: python2 /tmp/test-unit-1/test_network_connections.py --verbose
|
||||
when: python2_available is succeeded
|
||||
register: python2_result
|
||||
|
||||
- name: Check if python3 is available
|
||||
command: python3 --version
|
||||
ignore_errors: true
|
||||
register: python3_available
|
||||
when: true
|
||||
|
||||
- name: Run python3 unit tests
|
||||
command: python3 /tmp/test-unit-1/test_network_connections.py --verbose
|
||||
when: python3_available is succeeded
|
||||
register: python3_result
|
||||
|
||||
- name: Show python2 unit test results
|
||||
debug:
|
||||
var: python2_result.stderr_lines
|
||||
when: python2_result is succeeded
|
||||
|
||||
- name: Show python3 unit test results
|
||||
debug:
|
||||
var: python3_result.stderr_lines
|
||||
when: python3_result is succeeded
|
||||
|
||||
- name: Ensure that at least one python unit test ran
|
||||
fail:
|
||||
msg: Tests did not run with python2 or python3
|
||||
when: not (python2_available is succeeded or python3_available is succeeded)
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
# set network provider and gather facts
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: Set network provider to 'initscripts'
|
||||
set_fact:
|
||||
network_provider: initscripts
|
||||
|
||||
# workaround for: https://github.com/ansible/ansible/issues/27973
|
||||
# There is no way in Ansible to abort a playbook hosts with specific OS
|
||||
# releases Therefore we include the playbook with the tests only if the hosts
|
||||
# would support it.
|
||||
- import_playbook: playbooks/tests_vlan_mtu.yml
|
||||
15
roles/linux-system-roles.network/tests/tests_vlan_mtu_nm.yml
Normal file
15
roles/linux-system-roles.network/tests/tests_vlan_mtu_nm.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
# set network provider and gather facts
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: Set network provider to 'nm'
|
||||
set_fact:
|
||||
network_provider: nm
|
||||
|
||||
# workaround for: https://github.com/ansible/ansible/issues/27973
|
||||
# There is no way in Ansible to abort a playbook hosts with specific OS
|
||||
# releases Therefore we include the playbook with the tests only if the hosts
|
||||
# would support it.
|
||||
# The test requires NetworkManager, therefore it cannot run on RHEL 6 or CentOS 6.
|
||||
- import_playbook: playbooks/tests_vlan_mtu.yml
|
||||
when: ansible_distribution_major_version != '6'
|
||||
6
roles/linux-system-roles.network/tests/unit/helpers/ethtool
Executable file
6
roles/linux-system-roles.network/tests/unit/helpers/ethtool
Executable file
@@ -0,0 +1,6 @@
|
||||
#! /bin/bash
|
||||
|
||||
if [ "${1}" == "-P" ] && [ "${2}" != "" ]
|
||||
then
|
||||
echo "Permanent address: 23:00:00:00:00:00"
|
||||
fi
|
||||
2236
roles/linux-system-roles.network/tests/unit/test_network_connections.py
Executable file
2236
roles/linux-system-roles.network/tests/unit/test_network_connections.py
Executable file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python
|
||||
""" Tests for network_connections Ansible module """
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
TESTS_BASEDIR = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(1, os.path.join(TESTS_BASEDIR, "../..", "library"))
|
||||
sys.path.insert(1, os.path.join(TESTS_BASEDIR, "../..", "module_utils"))
|
||||
|
||||
try:
|
||||
from unittest import mock
|
||||
except ImportError: # py2
|
||||
import mock
|
||||
|
||||
sys.modules["ansible"] = mock.Mock()
|
||||
sys.modules["ansible.module_utils.basic"] = mock.Mock()
|
||||
sys.modules["ansible.module_utils"] = mock.Mock()
|
||||
sys.modules["ansible.module_utils.network_lsr"] = __import__("network_lsr")
|
||||
|
||||
with mock.patch.dict("sys.modules", {"gi": mock.Mock(), "gi.repository": mock.Mock()}):
|
||||
# pylint: disable=import-error, wrong-import-position
|
||||
from network_lsr import nm_provider
|
||||
|
||||
|
||||
def test_get_nm_ethtool_feature():
|
||||
""" Test get_nm_ethtool_feature() """
|
||||
with mock.patch.object(nm_provider.Util, "NM") as nm_mock:
|
||||
nm_feature = nm_provider.get_nm_ethtool_feature("esp-hw-offload")
|
||||
assert nm_feature == nm_mock.return_value.ETHTOOL_OPTNAME_FEATURE_ESP_HW_OFFLOAD
|
||||
Reference in New Issue
Block a user