ssplatt / saltstack-infratest-module

A Salt module using the testinfra python module for infrastructure compliance testing and auditing.
GNU General Public License v3.0
24 stars 4 forks source link

Unhandled Error on failed Test Results for Absent File and Absent Pkg #4

Open khaije1 opened 7 years ago

khaije1 commented 7 years ago

The below pillar/infratest config caused an unhandled exception that prevents the results from returning. The error for the package test is below but the file error is very similar.

infratest:                                                                                                                                                                           
  file:                                                                                                                                                                                                                                                                                                                                           
    '/root/.ssh/authorized_keys':                                                                                                                                                    
      exists: true                                                                                                                                                                   
      type: file                                                                                                                                                                     
      mode: 0600                                                                                                                                                                     
      user: root                                                                                                                                                                     
      group: root                                                                                                                                                                    
  package:                                                                                                                                                                           
    'exim4':                                                                                                                                                                         
      installed: true                                                                                                                                                                
      version: 4.84  
AssertionError: Unexpected exit code 1 for CommandResult(command='rpm -q --queryformat="%                                                                                            
{VERSION}" exim4', exit_status=1, stdout='package exim4 is not installed\n', stderr=None)                                                                                            
Traceback (most recent call last):                                                                                                                                                   
  File "/bin/salt-call", line 11, in <module>                                                                                                                                        
    salt_call()                                                                                                                                                                      
  File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 379, in salt_call                                                                                                    
    client.run()                                                                                                                                                                     
  File "/usr/lib/python2.7/site-packages/salt/cli/call.py", line 58, in run                                                                                                          
    caller.run()                                                                                                                                                                     
  File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 134, in run                                                                                                       
    ret = self.call()                                                                                                                                                                
  File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 197, in call                                                                                                      
    ret['return'] = func(*args, **kwargs)                                                                                                                                            
  File "/var/cache/salt/minion/extmods/modules/infratest.py", line 762, in run_all                                                                                                   
    package_version(key, vals['version'])                                                                                                                                            
  File "/var/cache/salt/minion/extmods/modules/infratest.py", line 360, in package_versio                                                                                            
n                                                                                                                                                                                    
    if Package(thing).version.startswith(str(expected)):                                                                                                                             
  File "/usr/lib/python2.7/site-packages/testinfra/modules/package.py", line 143, in vers                                                                                            
ion                                                                                                                                                                                  
    self.name)                                                                                                                                                                       
  File "/usr/lib/python2.7/site-packages/testinfra/host.py", line 85, in check_output                                                                                                
    'Unexpected exit code %s for %s' % (out.rc, out))                                                                                                                                
AssertionError: Unexpected exit code 1 for CommandResult(command='rpm -q --queryformat="%                                                                                            
{VERSION}" exim4', exit_status=1, stdout='package exim4 is not installed\n', stderr=None)                                                                                            
[root@salt-master-d1 ~]# salt-call infratest.run_all                                                                                                                                 
[WARNING ] /var/cache/salt/minion/extmods/modules/infratest.py:25: DeprecationWarning: ge                                                                                            
t_backend() is deprecated, use get_host() instead                                                                                                                                    
  conn = testinfra.get_backend('local://')                                                                                                                                           

[WARNING ] /var/cache/salt/minion/extmods/modules/infratest.py:26: DeprecationWarning: ge                                                                                            
t_module() is deprecated, use new host API                                                                                                                                           
  File = conn.get_module("File")                                                    

Thanks for the project and let me know if I can provide any info or assistance!

ssplatt commented 7 years ago

It looks like you may not be on the latest code. Could you do a git pull and try again please?

khaije1 commented 7 years ago

Well noted. I retried by adding the latest infratest module from https://raw.githubusercontent.com/ssplatt/saltstack-infratest-module/master/infratest.py to my roots folder as '_modules/infratest.py'

This produced a similar error to the first one.

Notably I only get this error when the file or package doesn't exist. This is on Salt version 2016.11.6

[root@salt-master-d1 _modules]# salt-call infratest.run_all details=True                                                                                                  
[WARNING ] /var/cache/salt/minion/extmods/modules/infratest.py:25: DeprecationWarning: get_backend() is deprecated, use get_host() instead                                
  conn = testinfra.get_backend('local://')                                                                                                                                

[WARNING ] /var/cache/salt/minion/extmods/modules/infratest.py:26: DeprecationWarning: get_module() is deprecated, use new host API                                       
  File = conn.get_module("File")                                                                                                                                          

[ERROR   ] An un-handled exception was caught by salt's global exception handler:                                                                                         
AssertionError: Unexpected exit code 1 for CommandResult(command='stat -c %U /root/.ssh/authorized_keys', exit_status=1, stdout=None, stderr='stat: cannot stat \xe2\x80\ 
x98/root/.ssh/authorized_keys\xe2\x80\x99: No such file or directory\n')                                                                                                  
Traceback (most recent call last):                                                                                                                                        
  File "/bin/salt-call", line 11, in <module>                                                                                                                             
    salt_call()                                                                                                                                                           
  File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 379, in salt_call                                                                                         
    client.run()                                                                                                                                                          
  File "/usr/lib/python2.7/site-packages/salt/cli/call.py", line 58, in run                                                                                               
    caller.run()                                                                                                                                                          
  File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 134, in run                                                                                            
    ret = self.call()                                                                                                                                                     
  File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 197, in call                                                                                           
    ret['return'] = func(*args, **kwargs)                                                                                                                                 
  File "/var/cache/salt/minion/extmods/modules/infratest.py", line 733, in run_all                                                                                        
    file_user(key, vals['user'])                                                                                                                                          
  File "/var/cache/salt/minion/extmods/modules/infratest.py", line 172, in file_user                                                                                      
    if File(thing).user == expected:                                                                                                                                      
  File "/usr/lib/python2.7/site-packages/testinfra/modules/file.py", line 190, in user                                                                                    
    return self.check_output("stat -c %%U %s", self.path)                                                                                                                 
  File "/usr/lib/python2.7/site-packages/testinfra/host.py", line 85, in check_output                                                                                     
    'Unexpected exit code %s for %s' % (out.rc, out))                                                                                                                     
AssertionError: Unexpected exit code 1 for CommandResult(command='stat -c %U /root/.ssh/authorized_keys', exit_status=1, stdout=None, stderr='stat: cannot stat \xe2\x80\ 
x98/root/.ssh/authorized_keys\xe2\x80\x99: No such file or directory\n')                                                                                                  
Traceback (most recent call last):                                                                                                                                        
  File "/bin/salt-call", line 11, in <module>                                                                                                                             
    salt_call()                                                                                                                                                           
  File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 379, in salt_call                                                                                         
    client.run()                                                                                                                                                          
  File "/usr/lib/python2.7/site-packages/salt/cli/call.py", line 58, in run                                                                                               
    caller.run()                                                                                                                                                          
  File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 134, in run                                                                                            
    ret = self.call()                                                                                                                                                     
  File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 197, in call                                                                                           
    ret['return'] = func(*args, **kwargs)                                                                                                                                 
  File "/var/cache/salt/minion/extmods/modules/infratest.py", line 733, in run_all                                                                                        
    file_user(key, vals['user'])                                                                                                                                          
  File "/var/cache/salt/minion/extmods/modules/infratest.py", line 172, in file_user                                                                                      
    if File(thing).user == expected:                                                                                                                                      
  File "/usr/lib/python2.7/site-packages/testinfra/modules/file.py", line 190, in user                                                                                    
    return self.check_output("stat -c %%U %s", self.path)                                                                                                                 
  File "/usr/lib/python2.7/site-packages/testinfra/host.py", line 85, in check_output                                                                                     
    'Unexpected exit code %s for %s' % (out.rc, out))                                                                                                                     
AssertionError: Unexpected exit code 1 for CommandResult(command='stat -c %U /root/.ssh/authorized_keys', exit_status=1, stdout=None, stderr='stat: cannot stat \xe2\x80\ 
x98/root/.ssh/authorized_keys\xe2\x80\x99: No such file or directory\n')                                                                                                  
[root@salt-master-d1 _modules]#