Forum Discussion

Chris_Phillips's avatar
Icon for Nimbostratus rankNimbostratus
Jan 30, 2012

Any iRules out there for a dummy pool member?




Is there anyone out there who has possibly written a series of irules to emulate a faulty http client? I think it could be really handy to have a pool member pull apart a query string like "?delay=5&code=503&fail_rate=0.3" and respond accordingly to allow a really quick way to see what a monitor or other "normal" iRules would do when the pool member acts as requested?




I might look to write something similar to this if not, as I'd think that the time spent would be well worth it.










3 Replies

  • Hi Chris,



    I use a series of HTTP::respond based iRules on a second LTM for testing server responses. I haven't done anything with percentage failures though. Here's a simple example which sets the server response code based on the URI:



    when HTTP_REQUEST {
       set data {Some data to send to the client.  If you want to use variables in here, replace the curly braces with quotes.}
        Look for a URI starting with a forward slash and then 3 digits (the first digit being 1-5)
        If one is found, set it as the HTTP response code.  Else, send back an HTTP 200
       if {[string match {/[1-5][0-9][0-9]*} [HTTP::path]]}{
           Send the response with the status code from the requested path and data
          HTTP::respond [string range [HTTP::path] 1 3] content $data "a_header_name" "a_header_value"
          log local0. "Sending [string range [HTTP::path] 1 3] response with $data"
       } else {
           Send a 200 response with data
          HTTP::respond 200 content $data "a_header_name" "a_header_value"
          log local0. "Sending default 200 response with $data"



    You could expand on this to send a failure X percent of the time using rand:



    Check if this should be a failure


    if { rand() < [URI::query [HTTP::uri] "fail_rate" }



    To add delay, you could use the after command:






    If you get something tested, it would make an interesting Codeshare example 🙂



  • I got something working for a number of scenarios, but of course there's no way to prevent a client connection this way if everything comes in at http level. I'd like to be able to force an LB_FAILED but I think that's got to be impossible within an iRule alone.
  • To trigger LB_FAILED, you could set a destination IP which doesn't answer arp using the node command.