Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] folder creation always lowers the foldername #569

Closed
Mik3yZ opened this issue Feb 21, 2024 · 10 comments · Fixed by #570
Closed

[BUG] folder creation always lowers the foldername #569

Mik3yZ opened this issue Feb 21, 2024 · 10 comments · Fixed by #570
Assignees
Labels
bug Something isn't working module:folder This affects the folder module

Comments

@Mik3yZ
Copy link
Contributor

Mik3yZ commented Feb 21, 2024

Describe the bug
When creating a folder with uppercase letters, the folder.py changes it to lowercase.

Component Name
Component Name: folder

Ansible Version

$ ansible --version
ansible [core 2.14.13]
  config file = /home/user/repos/ansible-checkmk/ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user/venvs/ansible-checkmk/lib64/python3.9/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/user/venvs/ansible-checkmk/bin/ansible
  python version = 3.9.16 (main, May 29 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/home/user/venvs/ansible-checkmk/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Checkmk Version and Edition

Checkmk Enterprise Edition 2.2.0p20

Collection Version

$ ansible-galaxy collection list | grep checkmk.general
checkmk.general        4.3.1  

To Reproduce
Create a folder with:

- name: "Create folder"
  checkmk.general.folder:
    server_url: "{{ master_site_baseurl }}"
    site: "{{ master_site }}"
    automation_user: "{{ automation_user }}"
    automation_secret: "{{ automation_secret }}"
    path: "/foldername"
    name: "FolderName"
    state: "present"

Expected behavior
A folder named FolderName, with path /foldername

Actual behavior
A folder named foldername with path /foldername

Minimum reproduction example
See above

Additional context
folder.py contains:

(self.desired["parent"], self.desired["name"]) = self._normalize_path(
self.params.get("path")

And this function (_normalize_path) changes the string to lowercase:

def _normalize_path(self, path):
p = Path(path)
if not p.is_absolute():
p = Path("/").joinpath(p)
return str(p.parent).lower(), p.name

I would advise to not normalize the name / title as a path.

@Mik3yZ Mik3yZ added the bug Something isn't working label Feb 21, 2024
@github-actions github-actions bot added the module:folder This affects the folder module label Feb 21, 2024
@msekania
Copy link
Contributor

msekania commented Feb 21, 2024

Hi @Mik3yZ,

I would say works as intended.

Folder title and path (folder name) are two different parameters.
path (folder name) is and to best of my knowledge should be low case.
title (alias name in folder module) on the other hand, can also contain capital letters.

@Mik3yZ
Copy link
Contributor Author

Mik3yZ commented Feb 21, 2024

Hi @msekania

Maybe my description was a bit off, changed it to reflect what i mean. Hope this makes thing clearer.

@Mik3yZ
Copy link
Contributor Author

Mik3yZ commented Feb 21, 2024

So, to come back to your last sentence @msekania, title (alias name in the module) is parsed through function _normalize_path, and thus alway transformed to lowercase.

@msekania
Copy link
Contributor

msekania commented Feb 21, 2024

So, to come back to your last sentence @msekania, title (alias name in the module) is parsed through function _normalize_path, and thus alway transformed to lowercase.

lines 220-221: _normalize_path(...) is called with a parameter path, hence path is parsed with _normalize_path(...) not the name (alias title).

@Mik3yZ
Copy link
Contributor Author

Mik3yZ commented Feb 21, 2024

true, however it does set (self.desired["parent"], self.desired["name"]) with that processed value. please run my example with 4.3.1 and see for yourself.

@msekania
Copy link
Contributor

msekania commented Feb 21, 2024

self.desired["title"] = self.params.get("title", self.desired["name"])

states it explicitly what goes to title

name parameter of the module aliases title

name=dict(
type="str",
required=False,
aliases=["title"],
),

@Mik3yZ
Copy link
Contributor Author

Mik3yZ commented Feb 21, 2024

yes, i saw that too. however i do get only lowercase names while creating the folders.

i would then say line 220 needs to be changed from:

(self.desired["parent"], self.desired["name"]) = self._normalize_path(
to
(self.desired["parent"], self.desired["path"]) = self._normalize_path(

@msekania
Copy link
Contributor

msekania commented Feb 21, 2024

yes, i saw that too. however i do get only lowercase names while creating the folders.

i would then say line 220 needs to be changed from:

(self.desired["parent"], self.desired["name"]) = self._normalize_path( to (self.desired["parent"], self.desired["path"]) = self._normalize_path(

self.desired["title"] = self.params.get("title", self.desired["name"])
No, actually that's fine, because if title is not defined self.desired["name"] folder is a default name

problem is somewhere else, because self.params.get("title") is Null instead of Name.

@msekania
Copy link
Contributor

It should be
self.desired["title"] = self.params.get("name", self.desired["name"])

I'll make corrections

@msekania
Copy link
Contributor

@Mik3yZ ,

see the fix #570

Thanks for reporting the issue!

@robin-checkmk robin-checkmk linked a pull request Mar 5, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module:folder This affects the folder module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants