def wrapper(*args, **kwargs): directory_existed = False if not functional: old_vdsm_hooks = constants.P_VDSM_HOOKS constants.P_VDSM_HOOKS = tempfile.mkdtemp() hook_path = constants.P_VDSM_HOOKS + '/' + hook_dir try: os.mkdir(hook_path) except OSError as mkdir_error: if mkdir_error.errno == errno.EEXIST: directory_existed = True else: raise cookie_file = _createHookScript(hook_path, hook_name, hook_script) output = None try: kwargs['hook_cookiefile'] = cookie_file output = test_function(*args, **kwargs) finally: if directory_existed: utils.rmFile(hook_path + '/' + hook_name) else: utils.rmTree(hook_path) utils.rmFile(cookie_file) if not functional: constants.P_VDSM_HOOKS = old_vdsm_hooks return output
def tearDown(self): self.patch.revert() utils.rmTree(self._test_dir)