Commit Graph

268 Commits

Author SHA1 Message Date
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
a94eda613f feat(inventory): Support stopped VMs
This enables the inventory to list stopped VMs by refactoring
the add_from_namespace method. The method is now looking up the related
VM and VMIs for a host and adds all status attributes of both objects
to the host's vars. To distinguish the origin of vars an appropriate
prefix (vm_ or vmi_) is applied to their name. The inventory now supports
hosts comprising just a VM (stopped), just a VMI or both.

This changes some of the hostvars previously reported by the inventory
plugin:

Dropped:
- object_type
- cluster_name

Now prefixed with vm_ or vmi_ according to the origin:
- labels
- annotations
- resource_version
- uid

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-03 16:04:47 +02:00
Felix Matouschek
8ae9a395e9 cleanup(inventory): Consolidate fetching resources with K8SClient
This consolidates fetching of resources with K8SClient by introducing
the get_resources method, which is can be called by getters for certain
kinds of objects.

The former get_vmis_for_namespace method, which contains the main logic
of the inventory is renamed to populate_inventory_from_namespace.

This refactors the following getters:

- get_available_namespaces
- get_ssh_services_for_namespace

This introduces the following getters:

- get_vms_for_namespace (to be used in the following commit)
- get_vmis_for_namespace

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:56:04 +02:00
Felix Matouschek
01a0e535e2 cleanup(inventory): Move set_composable_vars to bottom of file
This suits the control flow a bit better and helps refactoring the
inventory plugin.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:56:04 +02:00
Felix Matouschek
63a03d75b2 cleanup(inventory): Rename GetVmiOptions to InventoryOptions
... and ensure base_domain is always initialized with the cluster
domain. This is done in preparation for a major refactoring of the
inventory plugin.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:56:04 +02:00
Felix Matouschek
241ca75b28 cleanup(inventory): Make methods more robust
Make the logic in the following methods more robust and add type hints
where appropriate.

- get_host_from_service
- get_port_from_service
- is_windows
- setup
- fetch_objects
- set_ansible_host_and_port
- set_composable_vars

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:55:50 +02:00
Felix Matouschek
83bcffedd7 cleanup(inventory): Drop unneeded connection_plugin and transport
These two variables seem to be unused and removing them did not have any
effect.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:54:43 +02:00
Felix Matouschek
4b70e0471f cleanup(inventory): Apply pylint suggestions
Make pylint happy by applying some simple suggestions.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-07-01 11:54:43 +02:00
kubevirt-bot
d604a314a4 Merge pull request #115 from 0xFelix/small-improvements-2
Several minor improvements
2024-07-01 11:42:53 +02:00
Felix Matouschek
1bcef9c64d cleanup: Sync galaxy.yml with requirements.yml
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-27 16:14:12 +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
52d4b4c731 cleanup: Sync kind version in integration yaml
Use kind v0.23.0 in integration.yml and hack/e2e-setup.sh.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-27 16:01:38 +02:00
Felix Matouschek
e2f55848c1 ci: Check if tree is clean before running other jobs
Run make format and check if the tree is still clean before running
other CI jobs.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-27 16:01:38 +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
Felix Matouschek
d7d70125a7 chore: Add .vscode launch configs
Add vscode launch configs to debug the modules and the inventory plugin.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-27 15:44:21 +02:00
Felix Matouschek
35b2d3ef6b tests: Use ansible-test for integration tests
Integration tests do not work with tox, therefore use ansible-test to
run them.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-27 15:43:03 +02:00
kubevirt-bot
4f236a15ce Merge pull request #113 from 0xFelix/py3.10-millestone
fix(ci): Do not test ansible-core milestone with py3.10
2024-06-26 10:37:37 +02:00
Felix Matouschek
9a8cafd6b1 fix(ci): Do not test ansible-core milestone with py3.10
Python 3.10 is no longer supported by ansible-core milestone, so this
excludes it from the test matrices.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-26 09:37:51 +02:00
kubevirt-bot
2b8f96fce3 Merge pull request #97 from jcanocan/inventory-unit-tests
Inventory unit tests
2024-06-19 17:21:52 +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
kubevirt-bot
2606b267d4 Merge pull request #111 from 0xFelix/kc-5.0.0
chore: Ensure compatibility with kubernetes.core >=3.1.0,<6.0.0
2024-06-18 11:47:47 +02:00
Felix Matouschek
738c70073e chore: Ensure compatibility with kubernetes.core >=3.1.0,<6.0.0
Ensure compatibility with kubernetes.core >=3.1.0,<6.0.0 and update
requirements.yml.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-18 07:59:06 +02:00
Felix Matouschek
d55c48ede4 Merge pull request #112 from 0xFelix/ci-devel
fix(ci): Do not test ansible-core devel with py3.10

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-18 07:58:11 +02:00
Felix Matouschek
c4b7cc69e7 fix(ci): Do not test ansible-core devel with py3.10
Python 3.10 is no longer supported by ansible-core devel, so this
excludes it from the test matrices.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-18 07:56:47 +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
kubevirt-bot
65f4ac6602 Merge pull request #107 from jcanocan/fix-pr-96-issues
tests: Address comments of #96
2024-06-14 14:36:24 +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
kubevirt-bot
020f3c1380 Merge pull request #109 from 0xFelix/improve-e2e
Bump e2e software versions
2024-06-13 11:36:24 +02:00
Felix Matouschek
634ccb8363 chore: Bump versions in hack/e2e-setup.sh
Bump the versions of installed software components during the e2e test setup
to the latest stable releases.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-13 11:19:20 +02:00
Felix Matouschek
1a814389fe fix: Allow running make cluster-down when binaries are missing
Swap the order of commands in hack/e2e-setup.sh, so it becomes possible
to run 'make cluster-down` when the kind/kubectl binaries are missing.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-13 11:18:17 +02:00
kubevirt-bot
10b34fdf24 Merge pull request #101 from 0xFelix/apache2
Change license to Apache 2.0
2024-06-13 10:24:24 +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
Felix Matouschek
df629ac39e chore: Drop vendored document fragments
Drop the vendored document fragments from kubernetes.core to slightly
enhance the documented options and to allow changing the license of the
collection.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-11 11:39:21 +02:00
kubevirt-bot
44e84622ed Merge pull request #108 from mperetzred/kubevirt_vm_ssh_key
kubevirt_vm integration tests: changed ssh key type to RSA for FIPS mode
2024-06-10 17:56:20 +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
kubevirt-bot
5c57d623aa Merge pull request #106 from 0xFelix/fix-kubevirt-vm-verify
fix(tests,kubevirt_vm): Fix assertion in verify.yml
2024-06-06 17:35:42 +02: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
kubevirt-bot
520bf8d74f Merge pull request #105 from 0xFelix/runtime-2.15
chore: Update supported ansible-core versions to >=2.15
2024-06-05 09:59:43 +02:00
Felix Matouschek
fa6601cbe4 chore: Update supported ansible-core versions to >=2.15
Update the supported versions of ansible-core to >=2.15.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-05 09:16:56 +02:00
kubevirt-bot
92b11b5584 Merge pull request #103 from 0xFelix/ci-fixes
Make kubevirt_vm tests more robust
2024-06-04 10:37:37 +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
kubevirt-bot
4205a8328d Merge pull request #104 from 0xFelix/ansible-2.17
Bump tested ansible-core versions to 2.15-2.17
2024-06-04 08:21:35 +02:00
Felix Matouschek
57b172a865 chore(ci.yml): Bump tested ansible-core versions
Bump the tested ansible-core versions in integration.yml to the
latest supported versions (2.15-2.17).

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-03 16:41:40 +02:00
Felix Matouschek
14e9481e19 chore(integration.yml): Bump tested ansible-core versions
Bump the tested ansible-core versions in integration.yml to the latest
supported versions (2.15-2.17).

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
2024-06-03 16:38:42 +02:00