Example #1
0
    def wait_for_mc_stats_no_timeout(master,
                                     bucket,
                                     stat_key,
                                     stat_value,
                                     timeout_in_seconds=-1,
                                     verbose=True):
        log = logger.get("infra")
        log.info(
            "Waiting for bucket {0} stat : {1} to match {2} on {3}".format(
                bucket, stat_key, stat_value, master.ip))
        # keep retrying until reaches the server
        stats = dict()
        while not stats:
            try:
                c = MemcachedClient(master.ip, constants.memcached_port)
                c.sasl_auth_plain(bucket, '')
                stats = c.stats()
            except Exception as e:
                stats = dict()
                sleep(2,
                      "Exception: %s. Will retry.." % str(e),
                      log_type="infra")
            finally:
                c.close()

        while str(stats[stat_key]) != str(stat_value):
            c = MemcachedClient(master.ip, constants.memcached_port)
            c.sasl_auth_plain(bucket, '')
            stats = c.stats()
            c.close()
            if verbose:
                log.info("{0} : {1}".format(stat_key, stats[stat_key]))
            sleep(5, log_type="infra")
        return True
    def wait_for_mc_stats_no_timeout(master, bucket, stat_key, stat_value, timeout_in_seconds=-1, verbose=True):
        log.info(
            "waiting for bucket {0} stat : {1} to match {2} on {3}".format(bucket, stat_key, stat_value, master.ip)
        )
        # keep retrying until reaches the server
        stats = {}
        while not stats:
            try:
                c = MemcachedClient(master.ip, 11210)
                c.sasl_auth_plain(bucket, "")
                stats = c.stats()
            except Exception as e:
                log.info("Exception: {0}, retry in 2 seconds ...".format(str(e)))
                stats = {}
                time.sleep(2)
            finally:
                c.close()

        while str(stats[stat_key]) != str(stat_value):
            c = MemcachedClient(master.ip, 11210)
            c.sasl_auth_plain(bucket, "")
            stats = c.stats()
            c.close()
            if verbose:
                log.info("{0} : {1}".format(stat_key, stats[stat_key]))
            time.sleep(5)
        return True
Example #3
0
    def wait_for_mc_stats_no_timeout(master,
                                     bucket,
                                     stat_key,
                                     stat_value,
                                     timeout_in_seconds=-1,
                                     verbose=True):
        log.info("waiting for bucket {0} stat : {1} to match {2} on {3}".format(bucket, stat_key, \
                                                                                stat_value, master.ip))
        # keep retrying until reaches the server
        stats = {}
        while not stats:
            try:
                c = MemcachedClient(master.ip, 11210)
                c.sasl_auth_plain(bucket, '')
                stats = c.stats()
            except Exception as e:
                log.info("Exception: {0}, retry in 2 seconds ...".format(
                    str(e)))
                stats = {}
                time.sleep(2)
            finally:
                c.close()

        while str(stats[stat_key]) != str(stat_value):
            c = MemcachedClient(master.ip, 11210)
            c.sasl_auth_plain(bucket, '')
            stats = c.stats()
            c.close()
            if verbose:
                log.info("{0} : {1}".format(stat_key, stats[stat_key]))
            time.sleep(5)
        return True
Example #4
0
    def wait_for_mc_stats_no_timeout(master, bucket, stat_key, stat_value, timeout_in_seconds=-1, verbose=True):
        log.info("waiting for bucket {0} stat : {1} to match {2} on {3}".format(bucket, stat_key, \
                                                                                stat_value, master.ip))
        c = MemcachedClient(master.ip, 11210)
        stats = c.stats()
        c.close()

        while str(stats[stat_key]) != str(stat_value):
            c = MemcachedClient(master.ip, 11210)
            stats = c.stats()
            c.close()
            if verbose:
                log.info("{0} : {1}".format(stat_key, stats[stat_key]))
            time.sleep(5)
        return True
Example #5
0
class EPStatChecker(StatChecker):
    def __init__(self, host=cfg.COUCHBASE_IP, port=11210):
        self.host = host
        self.port = port
        self.client = None

        try:
            self.client = MemcachedClient(self.host, self.port)
        except MemcachedError as ex:
            msg = "error connecting to host %s for gathering postconditions"\
                   %  self.host
            logger.error(msg)
            pass

    @property
    def stat_keys(self):
        keys = []

        stats = self.get_stats()
        if stats:
            keys = list(stats.keys())
        return keys

    def get_stats(self):
        stats = None

        if self.client:
            try:
                stats = self.client.stats()
            except Exception:
                logger.info("unable to get stats from host: %s:%s" %\
                    (self.host, self.port))

        return stats
Example #6
0
 def wait_for_mc_stats(master,
                       bucket,
                       stat_key,
                       stat_value,
                       timeout_in_seconds=120,
                       verbose=True):
     log = logger.get("infra")
     log.info("Waiting for bucket {0} stat: {1} to match {2} on {3}".format(
         bucket, stat_key, stat_value, master.ip))
     start = time.time()
     verified = False
     while (time.time() - start) <= timeout_in_seconds:
         c = MemcachedClient(master.ip, constants.memcached_port)
         stats = c.stats()
         c.close()
         if stats and stat_key in stats \
                 and str(stats[stat_key]) == str(stat_value):
             log.info("{0} : {1}".format(stat_key, stats[stat_key]))
             verified = True
             break
         else:
             if stats and stat_key in stats:
                 if verbose:
                     log.info("{0} : {1}".format(stat_key, stats[stat_key]))
             sleep_time = 2
             if not verbose:
                 sleep_time = 0.1
             sleep(sleep_time, log_type="infra")
     return verified
Example #7
0
    def get_vBuckets_info(master):
        """
        return state and count items for all vbuckets for each node
        format: dict: {u'1node_ip1': {'vb_79': ['replica', '0'], 'vb_78': ['active', '0']..}, u'1node_ip1':....}
        """
        rest = RestConnection(master)
        port = rest.get_nodes_self().memcached
        nodes = rest.node_statuses()
        _nodes_stats = {}
        for node in nodes:
            stat = {}
            buckets = []
            _server = {"ip": node.ip, "port": node.port, "username": master.rest_username,
                           "password": master.rest_password}
            try:
                buckets = rest.get_buckets()
                mc = MemcachedClient(node.ip, port)
                stat_hash = mc.stats("hash")
            except Exception:
                if not buckets:
                    log.error("There are not any buckets in {0}:{1} node".format(node.ip, node.port))
                else:
                    log.error("Impossible to get vBucket's information for {0}:{1} node".format(node.ip, node.port))
                    _nodes_stats[node.ip + ":" + str(node.port)]
                continue
            mc.close()
            vb_names = [key[:key.index(":")] for key in list(stat_hash.keys())]

            for name in vb_names:
                stat[name] = [stat_hash[name + ":state"], stat_hash[name + ":counted"]]
            _nodes_stats[node.ip + ":" + str(port)] = stat
        log.info(_nodes_stats)
        return _nodes_stats
Example #8
0
 def get_mb_stats(servers, key):
     for server in servers:
         c = MemcachedClient(server.ip, 11210)
         log.info("Get flush param on server {0}, {1}".format(server, key))
         value = c.stats().get(key, None)
         log.info("Get flush param on server {0}, {1}".format(server, value))
         c.close()
Example #9
0
 def wait_for_mc_stats(master,
                       bucket,
                       stat_key,
                       stat_value,
                       timeout_in_seconds=120,
                       verbose=True):
     log.info("waiting for bucket {0} stat : {1} to match {2} on {3}".format(bucket, stat_key, \
                                                                             stat_value, master.ip))
     start = time.time()
     verified = False
     while (time.time() - start) <= timeout_in_seconds:
         c = MemcachedClient(master.ip, 11210)
         stats = c.stats()
         c.close()
         if stats and stat_key in stats and str(
                 stats[stat_key]) == str(stat_value):
             log.info("{0} : {1}".format(stat_key, stats[stat_key]))
             verified = True
             break
         else:
             if stats and stat_key in stats:
                 if verbose:
                     log.info("{0} : {1}".format(stat_key, stats[stat_key]))
             if not verbose:
                 time.sleep(0.1)
             else:
                 time.sleep(2)
     return verified
Example #10
0
    def get_vBuckets_info(master):
        """
        return state and count items for all vbuckets for each node
        format: dict: {u'1node_ip1': {'vb_79': ['replica', '0'], 'vb_78': ['active', '0']..}, u'1node_ip1':....}
        """
        rest = RestConnection(master)
        port = rest.get_nodes_self().memcached
        nodes = rest.node_statuses()
        _nodes_stats= {}
        for node in nodes:
            stat={}
            buckets = []
            _server = {"ip": node.ip, "port": node.port, "username": master.rest_username,
                           "password": master.rest_password}
            try:
                buckets = rest.get_buckets()
                mc = MemcachedClient(node.ip, port)
                stat_hash = mc.stats("hash")
            except Exception:
                if not buckets:
                    log.error("There are not any buckets in {0}:{1} node".format(node.ip, node.port))
                else:
                    log.error("Impossible to get vBucket's information for {0}:{1} node".format(node.ip, node.port))
                    _nodes_stats[node.ip+":"+str(node.port)]
                continue
            mc.close()
            vb_names=[key[:key.index(":")] for key in stat_hash.keys()]

            for name in vb_names:
                stat[name]=[stat_hash[name + ":state"], stat_hash[name+":counted"]]
            _nodes_stats[node.ip+":"+str(port)] = stat
        log.info(_nodes_stats)
        return _nodes_stats
Example #11
0
 def get_mb_stats(servers, key):
     log = logger.get("infra")
     for server in servers:
         c = MemcachedClient(server.ip, constants.memcached_port)
         log.info("Get flush param on server {0}, {1}".format(server, key))
         val = c.stats().get(key, None)
         log.info("Get flush param on server {0}, {1}".format(server, val))
         c.close()
Example #12
0
 def get_mb_stats(servers, key):
     log = logger.Logger.get_logger()
     for server in servers:
         c = MemcachedClient(server.ip, 11210)
         log.info("Get flush param on server {0}, {1}".format(server, key))
         value = c.stats().get(key, None)
         log.info("Get flush param on server {0}, {1}".format(server, value))
         c.close()
Example #13
0
 def verify_stat(self, items, value="active"):
     mc = MemcachedClient(self.cluster.master.ip, constants.memcached_port)
     mc.sasl_auth_plain(self.cluster.master.rest_username,
                        self.cluster.master.rest_password)
     mc.bucket_select('default')
     stats = mc.stats()
     self.assertEquals(stats['ep_compression_mode'], value)
     self.assertEquals(int(stats['ep_item_compressor_num_compressed']),
                       items)
     self.assertNotEquals(int(stats['vb_active_itm_memory']),
                          int(stats['vb_active_itm_memory_uncompressed']))
Example #14
0
    def do_setWithMeta_twice(self):
        mc = MemcachedClient(self.cluster.master.ip, 11210)
        mc.sasl_auth_plain(self.cluster.master.rest_username,
                           self.cluster.master.rest_password)
        mc.bucket_select('default')

        try:
            mc.setWithMeta('1', '{"Hello":"World"}', 3600, 0, 1,
                           0x1512a3186faa0000)
        except MemcachedError as error:
            self.log.info("<MemcachedError #%d ``%s''>" %
                          (error.status, error.message))
            self.fail("Error on First setWithMeta()")

        stats = mc.stats()
        self.log.info('curr_items: {0} and curr_temp_items:{1}'.format(
            stats['curr_items'], stats['curr_temp_items']))
        self.log.info("Sleeping for 5 and checking stats again")
        time.sleep(5)
        stats = mc.stats()
        self.log.info('curr_items: {0} and curr_temp_items:{1}'.format(
            stats['curr_items'], stats['curr_temp_items']))

        try:
            mc.setWithMeta('1', '{"Hello":"World"}', 3600, 0, 1,
                           0x1512a3186faa0000)
        except MemcachedError as error:
            stats = mc.stats()
            self.log.info(
                'After 2nd setWithMeta(), curr_items: {} and curr_temp_items:{}'
                .format(stats['curr_items'], stats['curr_temp_items']))
            if int(stats['curr_temp_items']) == 1:
                self.fail(
                    "Error on second setWithMeta(), expected curr_temp_items to be 0"
                )
            else:
                self.log.info("<MemcachedError #%d ``%s''>" %
                              (error.status, error.message))
Example #15
0
 def wait_for_warmup(self, host, port):
     if self.bucket_type == 'ephemeral': return
     while True:
         client = McdClient(host, port)
         try:
             client.bucket_select("default")
             response = client.stats()
             # check the old style or new style (as of 4.5) results
             mode = response.get('ep_degraded_mode')
             if mode is not None:
                 if mode == '0' or mode == 'false':
                     break
         except Exception as ex:
             pass
         self.sleep(1)
Example #16
0
 def wait_for_mc_stats(master, bucket, stat_key, stat_value, timeout_in_seconds=120, verbose=True):
     log.info("waiting for bucket {0} stat : {1} to match {2} on {3}".format(bucket, stat_key, \
                                                                             stat_value, master.ip))
     start = time.time()
     verified = False
     while (time.time() - start) <= timeout_in_seconds:
         c = MemcachedClient(master.ip, 11210)
         stats = c.stats()
         c.close()
         if stats and stat_key in stats and str(stats[stat_key]) == str(stat_value):
             log.info("{0} : {1}".format(stat_key, stats[stat_key]))
             verified = True
             break
         else:
             if stats and stat_key in stats:
                 if verbose:
                     log.info("{0} : {1}".format(stat_key, stats[stat_key]))
             if not verbose:
                 time.sleep(0.1)
             else:
                 time.sleep(2)
     return verified
class EPStatChecker(StatChecker):

    def __init__(self,
                 host = cfg.COUCHBASE_IP,
                 port = 11210):
        self.host = host
        self.port = port
        self.client = None

        try:
            self.client = MemcachedClient(self.host, self.port)
        except MemcachedError as ex:
            msg = "error connecting to host %s for gathering postconditions"\
                   %  self.host
            logger.error(msg)
            pass

    @property
    def stat_keys(self):
        keys = []

        stats = self.get_stats()
        if stats:
            keys = stats.keys()
        return keys

    def get_stats(self):
        stats = None

        if self.client:
            try:
                stats = self.client.stats()
            except Exception:
                logger.info("unable to get stats from host: %s:%s" %\
                    (self.host, self.port))

        return stats