本文整理汇总了Python中mongo_orchestration.servers.Server.restart方法的典型用法代码示例。如果您正苦于以下问题:Python Server.restart方法的具体用法?Python Server.restart怎么用?Python Server.restart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongo_orchestration.servers.Server
的用法示例。
在下文中一共展示了Server.restart方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ServerAuthTestCase
# 需要导入模块: from mongo_orchestration.servers import Server [as 别名]
# 或者: from mongo_orchestration.servers.Server import restart [as 别名]
class ServerAuthTestCase(unittest.TestCase):
def setUp(self):
PortPool().change_range()
self.mongod = os.path.join(os.environ.get('MONGOBIN', ''), 'mongod')
self.server = Server(self.mongod, {}, auth_key='secret', login='admin', password='admin')
self.server.start()
def tearDown(self):
if hasattr(self, 'server'):
self.server.stop()
self.server.cleanup()
def test_mongos(self):
self.server.stop()
self.server.cleanup()
self.server = Server(self.mongod, {'configsvr': True}, auth_key='secret')
self.server.start(30)
mongos = os.path.join(os.environ.get('MONGOBIN', ''), 'mongos')
self.server2 = Server(mongos, {'configdb': self.server.info()['uri']}, auth_key='secret', login='admin', password='admin')
self.server2.start()
for server in (self.server, self.server2):
c = pymongo.MongoClient(server.host, server.port)
self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
self.assertTrue(c.admin.authenticate('admin', 'admin'))
self.assertTrue(isinstance(c.admin.collection_names(), list))
self.assertTrue(c.admin.logout() is None)
self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
self.server2.stop()
self.server2.cleanup()
def test_auth_connection(self):
self.assertTrue(isinstance(self.server.connection.admin.collection_names(), list))
c = pymongo.MongoClient(self.server.host, self.server.port)
self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
self.server.restart()
c = pymongo.MongoClient(self.server.host, self.server.port)
self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
def test_auth_admin(self):
c = pymongo.MongoClient(self.server.host, self.server.port)
self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
self.assertTrue(c.admin.authenticate('admin', 'admin'))
self.assertTrue(isinstance(c.admin.collection_names(), list))
self.assertTrue(c.admin.logout() is None)
self.assertRaises(pymongo.errors.OperationFailure, c.admin.collection_names)
def test_auth_collection(self):
c = pymongo.MongoClient(self.server.host, self.server.port)
self.assertTrue(c.admin.authenticate('admin', 'admin'))
db = c.test_server_auth
db.add_user('user', 'userpass', roles=['readWrite'])
c.admin.logout()
self.assertTrue(db.authenticate('user', 'userpass'))
self.assertTrue(db.foo.insert({'foo': 'bar'}, safe=True, wtimeout=1000))
self.assertTrue(isinstance(db.foo.find_one(), dict))
db.logout()
self.assertRaises(pymongo.errors.OperationFailure, db.foo.find_one)
示例2: ServerTestCase
# 需要导入模块: from mongo_orchestration.servers import Server [as 别名]
# 或者: from mongo_orchestration.servers.Server import restart [as 别名]
class ServerTestCase(unittest.TestCase):
def setUp(self):
PortPool().change_range()
self.mongod = os.path.join(os.environ.get('MONGOBIN', ''), 'mongod')
self.server = Server(self.mongod, {})
def tearDown(self):
if hasattr(self, 'server'):
self.server.stop()
self.server.cleanup()
def test_server(self):
self.assertTrue(isinstance(self.server, Server))
def test_init_path(self):
self.server.cleanup()
mongod = os.path.join(os.environ.get('MONGOBIN', ''), 'mongod')
log_dir = os.path.join(tempfile.gettempdir(), os.path.split(tempfile.mktemp())[-1])
log_path = tempfile.mktemp(dir=log_dir)
db_path = os.path.join(tempfile.gettempdir(), os.path.split(tempfile.mktemp())[-1])
self.assertFalse(os.path.exists(log_dir))
self.assertFalse(os.path.exists(db_path))
self.server = Server(mongod, {'logpath': log_path, 'dbpath': db_path})
self.assertTrue(os.path.exists(log_dir))
self.assertTrue(os.path.exists(db_path))
def test_mongos(self):
self.server.cleanup()
self.server = Server(self.mongod, {'configsvr': True})
self.server.start(30)
mongos = os.path.join(os.environ.get('MONGOBIN', ''), 'mongos')
self.server2 = Server(mongos, {'configdb': self.server.info()['uri']})
self.assertTrue(self.server2.start())
self.assertTrue(self.server2.info()['statuses'].get('mongos', False))
self.server2.stop()
self.server2.cleanup()
def test_run_command(self):
self.server.start(30)
def test_info(self):
self.server.start(30)
info = self.server.info()
for item in ("uri", "mongodb_uri", "statuses", "serverInfo", "procInfo", "orchestration"):
self.assertTrue(item in info)
self.assertTrue(info['mongodb_uri'].find(info['uri']))
self.assertTrue(info['mongodb_uri'].find('mongodb://') == 0)
fd_log, log_path = tempfile.mkstemp()
os.close(fd_log)
db_path = tempfile.mkdtemp()
params = {'logpath': log_path, 'dbpath': db_path}
server2 = Server(self.mongod, params)
server2.start()
info2 = server2.info()
for param, value in params.items():
self.assertTrue(info2['procInfo']['params'].get(param, value) == value)
server2.stop()
info = server2.info()
self.assertEqual(len(info['serverInfo']), 0)
self.assertEqual(len(info['statuses']), 0)
self.assertEqual(info['orchestration'], 'servers')
server2.cleanup()
def test_command(self):
self.assertRaises(pymongo.errors.PyMongoError, self.server.run_command, 'serverStatus', None, False)
self.server.start(30)
self.assertEqual(self.server.run_command('serverStatus', arg=None, is_eval=False).get('ok', -1), 1)
self.assertEqual(self.server.run_command('db.getName()', arg=None, is_eval=True), 'admin')
def test_start(self):
self.assertNotIn('pid', self.server.info()['procInfo'])
self.assertTrue(self.server.start(30))
self.assertTrue(self.server.info()['procInfo']['pid'] > 0)
fake_server = Server('fake_proc_', {})
self.assertRaises(OSError, fake_server.start, 5)
fake_server.cleanup()
def test_start_with_repair(self):
self.server.cleanup()
self.server = Server(self.mongod, {"journal": False})
self.server.start(30)
os.kill(self.server.pid, 9)
self.assertTrue(self.server._is_locked)
self.assertTrue(self.server.start(20))
def test_stop(self):
self.assertTrue(self.server.start(60))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server = self.server.hostname.split(':')[0]
s.connect((server, self.server.cfg['port']))
self.assertTrue(self.server.stop())
self.assertRaises(socket.error, s.connect, (server, self.server.cfg['port']))
def test_restart(self):
self.assertTrue(self.server.start(30))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server = self.server.hostname.split(':')[0]
s.connect((server, self.server.cfg['port']))
#.........这里部分代码省略.........