diff --git a/docs/conf.py b/docs/conf.py index 8b8d7dc..29c727f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,19 +15,20 @@ import datetime import os import sys -sys.path.insert(0, os.path.abspath('../plugins/module_utils/')) + +sys.path.insert(0, os.path.abspath("../plugins/module_utils/")) # sys.path.insert(0, os.path.abspath('.')) # -- Project information ----------------------------------------------------- -project = 'Kubevirt Ansible Collection' -copyright = '{y} Red Hat, Inc.'.format(y=datetime.date.today().year) -author = 'Red Hat, Inc.' +project = "Kubevirt Ansible Collection" +copyright = "{y} Red Hat, Inc.".format(y=datetime.date.today().year) +author = "Red Hat, Inc." # The short X.Y version -version = '' +version = "" # The full version, including alpha/beta/rc tags -release = '' +release = "" # -- General configuration --------------------------------------------------- @@ -40,24 +41,24 @@ release = '' # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'myst_parser', - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx_antsibull_ext', - 'ansible_basic_sphinx_ext', + "myst_parser", + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx_antsibull_ext", + "ansible_basic_sphinx_ext", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = ['.rst', '.md'] +source_suffix = [".rst", ".md"] # The master toctree document. -master_doc = 'index' +master_doc = "index" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -69,20 +70,20 @@ language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path . -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.tmp'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".tmp"] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'ansible' +pygments_style = "ansible" -highlight_language = 'YAML+Jinja' +highlight_language = "YAML+Jinja" # -- Options for HTML output ------------------------------------------------- -html_theme_path = ['_themes'] +html_theme_path = ["_themes"] # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # # html_theme = 'alabaster' -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -109,7 +110,7 @@ html_static_path = [] # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. -htmlhelp_basename = 'KubevirtCollectionDoc' +htmlhelp_basename = "KubevirtCollectionDoc" # -- Options for LaTeX output ------------------------------------------------ @@ -118,15 +119,12 @@ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # # 'preamble': '', - # Latex figure (float) alignment # # 'figure_align': 'htbp', @@ -136,8 +134,13 @@ latex_elements = { # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'KubevirtCollection.tex', 'Red Hat Kubevirt Ansible Collection Documentation', - 'Red Hat, Inc.', 'manual'), + ( + master_doc, + "KubevirtCollection.tex", + "Red Hat Kubevirt Ansible Collection Documentation", + "Red Hat, Inc.", + "manual", + ), ] @@ -146,8 +149,13 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'KubevirtCollection', 'Red Hat Kubevirt Ansible Collection Documentation', - [author], 1) + ( + master_doc, + "KubevirtCollection", + "Red Hat Kubevirt Ansible Collection Documentation", + [author], + 1, + ) ] @@ -157,9 +165,15 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'KubevirtCollection', 'Red Hat Kubevirt Ansible Collection Documentation', - author, 'KubevirtCollection', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "KubevirtCollection", + "Red Hat Kubevirt Ansible Collection Documentation", + author, + "KubevirtCollection", + "One line description of project.", + "Miscellaneous", + ), ] @@ -168,4 +182,7 @@ texinfo_documents = [ # -- Options for intersphinx extension --------------------------------------- # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'python': ('https://docs.python.org/2', None), 'ansible': ('https://docs.ansible.com/ansible/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/2", None), + "ansible": ("https://docs.ansible.com/ansible/latest/", None), +} diff --git a/tests/unit/modules/test_module_kubevirt_vm.py b/tests/unit/modules/test_module_kubevirt_vm.py index 709b185..16f5964 100644 --- a/tests/unit/modules/test_module_kubevirt_vm.py +++ b/tests/unit/modules/test_module_kubevirt_vm.py @@ -19,7 +19,7 @@ from ansible_collections.kubevirt.core.tests.unit.utils.ansible_module_mock impo exit_json, fail_json, set_module_args, - get_api_client + get_api_client, ) FIXTURE1 = { @@ -28,24 +28,15 @@ FIXTURE1 = { "metadata": { "name": "testvm", "namespace": "default", - "labels": { - "environment": "staging", - "service": "loadbalancer" - } + "labels": {"environment": "staging", "service": "loadbalancer"}, }, "spec": { "running": True, - "instancetype": { - "name": "u1.medium" - }, - "preference": { - "name": "fedora" - }, + "instancetype": {"name": "u1.medium"}, + "preference": {"name": "fedora"}, "dataVolumeTemplates": [ { - "metadata": { - "name": "testdv" - }, + "metadata": {"name": "testdv"}, "spec": { "source": { "registry": { @@ -53,36 +44,22 @@ FIXTURE1 = { }, }, "storage": { - "accessModes": [ - "ReadWriteOnce" - ], - "resources": { - "requests": { - "storage": "5Gi" - } - } - } - } + "accessModes": ["ReadWriteOnce"], + "resources": {"requests": {"storage": "5Gi"}}, + }, + }, } ], "template": { "metadata": { - "labels": { - "environment": "staging", - "service": "loadbalancer" - } + "labels": {"environment": "staging", "service": "loadbalancer"} }, - "spec": { - "domain": { - "devices": {} - }, - "terminationGracePeriodSeconds": 180 - } - } - } + "spec": {"domain": {"devices": {}}, "terminationGracePeriodSeconds": 180}, + }, + }, } -METADATA = '''apiVersion: kubevirt.io/v1 +METADATA = """apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: "testvm" @@ -118,78 +95,70 @@ spec: domain: devices: {} terminationGracePeriodSeconds: 180 -''' +""" FIXTURE2 = { - 'name': 'testvm', - 'namespace': 'default', - 'state': 'present', - 'labels': { - 'service': 'loadbalancer', - 'environment': 'staging' - }, - 'instancetype': { - 'name': 'u1.medium' - }, - 'preference': { - 'name': 'fedora' - }, - 'data_volume_templates': [ + "name": "testvm", + "namespace": "default", + "state": "present", + "labels": {"service": "loadbalancer", "environment": "staging"}, + "instancetype": {"name": "u1.medium"}, + "preference": {"name": "fedora"}, + "data_volume_templates": [ { - 'metadata': { - 'name': 'testdv' - }, - 'spec': { - 'source': { - 'registry': { - 'url': 'docker://quay.io/containerdisks/fedora:latest' + "metadata": {"name": "testdv"}, + "spec": { + "source": { + "registry": { + "url": "docker://quay.io/containerdisks/fedora:latest" }, }, - 'storage': { - 'accessModes': [ - 'ReadWriteOnce' - ], - 'resources': { - 'requests': { - 'storage': '5Gi' - } - } - } - } + "storage": { + "accessModes": ["ReadWriteOnce"], + "resources": {"requests": {"storage": "5Gi"}}, + }, + }, } ], - 'spec': { - 'domain': { - 'devices': {} - }, - 'terminationGracePeriodSeconds': 180 - }, - 'api_version': 'kubevirt.io/v1', 'running': True, 'wait': False, 'wait_sleep': 5, 'wait_timeout': 120, 'force': False, - 'generate_name': None, 'annotations': None, 'kubeconfig': None, 'context': None, 'host': None, 'api_key': None, - 'username': None, 'password': None, 'validate_certs': None, 'ca_cert': None, 'client_cert': None, 'client_key': None, - 'proxy': None, 'no_proxy': None, 'proxy_headers': None, 'persist_config': None, 'impersonate_user': None, - 'impersonate_groups': None, 'delete_options': None, - 'resource_definition': METADATA, - 'wait_condition': { - 'type': 'Ready', - 'status': True - } + "spec": {"domain": {"devices": {}}, "terminationGracePeriodSeconds": 180}, + "api_version": "kubevirt.io/v1", + "running": True, + "wait": False, + "wait_sleep": 5, + "wait_timeout": 120, + "force": False, + "generate_name": None, + "annotations": None, + "kubeconfig": None, + "context": None, + "host": None, + "api_key": None, + "username": None, + "password": None, + "validate_certs": None, + "ca_cert": None, + "client_cert": None, + "client_key": None, + "proxy": None, + "no_proxy": None, + "proxy_headers": None, + "persist_config": None, + "impersonate_user": None, + "impersonate_groups": None, + "delete_options": None, + "resource_definition": METADATA, + "wait_condition": {"type": "Ready", "status": True}, } class TestCreateVM(unittest.TestCase): def setUp(self): self.mock_module_helper = patch.multiple( - basic.AnsibleModule, - exit_json=exit_json, - fail_json=fail_json + basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json ) self.mock_module_helper.start() - self.mock_runner = patch.multiple( - runner, - get_api_client=get_api_client - ) + self.mock_runner = patch.multiple(runner, get_api_client=get_api_client) self.mock_runner.start() # Stop the patch after test execution @@ -208,56 +177,37 @@ class TestCreateVM(unittest.TestCase): "name": "testvm", "namespace": "default", "state": "present", - "labels": { - "service": "loadbalancer", - "environment": "staging" - }, - 'instancetype': { - 'name': 'u1.medium' - }, - 'preference': { - 'name': 'fedora' - }, - 'data_volume_templates': [ + "labels": {"service": "loadbalancer", "environment": "staging"}, + "instancetype": {"name": "u1.medium"}, + "preference": {"name": "fedora"}, + "data_volume_templates": [ { - 'metadata': { - 'name': 'testdv' - }, - 'spec': { - 'source': { - 'registry': { - 'url': 'docker://quay.io/containerdisks/fedora:latest' + "metadata": {"name": "testdv"}, + "spec": { + "source": { + "registry": { + "url": "docker://quay.io/containerdisks/fedora:latest" }, }, - 'storage': { - 'accessModes': [ - 'ReadWriteOnce' - ], - 'resources': { - 'requests': { - 'storage': '5Gi' - } - } - } - } + "storage": { + "accessModes": ["ReadWriteOnce"], + "resources": {"requests": {"storage": "5Gi"}}, + }, + }, } ], - 'spec': { - 'domain': { - 'devices': {} - }, - 'terminationGracePeriodSeconds': 180 - } + "spec": { + "domain": {"devices": {}}, + "terminationGracePeriodSeconds": 180, + }, } ) with patch.object(runner, "perform_action") as mock_run_command: - mock_run_command.return_value = ( - { - "method": "create", - "changed": True, - "result": "success" - } - ) # successful execution + mock_run_command.return_value = { + "method": "create", + "changed": True, + "result": "success", + } # successful execution with self.assertRaises(AnsibleExitJson) as result: kubevirt_vm.main() mock_run_command.assert_called_once_with( diff --git a/tests/unit/utils/ansible_module_mock.py b/tests/unit/utils/ansible_module_mock.py index 8af5232..7904f9f 100644 --- a/tests/unit/utils/ansible_module_mock.py +++ b/tests/unit/utils/ansible_module_mock.py @@ -47,5 +47,5 @@ def fail_json(*args, **kwargs): def get_api_client(*args, **kwargs): - """function to patch over get_api_client """ + """function to patch over get_api_client""" pass