[asterisk-dev] Question on the testconditions in the asterisk testsuite

Matthew Jordan mjordan at digium.com
Fri Sep 28 08:54:52 CDT 2012



----- Original Message ----- 

> From: "nitesh bansal" <nitesh.bansal at gmail.com>
> To: asterisk-dev at lists.digium.com
> Sent: Friday, September 28, 2012 7:29:43 AM
> Subject: [asterisk-dev] Question on the testconditions in the
> asterisk testsuite

> Hello All,

> I am using the asterisk test suite version 3478. I am writing some
> tests for which i would like to validate the testcondition "
> channels " after the test is executed and i tried defining the
> condition in the test-config.yaml for that specific
> test, but it did not work as it was undefined in the global
> test-config.yaml. I would like to know is there a way to just enable
> the condition for this particular test and not defining it in global
> test-config.yaml, please let me know if it
> is possible and if its not possible, is there any harm if i remove
> the check for the definition of a testcondition in the global
> test-config.yaml?

So, first of all: cool!  I'm pretty excited that someone is making use
of that feature in the Test Suite.  You may want to be aware that the pre/post
checking framework is a little on the 'bleeding edge' side of things, and
usually takes some tweaking - and some knowledge of Asterisk to understand why
things may be the way they are when a test finishes.

Anyway, this does look like it could be viewed as a bug in the TestCase class.
In general, the pre/post condition framework assumes you're turning it on for
the Test Suite as a whole, and lets you tweak the settings on a test by test
basis.  The configuration of the pre/post-conditions grew a bit organically
(they started off being only global, then got local overrides, then got aliases
to the actual Python package/module to load and instantiate as people got tired
of typing foo.bar.yackity all the time).  I don't see any harm in letting tests
define their conditions only locally if they so choose.  To do so, you'd want to
remove this snippet of code in TestCase:

        """ If there are no global conditions return """
        if (len(self.global_conditions) == 0):
            return

I've removed it and set up a channel condition check in the dialplan test:

properties:
    minversion: '1.8.0.0'
    dependencies:
        - python : 'twisted'
        - python : 'starpy'
        - asterisk : 'res_crypto'
    tags:
        - dialplan
    testconditions:
        - name: 'channels'
          allowedchannels: 0

Note that you'll still need to define the actual 'channel' pre/post-condition
in the global test-config.yaml:

# Global settings
global-settings:
    # The active test configuration.  The value must match a subsequent key
    # in this file, which defines the global settings to apply to the test execution
    # run.
    test-configuration: config-standard

    # The following sequence defines for any test configuration the available pre-
    # and post-test conditions.  The 'name' field specifies how the test configurations
    # refer to the pre- and post-test conditions in order to activate them.
    condition-definitions:
            -
                name: 'channels'
                pre:
                    typename: 'asterisk.ChannelTestCondition.ChannelTestCondition'
                post:
                    typename: 'asterisk.ChannelTestCondition.ChannelTestCondition'

After doing this, running the dialplan test shows the channel condition object
being created and run before and afer the test.

[Sep 28 08:40:56] DEBUG[4840]: asterisk.TestConditions:117 evaluate_pre_checks: Evaluating pre checks
[Sep 28 08:40:56] DEBUG[4840]: asterisk.TestConditions:172 __evaluate_check: Evaluating asterisk.ChannelTestCondition.ChannelTestCondition
[Sep 28 08:40:56] DEBUG[4840]: asterisk.asterisk:590 cli_exec: Executing ['/usr/sbin/asterisk', '-C', '/tmp/asterisk-testsuite/dialplan/ast6/etc/asterisk/asterisk.conf', '-rx', 'core show channels'] ...
[Sep 28 08:40:56] DEBUG[4840]: asterisk.asterisk:62 __cli_output_callback: Asterisk CLI 127.0.0.1 exited 0
[Sep 28 08:40:56] DEBUG[4840]: asterisk.asterisk:63 __cli_output_callback: Channel              Location             State   Application(Data)             
0 active channels
0 active calls
0 calls processed
Asterisk ending (0).

...


[Sep 28 08:40:56] DEBUG[4840]: asterisk.TestConditions:133 evaluate_post_checks: Evaluating post checks
[Sep 28 08:40:56] DEBUG[4840]: asterisk.TestConditions:172 __evaluate_check: Evaluating asterisk.ChannelTestCondition.ChannelTestCondition
[Sep 28 08:40:56] DEBUG[4840]: asterisk.asterisk:590 cli_exec: Executing ['/usr/sbin/asterisk', '-C', '/tmp/asterisk-testsuite/dialplan/ast6/etc/asterisk/asterisk.conf', '-rx', 'core show channels'] ...
[Sep 28 08:40:56] DEBUG[4840]: asterisk.asterisk:62 __cli_output_callback: Asterisk CLI 127.0.0.1 exited 0
[Sep 28 08:40:56] DEBUG[4840]: asterisk.asterisk:63 __cli_output_callback: Channel              Location             State   Application(Data)             
0 active channels
0 active calls
2 calls processed
Asterisk ending (0).


If you remove that code, I think your test should work.  Note that your test
does have to inherit from TestCase for the pre/post-condition checking framework
to be enabled at all.

If it does work for you, and you experience not other problems, let me know and
I'll commit that change to TestCase.

Thanks!

--
Matthew Jordan
Digium, Inc. | Engineering Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com & http://asterisk.org



More information about the asterisk-dev mailing list