2017 up to now  | 2016 | 2015 | 2014 | 2013 | 2012 | 2011 | 2010 | 2009 | 2008 | 2007

(older archive entries before 2007 are not shown here, but included in the onsite-search)

Mailing List - Entries of 2011


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [QF-Test] Executing shell commands, and checking output


  • Subject: Re: [QF-Test] Executing shell commands, and checking output
  • From: Gregor Schmid <Gregor.Schmid@?.de>
  • Date: Thu, 12 May 2011 14:18:16 +0200

Hi Lee,

that looks pretty good!

To turn this into a procedure, simply move the three nodes to
a procedure and replace the variable parts with a parameter lookup,
e.g.

+ Shell command "ssh $(user)@$(address) hostname" [client test]
+ Wait for Process to Terminate [client test]
+ Sever script:

import re
out = rc.lookup("qftest", "client.output.test", expand=false)
regexp = rc.lookup("regexp")
rc.check(re.search(regexp, out), "Hostname check", level=rc.ERROR, nowrap=true)

I.e you'll have three parameters "user", "address" and "regexp". You
can define default values in the Procedure node but you don't have to.

Best regards,
    Greg


Wild Lee <Lee.Wild@?.com> writes:

> Hi again
>
> OK, I have got a little further. I found the info on rc.checkEqual, and also
> rc.check.
> I have also found how to check text returned from a shell command against a
> regexp.
>
> Does this look reasonable:
>
> First, an "Execute Shell Command" node that executes: "ssh user@address
> hostname" with Client set to "test"
> Next, a "Wait for Process to Terminate" node with Client set to "test"
> And then, a Server Script:
>     import re
>     out = rc.lookup("qftest", "client.output.test", expand=false)
>     rc.check(re.search(r"[A-Z]{2}[0-9]{2}_[0-9]{2}", out), "Hostname check",
> level=rc.ERROR, nowrap=true)
>
> It seems to work OK.
>
> My next task is to set this up as a generic procedure, and pass in the
> username/address of the target machine, and the regexp, as variables.....
>
> Any comments or advice - does what I've done so far look OK or are there any
> better ways ?
>
> Thanks!
> Lee
>
>
>
>
>
>> -----Original Message-----
>> From: Wild Lee [mailto:Lee.Wild@?.com]
>> Sent: 12 May 2011 07:53
>> To: qftest-list@?.de
>> Cc: 'Gregor Schmid'
>> Subject: Re: [QF-Test] Executing shell commands, and checking output
>> 
>> 
>> Hi Greg
>> 
>> Thanks for the prompt response.
>> 
>> Where might I find more detail about rc.checkEqual syntax ? 
>> I have not been able to find it yet.
>> I am not sure what the different parameters mean (I see in 
>> your example,
>> there are 3...)
>> 
>> Also, how could I implement regular expressions with rc.checkEqual ?
>> For example, I might not need to check the exact hostname of 
>> a machine, just
>> whether it is of a specific format, for example
>> [A-Z][A-Z][0-9][0-9]_[0-9][0-9] (eg "AB01_01").
>> 
>> I assume I could then create a generic hostname-checking 
>> script inside a
>> procedure, and I could pass in 2 variables - 1 being the 
>> address of the
>> machine to run the command on, and 2 being a regexp that the 
>> returned value
>> should match.
>> Does that sound reasonable ?
>> Is it feasible to pass regexps as variables ?
>> 
>> Thanks again for your help.
>> Lee
>> 
>> > -----Original Message-----
>> > From: Gregor Schmid [mailto:Gregor.Schmid@?.de]
>> > Sent: 11 May 2011 19:56
>> > To: qftest-list@?.de
>> > Cc: Wild Lee
>> > Subject: Re: [QF-Test] Executing shell commands, and checking output
>> > 
>> > 
>> > 
>> > Hi Lee,
>> > 
>> > your approach is quite reasonable, but you'll need a bit of 
>> scripting.
>> > 
>> > First, be sure to follow the shell command node with a 
>> matching 'Wait
>> > for client to terminate' to avoid timing problems.
>> > 
>> > Next, the output of the client is available via the QF-Test variable
>> > ${qftest:client.output.<name>} where <name> is the name of 
>> the client
>> > that was started. In a Jython or Groovy server script you should
>> > always access this via rc.lookup instead of the ${} syntax. To check
>> > this against an expected value, use rc.checkEqual.
>> > 
>> > Jython Example:
>> > 
>> > output = rc.lookup("qftest", "client.output.test", expand=false)
>> > rc.checkEqual(output, "myhost", "Expected hostname")
>> > 
>> > Best regards,
>> >     Greg
>> > 
>> > Wild Lee <Lee.Wild@?.com> writes:
>> > 
>> > > Hi
>> > >  
>> > > I am hoping to do the following, using QFTest installed on 
>> > a Linux machine:
>> > >  
>> > > 1) Execute a shell command, for example: "ssh user@machine 
>> > hostname".
>> > >  - this would launch the "hostname" command on a remote 
>> > machine via SSH, and return the hostname
>> > > to QFTest.
>> > >  
>> > > 2) Check the returned text to see if it matches a certain pattern.
>> > >  
>> > > Now, I can lauch execute the command OK, using "Execute 
>> > Shell Command". I have used the Client
>> > > name "test".
>> > > I can see in the terminal window that the command has 
>> > executed and the hostname has been returned.
>> > >  
>> > > But how do I go about checking that hostname against a 
>> > pattern, to determine a Pass/Fail ?
>> > > Is it possible to use one of the usual Check nodes, or do I 
>> > have to somehow do this in Jython ?
>> > >  
>> > > The reason behind this is that we have some tests we'd like 
>> > to carry out on remote embedded
>> > > machines, that do no have any form of Java GUI or web 
>> > interface available.
>> > > They only have a command-level interface, and an SSH daemon.
>> > > So I am trying to find ways that we can launch commands via 
>> > SSH from QF-Test and check the
>> > > responses (which is why I am using QFTest on a Linux 
>> > machine, as SSH is readily available from
>> > > commandline and can be used with "Execute Shell Command").
>> > > We use QF-Test for other (GUI) tests so it would be good to 
>> > be able to carry these tests out using
>> > > the same tool.
>> > > If there are better ways of doing this I'd be happy to know.
>> > >  
>> > > Any pointers/help would be most appreciated !
>> > > I am a QF-Test novice as you may be able to tell.
>> > >  
>> > > Regards
>> > > Lee
>> > 
>> > -- 
>> > Gregor Schmid                                Gregor.Schmid@?.de
>> > Quality First Software GmbH                     http://www.qfs.de
>> > Tulpenstr. 41                               Tel: +49 8171 38648-0
>> > DE-82538 Geretsried                         Fax: +49 8171 3864816
>> > GF: Gregor Schmid, Karlheinz Kellerer          HRB München 140833
>> > 
>> 
>> This email, including any attachment, is a confidential communication
>> intended solely for the use of the individual or entity to whom it is
>> addressed. It contains information which is private and may 
>> be proprietary
>> or covered by legal professional privilege. If you have 
>> received this email
>> in error, please notify the sender upon receipt, and 
>> immediately delete it
>> from your system.
>> 
>> Anything contained in this email that is not connected with 
>> the businesses
>> of this company is neither endorsed by nor is the liability 
>> of this company.
>> 
>> Whilst we have taken reasonable precautions to ensure that 
>> any attachment to
>> this email has been swept for viruses, we cannot accept 
>> liability for any
>> damage sustained as a result of software viruses, and would 
>> advise that you
>> carry out your own virus checks before opening any attachment.
-- 
Gregor Schmid                                Gregor.Schmid@?.de
Quality First Software GmbH                     http://www.qfs.de
Tulpenstr. 41                               Tel: +49 8171 38648-0
DE-82538 Geretsried                         Fax: +49 8171 3864816
GF: Gregor Schmid, Karlheinz Kellerer          HRB München 140833