Commit Graph

58 Commits

Author SHA1 Message Date
Javier Cano Cano
191d0bb647 feat: run the formatter across the test inventory
It standardizes the code format across all the unit tests codebase.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-06-19 16:57:50 +02:00
Javier Cano Cano
81fc608b44 feat: Refactor kubevirt unit test suite
It refactors the test suite to reduce the amount of fixtures used on it.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-06-19 16:57:50 +02:00
Javier Cano Cano
d7e3ba486e test(kubevirt): add get_vmis_for_namespace missing cases.
Adds two missing execution paths when the `network_name` is provided and
when there are not VMIs to collect.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-06-19 16:57:50 +02:00
Javier Cano Cano
3d03f8a952 test(kubevirt): add inventory unit tests
It adds unit tests for the following functions:
- set_composable_vars
- format_dynamic_api_exc

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-06-19 16:57:48 +02:00
Javier Cano Cano
7abe530e94 feat: refactor add_group and add_host fixtures.
It refactors fixtures: `add_group` and `add_host` to improve fixtures
reusability in further scenarios.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-06-17 11:58:41 +02:00
Javier Cano Cano
a8eb5643db tests: Address comments of #96
It fixes concerns posted on
https://github.com/kubevirt/kubevirt.core/pull/96

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-06-14 11:10:26 +02:00
Felix Matouschek
5d31db3ea2 chore: Change license Apache 2.0
Change the license of the collection to Apache 2.0 to be compliant with
the CNCF licensing requirements.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-11 11:39:32 +02:00
mperetz
050799a084 kubevirt_vm integration tests: changed ssh key type to RSA for FIPS mode
Signed-off-by: mperetzred <mperetz@redhat.com>
2024-06-10 16:59:04 +03:00
Felix Matouschek
ea8447dee8 fix(tests,kubevirt_vm): Fix assertion in verify.yml
Fix the assertion that was introduced in
2521e8ba24 by removing the superfluous 'd'
at the end of the variable names.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-05 16:17:31 +02:00
Felix Matouschek
2521e8ba24 fix(tests,kubevirt_vm): Assert there are no or expected changes
Assert there are no or expected changes in verify.yml of the kubevirt_vm
integration test. This is necessary since in downstream tests the
kubemacpool operator might add annotations to the VM which can trigger a
changed result.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-04 09:53:53 +02:00
Felix Matouschek
e1b2094e4e fix(tests,kubevirt_vm): Make waiting for VM more robust
This changes the runme.sh of the kubevirt_vm integration tests to retry
the connection to the VM until a login is possible. This is necessary
since it is not possible with Ansible alone to retry a task in case the
connection failed with the unreachable status. This can happen when the
sshd of the VM already accepts connections but a login is not yet
possible because the VM is still booting up.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-04 09:53:53 +02:00
Javier Cano Cano
2b8767b424 test: add kubevirt inventory unit tests
Add unit tests for the following kubevirt functions:

- get_default_host_name
- get_host_from_service
- get_port_from_service
- parse
- fetch_objects
- get_cluster_domain
- get_available_namespaces
- get_vmis_for_namespace
- get_ssh_services_for_namespace
- set_ansible_host_and_port

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-05-15 17:41:50 +02:00
kubevirt-bot
10d8c23138 Merge pull request #92 from jcanocan/add-template-tests
tests: add render_template unit tests
2024-04-29 10:54:05 +02:00
Javier Cano Cano
86d1d748df tests: add render_template unit tests
It adds unit tests for the render_template function. These test cases
cover all cases for non-mandatory fields in the VM template.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-04-29 10:27:52 +02:00
Felix Matouschek
71a88007fe feat(kubevirt_vm_info): Set wait_condition based on running
Add the running parameter to kubevirt_vm_info from which the
wait_condition is derived from when parameter wait is set to
yes.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-24 18:48:39 +02:00
Felix Matouschek
9d24aa878d cleanup: Run formatter on test_kubevirt_vm.py
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-24 18:38:51 +02:00
Javier Cano Cano
44936096ce test: add kubevirt_vm delete test case
Adds a test to assert deletion options are the expected.
Refactors python fixtures to reuse common fields in both create and
delete tests.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-04-24 15:57:32 +02:00
Felix Matouschek
86cee0172f fix(kubevirt_vm): Set wait_condition based on running
To properly wait for a state change in the kubevirt_vm module the
wait_condition needs to adapted to the state of running.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-24 14:53:41 +02:00
Felix Matouschek
e5edf072cc cleanup: Cleanup YAML passed to k8s module
Cleanup the YAML passed to the k8s module so it conforms to yaml output
you would expect from yaml.dump. Also refactor the tests to get rid of
duplicate definitions and make use of pytest.mark.parametrize and
yaml.dump.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-24 12:16:10 +02:00
Javier Cano Cano
3814d1deb5 test: add kubevirt_vm test cases
Adds unit test to assert VM label and field selectors work as expected.
Refactors python fixtures to reuse defaults and avoid code duplication.

Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
2024-04-18 17:01:30 +02:00
Felix Matouschek
ee7f99267c chore: Add requirements.txt for ansible-test units
Add the requirements.txt with requirements needed by ansible-test units.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-16 18:17:37 +02:00
Felix Matouschek
a3abcbedd4 feat: Set ansible_connection to winrm for Windows hosts
This changes the inventory plugin so that it sets the ansible_connection
to winrm if it detected a Windows host. If it did not detect a Windows
host the ansible_connection is no longer set, so Ansible falls back to
its default value of ssh. The detection of SSH services for hosts using
winrm is disabled.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-16 16:38:54 +02:00
Felix Matouschek
7c5de4adf9 cleanup: Run make format
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-16 16:38:54 +02:00
Felix Matouschek
5ae19f9623 tests: Add basic unit tests for inventory plugin
Add a test file for the inventory plugin with some basic unit tests.
This file can be used to add more tests in the future.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-16 15:16:37 +02:00
Felix Matouschek
1947fe9ca8 cleanup: Reorganize unit tests
Reorganize unit tests so the directory structure looks like the
structure used in most other collections.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-15 13:58:08 +02:00
Felix Matouschek
9848f66036 cleanup: Migrate existing unit tests to pytest
Cleanup the existing unit tests and move them to pytest. By using pytest
it becomes easier to add new tests for existing functionality in the
collection.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-15 13:58:08 +02:00
Felix Matouschek
e2d2da2670 chore: Add tox configuration
Add tox configuration that allows to build a venv for development and to
format source files. To make use of it add appropriate Makefile targets.

Drop unneeded requirements from requirements.txt and
test-requirements.txt and add needed requirements.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-04-12 10:23:38 +02:00
Felix Matouschek
1772f182e0 chore: Rework gitignore
Rework gitignore by combining all gitignore files and adding files
generated by running tests.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-20 10:19:13 +01:00
Felix Matouschek
651e1d6718 fix: Rename tests/config.yaml to tests/config.yml
The file extension of the file needs to be .yml, so ansible-test is able
to pick it up.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-20 09:19:28 +01:00
Felix Matouschek
41751fe432 chore: Fix names in inventory cleanup
We are deleting VMs, not creating VMs. Therefore change the names to
reflect that.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-18 17:21:52 +01:00
Felix Matouschek
eb2291692d tests: Cleanup after inventory test
Cleanup the created the created VMs after the inventory integration
tests collected the inventory test results to not leave running VMs
behind after the test finished.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-18 17:00:53 +01:00
Felix Matouschek
926989e7ef cleanup: Remove unneeded inventory file
Remove unneeded tests/integration/inventory file, which likely got added
by accident.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-11 13:13:43 +01:00
Felix Matouschek
62007c326a ci: Cleanup kubevirt_vm_info integration test
- Use uniform way of naming plays, tasks and VMs
- Use defaults where possible

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-04 14:02:08 +01:00
Felix Matouschek
ed642885ab ci: Cleanup kubevirt_vm integration test
- Use uniform way of naming plays, tasks and VMs
- Use uniform way of ordering task parameters
- Use defaults where possible
- Use CentOS 9 Stream instancetype and preference
- Generate SSH private key with empty password (-N "")
- Disable strict host key checking
- Add .gitignore for test files
- Fix skipping test key creation if already existent

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-04 14:02:08 +01:00
Felix Matouschek
b928cb5b29 ci: Cleanup inventory_kubevirt integration test
- Use uniform way of naming plays, tasks and VMs
- Use uniform way of ordering task parameters
- Use defaults where possible
- Use CentOS Stream 9 as VM OS
- Drop unneeded environment variables
- Use FQCN of Ansible modules
- Add missing test for empty inventory
- Add .gitignore for test files

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-04 14:02:03 +01:00
Felix Matouschek
5e2f152c7d ci: Fix failing integration tests
The default name of the default user in centos.stream9 is cloud-user.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-01 16:01:51 +01:00
Felix Matouschek
9e2fc74ccb ci: Fix non failing integration tests
Remove { } from runme.sh files to avoid failures being masked.
Re-add install of ansible.posix to have the
ansible.posix.profile_task callback available.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-03-01 14:50:33 +01:00
kubevirt-bot
29516d3bfd Merge pull request #45 from 0xFelix/misc-cleanups
Misc cleanups
2024-02-29 15:58:57 +01:00
Felix Matouschek
69f7699c08 chore: Remove unneeded sanity test ignore files
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-02-29 14:06:31 +01:00
Felix Matouschek
49638c31b5 chore: Run black formatter on project files
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-02-29 14:06:16 +01:00
Felix Matouschek
44e1c0a719 cleanup: Update requirements throughout the project
Update the requirements throughout the project to be in sync and to
reflect the current state of dependencies.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-02-29 14:03:19 +01:00
kubevirt-bot
4429ac8c03 Merge pull request #39 from 0xFelix/bump-version-e2e
Bump e2e-setup.sh version and ensure compatibility with KubeVirt >=1.1.0
2024-02-29 13:08:57 +01:00
Felix Matouschek
77ece9d466 ci: Add yamllint to CI linter job
This adds yamllint to the CI linter job and sets the maximum line
length to 140 like in kubevirt/kubevirt.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-02-29 11:41:49 +01:00
Felix Matouschek
fa9183c21a hack: Bump e2e-setup.sh version
Bump the software versions defined in hack/e2e-setup.sh to the latest
ones and sync version installed of kind in github integration tests
with e2e-setup.sh. Update the CentOS 9 Stream preference name used in
the tests to the new name in common-instancetypes v0.4.0.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-02-29 09:47:50 +01:00
Felix Matouschek
74f4a48ac1 Pin python version
Pin the supported python version in tests/config.yaml and mention it in
README.md.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-02-26 17:04:19 +01:00
Felix Matouschek
bb132b1682 Move test .kubeconfig into CI setup
Inline the creation of a test .kubeconfig into the CI setup.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-02-26 16:59:03 +01:00
Felix Matouschek
6ee5a9c7c9 ansible-lint: Groom the .ansible-lint file
- Enable production profile
- Remove excludes no longer necessary
- Try to not skip any tests

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-02-26 16:31:56 +01:00
kubevirt-bot
d1318db8db Merge pull request #24 from 0xFelix/info_module
kubevirt_vm_info: Add info module for VirtualMachines
2023-09-07 15:57:28 +02:00
Felix Matouschek
6486766b11 kubevirt_vm_info: Add info module for VirtualMachines
This adds the kubevirt_vm_info module, which returns the same results as
the kubevirt_vm module, but is limited to read-only functionality.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2023-09-06 13:04:07 +02:00
Felix Matouschek
e33b479326 inventory: Add create_groups option
This adds the create_groups option to the inventory, which allows to
control the creation of groups from labels on VirtualMachines. By
default it is disabled.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2023-09-05 15:56:46 +02:00