forked from ungleich-public/cdist
		
	Fix exec/{local,remote} tests. Add exec/local test to make test.
This commit is contained in:
		
					parent
					
						
							
								3f6a300567
							
						
					
				
			
			
				commit
				
					
						519eb60664
					
				
			
		
					 3 changed files with 22 additions and 5 deletions
				
			
		| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					from .local import *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
					    import unittest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    unittest.main()
 | 
				
			||||||
| 
						 | 
					@ -61,6 +61,7 @@ class LocalTestCase(test.CdistTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.local = local.Local(
 | 
					        self.local = local.Local(
 | 
				
			||||||
            target_host=target_host,
 | 
					            target_host=target_host,
 | 
				
			||||||
 | 
					            target_host_tags=None,
 | 
				
			||||||
            base_root_path=self.host_base_path,
 | 
					            base_root_path=self.host_base_path,
 | 
				
			||||||
            host_dir_name=self.hostdir,
 | 
					            host_dir_name=self.hostdir,
 | 
				
			||||||
            exec_path=test.cdist_exec_path
 | 
					            exec_path=test.cdist_exec_path
 | 
				
			||||||
| 
						 | 
					@ -124,6 +125,7 @@ class LocalTestCase(test.CdistTestCase):
 | 
				
			||||||
                'localhost',
 | 
					                'localhost',
 | 
				
			||||||
                'localhost',
 | 
					                'localhost',
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
 | 
					            target_host_tags=None,
 | 
				
			||||||
            base_root_path=self.host_base_path,
 | 
					            base_root_path=self.host_base_path,
 | 
				
			||||||
            host_dir_name=self.hostdir,
 | 
					            host_dir_name=self.hostdir,
 | 
				
			||||||
            exec_path=test.cdist_exec_path,
 | 
					            exec_path=test.cdist_exec_path,
 | 
				
			||||||
| 
						 | 
					@ -147,6 +149,7 @@ class LocalTestCase(test.CdistTestCase):
 | 
				
			||||||
                'localhost',
 | 
					                'localhost',
 | 
				
			||||||
                'localhost',
 | 
					                'localhost',
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
 | 
					            target_host_tags=None,
 | 
				
			||||||
            base_root_path=self.host_base_path,
 | 
					            base_root_path=self.host_base_path,
 | 
				
			||||||
            host_dir_name=self.hostdir,
 | 
					            host_dir_name=self.hostdir,
 | 
				
			||||||
            exec_path=test.cdist_exec_path,
 | 
					            exec_path=test.cdist_exec_path,
 | 
				
			||||||
| 
						 | 
					@ -176,10 +179,11 @@ class LocalTestCase(test.CdistTestCase):
 | 
				
			||||||
                'localhost',
 | 
					                'localhost',
 | 
				
			||||||
                'localhost',
 | 
					                'localhost',
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
 | 
					            target_host_tags=None,
 | 
				
			||||||
            base_root_path=self.host_base_path,
 | 
					            base_root_path=self.host_base_path,
 | 
				
			||||||
            host_dir_name=self.hostdir,
 | 
					            host_dir_name=self.hostdir,
 | 
				
			||||||
            exec_path=test.cdist_exec_path,
 | 
					            exec_path=test.cdist_exec_path,
 | 
				
			||||||
            configuration=configuration
 | 
					            configuration=configuration.get_config(section='GLOBAL')
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        link_test_local._create_conf_path_and_link_conf_dirs()
 | 
					        link_test_local._create_conf_path_and_link_conf_dirs()
 | 
				
			||||||
| 
						 | 
					@ -191,24 +195,29 @@ class LocalTestCase(test.CdistTestCase):
 | 
				
			||||||
    # other tests
 | 
					    # other tests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_run_success(self):
 | 
					    def test_run_success(self):
 | 
				
			||||||
 | 
					        self.local.create_files_dirs()
 | 
				
			||||||
        self.local.run([bin_true])
 | 
					        self.local.run([bin_true])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_run_fail(self):
 | 
					    def test_run_fail(self):
 | 
				
			||||||
 | 
					        self.local.create_files_dirs()
 | 
				
			||||||
        self.assertRaises(cdist.Error, self.local.run, [bin_false])
 | 
					        self.assertRaises(cdist.Error, self.local.run, [bin_false])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_run_script_success(self):
 | 
					    def test_run_script_success(self):
 | 
				
			||||||
 | 
					        self.local.create_files_dirs()
 | 
				
			||||||
        handle, script = self.mkstemp(dir=self.temp_dir)
 | 
					        handle, script = self.mkstemp(dir=self.temp_dir)
 | 
				
			||||||
        with os.fdopen(handle, "w") as fd:
 | 
					        with os.fdopen(handle, "w") as fd:
 | 
				
			||||||
            fd.writelines(["#!/bin/sh\n", bin_true])
 | 
					            fd.writelines(["#!/bin/sh\n", bin_true])
 | 
				
			||||||
        self.local.run_script(script)
 | 
					        self.local.run_script(script)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_run_script_fail(self):
 | 
					    def test_run_script_fail(self):
 | 
				
			||||||
 | 
					        self.local.create_files_dirs()
 | 
				
			||||||
        handle, script = self.mkstemp(dir=self.temp_dir)
 | 
					        handle, script = self.mkstemp(dir=self.temp_dir)
 | 
				
			||||||
        with os.fdopen(handle, "w") as fd:
 | 
					        with os.fdopen(handle, "w") as fd:
 | 
				
			||||||
            fd.writelines(["#!/bin/sh\n", bin_false])
 | 
					            fd.writelines(["#!/bin/sh\n", bin_false])
 | 
				
			||||||
        self.assertRaises(cdist.Error, self.local.run_script, script)
 | 
					        self.assertRaises(cdist.Error, self.local.run_script, script)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_run_script_get_output(self):
 | 
					    def test_run_script_get_output(self):
 | 
				
			||||||
 | 
					        self.local.create_files_dirs()
 | 
				
			||||||
        handle, script = self.mkstemp(dir=self.temp_dir)
 | 
					        handle, script = self.mkstemp(dir=self.temp_dir)
 | 
				
			||||||
        with os.fdopen(handle, "w") as fd:
 | 
					        with os.fdopen(handle, "w") as fd:
 | 
				
			||||||
            fd.writelines(["#!/bin/sh\n", "echo foobar"])
 | 
					            fd.writelines(["#!/bin/sh\n", "echo foobar"])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,8 +22,6 @@
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import getpass
 | 
					import getpass
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
import string
 | 
					 | 
				
			||||||
import random
 | 
					 | 
				
			||||||
import multiprocessing
 | 
					import multiprocessing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import cdist
 | 
					import cdist
 | 
				
			||||||
| 
						 | 
					@ -40,7 +38,8 @@ class RemoteTestCase(test.CdistTestCase):
 | 
				
			||||||
            'localhost',
 | 
					            'localhost',
 | 
				
			||||||
            'localhost',
 | 
					            'localhost',
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        self.base_path = self.temp_dir
 | 
					        # another temp dir for remote base path
 | 
				
			||||||
 | 
					        self.base_path = self.mkdtemp()
 | 
				
			||||||
        user = getpass.getuser()
 | 
					        user = getpass.getuser()
 | 
				
			||||||
        remote_exec = "ssh -o User=%s -q" % user
 | 
					        remote_exec = "ssh -o User=%s -q" % user
 | 
				
			||||||
        remote_copy = "scp -o User=%s -q" % user
 | 
					        remote_copy = "scp -o User=%s -q" % user
 | 
				
			||||||
| 
						 | 
					@ -113,7 +112,8 @@ class RemoteTestCase(test.CdistTestCase):
 | 
				
			||||||
        os.close(handle)
 | 
					        os.close(handle)
 | 
				
			||||||
        target = self.mkdtemp(dir=self.temp_dir)
 | 
					        target = self.mkdtemp(dir=self.temp_dir)
 | 
				
			||||||
        self.remote.transfer(source, target)
 | 
					        self.remote.transfer(source, target)
 | 
				
			||||||
        self.assertTrue(os.path.isfile(target))
 | 
					        self.assertTrue(os.path.isfile(
 | 
				
			||||||
 | 
					            os.path.join(target, os.path.basename(source))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_transfer_dir(self):
 | 
					    def test_transfer_dir(self):
 | 
				
			||||||
        source = self.mkdtemp(dir=self.temp_dir)
 | 
					        source = self.mkdtemp(dir=self.temp_dir)
 | 
				
			||||||
| 
						 | 
					@ -206,6 +206,7 @@ class RemoteTestCase(test.CdistTestCase):
 | 
				
			||||||
        output = r.run_script(script, env=env, return_output=True)
 | 
					        output = r.run_script(script, env=env, return_output=True)
 | 
				
			||||||
        self.assertEqual(output, "test_object\n")
 | 
					        self.assertEqual(output, "test_object\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    import unittest
 | 
					    import unittest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue