chore: Run black formatter on project files

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This commit is contained in:
Felix Matouschek
2024-02-29 14:06:16 +01:00
parent 4429ac8c03
commit 49638c31b5
3 changed files with 134 additions and 167 deletions

View File

@@ -15,19 +15,20 @@
import datetime import datetime
import os import os
import sys 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('.')) # sys.path.insert(0, os.path.abspath('.'))
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = 'Kubevirt Ansible Collection' project = "Kubevirt Ansible Collection"
copyright = '{y} Red Hat, Inc.'.format(y=datetime.date.today().year) copyright = "{y} Red Hat, Inc.".format(y=datetime.date.today().year)
author = 'Red Hat, Inc.' author = "Red Hat, Inc."
# The short X.Y version # The short X.Y version
version = '' version = ""
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = '' release = ""
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
@@ -40,24 +41,24 @@ release = ''
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones. # ones.
extensions = [ extensions = [
'myst_parser', "myst_parser",
'sphinx.ext.autodoc', "sphinx.ext.autodoc",
'sphinx.ext.intersphinx', "sphinx.ext.intersphinx",
'sphinx_antsibull_ext', "sphinx_antsibull_ext",
'ansible_basic_sphinx_ext', "ansible_basic_sphinx_ext",
] ]
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ["_templates"]
# The suffix(es) of source filenames. # The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string: # You can specify multiple suffix as a list of string:
# #
# source_suffix = ['.rst', '.md'] # source_suffix = ['.rst', '.md']
source_suffix = ['.rst', '.md'] source_suffix = [".rst", ".md"]
# The master toctree document. # The master toctree document.
master_doc = 'index' master_doc = "index"
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
@@ -69,20 +70,20 @@ language = None
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path . # 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. # 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 ------------------------------------------------- # -- 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 # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
# #
# html_theme = 'alabaster' # 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 # 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 # further. For a list of options available for each theme, see the
@@ -109,7 +110,7 @@ html_static_path = []
# -- Options for HTMLHelp output --------------------------------------------- # -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'KubevirtCollectionDoc' htmlhelp_basename = "KubevirtCollectionDoc"
# -- Options for LaTeX output ------------------------------------------------ # -- Options for LaTeX output ------------------------------------------------
@@ -118,15 +119,12 @@ latex_elements = {
# The paper size ('letterpaper' or 'a4paper'). # The paper size ('letterpaper' or 'a4paper').
# #
# 'papersize': 'letterpaper', # 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt'). # The font size ('10pt', '11pt' or '12pt').
# #
# 'pointsize': '10pt', # 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble. # Additional stuff for the LaTeX preamble.
# #
# 'preamble': '', # 'preamble': '',
# Latex figure (float) alignment # Latex figure (float) alignment
# #
# 'figure_align': 'htbp', # 'figure_align': 'htbp',
@@ -136,8 +134,13 @@ latex_elements = {
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ 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 # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ 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, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
(master_doc, 'KubevirtCollection', 'Red Hat Kubevirt Ansible Collection Documentation', (
author, 'KubevirtCollection', 'One line description of project.', master_doc,
'Miscellaneous'), "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 --------------------------------------- # -- Options for intersphinx extension ---------------------------------------
# Example configuration for intersphinx: refer to the Python standard library. # 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),
}

View File

@@ -19,7 +19,7 @@ from ansible_collections.kubevirt.core.tests.unit.utils.ansible_module_mock impo
exit_json, exit_json,
fail_json, fail_json,
set_module_args, set_module_args,
get_api_client get_api_client,
) )
FIXTURE1 = { FIXTURE1 = {
@@ -28,24 +28,15 @@ FIXTURE1 = {
"metadata": { "metadata": {
"name": "testvm", "name": "testvm",
"namespace": "default", "namespace": "default",
"labels": { "labels": {"environment": "staging", "service": "loadbalancer"},
"environment": "staging",
"service": "loadbalancer"
}
}, },
"spec": { "spec": {
"running": True, "running": True,
"instancetype": { "instancetype": {"name": "u1.medium"},
"name": "u1.medium" "preference": {"name": "fedora"},
},
"preference": {
"name": "fedora"
},
"dataVolumeTemplates": [ "dataVolumeTemplates": [
{ {
"metadata": { "metadata": {"name": "testdv"},
"name": "testdv"
},
"spec": { "spec": {
"source": { "source": {
"registry": { "registry": {
@@ -53,36 +44,22 @@ FIXTURE1 = {
}, },
}, },
"storage": { "storage": {
"accessModes": [ "accessModes": ["ReadWriteOnce"],
"ReadWriteOnce" "resources": {"requests": {"storage": "5Gi"}},
], },
"resources": { },
"requests": {
"storage": "5Gi"
}
}
}
}
} }
], ],
"template": { "template": {
"metadata": { "metadata": {
"labels": { "labels": {"environment": "staging", "service": "loadbalancer"}
"environment": "staging",
"service": "loadbalancer"
}
}, },
"spec": { "spec": {"domain": {"devices": {}}, "terminationGracePeriodSeconds": 180},
"domain": { },
"devices": {} },
},
"terminationGracePeriodSeconds": 180
}
}
}
} }
METADATA = '''apiVersion: kubevirt.io/v1 METADATA = """apiVersion: kubevirt.io/v1
kind: VirtualMachine kind: VirtualMachine
metadata: metadata:
name: "testvm" name: "testvm"
@@ -118,78 +95,70 @@ spec:
domain: domain:
devices: {} devices: {}
terminationGracePeriodSeconds: 180 terminationGracePeriodSeconds: 180
''' """
FIXTURE2 = { FIXTURE2 = {
'name': 'testvm', "name": "testvm",
'namespace': 'default', "namespace": "default",
'state': 'present', "state": "present",
'labels': { "labels": {"service": "loadbalancer", "environment": "staging"},
'service': 'loadbalancer', "instancetype": {"name": "u1.medium"},
'environment': 'staging' "preference": {"name": "fedora"},
}, "data_volume_templates": [
'instancetype': {
'name': 'u1.medium'
},
'preference': {
'name': 'fedora'
},
'data_volume_templates': [
{ {
'metadata': { "metadata": {"name": "testdv"},
'name': 'testdv' "spec": {
}, "source": {
'spec': { "registry": {
'source': { "url": "docker://quay.io/containerdisks/fedora:latest"
'registry': {
'url': 'docker://quay.io/containerdisks/fedora:latest'
}, },
}, },
'storage': { "storage": {
'accessModes': [ "accessModes": ["ReadWriteOnce"],
'ReadWriteOnce' "resources": {"requests": {"storage": "5Gi"}},
], },
'resources': { },
'requests': {
'storage': '5Gi'
}
}
}
}
} }
], ],
'spec': { "spec": {"domain": {"devices": {}}, "terminationGracePeriodSeconds": 180},
'domain': { "api_version": "kubevirt.io/v1",
'devices': {} "running": True,
}, "wait": False,
'terminationGracePeriodSeconds': 180 "wait_sleep": 5,
}, "wait_timeout": 120,
'api_version': 'kubevirt.io/v1', 'running': True, 'wait': False, 'wait_sleep': 5, 'wait_timeout': 120, 'force': False, "force": False,
'generate_name': None, 'annotations': None, 'kubeconfig': None, 'context': None, 'host': None, 'api_key': None, "generate_name": None,
'username': None, 'password': None, 'validate_certs': None, 'ca_cert': None, 'client_cert': None, 'client_key': None, "annotations": None,
'proxy': None, 'no_proxy': None, 'proxy_headers': None, 'persist_config': None, 'impersonate_user': None, "kubeconfig": None,
'impersonate_groups': None, 'delete_options': None, "context": None,
'resource_definition': METADATA, "host": None,
'wait_condition': { "api_key": None,
'type': 'Ready', "username": None,
'status': True "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): class TestCreateVM(unittest.TestCase):
def setUp(self): def setUp(self):
self.mock_module_helper = patch.multiple( self.mock_module_helper = patch.multiple(
basic.AnsibleModule, basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json
exit_json=exit_json,
fail_json=fail_json
) )
self.mock_module_helper.start() self.mock_module_helper.start()
self.mock_runner = patch.multiple( self.mock_runner = patch.multiple(runner, get_api_client=get_api_client)
runner,
get_api_client=get_api_client
)
self.mock_runner.start() self.mock_runner.start()
# Stop the patch after test execution # Stop the patch after test execution
@@ -208,56 +177,37 @@ class TestCreateVM(unittest.TestCase):
"name": "testvm", "name": "testvm",
"namespace": "default", "namespace": "default",
"state": "present", "state": "present",
"labels": { "labels": {"service": "loadbalancer", "environment": "staging"},
"service": "loadbalancer", "instancetype": {"name": "u1.medium"},
"environment": "staging" "preference": {"name": "fedora"},
}, "data_volume_templates": [
'instancetype': {
'name': 'u1.medium'
},
'preference': {
'name': 'fedora'
},
'data_volume_templates': [
{ {
'metadata': { "metadata": {"name": "testdv"},
'name': 'testdv' "spec": {
}, "source": {
'spec': { "registry": {
'source': { "url": "docker://quay.io/containerdisks/fedora:latest"
'registry': {
'url': 'docker://quay.io/containerdisks/fedora:latest'
}, },
}, },
'storage': { "storage": {
'accessModes': [ "accessModes": ["ReadWriteOnce"],
'ReadWriteOnce' "resources": {"requests": {"storage": "5Gi"}},
], },
'resources': { },
'requests': {
'storage': '5Gi'
}
}
}
}
} }
], ],
'spec': { "spec": {
'domain': { "domain": {"devices": {}},
'devices': {} "terminationGracePeriodSeconds": 180,
}, },
'terminationGracePeriodSeconds': 180
}
} }
) )
with patch.object(runner, "perform_action") as mock_run_command: with patch.object(runner, "perform_action") as mock_run_command:
mock_run_command.return_value = ( mock_run_command.return_value = {
{ "method": "create",
"method": "create", "changed": True,
"changed": True, "result": "success",
"result": "success" } # successful execution
}
) # successful execution
with self.assertRaises(AnsibleExitJson) as result: with self.assertRaises(AnsibleExitJson) as result:
kubevirt_vm.main() kubevirt_vm.main()
mock_run_command.assert_called_once_with( mock_run_command.assert_called_once_with(

View File

@@ -47,5 +47,5 @@ def fail_json(*args, **kwargs):
def get_api_client(*args, **kwargs): def get_api_client(*args, **kwargs):
"""function to patch over get_api_client """ """function to patch over get_api_client"""
pass pass