remove useless script printing and reuse run() method
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
		
					parent
					
						
							
								ddb5bd16c9
							
						
					
				
			
			
				commit
				
					
						a4882e7e30
					
				
			
		
					 3 changed files with 3 additions and 49 deletions
				
			
		| 
						 | 
					@ -3,9 +3,6 @@
 | 
				
			||||||
- cleanup object_id handling
 | 
					- cleanup object_id handling
 | 
				
			||||||
    - have a look at singletons
 | 
					    - have a look at singletons
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- remove useless
 | 
					 | 
				
			||||||
    ERROR: monitoring02: Code that raised the error:
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- ensure that all types, which support --state support
 | 
					- ensure that all types, which support --state support
 | 
				
			||||||
    present and absent (consistent look and feel)
 | 
					    present and absent (consistent look and feel)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -119,26 +119,7 @@ class Local(object):
 | 
				
			||||||
        command = ["/bin/sh", "-e"]
 | 
					        command = ["/bin/sh", "-e"]
 | 
				
			||||||
        command.append(script)
 | 
					        command.append(script)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.log.debug("Local run script: %s", command)
 | 
					        self.run(command, env, return_output)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        if env is None:
 | 
					 | 
				
			||||||
            env = os.environ.copy()
 | 
					 | 
				
			||||||
        # Export __target_host for use in __remote_{copy,exec} scripts
 | 
					 | 
				
			||||||
        env['__target_host'] = self.target_host
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.log.debug("Local run script env: %s", env)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            if return_output:
 | 
					 | 
				
			||||||
                return subprocess.check_output(command, env=env).decode()
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                subprocess.check_call(command, env=env)
 | 
					 | 
				
			||||||
        except subprocess.CalledProcessError as error:
 | 
					 | 
				
			||||||
            script_content = self.run(["cat", script], return_output=True)
 | 
					 | 
				
			||||||
            self.log.error("Code that raised the error:\n%s", script_content)
 | 
					 | 
				
			||||||
            raise LocalScriptError(script, command, script_content)
 | 
					 | 
				
			||||||
        except EnvironmentError as error:
 | 
					 | 
				
			||||||
            raise cdist.Error(" ".join(command) + ": " + error.args[1])
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def link_emulator(self, exec_path):
 | 
					    def link_emulator(self, exec_path):
 | 
				
			||||||
        """Link emulator to types"""
 | 
					        """Link emulator to types"""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -139,32 +139,8 @@ class Remote(object):
 | 
				
			||||||
        Return the output as a string.
 | 
					        Return the output as a string.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        command = self._exec.split()
 | 
					 | 
				
			||||||
        command.append(self.target_host)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # export target_host for use in __remote_{exec,copy} scripts
 | 
					        command = ["/bin/sh", "-e"]
 | 
				
			||||||
        os_environ = os.environ.copy()
 | 
					 | 
				
			||||||
        os_environ['__target_host'] = self.target_host
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.log.debug("Remote run script: %s", command)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        # can't pass environment to remote side, so prepend command with
 | 
					 | 
				
			||||||
        # variable declarations
 | 
					 | 
				
			||||||
        if env:
 | 
					 | 
				
			||||||
            self.log.debug("Remote run script env: %s", env)
 | 
					 | 
				
			||||||
            command.extend(["%s=%s" % item for item in env.items()])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        command.extend(["/bin/sh", "-e"])
 | 
					 | 
				
			||||||
        command.append(script)
 | 
					        command.append(script)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        self.run(command, env, return_output)
 | 
				
			||||||
            if return_output:
 | 
					 | 
				
			||||||
                return subprocess.check_output(command, env=os_environ).decode()
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                subprocess.check_call(command, env=os_environ)
 | 
					 | 
				
			||||||
        except subprocess.CalledProcessError as error:
 | 
					 | 
				
			||||||
            script_content = self.run(["cat", script], return_output=True)
 | 
					 | 
				
			||||||
            self.log.error("Code that raised the error:\n%s", script_content)
 | 
					 | 
				
			||||||
            raise RemoteScriptError(script, command, script_content)
 | 
					 | 
				
			||||||
        except EnvironmentError as error:
 | 
					 | 
				
			||||||
            raise cdist.Error(" ".join(command) + ": " + error.args[1])
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue