Ejemplo n.º 1
0
 def test_mprocess_fail(self):
     fd_cfg, config_path = tempfile.mkstemp()
     os.close(fd_cfg)
     self.tmp_files.append(config_path)
     self.assertRaises(OSError, process.mprocess, 'fake-process_',
                       config_path, None, 30)
     process.write_config({"fake": True}, config_path)
     self.assertRaises(TimeoutError, process.mprocess, self.bin_path,
                       config_path, None, 30)
 def test_mprocess_fail(self):
     fd_cfg, config_path = tempfile.mkstemp()
     os.close(fd_cfg)
     self.tmp_files.append(config_path)
     self.assertRaises(OSError, process.mprocess,
                       'fake-process_', config_path, None, 30)
     process.write_config({"fake": True}, config_path)
     self.assertRaises(TimeoutError, process.mprocess,
                       'mongod', config_path, None, 30)
Ejemplo n.º 3
0
    def __init_mongod(self, params, add_auth=False):
        cfg = self.mongod_default.copy()
        cfg.update(params)

        # create db folder
        cfg['dbpath'] = self.__init_db(cfg.get('dbpath', None))

        if add_auth:
            cfg['auth'] = True
            if self.auth_key:
                cfg['keyFile'] = self.key_file

        # create logpath: goes in dbpath by default under process name + ".log"
        logpath = cfg.setdefault('logpath',
                                 os.path.join(cfg['dbpath'], 'mongod.log'))
        self.__init_logpath(logpath)

        # find open port
        if 'port' not in cfg:
            cfg['port'] = process.PortPool().port(check=True)

        self.__init_test_commands(cfg)

        if self.enable_majority_read_concern and self.version >= (3, 2):
            cfg['enableMajorityReadConcern'] = True

        return process.write_config(cfg), cfg
 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)
Ejemplo n.º 5
0
    def __init_mongod(self, params, add_auth=False):
        cfg = self.mongod_default.copy()
        cfg.update(params)

        # create db folder
        cfg['dbpath'] = self.__init_db(cfg.get('dbpath', None))

        if add_auth:
            cfg['auth'] = True
            if self.auth_key:
                cfg['keyFile'] = self.key_file

        # create logpath: goes in dbpath by default under process name + ".log"
        logpath = cfg.setdefault(
            'logpath', os.path.join(cfg['dbpath'], 'mongod.log'))
        self.__init_logpath(logpath)

        # find open port
        if 'port' not in cfg:
            cfg['port'] = process.PortPool().port(check=True)

        self.__init_test_commands(cfg)

        if self.enable_majority_read_concern and self.version >= (3, 2):
            cfg['enableMajorityReadConcern'] = True

        return process.write_config(cfg), cfg
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 def test_repair(self):
     port = self.pp.port(check=True)
     # Assume we're testing on 64-bit machines.
     self.cfg['nojournal'] = True
     lock_file = os.path.join(self.cfg['dbpath'], 'mongod.lock')
     config_path = process.write_config(self.cfg)
     self.tmp_files.append(config_path)
     proc, host = process.mprocess(self.bin_path,
                                   config_path,
                                   port=port,
                                   timeout=60)
     self.assertTrue(os.path.exists(lock_file))
     if platform.system() == 'Windows':
         # mongod.lock cannot be read by any external process on Windows.
         with self.assertRaises(IOError):
             open(lock_file, 'r')
     else:
         with open(lock_file, 'r') as fd:
             self.assertGreater(len(fd.read()), 0)
     proc.terminate()
     proc.communicate()
     process.repair_mongo(self.bin_path, self.cfg['dbpath'])
     with open(lock_file, 'r') as fd:
         contents = fd.read()
         self.assertEqual(len(contents), 0,
                          "lock_file contains: " + contents)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 def restart(self, timeout=300, config_callback=None):
     """restart server: stop() and start()
     return status of start command
     """
     self.stop()
     if config_callback:
         self.cfg = config_callback(self.cfg.copy())
     self.config_path = process.write_config(self.cfg)
     return self.start(timeout)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 def restart(self, timeout=300, config_callback=None):
     """restart server: stop() and start()
     return status of start command
     """
     self.stop()
     if config_callback:
         self.cfg = config_callback(self.cfg.copy())
     self.config_path = process.write_config(self.cfg)
     return self.start(timeout)
Ejemplo n.º 12
0
 def test_read_config(self):
     cfg = {
         "noprealloc": True,
         "smallfiles": False,
         "oplogSize": 10,
         "other": "some string"
     }
     config_path = process.write_config(cfg)
     self.tmp_files.append(config_path)
     self.assertEqual(process.read_config(config_path), cfg)
Ejemplo n.º 13
0
 def test_mprocess(self):
     port = self.pp.port(check=True)
     config_path = process.write_config(self.cfg)
     self.tmp_files.append(config_path)
     result = process.mprocess(self.bin_path, config_path, port=port)
     self.assertTrue(isinstance(result, tuple))
     proc, host = result
     self.assertTrue(isinstance(proc, subprocess.Popen))
     self.assertTrue(isinstance(host, str))
     process.kill_mprocess(proc)
 def test_mprocess(self):
     port = self.pp.port(check=True)
     config_path = process.write_config(self.cfg)
     self.tmp_files.append(config_path)
     result = process.mprocess(self.bin_path, config_path, port=port, timeout=60)
     self.assertTrue(isinstance(result, tuple))
     proc, host = result
     self.assertTrue(isinstance(proc, subprocess.Popen))
     self.assertTrue(isinstance(host, str))
     process.kill_mprocess(proc)
 def test_mprocess_busy_port(self):
     config_path = process.write_config(self.cfg)
     self.tmp_files.append(config_path)
     port = self.pp.port()
     self.listen_port(port, max_connection=0)
     proc, host = process.mprocess(self.executable, config_path,
                                   port=port, timeout=2)
     self.assertTrue(proc.pid > 0)
     self.assertEqual(host, self.hostname + ':' + str(port))
     self.sockets.pop(port).close()
     self.assertRaises(OSError, process.mprocess,
                       self.executable, '', port, 1)
Ejemplo n.º 16
0
 def test_mprocess_busy_port(self):
     config_path = process.write_config(self.cfg)
     self.tmp_files.append(config_path)
     port = self.pp.port()
     self.listen_port(port, max_connection=0)
     proc, host = process.mprocess(self.executable, config_path,
                                   port=port, timeout=2)
     self.assertTrue(proc.pid > 0)
     self.assertEqual(host, self.hostname + ':' + str(port))
     self.sockets.pop(port).close()
     self.assertRaises(OSError, process.mprocess,
                       self.executable, '', port, 1)
Ejemplo n.º 17
0
    def __init_mongos(self, params, ssl):
        cfg = params.copy()
        cfg.update(ssl)

        self.__init_logpath(cfg.get('logpath', None))

        # use keyFile
        if self.auth_key:
            cfg['keyFile'] = self.__init_auth_key(self.auth_key, tempfile.mkdtemp())

        if 'port' not in cfg:
            cfg['port'] = process.PortPool().port(check=True)

        return process.write_config(cfg), cfg
Ejemplo n.º 18
0
 def test_mprocess_timeout(self):
     port = self.pp.port()
     cfg = self.cfg.copy()
     cfg['journal'] = True
     config_path = process.write_config(cfg)
     self.tmp_files.append(config_path)
     proc, host = process.mprocess(self.bin_path, config_path, port, 0)
     self.assertTrue(isinstance(proc, subprocess.Popen))
     self.assertTrue(isinstance(host, str))
     process.kill_mprocess(proc)
     if platform.system() == 'Windows':
         raise SkipTest("Cannot test mongod startup timeout on Windows.")
     with self.assertRaises(TimeoutError):
         result = process.mprocess(self.bin_path, config_path, port, 0.1)
         print(result)
Ejemplo n.º 19
0
 def test_mprocess_timeout(self):
     port = self.pp.port()
     cfg = self.cfg.copy()
     cfg['journal'] = True
     config_path = process.write_config(cfg)
     self.tmp_files.append(config_path)
     proc, host = process.mprocess(self.bin_path, config_path, port, 0)
     self.assertTrue(isinstance(proc, subprocess.Popen))
     self.assertTrue(isinstance(host, str))
     process.kill_mprocess(proc)
     if platform.system() == 'Windows':
         raise SkipTest("Cannot test mongod startup timeout on Windows.")
     with self.assertRaises(TimeoutError):
         result = process.mprocess(self.bin_path, config_path, port, 0.1)
         print(result)
Ejemplo n.º 20
0
 def test_repair(self):
     port = self.pp.port(check=True)
     # Assume we're testing on 64-bit machines.
     self.cfg['nojournal'] = True
     lock_file = os.path.join(self.cfg['dbpath'], 'mongod.lock')
     config_path = process.write_config(self.cfg)
     self.tmp_files.append(config_path)
     proc, host = process.mprocess(self.bin_path, config_path, port=port, timeout=60)
     self.assertTrue(os.path.exists(lock_file))
     if platform.system() == 'Windows':
         # mongod.lock cannot be read by any external process on Windows.
         with self.assertRaises(IOError):
             open(lock_file, 'r')
     else:
         self.assertTrue(len(open(lock_file, 'r').read()) > 0)
     proc.terminate()
     process.repair_mongo(self.bin_path, self.cfg['dbpath'])
     self.assertFalse(len(open(lock_file, 'r').read()) > 0, "lock_file contains: {0}".format(open(lock_file, 'r').read()))
Ejemplo n.º 21
0
    def __init_mongos(self, params):
        cfg = params.copy()

        log_path = cfg.setdefault(
            'logpath',
            os.path.join(tempfile.mkdtemp(prefix='mongo-'), 'mongos.log'))
        self.__init_logpath(log_path)

        # use keyFile
        if self.auth_key:
            cfg['keyFile'] = self.key_file

        if 'port' not in cfg:
            cfg['port'] = process.PortPool().port(check=True)

        self.__init_test_commands(cfg)

        return process.write_config(cfg), cfg
Ejemplo n.º 22
0
    def __init_mongos(self, params):
        cfg = params.copy()

        log_path = cfg.setdefault(
            'logpath',
            os.path.join(orchestration_mkdtemp(prefix='mongo-'), 'mongos.log'))
        self.__init_logpath(log_path)

        # use keyFile
        if self.auth_key:
            cfg['keyFile'] = self.key_file

        if 'port' not in cfg:
            cfg['port'] = process.PortPool().port(check=True)

        self.__init_test_commands(cfg)

        return process.write_config(cfg), cfg
Ejemplo n.º 23
0
    def __init_mongod(self, params, add_auth=False):
        cfg = self.mongod_default.copy()
        cfg.update(params)

        # create db folder
        cfg['dbpath'] = self.__init_db(cfg.get('dbpath', None))

        if add_auth:
            cfg['auth'] = True
            if self.auth_key:
                cfg['keyFile'] = self.key_file

        # create logpath: goes in dbpath by default under process name + ".log"
        logpath = cfg.setdefault('logpath',
                                 os.path.join(cfg['dbpath'], 'mongod.log'))
        self.__init_logpath(logpath)

        # find open port
        if 'port' not in cfg:
            cfg['port'] = process.PortPool().port(check=True)

        self.__init_test_commands(cfg)
        self.__init_compressors(cfg)

        # Read concern majority requires MongoDB >= 3.2, WiredTiger storage
        # engine, and protocol version 1:
        # https://docs.mongodb.com/manual/reference/read-concern/
        if ('enableMajorityReadConcern' not in cfg
                and self.enable_majority_read_concern and self.version >=
            (3, 2)):
            if (cfg.get('storageEngine', 'wiredTiger') == 'wiredTiger'
                    and cfg.get('protocolVersion', 1) == 1):
                cfg['enableMajorityReadConcern'] = True
            else:
                logger.info(
                    'Not adding enableMajorityReadConcern because '
                    'storageEngine=%r and protocolVersion=%r is '
                    'incompatible' %
                    (cfg.get('storageEngine'), cfg.get('protocolVersion')))

        return process.write_config(cfg), cfg
Ejemplo n.º 24
0
    def __init_mongod(self, params, add_auth=False):
        cfg = self.mongod_default.copy()
        cfg.update(params)

        # create db folder
        cfg['dbpath'] = self.__init_db(cfg.get('dbpath', None))

        if add_auth:
            cfg['auth'] = True
            if self.auth_key:
                cfg['keyFile'] = self.key_file

        # create logpath: goes in dbpath by default under process name + ".log"
        logpath = cfg.setdefault(
            'logpath', os.path.join(cfg['dbpath'], 'mongod.log'))
        self.__init_logpath(logpath)

        # find open port
        if 'port' not in cfg:
            cfg['port'] = process.PortPool().port(check=True)

        self.__init_config_params(cfg)

        # Read concern majority requires MongoDB >= 3.2, WiredTiger storage
        # engine, and protocol version 1:
        # https://docs.mongodb.com/manual/reference/read-concern/
        if ('enableMajorityReadConcern' not in cfg
                and self.enable_majority_read_concern
                and self.version >= (3, 2)):
            if (cfg.get('storageEngine', 'wiredTiger') == 'wiredTiger'
                    and cfg.get('protocolVersion', 1) == 1):
                cfg['enableMajorityReadConcern'] = True
            else:
                logger.info('Not adding enableMajorityReadConcern because '
                            'storageEngine=%r and protocolVersion=%r is '
                            'incompatible' % (cfg.get('storageEngine'),
                                              cfg.get('protocolVersion')))

        return process.write_config(cfg), cfg
Ejemplo n.º 25
0
    def __init_mongod(self, params, ssl):
        cfg = self.mongod_default.copy()
        cfg.update(params)
        cfg.update(ssl)

        # create db folder
        cfg['dbpath'] = self.__init_db(cfg.get('dbpath', None))

        # use keyFile
        if self.auth_key:
            cfg['auth'] = True
            cfg['keyFile'] = self.__init_auth_key(self.auth_key, cfg['dbpath'])

        if self.login:
            cfg['auth'] = True

        # create logpath
        self.__init_logpath(cfg.get('logpath', None))

        # find open port
        if 'port' not in cfg:
            cfg['port'] = process.PortPool().port(check=True)

        return process.write_config(cfg), cfg
 def test_read_config(self):
     cfg = {"noprealloc": True, "smallfiles": False, "oplogSize": 10, "other": "some string"}
     config_path = process.write_config(cfg)
     self.tmp_files.append(config_path)
     self.assertEqual(process.read_config(config_path), cfg)