Commit Graph

76 Commits

Author SHA1 Message Date
Felix Matouschek
71ea312cfc kubevirt_vm: Run integration test in random namespace
Run the integration tests for kubevirt_vm in a random namespace
and cleanup after the tests finish.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-08-16 08:37:36 +02:00
Felix Matouschek
00690ebc4c inventory_kubevirt: Run integration test in random namespace
Run the integration tests for inventory_kubevirt in a random namespace
and cleanup after the tests finish.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-08-16 08:37:00 +02:00
Felix Matouschek
c1f651d972 feat(kubevirt_vm): Add support for RunStrategy
This change adds support for setting the RunStrategy of a VM.

Depending on the value set the wait condition for the VM is adjusted.
For the values Always, RerunOnFailure or Once the wait condition will
wait for the VM to run and be ready. For the value Halted the wait
condition will wait for the VM to not exist. For the value Manual
the wait condition is not set.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-16 10:20:09 +02:00
Felix Matouschek
501bd3d52f cleanup(kubevirt_vm): Simplify tests
Simplify kubevirt_vm tests by not using fixtures if not needed.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-12 11:09:23 +02:00
Felix Matouschek
a2de465d1f cleanup(kubevirt_vm_info): Simplify tests
Simplify kubevirt_vm_info tests by not using fixtures if not needed.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-12 11:09:23 +02:00
Felix Matouschek
9029574f7c cleanup(inventory): Mark methods as private
Mark all methods of the inventory which should be private with a underscore
prefix in their name.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-12 11:09:23 +02:00
Felix Matouschek
c55763b5aa cleanup(inventory,tests): Remove dependency on addict
Replace the remaining uses of addict's Dict with ResourceField of the
Kubernetes client. This allows to drop the dependency on addict.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-12 10:34:13 +02:00
Felix Matouschek
060ac97b68 fix(inventory): Fix inventory source caching
Fix inventory source caching by separating the fetching of objects and
populating the inventory. This way objects can be fetched from the K8S
API or from a configured cached and the cache related parameters on the
plugin now actually work.

The inventory source cache was tested with the ansible.builtin.jsonfile
cache plugin and 100k hosts (~2G JSON file). Though it took a noticeable
amount of time for the inventory plugin to run it worked fine and no
failures could be observed.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-12 10:32:24 +02:00
Felix Matouschek
a228fe2c26 cleanup(inventory): Rename default hostname method
Rename method get_default_host_name to get_default_hostname.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-11 15:28:32 +02:00
Felix Matouschek
c4570b2089 cleanup(inventory): Use dicts where possible
Use dicts instead of ResourceFields where possible to allow
easier serialization/deserialization of objects fetched from the K8S
API.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-11 12:07:09 +02:00
Felix Matouschek
fd9c30103d cleanup(inventory): Drop support for multiple connections
The support for connections to multiple clusters in the inventory
plugin is dropped to better align with user expectations and how other
inventories work. If inventories of multiple clusters are needed the
inventory can be run multiple times with different configurations.
This also helps to clean up the code and make it simpler.

For now this adds a compatibility helper so that configurations with a
single connection entry remain supported and a warning is emitted.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-10 15:32:40 +02:00
kubevirt-bot
f6a43206a6 Merge pull request #114 from 0xFelix/vm-vmi-2
feat,test(inventory): Support listing stopped VMs and major rework of unit tests
2024-07-03 16:24:57 +02:00
Felix Matouschek
f3b40ffdbd test(inventory): Add integration test for stopped VMs
Add an integration test that ensures that the inventory supports looking up
stopped VMs.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-03 16:04:51 +02:00
Felix Matouschek
3d501de002 test(inventory): Add blackbox unit test for stopped VMs
Add a blackbox unit test that ensures that the inventory supports looking up
stopped VMs.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-03 16:04:51 +02:00
Felix Matouschek
be65833724 cleanup(tests): Major rework of inventory unit tests
Rework the inventory unit tests by splitting up
tests/unit/plugins/inventory/test_kubevirt.py into multiple files,
by trying to simplify the test code and making it more robust and by
using appropriate fixtures. This also adds new tests or test cases to
improve code coverage. Tests that work from the black box perspective
are now located in a subdirectory.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-03 16:04:51 +02:00
Felix Matouschek
c096f069e3 cleanup(kubevirt_vm): Drop dependency on Jinja2
Drop the dependency on Jinja2 in the kubevirt_vm module by using dicts
to construct a VM instead of rendering jinja templates internally.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-03 14:40:50 +02:00
Felix Matouschek
1630cddc44 cleanup,test(modules): Cleanup module unit tests
Improve syntax in module unit tests and use only mocker instead of a
combination of mocker and monkeypatch.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-27 16:08:51 +02:00
Felix Matouschek
3261beff0a chore: Run make format
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-27 16:01:38 +02:00
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