Allow switching between running and run_strategy by always clearing the
other value. E.g. if run_strategy was provided then running set to None
to clear it or vice versa.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
If no namespaces were specified in the inventory config try to get all
available namespaces by trying to list OCP projects first. If the resource
was not found (no OCP cluster) fall back to regular namespaces.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
Add the hidden_fields argument to kubevirt_vm and kubevirt_{vm,vmi}_info
which allows to hide and ignore certain fields in the returned definition
of a VM or VMI. By default this argument is set to ignore changes to the
kubemacpool.io/transaction-timestamp annotation and managed fields, which
may change at any time and cause the modules to return a changed status
although nothing has changed other than their values.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
ansible-core 2.19 changes the way templates are trusted and provides a
new way of patching module args in unit tests.
With this commit the following changes are made to ensure compatibility
with ansible-core >= 2.19:
- Mark inputs to composable as trusted to align with the new template
trust model.
- Utilize the updated method for patching module arguments in unit tests
if available.
- Replace direct access to the self._cache attribute with the inventory's
cache property.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This adds the unset_ansible_port option to the inventory, which allows to
control if the value of ansible_port should be unset if no non-default
value was found.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This feature adds looking up winrm services and tries to populate the
ansible_host and ansible_port variables with the values from a
found service for the host. It looks up both winrm HTTP and HTTPS
services and prefers HTTPS if it found both for a given host.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
Add the kubevirt_vmi_info module which allows to fetch information about
VirtualMachineInstance(s).
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
Extract the execute_module function from the kubevirt_vm_info module to
make it available for other modules.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
It refactors fixtures: `add_group` and `add_host` to improve fixtures
reusability in further scenarios.
Signed-off-by: Javier Cano Cano <jcanocan@redhat.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Reorganize unit tests so the directory structure looks like the
structure used in most other collections.
Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>