question

MikeKulls avatar image
MikeKulls asked MikeKulls answered

Session level variable / class variables

Is it possible to create a variable that is associated with a session profile? Basically the equivalent of a class variable in Java. We have a need to keep a variable between various quick calls. An example would be with an SSH session we have a quickcall that starts a process which sends data to a temporary file. Then there is another quickcall that retrieves the data from the file. We need to store the filename for use between the 2 quickcalls. We could return the filename from the first quickcall and pass it to the second one but not as neat and become difficult for more complex situations. We could create the filename as a global variable but that is messy because the variable could be overwritten by another procedure and we will run into problems if we run 2 sessions.

iTestsession profile
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

amichaels avatar image
amichaels answered MikeKulls commented

AFAIK, there is nothing equivalent in nature to a class variable, or a static variable. What you can do is just set a variable in the scope that calls both quickcalls. This isn't global (using gset or gget), but it is global to the current test case.

1 comment
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

MikeKulls avatar image MikeKulls commented ·

This isn't ideal as it means the quickcalls cannot be black boxed as much as I would like. It's then up to the user of my quickcalls to store state for the quickcalls. This makes using my quickcalls more complex and more prone to error. For example, the user could forgot to pass the variable back to the call or pass the wrong value etc. This should probably be a feature request as this has come up a number of times for me and I doubt I'm the only person who has this requirement.

A good work around would probably be to create a global variable with a session id in its name, or something like that.

0 Likes 0 ·
amichaels avatar image
amichaels answered

Another alternative might be to make the file name a parameter or a property on the device in a topology. In the latter, you can use the tbml command to retrieve the value (but you can't modify it. Same with a parameter)

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

MikeKulls avatar image
MikeKulls answered

This looks like a possible workaround. The first quickcall has args of name and value, the second one just name. This isn't perfect but does appear to solve the problem at hand. The only downside is that the variables aren't private to the session. I'd be interested in people's opinions.

itest.png

The other option that might be a possibility is there is a section in the variable tree called profiles that appears to have 1 branch per session. If the syntax to add something to that branch could be found that might work.


itest.png (3.6 KiB)
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.