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

Setting properties with state zfs.filesystem_present causes python errors in PY3 #54448

Closed
mngan opened this issue Sep 10, 2019 · 4 comments
Closed
Labels
Bug broken, incorrect, or confusing behavior Confirmed Salt engineer has confirmed bug/feature - often including a MCVE Core relates to code central or existential to Salt Execution-Module P4 Priority 4 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@mngan
Copy link

mngan commented Sep 10, 2019

Description of Issue

Using the state zfs.filesystem_present with properties under PY3 causes the execution module function zfs.set to pass dict_values and dict_keys types through to zfs.utils.zfs_command which causes any non-list type to be wrapped in a list. Casting the dict_values and dict_keys to a list fixes this issue in PY3

Setup

Here is a salt state salt/observium/fs.sls that I created. It tries to create a filesystem (root) from a pre-existing zpool called observium, and set a specific mount point for the filesystem.

obs_zfs:
  file.directory:
    - name: /opt/observium
  zfs.filesystem_present:
    - name: observium/root
    - create_parent: True
    - properties:
        mountpoint: /opt/observium

By applying this patch, I was able to successfully apply the state above

diff --git a/salt/modules/zfs.py b/salt/modules/zfs.py
index 151e5e1aef..98fce2f2ce 100644
--- a/salt/modules/zfs.py
+++ b/salt/modules/zfs.py
@@ -1145,8 +1145,8 @@ def set(*dataset, **kwargs):
     res = __salt__['cmd.run_all'](
         __utils__['zfs.zfs_command'](
             command='set',
-            property_name=filesystem_properties.keys(),
-            property_value=filesystem_properties.values(),
+            property_name=list(filesystem_properties.keys()),
+            property_value=list(filesystem_properties.values()),
             target=list(dataset),
         ),
         python_shell=False,

Steps to Reproduce Issue

Apply the state above results in the error below

2019-09-09 20:01:36,195 [salt.state       :1852][INFO    ][23094] Executing state zfs.filesystem_present for [observium/root]
2019-09-09 20:01:36,200 [salt.loaded.int.module.cmdmod:397 ][INFO    ][23094] Executing command '/sbin/zfs list -t filesystem observium/root' in directory '/home/milton'
2019-09-09 20:01:36,211 [salt.loaded.int.module.cmdmod:397 ][INFO    ][23094] Executing command '/sbin/zfs get -H -o name,property,value -t filesystem all observium/root' in directory '/home/milton'
2019-09-09 20:01:36,231 [salt.state       :322 ][ERROR   ][23094] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/state.py", line 1933, in call
    **cdata['kwargs'])
  File "/usr/lib/python3/dist-packages/salt/loader.py", line 1939, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/states/zfs.py", line 582, in filesystem_present
    cloned_from=cloned_from,
  File "/usr/lib/python3/dist-packages/salt/states/zfs.py", line 483, in _dataset_present
    mod_res = __salt__['zfs.set'](name, **{prop: properties[prop]})
  File "/usr/lib/python3/dist-packages/salt/modules/zfs.py", line 1150, in set
    target=list(dataset),
  File "/usr/lib/python3/dist-packages/salt/utils/zfs.py", line 644, in zfs_command
    target=target,
  File "/usr/lib/python3/dist-packages/salt/utils/zfs.py", line 263, in _command
    val=to_auto(key, val, source=source, convert_to_human=False),
  File "/usr/lib/python3/dist-packages/salt/utils/zfs.py", line 572, in to_auto
    return _auto('to', name, value, source, convert_to_human)
  File "/usr/lib/python3/dist-packages/salt/utils/zfs.py", line 169, in _auto
    value_type = props[name]['type'] if name in props else 'str'
TypeError: unhashable type: 'dict_keys'

Versions Report

Master and minion are running the same version of salt.

Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: unknown
       dateutil: 2.6.1
      docker-py: Not Installed
          gitdb: 2.0.3
      gitpython: 2.1.8
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.7
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.15+ (default, Jul  9 2019, 16:51:35)
   python-gnupg: 0.4.1
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: 2.0.3
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.2.5

System Versions:
           dist: Ubuntu 18.04 bionic
         locale: UTF-8
        machine: x86_64
        release: 4.15.0-60-generic
         system: Linux
        version: Ubuntu 18.04 bionic
@DmitryKuzmenko DmitryKuzmenko added Bug broken, incorrect, or confusing behavior Confirmed Salt engineer has confirmed bug/feature - often including a MCVE Execution-Module severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around P4 Priority 4 Core relates to code central or existential to Salt labels Sep 10, 2019
@DmitryKuzmenko DmitryKuzmenko added this to the Approved milestone Sep 10, 2019
@silenius
Copy link
Contributor

Same problem here:

----------                                            
          ID: zfs_dataset_22                                              
    Function: zfs.filesystem_present                                                                                                                                                                                                                                                                                           
        Name: zroot/data/jails/pg11/data11                                    
      Result: False                                                                                                                                                                                                                                                                                                            
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/local/lib/python3.6/site-packages/salt/state.py", line 1933, in call                                                                                                                                                                                                                                
                  **cdata['kwargs'])                                      
                File "/usr/local/lib/python3.6/site-packages/salt/loader.py", line 1939, in wrapper                                                                                                                                                                                                                            
                  return f(*args, **kwargs)                                                                                                                    
                File "/usr/local/lib/python3.6/site-packages/salt/states/zfs.py", line 582, in filesystem_present
                  cloned_from=cloned_from,                                                                                                                                                                                                                                                                                     
                File "/usr/local/lib/python3.6/site-packages/salt/states/zfs.py", line 483, in _dataset_present
                  mod_res = __salt__['zfs.set'](name, **{prop: properties[prop]})                                                                                                                                                                                                                                              
                File "/usr/local/lib/python3.6/site-packages/salt/modules/zfs.py", line 1150, in set
                  target=list(dataset),                                                                                                                        
                File "/usr/local/lib/python3.6/site-packages/salt/utils/zfs.py", line 644, in zfs_command
                  target=target,                                                                                                                               
                File "/usr/local/lib/python3.6/site-packages/salt/utils/zfs.py", line 263, in _command                                                         
                  val=to_auto(key, val, source=source, convert_to_human=False),                                                                                
                File "/usr/local/lib/python3.6/site-packages/salt/utils/zfs.py", line 572, in to_auto                               
                  return _auto('to', name, value, source, convert_to_human)
                File "/usr/local/lib/python3.6/site-packages/salt/utils/zfs.py", line 169, in _auto                                                                                                                                                                                                                            
                  value_type = props[name]['type'] if name in props else 'str'
              TypeError: unhashable type: 'dict_keys'                                                                                                          
     Started: 11:31:41.549138                                       
    Duration: 754.413 ms                                                      
     Changes:                                                                                                                                                  
----------                                                                
    Salt Version:
               Salt: 2019.2.0
     
    Dependency Versions:
               cffi: 1.12.3
           cherrypy: Not Installed
           dateutil: Not Installed
          docker-py: Not Installed
              gitdb: Not Installed
          gitpython: Not Installed
              ioflo: Not Installed
             Jinja2: 2.10.1
            libgit2: Not Installed
            libnacl: Not Installed
           M2Crypto: Not Installed
               Mako: Not Installed
       msgpack-pure: Not Installed
     msgpack-python: 0.6.2
       mysql-python: Not Installed
          pycparser: 2.19
           pycrypto: 2.6.1
       pycryptodome: Not Installed
             pygit2: Not Installed
             Python: 3.6.9 (default, Nov  5 2019, 11:24:49)
       python-gnupg: Not Installed
             PyYAML: 5.1
              PyZMQ: 18.1.0
               RAET: Not Installed
              smmap: Not Installed
            timelib: Not Installed
            Tornado: 4.5.3
                ZMQ: 4.3.1
     
    System Versions:
               dist:   
             locale: US-ASCII
            machine: amd64
            release: 12.1-RELEASE-p1
             system: FreeBSD
            version: Not Installed

@silenius silenius mentioned this issue Nov 20, 2019
dwoz pushed a commit that referenced this issue Jan 2, 2020
@dwoz dwoz closed this as completed in 7ac44f0 Jan 2, 2020
@asomers
Copy link
Contributor

asomers commented Feb 7, 2020

Is there a workaround?

@L4rS6
Copy link
Contributor

L4rS6 commented Feb 10, 2020

Why are you looking for a workaround? This has already been fixed by #55374

@asomers
Copy link
Contributor

asomers commented Feb 10, 2020

For use on environments that still use version 2019.02, a workaround is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Confirmed Salt engineer has confirmed bug/feature - often including a MCVE Core relates to code central or existential to Salt Execution-Module P4 Priority 4 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

5 participants