def test_write_config_with_specify_config_path(self): cfg = {'port': 27017, 'objcheck': 'true'} fd_key, file_path = tempfile.mkstemp() os.close(fd_key) config_path = process.write_config(cfg, file_path) self.assertEqual(file_path, config_path) process.cleanup_mprocess(config_path, cfg)
def test_cleanup_process(self): fd_cfg, config_path = tempfile.mkstemp() fd_key, key_file = tempfile.mkstemp() fd_log, log_path = tempfile.mkstemp() db_path = tempfile.mkdtemp() self.assertTrue(os.path.exists(config_path)) self.assertTrue(os.path.exists(key_file)) self.assertTrue(os.path.exists(log_path)) self.assertTrue(os.path.exists(db_path)) with os.fdopen(fd_cfg, 'w') as fd: fd.write('keyFile={key_file}\n' 'logPath={log_path}\n' 'dbpath={db_path}'.format(**locals())) for fd in (fd_cfg, fd_key, fd_log): try: os.close(fd) except OSError: # fd_cfg may be closed already if fdopen() didn't raise pass cfg = {'keyFile': key_file, 'logPath': log_path, 'dbpath': db_path} process.cleanup_mprocess(config_path, cfg) self.assertFalse(os.path.exists(config_path)) self.assertFalse(os.path.exists(key_file)) self.assertFalse(os.path.exists(log_path)) self.assertFalse(os.path.exists(db_path))
def tearDown(self): for s in self.sockets: self.sockets[s].close() if self.cfg: process.cleanup_mprocess('', self.cfg) for item in self.tmp_files: if os.path.exists(item): os.remove(item)
def test_write_config(self): cfg = {'port': 27017, 'objcheck': 'true'} config_path = process.write_config(cfg) self.assertTrue(os.path.exists(config_path)) config_data = open(config_path, 'r').read() self.assertTrue('port=27017' in config_data) self.assertTrue('objcheck=true' in config_data) process.cleanup_mprocess(config_path, cfg)
def test_write_config(self): cfg = {'port': 27017, 'objcheck': 'true'} config_path = process.write_config(cfg) self.assertTrue(os.path.exists(config_path)) with open(config_path, 'r') as fd: config_data = fd.read() self.assertTrue('port=27017' in config_data) self.assertTrue('objcheck=true' in config_data) process.cleanup_mprocess(config_path, cfg)
def cleanup(self): """remove server data""" process.cleanup_mprocess(self.config_path, self.cfg)