forked from ungleich-public/cdist
		
	commit broken code
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
		
					parent
					
						
							
								20aafe62f5
							
						
					
				
			
			
				commit
				
					
						f21ce6a0db
					
				
			
		
					 1 changed files with 31 additions and 8 deletions
				
			
		
							
								
								
									
										39
									
								
								bin/cdist
									
										
									
									
									
								
							
							
						
						
									
										39
									
								
								bin/cdist
									
										
									
									
									
								
							| 
						 | 
					@ -98,6 +98,7 @@ class Cdist:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def __init__(self, target_host, initial_manifest=False):
 | 
					   def __init__(self, target_host, initial_manifest=False):
 | 
				
			||||||
      self.target_host = target_host
 | 
					      self.target_host = target_host
 | 
				
			||||||
 | 
					      self.remote_prefix = ["ssh", "root@" + self.target_host]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      # log.info("foobar")
 | 
					      # log.info("foobar")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -139,26 +140,47 @@ class Cdist:
 | 
				
			||||||
      log.error(*args)
 | 
					      log.error(*args)
 | 
				
			||||||
      sys.exit(1)
 | 
					      sys.exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   def remote_cat(filename):
 | 
				
			||||||
 | 
					      cmd = self.remote_prefix
 | 
				
			||||||
 | 
					      cmd.append("cat")
 | 
				
			||||||
 | 
					      cmd.append(filename)
 | 
				
			||||||
 | 
					      try:
 | 
				
			||||||
 | 
					         subprocess.call(cmd)
 | 
				
			||||||
 | 
					      except subprocess.CalledProcessError:
 | 
				
			||||||
 | 
					         log.error("Remote cat failed")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def shell_run_or_debug_fail(self, script, *args, **kargs):
 | 
					   def shell_run_or_debug_fail(self, script, *args, **kargs):
 | 
				
			||||||
      # Manually execute /bin/sh, because sh -e does what we want
 | 
					      # Manually execute /bin/sh, because sh -e does what we want
 | 
				
			||||||
      # and sh -c -e does not exit if /bin/false called
 | 
					      # and sh -c -e does not exit if /bin/false called
 | 
				
			||||||
      args[0].insert(0,"/bin/sh")
 | 
					      args[0][:0] = [ "/bin/sh", "-e" ]
 | 
				
			||||||
      args[0].insert(1,"-e")
 | 
					 | 
				
			||||||
      log.debug("Shell exec: " + " ".join(*args))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if "remote" in kargs:
 | 
				
			||||||
 | 
					         log.debug("Remote found")
 | 
				
			||||||
 | 
					         if kargs["remote"]:
 | 
				
			||||||
 | 
					            args[0][:0] = self.remote_prefix
 | 
				
			||||||
 | 
					            remote = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					         del kargs["remote"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      log.debug("Shell exec: " + " ".join(*args))
 | 
				
			||||||
      try:
 | 
					      try:
 | 
				
			||||||
         subprocess.check_call(*args, **kargs)
 | 
					         subprocess.check_call(*args, **kargs)
 | 
				
			||||||
      except subprocess.CalledProcessError:
 | 
					      except subprocess.CalledProcessError:
 | 
				
			||||||
         script_fd = open(script)
 | 
					         log.error("Code that raised the error:\n")
 | 
				
			||||||
         log.error("Code that raised the error:\n" + script_fd.read())
 | 
					         if remote:
 | 
				
			||||||
         script_fd.close()
 | 
					            remote_cat(script)
 | 
				
			||||||
 | 
					         else:
 | 
				
			||||||
 | 
					            script_fd = open(script)
 | 
				
			||||||
 | 
					            print(script_fd.read())
 | 
				
			||||||
 | 
					            script_fd.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         self.exit_error("Non-Zero exit code exit of " + " ".join(*args))
 | 
					         self.exit_error("Non-Zero exit code exit of " + " ".join(*args))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def run_or_fail(self, *args, **kargs):
 | 
					   def run_or_fail(self, *args, **kargs):
 | 
				
			||||||
      if "remote" in kargs:
 | 
					      if "remote" in kargs:
 | 
				
			||||||
         log.debug("Remote found")
 | 
					         log.debug("Remote found")
 | 
				
			||||||
         if kargs["remote"]:
 | 
					         if kargs["remote"]:
 | 
				
			||||||
            args[0][:0] = ["ssh", "root@" + self.target_host]
 | 
					            args[0][:0] = self.remote_prefix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         del kargs["remote"]
 | 
					         del kargs["remote"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -166,7 +188,7 @@ class Cdist:
 | 
				
			||||||
      try:
 | 
					      try:
 | 
				
			||||||
         subprocess.check_call(*args, **kargs)
 | 
					         subprocess.check_call(*args, **kargs)
 | 
				
			||||||
      except subprocess.CalledProcessError:
 | 
					      except subprocess.CalledProcessError:
 | 
				
			||||||
         self.exit_error("Command failed: " + " ".join(*newargs))
 | 
					         self.exit_error("Command failed: " + " ".join(*args))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def remove_remote_dir(self, destination):
 | 
					   def remove_remote_dir(self, destination):
 | 
				
			||||||
      self.run_or_fail(["rm", "-rf",  destination], remote=True)
 | 
					      self.run_or_fail(["rm", "-rf",  destination], remote=True)
 | 
				
			||||||
| 
						 | 
					@ -322,6 +344,7 @@ class Cdist:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      explorers = self.list_type_explorers(type)
 | 
					      explorers = self.list_type_explorers(type)
 | 
				
			||||||
      for explorer in explorers:
 | 
					      for explorer in explorers:
 | 
				
			||||||
 | 
					         # THIS IS A BUG, because remote_cmd is NOT a copy
 | 
				
			||||||
         remote_cmd = cmd
 | 
					         remote_cmd = cmd
 | 
				
			||||||
         remote_cmd.append(os.path.join(self.remote_type_explorer_dir(type), explorer))
 | 
					         remote_cmd.append(os.path.join(self.remote_type_explorer_dir(type), explorer))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue