def get_set(port):
    try:
        output = interact.request(HOST, port, 'get')
        if output and len(output) > 2:
            return set([int(i) for i in output[1:-1].split(',')])
        return set()
    except:
        return set()
Example #2
0
def default_ally(game, hero):
    """
    Gain 1 attack; or gain 2 hp.
    """
    res = interact.request(zip('gain 1 attack', 'gain 2 hp'))
    if res == 0:
        hero.attack += 1
    elif res == 1:
        states.gain_hp(game, hero, 2)
Example #3
0
 def init(self, host, nodes):
     # we are trying to guess the current last state value
     # this is not exactly necessary but makes running
     # consecutive test runs easier to analyze
     result = interact.request(host, nodes[nodes.keys()[0]], 'get')
     if result:
         match = re.search(r'(\d+)]$', result)
         if match:
             self.idx = int(match.group(1))
def check_counters(nodes):
    if len(nodes) < 1:
        raise ValueError('no nodes given')

    counters = []
    for node, port in nodes.items():
        counter = interact.request(HOST, port, 'get')
        equal = all(x == counter for x in counters)

        if not equal:
            print('Counter of node "%s" [%s] does not match with other counters: %s' %
                  (node, counter, str(counters)))
            return None
        counters.append(counter)

    # all counters are the same -> return the first one for reference
    return int(counters[0])
def check_counters(nodes):
    if len(nodes) < 1:
        raise ValueError('no nodes given')

    counters = []
    for node, port in nodes.items():
        counter = interact.request(HOST, port, 'get')
        equal = all(x == counter for x in counters)

        if not equal:
            print(
                'Counter of node "%s" [%s] does not match with other counters: %s'
                % (node, counter, str(counters)))
            return None
        counters.append(counter)

    # all counters are the same -> return the first one for reference
    return int(counters[0])
Example #6
0
def check_states(nodes):
    if len(nodes) < 1:
        raise ValueError('no nodes given')

    states = []
    for node, port in nodes.items():
        result = interact.request(HOST, port, 'get')
        if not result:
            return None

        state = result[1:-1].split(',')
        state_set = set(state)
        equal = all(x == state_set for x in states)

        if not equal:
            print('State of node "%s" [%s] does not match with other states: %s' %
                  (node, state_set, str(states)))
            return None
        states.append(state_set)
    return states[0]
def dump_logs(nodes):
    if len(nodes) < 1:
        raise ValueError("no nodes given")

    for _, port in nodes.items():
        interact.request(HOST, port, "dump")
def get_counter(host, port):
    value = interact.request(host, port, "get")
    if value:
        return int(value)
    return None
    def init(self, host, nodes):
        # get first counter value
        counter = int(interact.request(host, nodes.values()[0], 'get'))
        self.state['counter'] = counter

        return self.state
    def init(self, host, nodes):
        # get first counter value
        counter = int(interact.request(host, nodes.values()[0], 'get'))
        self.state['counter'] = counter

        return self.state
Example #11
0
def dump_logs(nodes):
    if len(nodes) < 1:
        raise ValueError('no nodes given')

    for _, port in nodes.items():
        interact.request(HOST, port, 'dump')
Example #12
0
def get_counter(host, port):
    value = interact.request(host, port, 'get')
    if value:
        return int(value)
    return None