Code review comment for lp:~rvb/maas/retry-power-changes

Revision history for this message
Gavin Panella (allenap) wrote :

> I didn't mean that we don't need a real Django running; a mock one
> will do.  But we need something that responds like a real call to
> avoid the mistake that rvb made.

Ah, okeydoke, then I agree. I think we can dynamically create an amp.AMP
subclass with stub responders that correspond to a subset of amp.Command
calls.

Maybe something like:

    def make_stub_amp_thing(*commands):
        responders = {
            "responder_for_%s" % command.name:
                command.responder(Mock())
            for command in commands
        }
        return type("DynamicAMP", amp.AMP, responders)

    amp = make_stub_amp_thing(MakeMeASandwich)
    amp.responder_for_MakeMeASandwich.return_value = "Use sudo"

    call_responder(amp(), MakeMeASandwich, {
        "fillings": ["ketchup", "crisps", "scratchings"],
    })

The `Client` returned from ClusterService.getClient() needs to be
patched to use call_responder in this way. Or, as ClusterRPCFixture
does, the connections that the client uses need to be patched.

« Back to merge proposal