kubevirt_vm: Prevent unnecessary whitespace

This removes the unnecessary whitespace from the rendered VirtualMachine
template and adds a unit test for it.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This commit is contained in:
Felix Matouschek
2023-07-18 14:01:24 +02:00
parent 472bd8d917
commit 0875abc080
2 changed files with 28 additions and 6 deletions

View File

@@ -284,11 +284,11 @@ spec:
{% if instancetype %}
instancetype:
{{ instancetype | to_yaml | indent(4) }}
{% endif %}
{%- endif %}
{% if preference %}
preference:
{{ preference | to_yaml | indent(4) }}
{% endif %}
{%- endif %}
{% if data_volume_templates %}
dataVolumeTemplates:
{{ data_volume_templates | to_yaml | indent(4) }}

View File

@@ -35,6 +35,12 @@ FIXTURE1 = {
},
"spec": {
"running": True,
"instancetype": {
"name": "u1.medium"
},
"preference": {
"name": "fedora"
},
"dataVolumeTemplates": [
{
"metadata": {
@@ -86,6 +92,10 @@ metadata:
service: loadbalancer
spec:
running: True
instancetype:
name: u1.medium
preference:
name: fedora
dataVolumeTemplates:
- metadata:
name: testdv
@@ -118,6 +128,12 @@ FIXTURE2 = {
'service': 'loadbalancer',
'environment': 'staging'
},
'instancetype': {
'name': 'u1.medium'
},
'preference': {
'name': 'fedora'
},
'data_volume_templates': [
{
'metadata': {
@@ -149,10 +165,10 @@ FIXTURE2 = {
'terminationGracePeriodSeconds': 180
},
'api_version': 'kubevirt.io/v1', 'running': True, 'wait': False, 'wait_sleep': 5, 'wait_timeout': 120, 'force': False,
'generate_name': None, 'annotations': None, 'instancetype': None, 'preference': 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,
'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',
@@ -196,6 +212,12 @@ class TestCreateVM(unittest.TestCase):
"service": "loadbalancer",
"environment": "staging"
},
'instancetype': {
'name': 'u1.medium'
},
'preference': {
'name': 'fedora'
},
'data_volume_templates': [
{
'metadata': {