diff --git a/.github/workflows/ansible-test.yml b/.github/workflows/ansible-test.yml index 4491916..8758cfc 100644 --- a/.github/workflows/ansible-test.yml +++ b/.github/workflows/ansible-test.yml @@ -26,6 +26,7 @@ jobs: sanity: name: Sanity (Ⓐ${{ matrix.ansible }}) strategy: + fail-fast: true matrix: ansible: # It's important that Sanity is tested against all stable-X.Y branches @@ -56,8 +57,11 @@ jobs: - name: Install ansible-base (${{ matrix.ansible }}) run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check + - name: Install deps + run: pip install kubernetes --disable-pip-version-check + - name: Install collection dependencies - run: ansible-galaxy collection install 'community.kubernetes:<2.0.0' -p . + run: ansible-galaxy collection install 'kubernetes.core' -p . # run ansible-test sanity inside of Docker. # The docker container has all the pinned dependencies that are required @@ -97,12 +101,18 @@ jobs: - name: Install ansible-base (${{ matrix.ansible }}) run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check + - name: Remove old pyyaml + run: pip uninstall -y pyyaml + + - name: Install deps + run: pip install kubernetes --disable-pip-version-check + - name: Install collection dependencies - run: ansible-galaxy collection install 'community.kubernetes:<2.0.0' -p . + run: ansible-galaxy collection install 'kubernetes.core' -p . # Run the unit tests - name: Run unit test - run: ansible-test units -v --color --docker --coverage + run: ansible-test units -v --color --docker --python 3.8 --coverage working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}} # ansible-test support producing code coverage date @@ -137,10 +147,6 @@ jobs: - stable-2.11 - devel python: - - 2.7 - - 3.5 - - 3.6 - - 3.7 - 3.8 - 3.9 exclude: @@ -161,8 +167,11 @@ jobs: - name: Install ansible-base (${{ matrix.ansible }}) run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check + - name: Install deps + run: pip install kubernetes --disable-pip-version-check + - name: Install collection dependencies - run: ansible-galaxy collection install 'community.kubernetes:<2.0.0' -p . + run: ansible-galaxy collection install 'kubernetes.core' -p . # Run the integration tests - name: Run integration test diff --git a/README.md b/README.md index 7b86d0a..3095430 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ Every voice is important and every idea is valuable. If you have something on yo ## External requirements -- python >= 2.7 -- openshift >= 0.8.2 +- python >= 3.6 +- kubernetes >= 12.0.1 ## Included Content diff --git a/changelogs/fragments/k8s-core-2-compatibility.yml b/changelogs/fragments/k8s-core-2-compatibility.yml new file mode 100644 index 0000000..0aeeff4 --- /dev/null +++ b/changelogs/fragments/k8s-core-2-compatibility.yml @@ -0,0 +1,4 @@ +major_changes: + - Drop Python 2.7 compatibility (https://github.com/ansible-collections/community.kubevirt/issues/33). + - Migrate from the ``community.kubernetes`` to ``kubernetes.core`` collection dependency (https://github.com/ansible-collections/community.kubevirt/issues/33). + - Change references from ``OpenShift`` to ``Kubernetes`` in the documentation (https://github.com/ansible-collections/community.kubevirt/issues/33). diff --git a/galaxy.yml b/galaxy.yml index f81c97e..a0af172 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ authors: - kubevirt (github.com/kubevirt) - tima (github.com/tima) dependencies: - community.kubernetes: '>=1.0.0,<2.0.0' + kubernetes.core: '>=2.0.0' description: license_file: LICENSE tags: diff --git a/plugins/doc_fragments/kubevirt_common_options.py b/plugins/doc_fragments/kubevirt_common_options.py index ed25b72..699f9af 100644 --- a/plugins/doc_fragments/kubevirt_common_options.py +++ b/plugins/doc_fragments/kubevirt_common_options.py @@ -122,10 +122,10 @@ class ModuleDocFragment(object): the virtual machine will not have a domain name at all. The DNS entry will resolve to the virtual machine, no matter if the virtual machine itself can pick up a hostname." requirements: - - python >= 2.7 - - openshift >= 0.8.2 + - python >= 3.6 + - kubernetes >= 12.0.1 notes: - - "In order to use this module you have to install Openshift Python SDK. + - "In order to use this module you have to install Kubernetes Python SDK. To ensure it's installed with correct version you can create the following task: - I(pip: name=openshift>=0.8.2)" + I(pip: name=kubernetes>=12.0.1)" ''' diff --git a/plugins/inventory/kubevirt.py b/plugins/inventory/kubevirt.py index b2d0646..eed8a4a 100644 --- a/plugins/inventory/kubevirt.py +++ b/plugins/inventory/kubevirt.py @@ -45,7 +45,7 @@ kubeconfig: description: - Path to an existing Kubernetes config file. If not provided, and no other connection - options are provided, the OpenShift client will attempt to load the default + options are provided, the Kubernetes client will attempt to load the default configuration file from I(~/.kube/config.json). Can also be specified via K8S_AUTH_KUBECONFIG environment variable. type: str @@ -115,7 +115,7 @@ type: str default: 'ansible' requirements: - - "openshift >= 0.6" + - "kubernetes >= 12.0.1" - "PyYAML >= 3.11" ''' @@ -140,7 +140,8 @@ import json -from ansible_collections.community.kubernetes.plugins.inventory.k8s import K8sInventoryException, InventoryModule as K8sInventoryModule, format_dynamic_api_exc +from ansible_collections.kubernetes.core.plugins.inventory.k8s import K8sInventoryException, InventoryModule as K8sInventoryModule, format_dynamic_api_exc +from ansible_collections.kubernetes.core.plugins.module_utils.common import get_api_client try: from openshift.dynamic.exceptions import DynamicApiError @@ -159,12 +160,12 @@ def setup(self, config_data, cache, cache_key): super(InventoryModule, self).setup(config_data, cache, cache_key) def fetch_objects(self, connections): - client = self.get_api_client() + client = get_api_client() vm_format = self.config_data.get('host_format', '{namespace}-{name}-{uid}') if connections: for connection in connections: - client = self.get_api_client(**connection) + client = get_api_client(**connection) name = connection.get('name', self.get_default_host_name(client.configuration.host)) if connection.get('namespaces'): namespaces = connection['namespaces'] diff --git a/plugins/module_utils/kubevirt.py b/plugins/module_utils/kubevirt.py index f13b9f9..8630044 100644 --- a/plugins/module_utils/kubevirt.py +++ b/plugins/module_utils/kubevirt.py @@ -6,16 +6,28 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import traceback +import copy +import re + from collections import defaultdict from distutils.version import Version from ansible.module_utils.common import dict_transformations from ansible.module_utils.common._collections_compat import Sequence -from ansible_collections.community.kubernetes.plugins.module_utils.common import list_dict_str -from ansible_collections.community.kubernetes.plugins.module_utils.raw import KubernetesRawModule -import copy -import re +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + +from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC, list_dict_str +from ansible_collections.kubernetes.core.plugins.module_utils.common import K8sAnsibleMixin, get_api_client + +try: + import yaml + from kubernetes.dynamic.exceptions import DynamicApiError, NotFoundError, ForbiddenError +except ImportError: + # Exceptions handled in common + pass MAX_SUPPORTED_API_VERSION = 'v1alpha3' API_GROUP = 'kubevirt.io' @@ -132,9 +144,37 @@ def __cmp__(self, other): return self._cmp(other) -class KubeVirtRawModule(KubernetesRawModule): - def __init__(self, *args, **kwargs): - super(KubeVirtRawModule, self).__init__(*args, **kwargs) +class KubeVirtRawModule(K8sAnsibleMixin): + def __init__(self, k8s_kind=None, *args, **kwargs): + module = AnsibleModule( + argument_spec=self.argspec, + supports_check_mode=True, + ) + + self.module = module + self.check_mode = self.module.check_mode + self.params = self.module.params + self.fail_json = self.module.fail_json + self.fail = self.module.fail_json + self.exit_json = self.module.exit_json + + super(KubeVirtRawModule, self).__init__(module, *args, **kwargs) + + self.client = get_api_client(self.module) + self.warnings = [] + + self.kind = k8s_kind or self.params.get('kind') + self.api_version = self.params.get('api_version') + self.name = self.params.get('name') + self.namespace = self.params.get('namespace') + + self.check_library_version() + self.set_resource_definitions(module) + + @property + def argspec(self): + argument_spec = copy.deepcopy(AUTH_ARG_SPEC) + return argument_spec @staticmethod def merge_dicts(base_dict, merging_dicts): @@ -306,7 +346,7 @@ def find_supported_resource(self, kind): str([r.api_version for r in sr]), API_GROUP, MAX_SUPPORTED_API_VERSION)) def _construct_vm_definition(self, kind, definition, template, params, defaults=None): - self.client = self.get_api_client() + self.client = get_api_client(self.module) disks = params.get('disks', []) memory = params.get('memory') diff --git a/plugins/modules/kubevirt_cdi_upload.py b/plugins/modules/kubevirt_cdi_upload.py index 13694b4..a9355dd 100644 --- a/plugins/modules/kubevirt_cdi_upload.py +++ b/plugins/modules/kubevirt_cdi_upload.py @@ -20,7 +20,7 @@ description: - - Use Openshift Python SDK to create UploadTokenRequest objects. + - Use Kubernetes Python SDK to create UploadTokenRequest objects. - Transfer contents of local files to the CDI Upload Proxy. options: @@ -59,12 +59,12 @@ choices: [ json, merge, strategic-merge ] extends_documentation_fragment: -- community.kubernetes.k8s_auth_options +- kubernetes.core.k8s_auth_options requirements: - - python >= 2.7 - - openshift >= 0.8.2 + - python >= 3.6 + - kubernetes >= 12.0.1 - requests >= 2.0.0 ''' @@ -84,9 +84,11 @@ import traceback from collections import defaultdict +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native -from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC -from ansible_collections.community.kubernetes.plugins.module_utils.raw import KubernetesRawModule +from ansible_collections.kubernetes.core.plugins.module_utils.common import K8sAnsibleMixin, get_api_client +from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC # 3rd party imports try: @@ -113,9 +115,15 @@ } -class KubeVirtCDIUpload(KubernetesRawModule): +class KubeVirtCDIUpload(K8sAnsibleMixin): def __init__(self, *args, **kwargs): - super(KubeVirtCDIUpload, self).__init__(*args, k8s_kind='UploadTokenRequest', **kwargs) + self.module = AnsibleModule( + argument_spec=self.argspec, + supports_check_mode=True, + ) + self.fail_json = self.module.fail_json + + super(KubeVirtCDIUpload, self).__init__(self.module, *args, k8s_kind='UploadTokenRequest', **kwargs) if not HAS_REQUESTS: self.fail("This module requires the python 'requests' package. Try `pip install requests`.") @@ -133,7 +141,7 @@ def execute_module(self): API = 'v1alpha1' KIND = 'UploadTokenRequest' - self.client = self.get_api_client() + self.client = get_api_client(self.module) api_version = 'upload.cdi.kubevirt.io/{0}'.format(API) pvc_name = self.params.get('pvc_name') diff --git a/plugins/modules/kubevirt_preset.py b/plugins/modules/kubevirt_preset.py index ab6063c..e8eb861 100644 --- a/plugins/modules/kubevirt_preset.py +++ b/plugins/modules/kubevirt_preset.py @@ -15,7 +15,7 @@ short_description: Manage KubeVirt virtual machine presets description: - - Use Openshift Python SDK to manage the state of KubeVirt virtual machine presets. + - Use Kubernetes Python SDK to manage the state of KubeVirt virtual machine presets. author: KubeVirt Team (@kubevirt) @@ -45,14 +45,14 @@ type: dict extends_documentation_fragment: -- community.kubernetes.k8s_auth_options +- kubernetes.core.k8s_auth_options - community.kubevirt.kubevirt_vm_options - community.kubevirt.kubevirt_common_options requirements: - - python >= 2.7 - - openshift >= 0.8.2 + - python >= 3.6 + - kubernetes >= 12.0.1 ''' EXAMPLES = ''' @@ -87,8 +87,7 @@ import copy import traceback - -from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC +from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC from ansible_collections.community.kubevirt.plugins.module_utils.kubevirt import ( virtdict, @@ -128,7 +127,7 @@ def execute_module(self): # defaults for template defaults = {'disks': [], 'volumes': [], 'interfaces': [], 'networks': []} - # Execute the CURD of VM: + # Execute the CRUD of VM: dummy, definition = self.construct_vm_definition(KIND, definition, definition, defaults) result_crud = self.execute_crud(KIND, definition) changed = result_crud['changed'] diff --git a/plugins/modules/kubevirt_pvc.py b/plugins/modules/kubevirt_pvc.py index d9c8ffc..6d938b7 100644 --- a/plugins/modules/kubevirt_pvc.py +++ b/plugins/modules/kubevirt_pvc.py @@ -19,7 +19,7 @@ author: KubeVirt Team (@kubevirt) description: - - Use Openshift Python SDK to manage PVCs on Kubernetes + - Use Kubernetes Python SDK to manage PVCs on Kubernetes - Support Containerized Data Importer out of the box options: @@ -139,12 +139,12 @@ default: 300 extends_documentation_fragment: -- community.kubernetes.k8s_auth_options +- kubernetes.core.k8s_auth_options requirements: - - python >= 2.7 - - openshift >= 0.8.2 + - python >= 3.6 + - kubernetes >= 12.0.1 ''' EXAMPLES = ''' @@ -250,9 +250,12 @@ import traceback from collections import defaultdict +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_native + +from ansible_collections.kubernetes.core.plugins.module_utils.common import K8sAnsibleMixin, get_api_client +from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC -from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC -from ansible_collections.community.kubernetes.plugins.module_utils.raw import KubernetesRawModule from ansible_collections.community.kubevirt.plugins.module_utils.kubevirt import virtdict, KubeVirtRawModule @@ -305,9 +308,15 @@ class CreatePVCFailed(Exception): pass -class KubevirtPVC(KubernetesRawModule): +class KubevirtPVC(K8sAnsibleMixin): def __init__(self): - super(KubevirtPVC, self).__init__() + self.module = AnsibleModule( + argument_spec=self.argspec, + supports_check_mode=True, + ) + self.fail_json = self.module.fail_json + + super(KubevirtPVC, self).__init__(self.module) @property def argspec(self): @@ -436,7 +445,7 @@ def execute_module(self): # 'resource_definition:' has lower priority than module parameters definition = dict(KubeVirtRawModule.merge_dicts(definition, self.resource_definitions[0])) - self.client = self.get_api_client() + self.client = get_api_client(self.module) resource = self.find_resource(KIND, API, fail=True) definition = self.set_defaults(resource, definition) result = self.perform_action(resource, definition) diff --git a/plugins/modules/kubevirt_rs.py b/plugins/modules/kubevirt_rs.py index 1e86dbd..888557c 100644 --- a/plugins/modules/kubevirt_rs.py +++ b/plugins/modules/kubevirt_rs.py @@ -15,7 +15,7 @@ short_description: Manage KubeVirt virtual machine replica sets description: - - Use Openshift Python SDK to manage the state of KubeVirt virtual machine replica sets. + - Use Kubernetes Python SDK to manage the state of KubeVirt virtual machine replica sets. author: KubeVirt Team (@kubevirt) @@ -51,14 +51,14 @@ type: int extends_documentation_fragment: -- community.kubernetes.k8s_auth_options +- kubernetes.core.k8s_auth_options - community.kubevirt.kubevirt_vm_options - community.kubevirt.kubevirt_common_options requirements: - - python >= 2.7 - - openshift >= 0.8.2 + - python >= 3.6 + - kubernetes >= 12.0.1 ''' EXAMPLES = ''' @@ -106,8 +106,7 @@ import copy import traceback - -from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC +from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC from ansible_collections.community.kubevirt.plugins.module_utils.kubevirt import ( virtdict, diff --git a/plugins/modules/kubevirt_template.py b/plugins/modules/kubevirt_template.py index ee478b8..217d235 100644 --- a/plugins/modules/kubevirt_template.py +++ b/plugins/modules/kubevirt_template.py @@ -15,7 +15,7 @@ short_description: Manage KubeVirt templates description: - - Use Openshift Python SDK to manage the state of KubeVirt templates. + - Use Kubernetes Python SDK to manage the state of KubeVirt templates. author: KubeVirt Team (@kubevirt) @@ -77,7 +77,7 @@ description: - "Extension for hinting at which elements should be considered editable. List of jsonpath selectors. The jsonpath root is the objects: element of the template." - - This is parameter can be used only when kubevirt addon is installed on your openshift cluster. + - This is parameter can be used only when kubevirt addon is installed on your kubernetes cluster. type: list default_disk: description: @@ -85,7 +85,7 @@ terms of bus (ide, scsi, sata, virtio, ...)" - The C(default_disk) parameter define configuration overlay for disks that will be applied on top of disks during virtual machine creation to define global compatibility and/or performance defaults defined here. - - This is parameter can be used only when kubevirt addon is installed on your openshift cluster. + - This is parameter can be used only when kubevirt addon is installed on your kubernetes cluster. type: dict default_volume: description: @@ -93,7 +93,7 @@ caches if those are exposed by the underlying volume implementation." - The C(default_volume) parameter define configuration overlay for volumes that will be applied on top of volumes during virtual machine creation to define global compatibility and/or performance defaults defined here. - - This is parameter can be used only when kubevirt addon is installed on your openshift cluster. + - This is parameter can be used only when kubevirt addon is installed on your kubernetes cluster. type: dict default_nic: description: @@ -101,7 +101,7 @@ to ensure OS compatibility and performance." - The C(default_nic) parameter define configuration overlay for nic that will be applied on top of nics during virtual machine creation to define global compatibility and/or performance defaults defined here. - - This is parameter can be used only when kubevirt addon is installed on your openshift cluster. + - This is parameter can be used only when kubevirt addon is installed on your kubernetes cluster. type: dict default_network: description: @@ -109,7 +109,7 @@ that specifies performance and connection parameters (L2 bridge for example)" - The C(default_network) parameter define configuration overlay for networks that will be applied on top of networks during virtual machine creation to define global compatibility and/or performance defaults defined here. - - This is parameter can be used only when kubevirt addon is installed on your openshift cluster. + - This is parameter can be used only when kubevirt addon is installed on your kubernetes cluster. type: dict icon_class: description: @@ -129,17 +129,17 @@ version: description: - Template structure version. - - This is parameter can be used only when kubevirt addon is installed on your openshift cluster. + - This is parameter can be used only when kubevirt addon is installed on your kubernetes cluster. type: str extends_documentation_fragment: -- community.kubernetes.k8s_auth_options -- community.kubernetes.k8s_state_options +- kubernetes.core.k8s_auth_options +- kubernetes.core.k8s_state_options requirements: - - python >= 2.7 - - openshift >= 0.8.2 + - python >= 3.6 + - kubernetes >= 12.0.1 ''' EXAMPLES = ''' @@ -201,7 +201,15 @@ import copy import traceback -from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC +try: + from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC + from ansible_collections.kubernetes.core.plugins.module_utils.common import get_api_client + HAS_KUBERNETES_COLLECTION = True +except ImportError as e: + HAS_KUBERNETES_COLLECTION = False + k8s_collection_import_exception = e + K8S_COLLECTION_ERROR = traceback.format_exc() + AUTH_ARG_SPEC = {} from ansible_collections.community.kubevirt.plugins.module_utils.kubevirt import ( virtdict, @@ -298,7 +306,7 @@ def execute_module(self): labels = definition['metadata']['labels'] labels['template.cnv.io/type'] = 'vm' - # Fill in Openshift/Kubevirt template annotations: + # Fill in Kubernetes/Kubevirt template annotations: annotations = definition['metadata']['annotations'] if self.params.get('display_name'): annotations['openshift.io/display-name'] = self.params.get('display_name') @@ -332,7 +340,7 @@ def execute_module(self): annotations['defaults.template.cnv.io/network'] = self.params.get('default_network').get('name') # Process objects: - self.client = self.get_api_client() + self.client = get_api_client(self.module) definition['objects'] = [] objects = self.params.get('objects') or [] for obj in objects: diff --git a/plugins/modules/kubevirt_vm.py b/plugins/modules/kubevirt_vm.py index 5526dc1..9af5aad 100644 --- a/plugins/modules/kubevirt_vm.py +++ b/plugins/modules/kubevirt_vm.py @@ -15,7 +15,7 @@ short_description: Manage KubeVirt virtual machine description: - - Use Openshift Python SDK to manage the state of KubeVirt virtual machines. + - Use Kubernetes Python SDK to manage the state of KubeVirt virtual machines. author: KubeVirt Team (@kubevirt) @@ -67,14 +67,14 @@ type: dict extends_documentation_fragment: -- community.kubernetes.k8s_auth_options +- kubernetes.core.k8s_auth_options - community.kubevirt.kubevirt_vm_options - community.kubevirt.kubevirt_common_options requirements: - - python >= 2.7 - - openshift >= 0.8.2 + - python >= 3.6 + - kubernetes >= 12.0.1 ''' EXAMPLES = ''' @@ -245,7 +245,9 @@ import copy import traceback -from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC +from ansible_collections.kubernetes.core.plugins.module_utils.common import get_api_client +from ansible_collections.kubernetes.core.plugins.module_utils.args_common import AUTH_ARG_SPEC + from ansible_collections.community.kubevirt.plugins.module_utils.kubevirt import ( virtdict, KubeVirtRawModule, @@ -421,7 +423,7 @@ def execute_module(self): # Start with fetching the current object to make sure it exists # If it does, but we end up not performing any operations on it, at least we'll be able to return # its current contents as part of the final json - self.client = self.get_api_client() + self.client = get_api_client(self.module) self._kind_resource = self.find_supported_resource(kind) k8s_obj = self.get_resource(self._kind_resource) if not self.check_mode and not vm_spec_change and k8s_state != 'absent' and not k8s_obj: diff --git a/tests/integration/targets/inventory_kubevirt/runme.sh b/tests/integration/targets/inventory_kubevirt/runme.sh index ea163ab..bb9bf84 100755 --- a/tests/integration/targets/inventory_kubevirt/runme.sh +++ b/tests/integration/targets/inventory_kubevirt/runme.sh @@ -1,11 +1,5 @@ #!/usr/bin/env bash -if [[ $(python --version 2>&1) =~ 2\.6 ]] - then - echo "Openshift client is not supported on Python 2.6" - exit 0 -fi - set -eux # TODO: quay.io/ansible/default-test-container:2.7.0 doesn't have virtualenv included @@ -13,7 +7,7 @@ apt -y update apt -y install python3-virtualenv source virtualenv.sh -pip install openshift -c constraints.txt +pip install --upgrade kubernetes ./server.py & diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index b05439d..c4304e5 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -1,17 +1,18 @@ -plugins/modules/kubevirt_cdi_upload.py validate-modules:mutually_exclusive-unknown plugins/modules/kubevirt_cdi_upload.py validate-modules:parameter-list-no-elements -plugins/modules/kubevirt_preset.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_cdi_upload.py import-2.6!skip plugins/modules/kubevirt_preset.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_preset.py validate-modules:parameter-type-not-in-doc -plugins/modules/kubevirt_pvc.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_preset.py import-2.6!skip plugins/modules/kubevirt_pvc.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_pvc.py validate-modules:return-syntax-error +plugins/modules/kubevirt_pvc.py import-2.6!skip plugins/modules/kubevirt_rs.py validate-modules:doc-required-mismatch -plugins/modules/kubevirt_rs.py validate-modules:mutually_exclusive-unknown plugins/modules/kubevirt_rs.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_rs.py validate-modules:parameter-type-not-in-doc -plugins/modules/kubevirt_template.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_rs.py import-2.6!skip plugins/modules/kubevirt_template.py validate-modules:parameter-list-no-elements -plugins/modules/kubevirt_vm.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_template.py import-2.6!skip plugins/modules/kubevirt_vm.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_vm.py validate-modules:parameter-type-not-in-doc +plugins/modules/kubevirt_vm.py import-2.6!skip +plugins/module_utils/kubevirt.py import-2.6!skip diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index b05439d..c4304e5 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -1,17 +1,18 @@ -plugins/modules/kubevirt_cdi_upload.py validate-modules:mutually_exclusive-unknown plugins/modules/kubevirt_cdi_upload.py validate-modules:parameter-list-no-elements -plugins/modules/kubevirt_preset.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_cdi_upload.py import-2.6!skip plugins/modules/kubevirt_preset.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_preset.py validate-modules:parameter-type-not-in-doc -plugins/modules/kubevirt_pvc.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_preset.py import-2.6!skip plugins/modules/kubevirt_pvc.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_pvc.py validate-modules:return-syntax-error +plugins/modules/kubevirt_pvc.py import-2.6!skip plugins/modules/kubevirt_rs.py validate-modules:doc-required-mismatch -plugins/modules/kubevirt_rs.py validate-modules:mutually_exclusive-unknown plugins/modules/kubevirt_rs.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_rs.py validate-modules:parameter-type-not-in-doc -plugins/modules/kubevirt_template.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_rs.py import-2.6!skip plugins/modules/kubevirt_template.py validate-modules:parameter-list-no-elements -plugins/modules/kubevirt_vm.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_template.py import-2.6!skip plugins/modules/kubevirt_vm.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_vm.py validate-modules:parameter-type-not-in-doc +plugins/modules/kubevirt_vm.py import-2.6!skip +plugins/module_utils/kubevirt.py import-2.6!skip diff --git a/tests/sanity/ignore-2.12.txt b/tests/sanity/ignore-2.12.txt index b05439d..c4304e5 100644 --- a/tests/sanity/ignore-2.12.txt +++ b/tests/sanity/ignore-2.12.txt @@ -1,17 +1,18 @@ -plugins/modules/kubevirt_cdi_upload.py validate-modules:mutually_exclusive-unknown plugins/modules/kubevirt_cdi_upload.py validate-modules:parameter-list-no-elements -plugins/modules/kubevirt_preset.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_cdi_upload.py import-2.6!skip plugins/modules/kubevirt_preset.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_preset.py validate-modules:parameter-type-not-in-doc -plugins/modules/kubevirt_pvc.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_preset.py import-2.6!skip plugins/modules/kubevirt_pvc.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_pvc.py validate-modules:return-syntax-error +plugins/modules/kubevirt_pvc.py import-2.6!skip plugins/modules/kubevirt_rs.py validate-modules:doc-required-mismatch -plugins/modules/kubevirt_rs.py validate-modules:mutually_exclusive-unknown plugins/modules/kubevirt_rs.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_rs.py validate-modules:parameter-type-not-in-doc -plugins/modules/kubevirt_template.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_rs.py import-2.6!skip plugins/modules/kubevirt_template.py validate-modules:parameter-list-no-elements -plugins/modules/kubevirt_vm.py validate-modules:mutually_exclusive-unknown +plugins/modules/kubevirt_template.py import-2.6!skip plugins/modules/kubevirt_vm.py validate-modules:parameter-list-no-elements plugins/modules/kubevirt_vm.py validate-modules:parameter-type-not-in-doc +plugins/modules/kubevirt_vm.py import-2.6!skip +plugins/module_utils/kubevirt.py import-2.6!skip diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 23e302a..5c27273 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -1,3 +1,10 @@ +plugins/modules/kubevirt_cdi_upload.py import-2.6!skip plugins/modules/kubevirt_preset.py validate-modules:parameter-type-not-in-doc +plugins/modules/kubevirt_preset.py import-2.6!skip plugins/modules/kubevirt_rs.py validate-modules:parameter-type-not-in-doc +plugins/modules/kubevirt_rs.py import-2.6!skip plugins/modules/kubevirt_vm.py validate-modules:parameter-type-not-in-doc +plugins/modules/kubevirt_vm.py import-2.6!skip +plugins/modules/kubevirt_pvc.py import-2.6!skip +plugins/modules/kubevirt_template.py import-2.6!skip +plugins/module_utils/kubevirt.py import-2.6!skip diff --git a/tests/unit/plugins/module_utils/test_kubevirt.py b/tests/unit/plugins/module_utils/test_kubevirt.py index 5cec7d4..d81bf7e 100644 --- a/tests/unit/plugins/module_utils/test_kubevirt.py +++ b/tests/unit/plugins/module_utils/test_kubevirt.py @@ -5,6 +5,7 @@ import pytest from ansible_collections.community.kubevirt.plugins.module_utils import kubevirt as mymodule +from ansible_collections.kubernetes.core.plugins.module_utils.common import K8sAnsibleMixin def test_simple_merge_dicts(): diff --git a/tests/unit/plugins/modules/kubevirt_fixtures.py b/tests/unit/plugins/modules/kubevirt_fixtures.py index 645c70c..4b7c3bf 100644 --- a/tests/unit/plugins/modules/kubevirt_fixtures.py +++ b/tests/unit/plugins/modules/kubevirt_fixtures.py @@ -2,15 +2,14 @@ __metaclass__ = type import pytest +from kubernetes.dynamic.resource import Resource from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.kubevirt.tests.unit.compat.mock import MagicMock -from ansible_collections.community.kubernetes.plugins.module_utils.common import K8sAnsibleMixin -from ansible_collections.community.kubernetes.plugins.module_utils.raw import KubernetesRawModule +from ansible_collections.kubernetes.core.plugins.module_utils.common import K8sAnsibleMixin, get_api_client from ansible_collections.community.kubevirt.plugins.module_utils.kubevirt import KubeVirtRawModule -import openshift.dynamic RESOURCE_DEFAULT_ARGS = {'api_version': 'v1alpha3', 'group': 'kubevirt.io', 'prefix': 'apis', 'namespaced': True} @@ -59,15 +58,15 @@ def base_fixture(monkeypatch): # Create mock methods in Resource directly, otherwise dyn client # tries binding those to corresponding methods in DynamicClient # (with partial()), which is more problematic to intercept - openshift.dynamic.Resource.get = MagicMock() - openshift.dynamic.Resource.create = MagicMock() - openshift.dynamic.Resource.delete = MagicMock() - openshift.dynamic.Resource.patch = MagicMock() - openshift.dynamic.Resource.search = MagicMock() - openshift.dynamic.Resource.watch = MagicMock() + kubernetes.dynamic.resource.Resource.get = MagicMock() + kubernetes.dynamic.resource.Resource.create = MagicMock() + kubernetes.dynamic.resource.Resource.delete = MagicMock() + kubernetes.dynamic.resource.Resource.patch = MagicMock() + kubernetes.dynamic.resource.Resource.search = MagicMock() + kubernetes.dynamic.resource.Resource.watch = MagicMock() # Globally mock some methods, since all tests will use this - KubernetesRawModule.patch_resource = MagicMock() - KubernetesRawModule.patch_resource.return_value = ({}, None) + K8sAnsibleMixin.patch_resource = MagicMock() + K8sAnsibleMixin.patch_resource.return_value = ({}, None) K8sAnsibleMixin.get_api_client = MagicMock() K8sAnsibleMixin.get_api_client.return_value = None K8sAnsibleMixin.find_resource = MagicMock() diff --git a/tests/unit/plugins/modules/test_kubevirt_rs.py b/tests/unit/plugins/modules/test_kubevirt_rs.py index b9425ee..95553c0 100644 --- a/tests/unit/plugins/modules/test_kubevirt_rs.py +++ b/tests/unit/plugins/modules/test_kubevirt_rs.py @@ -3,12 +3,12 @@ import pytest -openshiftdynamic = pytest.importorskip("openshift.dynamic") +kubernetesdynamic = pytest.importorskip("openshift.dynamic") from ansible_collections.community.kubevirt.tests.unit.plugins.modules.utils import set_module_args from .kubevirt_fixtures import base_fixture, RESOURCE_DEFAULT_ARGS, AnsibleExitJson -from ansible_collections.community.kubernetes.plugins.module_utils.raw import KubernetesRawModule +from ansible_collections.kubernetes.core.plugins.module_utils.common import K8sAnsibleMixin, get_api_client from ansible_collections.community.kubevirt.plugins.modules import kubevirt_rs as mymodule KIND = 'VirtualMachineInstanceReplicaSet' @@ -27,14 +27,14 @@ def test_scale_rs_nowait(_replicas, _changed): # Mock pre-change state: resource_args = dict(kind=KIND, **RESOURCE_DEFAULT_ARGS) - mymodule.KubeVirtVMIRS.find_supported_resource.return_value = openshiftdynamic.Resource(**resource_args) - res_inst = openshiftdynamic.ResourceInstance('', dict(kind=KIND, metadata={'name': _name}, spec={'replicas': 2})) - openshiftdynamic.Resource.get.return_value = res_inst - openshiftdynamic.Resource.search.return_value = [res_inst] + mymodule.KubeVirtVMIRS.find_supported_resource.return_value = kubernetesdynamic.Resource(**resource_args) + res_inst = kubernetesdynamic.ResourceInstance('', dict(kind=KIND, metadata={'name': _name}, spec={'replicas': 2})) + kubernetesdynamic.Resource.get.return_value = res_inst + kubernetesdynamic.Resource.search.return_value = [res_inst] # Final state, after patching the object - KubernetesRawModule.patch_resource.return_value = dict(kind=KIND, metadata={'name': _name}, - spec={'replicas': _replicas}), None + K8sAnsibleMixin.patch_resource.return_value = dict(kind=KIND, metadata={'name': _name}, + spec={'replicas': _replicas}), None # Run code: with pytest.raises(AnsibleExitJson) as result: @@ -56,19 +56,19 @@ def test_scale_rs_wait(_replicas, _success): # Mock pre-change state: resource_args = dict(kind=KIND, **RESOURCE_DEFAULT_ARGS) - mymodule.KubeVirtVMIRS.find_supported_resource.return_value = openshiftdynamic.Resource(**resource_args) - res_inst = openshiftdynamic.ResourceInstance('', dict(kind=KIND, metadata={'name': _name}, spec={'replicas': 2})) - openshiftdynamic.Resource.get.return_value = res_inst - openshiftdynamic.Resource.search.return_value = [res_inst] + mymodule.KubeVirtVMIRS.find_supported_resource.return_value = kubernetesdynamic.Resource(**resource_args) + res_inst = kubernetesdynamic.ResourceInstance('', dict(kind=KIND, metadata={'name': _name}, spec={'replicas': 2})) + kubernetesdynamic.Resource.get.return_value = res_inst + kubernetesdynamic.Resource.search.return_value = [res_inst] # ~Final state, after patching the object (`replicas` match desired state) - KubernetesRawModule.patch_resource.return_value = dict(kind=KIND, name=_name, metadata={'name': _name}, - spec={'replicas': 5}), None + K8sAnsibleMixin.patch_resource.return_value = dict(kind=KIND, name=_name, metadata={'name': _name}, + spec={'replicas': 5}), None # Final final state, as returned by resource.watch() final_obj = dict(metadata=dict(name=_name), status=dict(readyReplicas=_replicas), **resource_args) - event = openshiftdynamic.ResourceInstance(None, final_obj) - openshiftdynamic.Resource.watch.return_value = [dict(object=event)] + event = kubernetesdynamic.ResourceInstance(None, final_obj) + kubernetesdynamic.Resource.watch.return_value = [dict(object=event)] # Run code: with pytest.raises(Exception) as result: diff --git a/tests/unit/plugins/modules/test_kubevirt_vm.py b/tests/unit/plugins/modules/test_kubevirt_vm.py index 975876e..64b22f0 100644 --- a/tests/unit/plugins/modules/test_kubevirt_vm.py +++ b/tests/unit/plugins/modules/test_kubevirt_vm.py @@ -3,7 +3,7 @@ import pytest -openshiftdynamic = pytest.importorskip("openshift.dynamic") +kubernetesdynamic = pytest.importorskip("openshift.dynamic") from ansible_collections.community.kubevirt.tests.unit.plugins.modules.utils import set_module_args from .kubevirt_fixtures import base_fixture, RESOURCE_DEFAULT_ARGS, AnsibleExitJson @@ -11,7 +11,7 @@ from ansible_collections.community.kubevirt.plugins.module_utils.kubevirt import KubeVirtRawModule from ansible_collections.community.kubevirt.plugins.modules import kubevirt_vm as mymodule -KIND = 'VirtulMachine' +KIND = 'VirtualMachine' @pytest.mark.usefixtures("base_fixture") @@ -30,8 +30,8 @@ def test_create_vm_with_multus_nowait(): # State as "returned" by the "k8s cluster": resource_args = dict(kind=KIND, **RESOURCE_DEFAULT_ARGS) - KubeVirtRawModule.find_supported_resource.return_value = openshiftdynamic.Resource(**resource_args) - openshiftdynamic.Resource.get.return_value = None # Object doesn't exist in the cluster + KubeVirtRawModule.find_supported_resource.return_value = kubernetesdynamic.Resource(**resource_args) + kubernetesdynamic.Resource.get.return_value = None # Object doesn't exist in the cluster # Run code: with pytest.raises(AnsibleExitJson) as result: @@ -55,8 +55,8 @@ def test_vm_is_absent(_wait): # State as "returned" by the "k8s cluster": resource_args = dict(kind=KIND, **RESOURCE_DEFAULT_ARGS) - KubeVirtRawModule.find_supported_resource.return_value = openshiftdynamic.Resource(**resource_args) - openshiftdynamic.Resource.get.return_value = None # Object doesn't exist in the cluster + KubeVirtRawModule.find_supported_resource.return_value = kubernetesdynamic.Resource(**resource_args) + kubernetesdynamic.Resource.get.return_value = None # Object doesn't exist in the cluster # Run code: with pytest.raises(AnsibleExitJson) as result: @@ -78,8 +78,8 @@ def test_vmpreset_create(): # State as "returned" by the "k8s cluster": resource_args = dict(kind=KIND, **RESOURCE_DEFAULT_ARGS) - KubeVirtRawModule.find_supported_resource.return_value = openshiftdynamic.Resource(**resource_args) - openshiftdynamic.Resource.get.return_value = None # Object doesn't exist in the cluster + KubeVirtRawModule.find_supported_resource.return_value = kubernetesdynamic.Resource(**resource_args) + kubernetesdynamic.Resource.get.return_value = None # Object doesn't exist in the cluster # Run code: with pytest.raises(AnsibleExitJson) as result: @@ -99,8 +99,8 @@ def test_vmpreset_is_absent(): # State as "returned" by the "k8s cluster": resource_args = dict(kind=KIND, **RESOURCE_DEFAULT_ARGS) - KubeVirtRawModule.find_supported_resource.return_value = openshiftdynamic.Resource(**resource_args) - openshiftdynamic.Resource.get.return_value = None # Object doesn't exist in the cluster + KubeVirtRawModule.find_supported_resource.return_value = kubernetesdynamic.Resource(**resource_args) + kubernetesdynamic.Resource.get.return_value = None # Object doesn't exist in the cluster # Run code: with pytest.raises(AnsibleExitJson) as result: diff --git a/tests/unit/requirements.txt b/tests/unit/requirements.txt index 1a1f0df..db851df 100644 --- a/tests/unit/requirements.txt +++ b/tests/unit/requirements.txt @@ -1,4 +1,2 @@ # requirement for kubevirt modules -openshift ; python_version >= '2.7' -ruamel.yaml < 0.17 ; python_version >= '2.7' and python_version < '3.5' -ruamel.yaml.clib < 0.2.3 ; python_version >= '2.7' and python_version < '3.5' +kubernetes; python_version >= '3.6'