def having_a_running_server(step): world.farm = Farm.get(CONF.main.farm_id) world.server = None for server in world.farm.servers: if server.status == ServerStatus.RUNNING: world.server = server break world.assert_not_exist(world.server, 'Not see running server')
def assert_shard_status(step, serv_count): serv_count = int(serv_count) world.farm.servers.reload() server = None for serv in world.farm.servers: if serv.status == 'Running' and serv.role_id == world.mongodb_role.role_id: if serv.cluster_position == '0-0': server = serv LOG.info('Found server %s with cluster position %s' % (server.id, serv.cluster_position)) break world.assert_not_exist(server, 'Not find server with index 0-0') conn = world.db.get_connection(server, 27017) LOG.info('Create mongo connection to %s' % server.id) cur = conn.config.shards.find() rs_list = set([rs['host'].split('/')[0][-1] for rs in cur]) LOG.info('Get replicaset status and it %s' % rs_list) world.assert_not_equal(serv_count, len(rs_list), 'Replicaset count is not equal, see %s, but need %s' % (len(rs_list), serv_count))
def assert_check_replicaset(step, slaves, serv_ind): world.farm.servers.reload() server = None serv_ind = int(serv_ind) - 1 for serv in world.farm.servers: if serv.status == 'Running' and serv.role_id == world.mongodb_role.role_id: if int(serv.cluster_position[0]) == serv_ind: server = serv LOG.info('Found server %s with cluster position %s' % (server.id, serv.cluster_position)) break world.assert_not_exist(server, 'Not find shard server %s' % serv_ind) slaves = slaves.split(',') mongo = pymongo.Connection(server.public_ip, 27018, read_preference=pymongo.ReadPreference.SECONDARY) mongo.admin.authenticate('scalr', world.farm.db_info('mongodb')['password']) members = [member['name'].split('mongo')[1].split(':')[0][1:] for member in mongo.admin.command('replSetGetStatus')['members']] LOG.info('Members in replicaset %s are %s' % (serv_ind, ','.join(members))) for s in slaves: world.assert_not_in(s, members, 'Member %s not in replicaset, all members: %s' % (s, members))
def check_master(step, serv_as): server = getattr(world, serv_as) db_role = world.get_role() res = db_role.db.check_master(server) world.assert_not_exist(res, '%s is not master' % server.id) LOG.info('Master checked. %s is master. ' % serv_as)
def check_master(step, serv_as): server = getattr(world, serv_as) res = world.db.check_master(server) world.assert_not_exist(res, '%s is not master' % server.id)