Commit Graph

41 Commits

Author SHA1 Message Date
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
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
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
kubevirt-bot
29516d3bfd Merge pull request #45 from 0xFelix/misc-cleanups
Misc cleanups
2024-02-29 15:58:57 +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
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
38c76a9545 Rename collection to kubevirt.core
This replaces all occurences of the old kubernetes.core name.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2023-08-03 13:03:10 +02:00
Felix Matouschek
0875abc080 kubevirt_vm: Prevent unnecessary whitespace
This removes the unnecessary whitespace from the rendered VirtualMachine
template and adds a unit test for it.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2023-07-18 16:08:01 +02:00
Felix Matouschek
bce4f17188 kubevirt_vm: Allow to specify DataVolume templates
By allowing to specify DataVolume templates VMs with persistent storage
can be created using the kubevirt_vm module.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2023-07-18 13:40:52 +02:00
Felix Matouschek
6ba62f53e8 kubevirt_vm: Allow to specify template spec
By allowing to specify the template spec unnecessary abstraction is
avoided.

The following module args are replaced by the 'spec' arg:
  - termination_grace_period
  - interfaces
  - networks
  - volumes

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2023-07-18 11:31:32 +02:00
Felix Matouschek
b0971aca37 kubevirt_vm: Use {Instancetype,Preference}Matchers
Use InstancetypeMatchers and PreferenceMatchers directly instead of
providing multiple arguments to prevent unnecessary abstraction.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2023-07-18 10:41:15 +02:00
Felix Matouschek
68f5cc8e33 Update Ansible GitHub workflows
The workflows committed in the first commit were missing the
installation of required dependencies and other fixes.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2023-07-17 14:45:31 +02:00