Exemplo n.º 1
0
 def ha_nvec_get(self, hax_msg: int, nvec: List[HaNote]) -> None:
     LOG.debug('Got ha nvec of length %s from Motr land', len(nvec))
     self.queue.put(HaNvecGetEvent(hax_msg, nvec))
Exemplo n.º 2
0
def test_get_nvec_replies_something(mocker, planner, motr, consumer,
                                    consul_util):
    def new_kv(key: str, val: str):
        return {
            'Key': key,
            'CreateIndex': 1793,
            'ModifyIndex': 1793,
            'LockIndex': 0,
            'Flags': 0,
            'Value': val,
            'Session': ''
        }

    def my_get(key: str, recurse: bool = False, **kwds):
        if key == 'm0conf/nodes' and recurse:
            return [
                new_kv(k, v) for k, v in
                [('m0conf/nodes/0x6e00000000000001:0x3/processes'
                  '/0x7200000000000001:0x15',
                  json.dumps({
                      "name": "m0_server",
                      "state": "offline"
                  })), ('m0conf/nodes/cmu/processes/21/services/rm', '16'),
                 ('m0conf/nodes/localhost/processes/21/services/rms', '17'),
                 ('m0conf/nodes/0x6e00000000000001:0x3/processes'
                  '/0x7200000000000001:0x15/services/0x7300000000000001:0x10',
                  json.dumps({
                      "name": "rms",
                      "state": "failed"
                  })),
                 ('m0conf/nodes/0x6e00000000000001:0x3/processes'
                  '/0x7200000000000001:0x15/services/0x7300000000000001:0x10'
                  '/sdevs/0x6400000000000001:0x20',
                  json.dumps({
                      "name": "ios",
                      "state": "failed"
                  })),
                 ('m0conf/nodes/0x6e00000000000001:0x3/processes'
                  '/0x7200000000000001:0xa/services/0x7300000000000001:0xc',
                  json.dumps({
                      "name": "ios",
                      "state": "failed"
                  }))]
            ]
        elif key == 'm0conf/nodes/localhost/processes/7/services/rms':
            return new_kv('m0conf/nodes/localhost/processes/7/services/rms',
                          '17')
        elif key == 'm0conf/nodes/0x6e00000000000001:0x3':
            return new_kv(
                'm0conf/nodes/0x6e00000000000001:0x3',
                json.dumps({
                    "name": "localhost",
                    "state": "M0_NC_UNKNOWN"
                }))
        elif key == 'm0conf/sites' and recurse:
            return [
                new_kv(k, v) for k, v in
                [('m0conf/sites/0x5300000000000001:0x1/racks'
                  '/0x6100000000000001:0x2/encls/0x6500000000000001:0x4'
                  '/ctrls/0x6300000000000001:0x5',
                  json.dumps({"state": "M0_NC_UNKNOWN"})),
                 ('m0conf/sites/0x5300000000000001:0x1/racks'
                  '/0x6100000000000001:0x2/encls/0x6500000000000001:0x4'
                  '/ctrls/0x6300000000000001:0x6/drives'
                  '/0x6b00000000000001:0x2d',
                  json.dumps({"sdev": "0x6400000000000001:0x20"})),
                 ('m0conf/sites/0x5300000000000001:0x1/racks'
                  '/0x6100000000000001:0x2/encls/0x6500000000000001:0x4'
                  '/ctrls/0x6300000000000001:0x6',
                  json.dumps({"state": "M0_NC_UNKNOWN"}))]
            ]
        raise RuntimeError(f'Unexpected call: key={key}, recurse={recurse}')

    def my_services(name):
        if name == 'confd':
            return [{
                'Node': 'localhost',
                'Service': 'confd',
                'ServiceID': '7',
                'Address': '192.168.0.28',
                'ServiceAddress': '192.168.0.28',
                'ServicePort': '12345'
            }]
        if name == 'hax':
            return [{
                'Node': 'localhost',
                'Service': 'hax',
                'ServiceID': '45',
                'Address': '192.168.0.28',
                'ServiceAddress': '192.168.0.28',
                'ServicePort': '667'
            }]
        raise RuntimeError(f'Unexpected call: name={name}')

    patch = mocker.patch.object
    patch(consul_util.kv, 'kv_get', side_effect=my_get)
    patch(consul_util, 'get_leader_session_no_wait', return_value='localhost')
    patch(consul_util, 'get_session_node', return_value='localhost')

    patch(consul_util.catalog, 'get_services', side_effect=my_services)
    patch(consul_util, 'get_node_health_status', return_value='passing')
    patch(consul_util, 'get_service_health', return_value=ServiceHealth.OK)

    msg = HaNvecGetEvent(
        hax_msg=12,
        nvec=[
            HaNote(obj_t='SERVICE',
                   note=HaNoteStruct(
                       no_id=Fid.parse('0x7300000000000001:0x10').to_c(),
                       no_state=5)),
            HaNote(obj_t='PROCESS',
                   note=HaNoteStruct(
                       no_id=Fid.parse('0x7200000000000001:0x15').to_c(),
                       no_state=5)),
            HaNote(obj_t='DRIVE',
                   note=HaNoteStruct(
                       no_id=Fid.parse('0x6b00000000000001:0x2d').to_c(),
                       no_state=5)),
            HaNote(obj_t='CONTROLLER',
                   note=HaNoteStruct(
                       no_id=Fid.parse('0x6300000000000001:0x5').to_c(),
                       no_state=5))
        ])
    run_in_consumer(mocker, msg, planner, consumer, motr)
    traces = motr._ffi.traces
    assert AssertionPlan(
        tr_method('ha_nvec_reply')).exists(traces), 'ha_nvec_reply not invoked'
Exemplo n.º 3
0
 def ha_nvec_get(self, hax_msg: int, nvec: List[HaNote]) -> None:
     LOG.debug('Got ha nvec get of length %s from Motr land', len(nvec))
     self.planner.add_command(HaNvecGetEvent(hax_msg, nvec))
Exemplo n.º 4
0
def nvec_get():
    return HaNvecGetEvent(hax_msg=1, nvec=[])