예제 #1
0
 def test_output_logs_parsed_when_appending(self):
     """When output configuration is parsed when appending to a file."""
     self.assertEqual(
         ['/my.log', '/test.log'],
         sorted(util.get_config_logfiles({
             'def_log_file': '/my.log',
             'output': {'all': '>> /test.log'}})))
예제 #2
0
def remove_artifacts(remove_logs, remove_seed=False):
    """Helper which removes artifacts dir and optionally log files.

    @param: remove_logs: Boolean. Set True to delete the cloud_dir path. False
        preserves them.
    @param: remove_seed: Boolean. Set True to also delete seed subdir in
        paths.cloud_dir.
    @returns: 0 on success, 1 otherwise.
    """
    init = Init(ds_deps=[])
    init.read_cfg()
    if remove_logs:
        for log_file in get_config_logfiles(init.cfg):
            del_file(log_file)

    if not os.path.isdir(init.paths.cloud_dir):
        return 0  # Artifacts dir already cleaned
    seed_path = os.path.join(init.paths.cloud_dir, 'seed')
    for path in glob.glob('%s/*' % init.paths.cloud_dir):
        if path == seed_path and not remove_seed:
            continue
        try:
            if os.path.isdir(path) and not is_link(path):
                del_dir(path)
            else:
                del_file(path)
        except OSError as e:
            error('Could not remove {0}: {1}'.format(path, str(e)))
            return 1
    return 0
예제 #3
0
 def test_output_logs_parsed_when_teeing_files(self):
     """When output configuration is parsed when teeing files."""
     self.assertEqual(
         ['/himom.log', '/my.log'],
         sorted(util.get_config_logfiles({
             'def_log_file': '/my.log',
             'output': {'all': '|tee -a /himom.log'}})))
예제 #4
0
파일: clean.py 프로젝트: delphix/cloud-init
def remove_artifacts(remove_logs, remove_seed=False):
    """Helper which removes artifacts dir and optionally log files.

    @param: remove_logs: Boolean. Set True to delete the cloud_dir path. False
        preserves them.
    @param: remove_seed: Boolean. Set True to also delete seed subdir in
        paths.cloud_dir.
    @returns: 0 on success, 1 otherwise.
    """
    init = Init(ds_deps=[])
    init.read_cfg()
    if remove_logs:
        for log_file in get_config_logfiles(init.cfg):
            del_file(log_file)

    if not os.path.isdir(init.paths.cloud_dir):
        return 0  # Artifacts dir already cleaned
    seed_path = os.path.join(init.paths.cloud_dir, "seed")
    for path in glob.glob("%s/*" % init.paths.cloud_dir):
        if path == seed_path and not remove_seed:
            continue
        try:
            if os.path.isdir(path) and not is_link(path):
                del_dir(path)
            else:
                del_file(path)
        except OSError as e:
            error("Could not remove {0}: {1}".format(path, str(e)))
            return 1
    return 0
예제 #5
0
 def test_output_logs_parsed_when_appending(self):
     """When output configuration is parsed when appending to a file."""
     self.assertEqual(
         ['/my.log', '/test.log'],
         sorted(util.get_config_logfiles({
             'def_log_file': '/my.log',
             'output': {'all': '>> /test.log'}})))
예제 #6
0
 def test_output_logs_parsed_when_teeing_files(self):
     """When output configuration is parsed when teeing files."""
     self.assertEqual(
         ['/himom.log', '/my.log'],
         sorted(util.get_config_logfiles({
             'def_log_file': '/my.log',
             'output': {'all': '|tee -a /himom.log'}})))
예제 #7
0
 def test_default_log_file_present(self):
     """When default_log_file is set get_config_logfiles finds it."""
     self.assertEqual(
         ['/my.log'],
         util.get_config_logfiles({'def_log_file': '/my.log'}))
예제 #8
0
 def test_empty_cfg_returns_empty_list(self):
     """An empty config passed to get_config_logfiles returns empty list."""
     self.assertEqual([], util.get_config_logfiles(None))
     self.assertEqual([], util.get_config_logfiles({}))
예제 #9
0
 def test_default_log_file_present(self):
     """When default_log_file is set get_config_logfiles finds it."""
     self.assertEqual(
         ['/my.log'],
         util.get_config_logfiles({'def_log_file': '/my.log'}))
예제 #10
0
 def test_empty_cfg_returns_empty_list(self):
     """An empty config passed to get_config_logfiles returns empty list."""
     self.assertEqual([], util.get_config_logfiles(None))
     self.assertEqual([], util.get_config_logfiles({}))