示例#1
0
    def test_conf_dir_from_path_linking(self):
        """Ensure that links are correctly created for types in conf
           directories which are defined in CDIST_PATH"""

        test_type = "__cdist_test_type"

        os.environ['CDIST_PATH'] = conf_dir

        # bypass singleton from other tests if any
        cc.Configuration.instance = None

        configuration = cc.Configuration(argparse.Namespace(), env=os.environ)

        link_test_local = local.Local(
            target_host=(
                'localhost',
                'localhost',
                'localhost',
            ),
            target_host_tags=None,
            base_root_path=self.host_base_path,
            host_dir_name=self.hostdir,
            exec_path=test.cdist_exec_path,
            configuration=configuration.get_config(section='GLOBAL'))

        link_test_local._create_conf_path_and_link_conf_dirs()

        our_type_dir = os.path.join(link_test_local.type_path, test_type)

        self.assertTrue(os.path.isdir(our_type_dir))
示例#2
0
    def setUp(self):
        self.local_dir = self.mkdtemp()

        self.local = local.Local(target_host=self.target_host,
                                 base_path=self.local_dir,
                                 exec_path=cdist.test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.remote_dir = self.mkdtemp()
        remote_exec = self.remote_exec
        remote_copy = self.remote_copy
        self.remote = remote.Remote(target_host=self.target_host,
                                    remote_exec=remote_exec,
                                    remote_copy=remote_copy,
                                    base_path=self.remote_dir)
        self.remote.create_files_dirs()

        self.code = code.Code(self.target_host, self.local, self.remote)

        self.cdist_type = core.CdistType(self.local.type_path,
                                         '__dump_environment')
        self.cdist_object = core.CdistObject(self.cdist_type,
                                             self.local.object_path,
                                             'whatever')
        self.cdist_object.create()
示例#3
0
文件: context.py 项目: xtaran/cdist
    def __init__(self,
                 target_host,
                 remote_copy,
                 remote_exec,
                 initial_manifest=False,
                 add_conf_dirs=None,
                 exec_path=sys.argv[0],
                 debug=False):

        self.debug = debug
        self.target_host = target_host
        self.exec_path = exec_path

        # Context logging
        self.log = logging.getLogger(self.target_host)
        self.log.addFilter(self)

        # Local temp directory
        # FIXME: if __cdist_out_dir can be given from the outside, the same directory will be used for all hosts
        if '__cdist_out_dir' in os.environ:
            self.out_path = os.environ['__cdist_out_dir']
            self.temp_dir = None
        else:
            self.temp_dir = tempfile.mkdtemp()
            self.out_path = os.path.join(self.temp_dir, "out")

        self.local = local.Local(self.target_host,
                                 self.out_path,
                                 self.exec_path,
                                 add_conf_dirs=add_conf_dirs)

        self.initial_manifest = (initial_manifest or os.path.join(
            self.local.manifest_path, "init"))

        self._init_remote(remote_copy, remote_exec)
示例#4
0
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        self.local_path = os.path.join(self.temp_dir, "local")
        hostdir = cdist.str_hash(self.target_host[0])
        base_root_path = os.path.join(self.local_path, hostdir)
        self.remote_base_path = os.path.join(self.temp_dir, "remote")
        os.makedirs(self.remote_base_path)

        self.local = local.Local(
            target_host=self.target_host,
            target_host_tags=self.target_host_tags,
            base_root_path=base_root_path,
            host_dir_name=hostdir,
            exec_path=test.cdist_exec_path,
            add_conf_dirs=[conf_dir],
        )

        self.local.create_files_dirs()

        self.remote = remote.Remote(target_host=self.target_host,
                                    remote_exec=self.remote_exec,
                                    remote_copy=self.remote_copy,
                                    base_path=self.remote_base_path)
        self.remote.create_files_dirs()

        self.explorer = explorer.Explorer(self.target_host, self.local,
                                          self.remote)
示例#5
0
文件: __init__.py 项目: evax/cdist
    def setUp(self):
        self.target_host = 'localhost'

        self.local_base_path = local_base_path
        self.out_path = self.mkdtemp()
        self.local = local.Local(self.target_host, self.local_base_path,
                                 self.out_path)
        self.local.create_directories()

        self.remote_base_path = self.mkdtemp()
        self.user = getpass.getuser()
        remote_exec = "ssh -o User=%s -q" % self.user
        remote_copy = "scp -o User=%s -q" % self.user
        self.remote = remote.Remote(self.target_host, self.remote_base_path,
                                    remote_exec, remote_copy)

        self.code = code.Code(self.target_host, self.local, self.remote)

        self.cdist_type = core.CdistType(self.local.type_path,
                                         '__dump_environment')
        self.cdist_object = core.CdistObject(self.cdist_type,
                                             self.local.object_path,
                                             'whatever')
        self.cdist_object.create()

        self.log = logging.getLogger("cdist")
示例#6
0
文件: __init__.py 项目: evax/cdist
 def setUp(self):
     self.temp_dir = self.mkdtemp()
     self.target_host = 'localhost'
     out_path = self.temp_dir
     _local_base_path = fixtures
     self.local = local.Local(self.target_host, _local_base_path, out_path)
     self.local.create_directories()
     self.local.link_emulator(cdist.test.cdist_exec_path)
     self.manifest = core.Manifest(self.target_host, self.local)
示例#7
0
    def setUp(self):

        target_host = 'localhost'
        self.temp_dir = self.mkdtemp()
        self.out_path = self.temp_dir

        self.local = local.Local(target_host=target_host,
                                 out_path=self.out_path,
                                 exec_path=test.cdist_exec_path)

        self.home_dir = os.path.join(os.environ['HOME'], ".cdist")
示例#8
0
文件: __init__.py 项目: evax/cdist
 def setUp(self):
     self.orig_environ = os.environ
     os.environ = os.environ.copy()
     self.temp_dir = self.mkdtemp()
     self.target_host = 'localhost'
     out_path = self.temp_dir
     self.local = local.Local(self.target_host, local_base_path, out_path)
     self.local.create_directories()
     self.local.link_emulator(cdist.test.cdist_exec_path)
     self.manifest = manifest.Manifest(self.target_host, self.local)
     self.log = logging.getLogger(self.target_host)
示例#9
0
文件: __init__.py 项目: zakkg3/cdist
    def setUp(self):
        # logging.root.setLevel(logging.TRACE)
        save_output_streams = False
        self.temp_dir = self.mkdtemp()

        self.local_dir = os.path.join(self.temp_dir, "local")
        self.hostdir = cdist.str_hash(self.target_host[0])
        self.host_base_path = os.path.join(self.local_dir, self.hostdir)
        os.makedirs(self.host_base_path)
        self.local = local.Local(target_host=self.target_host,
                                 target_host_tags=None,
                                 base_root_path=self.host_base_path,
                                 host_dir_name=self.hostdir,
                                 exec_path=cdist.test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir],
                                 save_output_streams=save_output_streams)
        self.local.create_files_dirs()

        self.remote_dir = self.mkdtemp()
        remote_exec = self.remote_exec
        remote_copy = self.remote_copy
        self.remote = remote.Remote(
            target_host=self.target_host,
            remote_exec=remote_exec,
            remote_copy=remote_copy,
            base_path=self.remote_dir,
            stdout_base_path=self.local.stdout_base_path,
            stderr_base_path=self.local.stderr_base_path,
            save_output_streams=save_output_streams)
        self.remote.create_files_dirs()

        self.code = code.Code(self.target_host, self.local, self.remote)

        self.manifest = manifest.Manifest(self.target_host, self.local)

        self.cdist_type = core.CdistType(self.local.type_path,
                                         '__write_to_stdout_and_stderr')
        self.cdist_object = core.CdistObject(self.cdist_type,
                                             self.local.object_path,
                                             self.local.object_marker_name, '')
        self.cdist_object.create()
        self.output_dirs = {
            'object': {
                'stdout': os.path.join(self.cdist_object.absolute_path,
                                       'stdout'),
                'stderr': os.path.join(self.cdist_object.absolute_path,
                                       'stderr'),
            },
            'init': {
                'stdout': os.path.join(self.local.base_path, 'stdout'),
                'stderr': os.path.join(self.local.base_path, 'stderr'),
            },
        }
示例#10
0
文件: __init__.py 项目: lamby/cdist
    def setUp(self):
        self.orig_environ = os.environ
        os.environ = os.environ.copy()

        self.temp_dir = self.mkdtemp()
        base_path = os.path.join(self.temp_dir, "out")

        self.local = local.Local(target_host=self.target_host,
                                 base_path=base_path,
                                 exec_path=test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])

        self.local.create_files_dirs()
示例#11
0
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        base_path = os.path.join(self.temp_dir, "out")
        hostdir = cdist.str_hash(self.target_host[0])
        host_base_path = os.path.join(base_path, hostdir)

        self.local = local.Local(target_host=self.target_host,
                                 base_root_path=host_base_path,
                                 host_dir_name=hostdir,
                                 exec_path=test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()
        self.manifest = core.Manifest(self.target_host, self.local)
示例#12
0
文件: __init__.py 项目: lamby/cdist
    def setUp(self):
        self.orig_environ = os.environ
        os.environ = os.environ.copy()
        self.temp_dir = self.mkdtemp()

        out_path = self.temp_dir
        self.local = local.Local(target_host=self.target_host,
                                 base_path=out_path,
                                 exec_path=cdist.test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.manifest = manifest.Manifest(self.target_host, self.local)
        self.log = logging.getLogger(self.target_host)
示例#13
0
文件: __init__.py 项目: lamby/cdist
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        handle, self.script = self.mkstemp(dir=self.temp_dir)
        os.close(handle)
        base_path = self.temp_dir

        self.local = local.Local(target_host=self.target_host,
                                 base_path=base_path,
                                 exec_path=test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.manifest = core.Manifest(self.target_host, self.local)
        self.env = self.manifest.env_initial_manifest(self.script)
        self.env['__cdist_object_marker'] = self.local.object_marker_name
示例#14
0
文件: local.py 项目: lamby/cdist
    def test_dist_conf_dir_linking(self):
        """Ensure that links are correctly created for types included in distribution"""

        test_type = "__file"

        link_test_local = local.Local(
            target_host='localhost',
            base_path=self.out_parent_path,
            exec_path=test.cdist_exec_path,
        )

        link_test_local._create_conf_path_and_link_conf_dirs()

        our_type_dir = os.path.join(link_test_local.type_path, test_type)

        self.assertTrue(os.path.isdir(our_type_dir))
示例#15
0
    def setUp(self):
        self.target_host = 'localhost'

        self.local_base_path = local_base_path
        self.out_path = self.mkdtemp()
        self.local = local.Local(self.target_host, self.local_base_path, self.out_path)
        self.local.create_directories()

        self.remote_base_path = self.mkdtemp()
        self.user = getpass.getuser()
        remote_exec = "ssh -o User=%s -q" % self.user
        remote_copy = "scp -o User=%s -q" % self.user
        self.remote = remote.Remote(self.target_host, self.remote_base_path, remote_exec, remote_copy)

        self.explorer = explorer.Explorer(self.target_host, self.local, self.remote)

        self.log = logging.getLogger(self.target_host)
示例#16
0
    def __init__(self,
                 target_host,
                 initial_manifest=False,
                 base_path=False,
                 exec_path=sys.argv[0],
                 debug=False):

        self.debug = debug

        self.target_host = target_host

        # Only required for testing
        self.exec_path = exec_path

        # Context logging
        self.log = logging.getLogger(self.target_host)
        self.log.addFilter(self)

        # Local base directory
        self.base_path = (base_path or os.path.abspath(
            os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)))

        # Local temp directory
        # FIXME: if __cdist_out_dir can be given from the outside, the same directory will be used for all hosts
        if '__cdist_out_dir' in os.environ:
            self.out_path = os.environ['__cdist_out_dir']
            self.temp_dir = None
        else:
            self.temp_dir = tempfile.mkdtemp()
            self.out_path = os.path.join(self.temp_dir, "out")

        self.local = local.Local(self.target_host, self.base_path,
                                 self.out_path)

        self.initial_manifest = (initial_manifest or os.path.join(
            self.local.manifest_path, "init"))

        # Remote
        self.remote_base_path = os.environ.get('__cdist_remote_out_dir',
                                               "/var/lib/cdist")
        self.remote_exec = os.environ.setdefault('__remote_exec',
                                                 "ssh -o User=root -q")
        self.remote_copy = os.environ.setdefault('__remote_copy',
                                                 "scp -o User=root -q")
        self.remote = remote.Remote(self.target_host, self.remote_base_path,
                                    self.remote_exec, self.remote_copy)
示例#17
0
    def setUp(self):
        self.temp_dir = self.mkdtemp()
        base_path = self.temp_dir
        hostdir = cdist.str_hash(self.target_host[0])
        host_base_path = os.path.join(base_path, hostdir)
        handle, self.script = self.mkstemp(dir=self.temp_dir)
        os.close(handle)

        self.local = local.Local(target_host=self.target_host,
                                 base_root_path=host_base_path,
                                 host_dir_name=hostdir,
                                 exec_path=test.cdist_exec_path,
                                 add_conf_dirs=[conf_dir])
        self.local.create_files_dirs()

        self.manifest = core.Manifest(self.target_host, self.local)
        self.env = self.manifest.env_initial_manifest(self.script)
        self.env['__cdist_object_marker'] = self.local.object_marker_name
示例#18
0
 def setUp(self):
     self.orig_environ = os.environ
     os.environ = os.environ.copy()
     self.temp_dir = self.mkdtemp()
     handle, self.script = self.mkstemp(dir=self.temp_dir)
     os.close(handle)
     self.target_host = 'localhost'
     out_path = self.temp_dir
     self.local = local.Local(self.target_host, local_base_path, out_path)
     self.local.create_directories()
     self.env = {
         'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']),
         '__target_host': self.target_host,
         '__global': self.local.out_path,
         '__cdist_type_base_path': self.local.type_path, # for use in type emulator
         '__manifest': self.local.manifest_path,
         '__cdist_manifest': self.script,
     }
示例#19
0
    def setUp(self):

        target_host = (
            'localhost',
            'localhost',
            'localhost',
        )
        self.temp_dir = self.mkdtemp()
        self.out_parent_path = self.temp_dir
        self.hostdir = cdist.str_hash(target_host[0])
        self.host_base_path = op.join(self.out_parent_path, self.hostdir)
        self.out_path = op.join(self.host_base_path, "data")

        self.local = local.Local(target_host=target_host,
                                 base_root_path=self.host_base_path,
                                 host_dir_name=self.hostdir,
                                 exec_path=test.cdist_exec_path)

        self.home_dir = os.path.join(os.environ['HOME'], ".cdist")
示例#20
0
文件: local.py 项目: xuanhan863/cdist
 def setUp(self):
     self.temp_dir = self.mkdtemp()
     target_host = 'localhost'
     self.out_path = self.temp_dir
     self.base_path = local_base_path
     self.local = local.Local(target_host, self.base_path, self.out_path)