def wfm_ports_for_switch(ctx, switch_id):
    message = create_dump_state_by_switch(ctx.correlation_id,
                                          'wfm/kilda.topo.disco-bolt',
                                          switch_id)

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    if not records:
        LOG.error("wfm/kilda.topo.disco-bolt NO RESPONSE")

    retval = {}

    for record in records:
        data = json.loads(record.value)
        payload = data['payload']

        for port in payload['state']['discovery']:

            if port['consecutive_success'] == 0:
                status = 'DOWN'
            elif port['consecutive_failure'] == 0:
                status = 'UP'
            else:
                status = 'N/A'

            retval[int(port['port_id'])] = {
                'WFM_ISL_FOUND': 'FOUND' if port['found_isl'] else 'NOT FOUND',
                'WFM_ISL_STATUS': '{}'.format(status)
            }

    return retval
Exemple #2
0
def list_command(ctx):
    message = create_list(ctx.correlation_id)
    LOG.debug('command = {}'.format(message.serialize()))

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    print_table(records)
Exemple #3
0
def dump_state_command(ctx, destination, border, output_type):
    message = create_dump_state(ctx.correlation_id, destination=destination)
    LOG.debug('command = {}'.format(message.serialize()))

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    if output_type == 'table':
        print_table(records, border)
    elif output_type == 'json':
        for record in records:
            data = json.loads(record.value)
            print(pprint.pformat(data))
Exemple #4
0
def list_command(ctx):
    message = create_list(ctx.correlation_id)
    LOG.debug('command = {}'.format(message.serialize()))

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    table = PrettyTable(['Topology', 'Component', 'Task ID'])
    for record in records:
        data = json.loads(record.value)
        payload = data['payload']
        LOG.debug(pprint.pformat(data))
        table.add_row(
            [payload['topology'], payload['component'], payload['task_id']])
    print(table)
Exemple #5
0
 def print_message(record):
     try:
         data = json.loads(record.value)
         if data['clazz'] == 'org.openkilda.messaging.ctrl.CtrlRequest':
             LOG.info('New message in topic:\n%s', pprint.pformat(data))
             for filename in glob.glob(
                     os.path.join(res_dir, '*BoltState.json')):
                 with open(filename) as f:
                     message = json.load(f)
                     message['correlation_id'] = data['correlation_id']
                     send_with_context(
                         ctx, bytes(json.dumps(message).encode('utf-8')))
                     time.sleep(sleep)
     except Exception:
         LOG.exception('error')
         print(record)
Exemple #6
0
 def print_message(record):
     try:
         data = json.loads(record.value)
         if data['type'] == 'CTRL_REQUEST':
             LOG.info('New message in topic:\n%s', pprint.pformat(data))
             for i in range(1, count + 1):
                 m = Message(
                     'CTRL_RESPONSE', 'probe', {
                         'topology': 'topology-X',
                         'component': 'component-X',
                         'task_id': 'bolt-{}'.format(i)
                     }, data['correlation_id'])
                 send_with_context(ctx, m.serialize())
                 time.sleep(sleep)
     except Exception:
         LOG.exception('error')
         print(record)
Exemple #7
0
def dump_state_command(ctx, destination, border, output_type, allow_dangerous_operation):

    if not allow_dangerous_operation:
        click.secho("DON'T RUN ON PRODUCTION MAY CAUSE OVERSIZED KAFKA MESSAGE",
                    blink=True, bold=True)
        return

    message = create_dump_state(ctx.correlation_id, destination=destination)
    LOG.debug('command = {}'.format(message.serialize()))

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    if output_type == 'table':
        print_table(records, border)
    elif output_type == 'json':
        for record in records:
            data = json.loads(record.value)
            print(pprint.pformat(data))
def wfm_ports_for_switch(ctx, switch_id):
    message = create_dump_state_by_switch(ctx.correlation_id,
                                          'wfm/kilda.topo.disco-bolt',
                                          switch_id)

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    if not records:
        LOG.error("wfm/kilda.topo.disco-bolt NO RESPONSE")

    retval = {}

    for record in records:
        data = json.loads(record.value)
        payload = data['payload']

        for port in payload['state']['discovery']:
            retval[int(port['port_id'])] = {
                'WFM_ISL_STATUS': 'UP' if port['found_isl'] else 'DOWN'
            }

    return retval