saltstack-formulas / postgres-formula

http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
77 stars 283 forks source link

fix(macros.jinja): use `user` kwarg for schemas (required on FreeBSD) #293

Closed myii closed 4 years ago

myii commented 4 years ago

PR progress checklist (to be filled in by reviewers)


What type of PR is this?

Primary type

Secondary type

Does this PR introduce a BREAKING CHANGE?

No.

Related issues and/or pull requests

#119:

CC: @vutny.

Describe the changes you're proposing

Before:

       ----------                                                                                                                                                                                                    
                 ID: postgres_schema-db2-public                                                                                                                                                                      
           Function: postgres_schema.present                                                                                                                                                                         
               Name: public                                                                                                                                                                                          
             Result: False                                                                                                                                                                                           
            Comment: An exception occurred in this state: Traceback (most recent call last):                                                                                                                         
                File "/usr/local/lib/python3.6/site-packages/salt/modules/cmdmod.py", line 425, in _run                                                                                                              
                  pwd.getpwnam(runas)                                                                                                                                                                                
              KeyError: "getpwnam(): name not found: 'pgsql'"                                                                                                                                                        

              During handling of the above exception, another exception occurred:                                                                                                                                    

              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/postgres_schema.py", line 75, in present                                                                                                    
                  schema_attr = __salt__['postgres.schema_get'](dbname, name, **db_args)                                                                                                                             
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 2107, in schema_get                                                                                                     
                  db_password=db_password)                                                                                                                                                                           
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 2162, in schema_list                                                                                                    
                  password=db_password)                                                                                                                                                                              
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 438, in psql_query                                                                                                      
                  password=password)                                                                                                                                                                                 
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 377, in _psql_prepare_and_run                                                                                           
                  rcmd, runas=runas, password=password, host=host, port=port, user=user)                                                                                                                             
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 186, in _run_psql                                                                                                       
                  ret = __salt__['cmd.run_all'](cmd, python_shell=False, **kwargs)                                                                                                                                   
                File "/usr/local/lib/python3.6/site-packages/salt/modules/cmdmod.py", line 2069, in run_all                                                                                                          
                  **kwargs)                                                                                                                                                                                          
                File "/usr/local/lib/python3.6/site-packages/salt/modules/cmdmod.py", line 428, in _run                                                                                                              
                  'User \'{0}\' is not available'.format(runas)                                                                                                                                                      
              salt.exceptions.CommandExecutionError: User 'pgsql' is not available                                                                                                                                   
            Started: 19:40:05.540106                                                                                                                                                                                 
           Duration: 19.641 ms                                                                                                                                                                                       
            Changes:                                                                                                                                                                                                 
       ----------                                                                                                                                                                                                   
                 ID: postgres_schema-uuid-ossp                                                                                                                                                                       
           Function: postgres_schema.present                                                                                                                                                                         
               Name: uuid-ossp                                                                                                                                                                                       
             Result: False                                                                                                                                                                                           
            Comment: An exception occurred in this state: Traceback (most recent call last):                                                                                                                         
                File "/usr/local/lib/python3.6/site-packages/salt/modules/cmdmod.py", line 425, in _run                                                                                                              
                  pwd.getpwnam(runas)                                                                                                                                                                                
              KeyError: "getpwnam(): name not found: 'pgsql'"                                                                                                                                                        

              During handling of the above exception, another exception occurred:                                                                                                                                    

              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/postgres_schema.py", line 75, in present                                                                                                    
                  schema_attr = __salt__['postgres.schema_get'](dbname, name, **db_args)                                                                                                                             
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 2107, in schema_get                                                                                                     
                  db_password=db_password)                                                                                                                                                                           
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 2162, in schema_list                                                                                                    
                  password=db_password)                                                                                                                                                                              
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 438, in psql_query                                                                                                      
                  password=password)                                                                                                                                                                                 
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 377, in _psql_prepare_and_run                                                                                           
                  rcmd, runas=runas, password=password, host=host, port=port, user=user)                                                                                                                             
                File "/usr/local/lib/python3.6/site-packages/salt/modules/postgres.py", line 186, in _run_psql                                                                                                       
                  ret = __salt__['cmd.run_all'](cmd, python_shell=False, **kwargs)                                                                                                                                   
                File "/usr/local/lib/python3.6/site-packages/salt/modules/cmdmod.py", line 2069, in run_all                                                                                                          
                  **kwargs)                                                                                                                                                                                          
                File "/usr/local/lib/python3.6/site-packages/salt/modules/cmdmod.py", line 428, in _run                                                                                                              
                  'User \'{0}\' is not available'.format(runas)                                                                                                                                                      
              salt.exceptions.CommandExecutionError: User 'pgsql' is not available                                                                                                                                   
            Started: 19:40:05.561178                                                                                                                                                                                 
           Duration: 4.004 ms                                                                                                                                                                                        
            Changes:                                                                                                                                                                                                 

       Summary for local
       -------------
       Succeeded: 20 (changed=16)
       Failed:     2
       -------------
       Total states run:     22
       Total run time:   47.954 s

Pillar / config required to test the proposed changes

Debug log showing how the proposed changes work

After:

  ✔  Postgres service: should be running and enabled                                                                                                                                                                 
     ✔  Service postgresql is expected to be enabled                                                                                                                                                                 
     ✔  Service postgresql is expected to be running                                                                                                                                                                 
     ✔  Port 5432 is expected to be listening                                                                                                                                                                        
  ✔  Postgres configuration: should include the directory                                                                                                                                                            
     ✔  File /srv/my_tablespace is expected to be directory                                                                                                                                                          
     ✔  File /srv/my_tablespace is expected to be owned by "postgres"                                                                                                                                                
     ✔  File /srv/my_tablespace is expected to be grouped into "postgres"                                                                                                                                            
     ✔  File /srv/my_tablespace mode is expected to cmp == "0700"                                                                                                                                                    
  ✔  Postgres command: should match desired lines                                                                                                                                                                    
     ✔  Command: `su - postgres -c 'psql -p5432 -qtc "\l+ db2"'` stdout is expected to match /db2.*remoteUser.*UTF8.*en_US.UTF-8.*en_US.UTF-8.*my_space/                                                             

Profile Summary: 3 successful controls, 0 control failures, 0 controls skipped                                                                                                                                       
Test Summary: 8 successful, 0 failures, 0 skipped

Documentation checklist

Testing checklist

Additional context

saltstack-formulas-travis commented 4 years ago

:tada: This PR is included in version 0.40.5 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: