landro / TesTcl

when you don't have the balls to test your F5 BIG-IP iRules directly in production
https://testcl.com
BSD 3-Clause "New" or "Revised" License
98 stars 30 forks source link

Support for virtual #68

Open freedge opened 3 years ago

freedge commented 3 years ago

As documented here:

https://clouddocs.f5.com/api/irules/virtual.html

Currently I am using

on virtual name return foo
on virtual foo return ""

But then I cannot check that the virtual server is set properly. Ideally I would like to do something like

verify "Final virtual is the expected one after a match" "foo" eq { endstate_virtual }

(if it was possible to verify the value of a variable it would be great too) Thanks for the great tool!

landro commented 3 years ago

Do you have a simple irule that illustrates how it is typically used?

  1. jul. 2021 kl. 08:48 skrev frigo @.***>:

 As documented here:

https://clouddocs.f5.com/api/irules/virtual.html

Currently I am using

on virtual name return foo on virtual foo return "" But then I cannot check that the virtual server is set properly. Ideally I would like to do something like

verify "Final virtual is the expected one after a match" "foo" eq { endstate_virtual } (if it was possible to verify the value of a variable it would be great too) Thanks for the great tool!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

freedge commented 3 years ago

on the rules I am working with, the virtual name is used to deduce the partition of the server (it's also a suggestion from https://devcentral.f5.com/s/question/0D51T00006j36DJ/irule-access-to-partition-name) the virtual remoteserver is used to send traffic to a remote location.

Some variable is also shared between CLIENT_ACCEPTED and HTTP_REQUEST. While I know how to inject variables, I don't know how to validate the curpartition variable content in the example below:

when CLIENT_ACCEPTED priority 500 {
    set curpartition [lindex [split [virtual name] /] 1]
}

when HTTP_REQUEST priority 500 {
    HTTP::header insert X-Test-Partition $curpartition

    if { [HTTP::uri] contains "foobar" } {
        virtual myremoteserver
        HTTP::header insert X-Test-Request [virtual name]
    } else {
        HTTP::header insert X-Test-Request local 
    }
}

EDIT btw the value of virtual name is identical before and after the call to virtual myremoteserver