Author: gtjoseph Date: Mon Oct 13 11:21:09 2014 New Revision: 5721 URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=5721 Log: Testsuite: Tests for manager GetConfig and UpdateConfig AMI actions
This is the test for manager GetConfig and UpdateConfig corresponding to https://reviewboard.asterisk.org/r/4033/ Tested-by: George Joseph Review: https://reviewboard.asterisk.org/r/4072/ Added: asterisk/trunk/tests/manager/config/ asterisk/trunk/tests/manager/config/ManagerConfigTest.py (with props) asterisk/trunk/tests/manager/config/test-config.yaml (with props) Modified: asterisk/trunk/tests/manager/tests.yaml Added: asterisk/trunk/tests/manager/config/ManagerConfigTest.py URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/config/ManagerConfigTest.py?view=auto&rev=5721 ============================================================================== --- asterisk/trunk/tests/manager/config/ManagerConfigTest.py (added) +++ asterisk/trunk/tests/manager/config/ManagerConfigTest.py Mon Oct 13 11:21:09 2014 @@ -1,0 +1,67 @@ +#!/usr/bin/env python +''' +Copyright (C) 2014, Fairview 5 Engineering, LLC +George Joseph <[email protected]> + +This program is free software, distributed under the terms of +the GNU General Public License Version 2. +''' + +import sys +import os +import logging + +sys.path.append("lib/python") + +from test_case import TestCase +from syncami import SyncAMI + +LOGGER = logging.getLogger(__name__) + +class ManagerConfigTest(TestCase): + def __init__(self, path=None, config=None): + super(ManagerConfigTest, self).__init__(path, config) + self.create_asterisk() + self.config = config + + def run(self): + super(ManagerConfigTest, self).run() + self.passed = True + + try: + self.syncami = SyncAMI() + for x in self.config.get('ami-config'): + self.run_test(x) + if (not self.passed): + break + except Exception as e: + self.passed = False + LOGGER.error("Exception caught: %s" % e) + raise + finally: + self.stop_reactor() + + def run_test(self, test): + message = test.get('message') + res = self.syncami.send(message) + self.process_response(test, res, message) + + def process_response(self, test, actual, message): + expected = test.get('expected') + + if actual.get('Response') != expected.get('Response'): + LOGGER.error("Request failed...\nMessage: %s\n\nExpected: %s\n\nActual: %s" % (message, expected, actual.items())) + self.passed = False + return + + for name, evalue in expected.items(): + if name == 'Payload': + avalue = actual.get_payload().strip() + else: + avalue = actual.get(name) + + if avalue != evalue: + LOGGER.error("'%s' was '%s' instead of '%s'...\nMessage: %s\n\nExpected: %s\n\nActual: %s" %\ + (name, avalue, evalue, message, expected, actual.items())) + self.passed = False + break Propchange: asterisk/trunk/tests/manager/config/ManagerConfigTest.py ------------------------------------------------------------------------------ svn:eol-style = native Propchange: asterisk/trunk/tests/manager/config/ManagerConfigTest.py ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision URL Propchange: asterisk/trunk/tests/manager/config/ManagerConfigTest.py ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: asterisk/trunk/tests/manager/config/test-config.yaml URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/config/test-config.yaml?view=auto&rev=5721 ============================================================================== --- asterisk/trunk/tests/manager/config/test-config.yaml (added) +++ asterisk/trunk/tests/manager/config/test-config.yaml Mon Oct 13 11:21:09 2014 @@ -1,0 +1,408 @@ +testinfo: + summary: 'Test Manager GetConfig and UpdateConfig' + description: | + 'Test Manager GetConfig and UpdateConfig' +properties: + minversion: '12.7.0' + dependencies: + - python : 'twisted' + - python : 'starpy' + tags: + - manager + - AMI + +test-modules: + add-test-to-search-path: 'True' + test-object: + config-section: object-config + typename: 'ManagerConfigTest.ManagerConfigTest' + +object-config: + reactor-timeout: 15 + ami-config: + - ### Create a new config file + message: + Action: 'CreateConfig' + Filename: 'test.conf' + expected: + Response: 'Success' + Message: 'New configuration file created successfully' + + - ### Load initial values + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'NewCat' + Cat-000000: 'Cat1T' + Options-000000: 'template' + + Action-000001: 'Append' + Cat-000001: 'Cat1T' + Var-000001: 'type' + Value-000001: 'type1' + Options-000001: 'catfilter="TEMPLATES=restrict"' + + Action-000002: 'NewCat' + Cat-000002: 'Cat1' + Options-000002: 'inherit="Cat1T"' + + Action-000003: 'Append' + Cat-000003: 'Cat1' + Var-000003: 'var1' + Value-000003: 'value1' + + Action-000004: 'NewCat' + Cat-000004: 'Cat2T' + Options-000004: 'template' + + Action-000005: 'Append' + Cat-000005: 'Cat2T' + Var-000005: 'type' + Value-000005: 'type2' + Options-000005: 'catfilter="TEMPLATES=restrict"' + expected: + Response: 'Success' + + - ### Find the one concrete category + message: + Action: 'GetConfig' + Filename: 'test.conf' + expected: + Response: 'Success' + Category-000000: 'Cat1' + Templates-000000: 'Cat1T' + IsTemplate-000000: null + Line-000000-000000: 'type=type1' + Line-000000-000001: 'var1=value1' + Line-000000-000002: null + Category-000001: null + + - ### Find the fist template + message: + Action: 'GetConfig' + Filename: 'test.conf' + Category: 'Cat1T' + Filter: 'TEMPLATES=restrict' + expected: + Response: 'Success' + Category-000000: 'Cat1T' + IsTemplate-000000: '1' + Category-000001: null + + - ### Find both templates + message: + Action: 'GetConfig' + Filename: 'test.conf' + Filter: 'TEMPLATES=restrict' + expected: + Response: 'Success' + Category-000000: 'Cat1T' + IsTemplate-000000: '1' + Category-000001: 'Cat2T' + IsTemplate-000001: '1' + Category-000002: null + + - ### Find everything + message: + Action: 'GetConfig' + Filename: 'test.conf' + Filter: 'TEMPLATES=include' + expected: + Response: 'Success' + Category-000000: 'Cat1T' + IsTemplate-000000: '1' + Category-000001: 'Cat1' + IsTemplate-000001: null + Templates-000001: 'Cat1T' + Category-000002: 'Cat2T' + IsTemplate-000002: '1' + Category-000003: null + + - ### Test for non existent config file + message: + Action: 'GetConfig' + Filename: 'nonexistent.conf' + expected: + Response: 'Error' + + - ### Add a new category + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'NewCat' + Cat-000000: 'Cat3' + expected: + Response: 'Success' + + - ### Now delete it + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'DelCat' + Cat-000000: 'Cat3' + expected: + Response: 'Success' + + - ### Make sure it's gone + message: + Action: 'GetConfig' + Filename: 'test.conf' + Category: 'Cat3' + expected: + Response: 'Success' + Payload: 'No categories found' + + - ### Add a second Cat1 inheriting from Cat2T without ignoredups. Should fail. + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'NewCat' + Cat-000000: 'Cat1' + Options-000000: 'inherit="Cat2T"' + expected: + Response: 'Error' + Message: 'Create category did not complete successfully' + + - ### Add a second Cat1 inheriting from nonexistent cat. Should fail. + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'NewCat' + Cat-000000: 'Cat1' + Options-000000: 'ignoredups,inherit="CatZZZZZ"' + expected: + Response: 'Error' + Message: 'Create category did not complete successfully' + + - ### Add a second Cat1 inhetiting from Cat2T for real + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'NewCat' + Cat-000000: 'Cat1' + Options-000000: 'allowdups,inherit="Cat2T"' + + Action-000001: 'Append' + Cat-000001: 'Cat1' + Var-000001: 'varXXX' + Value-000001: 'valueXXX' + Options-000001: 'catfilter="type=type2"' + expected: + Response: 'Success' + + - ### With no filters make sure both Cat1's are returned + message: + Action: 'GetConfig' + Filename: 'test.conf' + Category: 'Cat1' + expected: + Response: 'Success' + Category-000000: 'Cat1' + Category-000001: 'Cat1' + Category-000002: null + + - ### With a filter make sure only 1 Cat1 is returned + message: + Action: 'GetConfig' + Filename: 'test.conf' + Category: 'Cat1' + Filter: 'varXXX=valueXXX' + expected: + Response: 'Success' + Category-000000: 'Cat1' + Line-000000-000000: 'type=type2' + Line-000000-000001: 'varXXX=valueXXX' + Line-000000-000002: null + Category-000001: null + + - ### With no filters this should delete BOTH Cat1's + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'DelCat' + Cat-000000: 'Cat1' + expected: + Response: 'Success' + + - ### Make sure both are gone + message: + Action: 'GetConfig' + Filename: 'test.conf' + Category: 'Cat1' + expected: + Response: 'Success' + Payload: 'No categories found' + Category-000000: null + + - ### Add 1 Cat1 back in again + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'NewCat' + Cat-000000: 'Cat1' + Options-000000: 'inherit="Cat1T"' + + Action-000001: 'Append' + Cat-000001: 'Cat1' + Var-000001: 'var1' + Value-000001: 'value1' + + Action-000002: 'Append' + Cat-000002: 'Cat1' + Var-000002: 'commonvar1' + Value-000002: 'commonvalue1' + + expected: + Response: 'Success' + + - ### Add a Cat2 in with a variable in common with Cat1 + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'NewCat' + Cat-000000: 'Cat2' + Options-000000: 'inherit="Cat2T"' + + Action-000001: 'Append' + Cat-000001: 'Cat2' + Var-000001: 'var2' + Value-000001: 'value2' + + Action-000002: 'Append' + Cat-000002: 'Cat2' + Var-000002: 'commonvar1' + Value-000002: 'commonvalue1' + expected: + Response: 'Success' + + - ### With only a filter make sure both Cat1 and Cat2 are returned + message: + Action: 'GetConfig' + Filename: 'test.conf' + Filter: 'commonvar1=commonvalue1' + expected: + Response: 'Success' + Category-000000: 'Cat1' + Category-000001: 'Cat2' + + - ### Now add a second Cat2 + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'NewCat' + Cat-000000: 'Cat2' + Options-000000: 'allowdups,inherit="Cat2T"' + + Action-000001: 'Append' + Cat-000001: 'Cat2' + Var-000001: 'var2' + Value-000001: 'value2' + + Action-000002: 'Append' + Cat-000002: 'Cat2' + Var-000002: 'commonvar1' + Value-000002: 'commonvalue1' + expected: + Response: 'Success' + + - ### Delete the commonvar1 from both + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'Delete' + Cat-000000: 'Cat2' + Var-000000: 'commonvar1' + expected: + Response: 'Success' + + - ### With only a filter only Cat1 should be returned + message: + Action: 'GetConfig' + Filename: 'test.conf' + Filter: 'commonvar1=commonvalue1' + expected: + Response: 'Success' + Category-000000: 'Cat1' + Category-000001: null + + - ### Just make sure all 3 are still there + message: + Action: 'GetConfig' + Filename: 'test.conf' + expected: + Response: 'Success' + Category-000000: 'Cat1' + Category-000001: 'Cat2' + Category-000002: 'Cat2' + Category-000003: null + + - ### Reset + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'DelCat' + Cat-000000: 'Cat1' + + Action-000001: 'DelCat' + Cat-000001: 'Cat2' + + Action-000002: 'NewCat' + Cat-000002: 'Cat1' + + Action-000003: 'Append' + Cat-000003: 'Cat1' + Var-000003: 'type' + Value-000003: 'type1' + + expected: + Response: 'Success' + + - ### Insert var1 back into Cat1 at line 0 + message: + Action: 'UpdateConfig' + SrcFilename: 'test.conf' + DstFilename: 'test.conf' + + Action-000000: 'Insert' + Cat-000000: 'Cat1' + Var-000000: 'var1' + Value-000000: 'value1' + Line-000000: '0' + expected: + Response: 'Success' + + - ### Make sure lines are now in the right order + message: + Action: 'GetConfig' + Filename: 'test.conf' + Category: 'Cat1' + expected: + Response: 'Success' + Category-000000: 'Cat1' + Line-000000-000000: 'var1=value1' + Line-000000-000001: 'type=type1' + Line-000000-000002: null Propchange: asterisk/trunk/tests/manager/config/test-config.yaml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: asterisk/trunk/tests/manager/config/test-config.yaml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision URL Propchange: asterisk/trunk/tests/manager/config/test-config.yaml ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: asterisk/trunk/tests/manager/tests.yaml URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/tests.yaml?view=diff&rev=5721&r1=5720&r2=5721 ============================================================================== --- asterisk/trunk/tests/manager/tests.yaml (original) +++ asterisk/trunk/tests/manager/tests.yaml Mon Oct 13 11:21:09 2014 @@ -6,6 +6,7 @@ - test: 'authtimeout' - test: 'acl-login' - test: 'bridge_actions' + - test: 'config' - dir: 'danger' - test: 'originate' - test: 'device_state_changed' -- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- svn-commits mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/svn-commits
