Skip to content

Commit

Permalink
tfpt: fix dict copy (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k authored Dec 5, 2024
1 parent bc997c7 commit efdebec
Show file tree
Hide file tree
Showing 54 changed files with 35 additions and 11 deletions.
6 changes: 3 additions & 3 deletions ix-dev/community/tftpd-hpa/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ icon: https://media.sys.truenas.net/apps/tftpd-hpa/icons/icon.png
keywords:
- tftp
- netboot
lib_version: 2.0.29
lib_version_hash: 3c2dd83143491fdfc23e5e13de9db0aa79bb7846a2b7c32a76a479e334c54590
lib_version: 2.0.32
lib_version_hash: 4a0bf69cccda322e191eab36ab81ca6d0c8e5d64a0b2fa117c609804b55b86c6
maintainers:
- email: [email protected]
name: truenas
Expand All @@ -36,4 +36,4 @@ sources:
- https://hub.docker.com/r/ixsystems/tftpd-hpa
title: TFTP Server
train: community
version: 1.1.0
version: 1.1.1
6 changes: 5 additions & 1 deletion ix-dev/community/tftpd-hpa/templates/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
{% do c1.ports.add_port(values.network.tftp_port, values.consts.internal_tftp_port) %}
{% endif %}

{% set tftpboot_store = dict(values.storage.tftpboot, **{"host_path_config": {"auto_permission": True}}) %}
{% set tftpboot_store = tpl.funcs.copy_dict(values.storage.tftpboot) %}
{% if values.storage.tftpboot.type == "host_path" %}
{% do tftpboot_store.host_path_config.update({"auto_permission": True}) %}
{% endif %}

{% do c1.add_storage("/tftpboot", tftpboot_store) %}
{% do perm_container.add_or_skip_action("tftpboot", tftpboot_store, dict(perm_config, **{"chmod": "0757" if values.tftpd.allow_create else "0555"})) %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import copy
import bcrypt
import secrets
from base64 import b64encode
Expand Down Expand Up @@ -79,7 +80,7 @@ def _is_number(self, string):
return False

def _copy_dict(self, dict):
return dict.copy()
return copy.deepcopy(dict)

def _merge_dicts(self, *dicts):
merged_dict = {}
Expand All @@ -93,6 +94,16 @@ def _disallow_chars(self, string: str, chars: list[str], key: str):
raise RenderError(f"Disallowed character [{char}] in [{key}]")
return string

def _or_default(self, value, default):
if not value:
return default
return value

def _temp_config(self, name):
if not name:
raise RenderError("Expected [name] to be set when calling [temp_config].")
return {"type": "temporary", "volume_config": {"volume_name": name}}

def _get_host_path(self, storage):
source_type = storage.get("type", "")
if not source_type:
Expand Down Expand Up @@ -133,4 +144,6 @@ def func_map(self):
"secure_string": self._secure_string,
"disallow_chars": self._disallow_chars,
"get_host_path": self._get_host_path,
"or_default": self._or_default,
"temp_config": self._temp_config,
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ def test_funcs(mock_values):
"values": [{"type": "ix_volume", "ix_volume_config": {"dataset_name": "test"}}],
"expected": "/mnt/test123",
},
{"func": "or_default", "values": [None, 1], "expected": 1},
{"func": "or_default", "values": [1, None], "expected": 1},
{"func": "or_default", "values": [False, 1], "expected": 1},
{"func": "or_default", "values": [True, 1], "expected": True},
{"func": "temp_config", "values": [""], "expect_raise": True},
{
"func": "temp_config",
"values": ["test"],
"expected": {"type": "temporary", "volume_config": {"volume_name": "test"}},
},
]

for test in tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ network:
host_network: false
tftp_port: 69

ix_volumes:
tftpboot: /opt/tests/mnt/tftpboot

storage:
tftpboot:
type: ix_volume
ix_volume_config:
dataset_name: tftpboot
type: host_path
host_path_config:
path: /opt/tests/mnt/tftpboot
create_host_path: true
additional_storage: []

0 comments on commit efdebec

Please sign in to comment.