3 Example script to inject a throttling command list to the test_collector.
5 Only intended for test purposes.
10 Copyright(c) <2016>, AT&T Intellectual Property. All other rights reserved.
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
15 1. Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright notice,
18 this list of conditions and the following disclaimer in the documentation
19 and/or other materials provided with the distribution.
20 3. All advertising materials mentioning features or use of this software
21 must display the following acknowledgement: This product includes
22 software developed by the AT&T.
23 4. Neither the name of AT&T nor the names of its contributors may be used to
24 endorse or promote products derived from this software without specific
25 prior written permission.
27 THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY
28 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY
31 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
34 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 ###############################################################################
43 # Functions to build up commandList contents
44 ###############################################################################
46 "return a provideThrottlingState command"
48 {'commandType': 'provideThrottlingState'}}
50 def command_interval(interval):
51 "return a measurementIntervalChange command"
53 {'commandType': 'measurementIntervalChange',
54 'measurementInterval': interval}}
56 def command_throttle(domain, fields, pairs):
57 "return a throttlingSpecification"
58 throttle_spec = {'eventDomain' : domain}
60 throttle_spec['suppressedFieldNames'] = fields
62 throttle_spec['suppressedNvPairsList'] = pairs
64 {'commandType': 'throttlingSpecification',
65 'eventDomainThrottleSpecification': throttle_spec}}
67 def command_nvpairs(field_name, pair_names):
68 "return a suppressedNvPairs"
69 return {'nvPairFieldName' : field_name,
70 'suppressedNvPairNames' : pair_names}
72 ###############################################################################
73 # Example functions to build up commandLists for various domains.
74 ###############################################################################
75 def command_list_empty():
76 return {'commandList' : []}
78 def command_list_provide():
79 return {'commandList' : [command_state()]}
81 def command_list_interval(interval):
82 return {'commandList' : [command_interval(interval)]}
84 def command_list_fault_suppress_fields():
85 "Throttling Specification - two suppressedFieldNames"
86 fields = ['alarmInterfaceA', 'alarmAdditionalInformation']
88 command_list = [command_throttle('fault', fields, pairs)]
89 return {'commandList' : command_list}
91 def command_list_fault_suppress_nothing():
92 "Throttling Specification - no suppression"
95 command_list = [command_throttle('fault', fields, pairs)]
96 return {'commandList' : command_list}
98 def command_list_fault_suppress_pairs():
99 "Throttling Specification - two suppressedNvPairNames"
101 pairs = [command_nvpairs('alarmAdditionalInformation',
103 command_list = [command_throttle('fault', fields, pairs)]
104 return {'commandList' : command_list}
106 def command_list_fault_suppress_fields_and_pairs():
107 "Throttling Specification - a mixture of fields and pairs"
108 fields = ['alarmInterfaceA']
109 pairs = [command_nvpairs('alarmAdditionalInformation',
111 command_list = [command_throttle('fault', fields, pairs)]
112 return {'commandList' : command_list}
114 def command_list_measurements_suppress_example():
115 "Throttling Specification - measurements"
116 fields = ['numberOfMediaPortsInUse', 'aggregateCpuUsage']
117 pairs = [command_nvpairs('cpuUsageArray',
119 command_list = [command_throttle('measurementsForVfScaling',
121 return {'commandList' : command_list}
123 def command_list_mobile_flow_suppress_example():
124 "Throttling Specification - mobile flow"
125 fields = ['radioAccessTechnology', 'samplingAlgorithm']
127 command_list = [command_throttle('mobileFlow', fields, pairs)]
128 return {'commandList' : command_list}
130 def command_list_state_change_suppress_example():
131 "Throttling Specification - state change"
132 fields = ['reportingEntityId', 'eventType', 'sourceId']
133 pairs = [command_nvpairs('additionalFields', ['Name1'])]
134 command_list = [command_throttle('stateChange', fields, pairs)]
135 return {'commandList' : command_list}
137 def command_list_syslog_suppress_example():
138 "Throttling Specification - syslog"
139 fields = ['syslogFacility', 'syslogProc', 'syslogProcId']
140 pairs = [command_nvpairs('additionalFields', ['Name1', 'Name4'])]
141 command_list = [command_throttle('syslog', fields, pairs)]
142 return {'commandList' : command_list}
144 def command_list_reset_all_domains():
145 "Throttling Specification - reset all domains"
146 command_list = [command_throttle('fault', [], []),
147 command_throttle('measurementsForVfScaling', [], []),
148 command_throttle('mobileFlow', [], []),
149 command_throttle('stateChange', [], []),
150 command_throttle('syslog', [], [])]
151 return {'commandList' : command_list}
154 fields = ['alarmInterfaceA']
155 pairs = [command_nvpairs('alarmAdditionalInformation',
157 command_list = [command_throttle('fault', fields, pairs),
158 command_interval(10),
160 return {'commandList' : command_list}
162 ###############################################################################
163 # Default command line values
164 ###############################################################################
165 DEFAULT_FQDN = "127.0.0.1"
168 ###############################################################################
169 # Command Line Parsing
170 ###############################################################################
171 parser = optparse.OptionParser()
172 parser.add_option('--fqdn',
175 default=DEFAULT_FQDN)
176 parser.add_option('--port',
179 default=DEFAULT_PORT,
181 options, remainder = parser.parse_args()
183 ###############################################################################
184 # Derive the Test Control URL
185 ###############################################################################
186 url = 'http://%s:%d/testControl/v1.1/commandList'%(options.fqdn, options.port)
188 ###############################################################################
189 # Create JSON and POST it to the Test Control URL.
190 ###############################################################################
191 command_list = command_list_fault_suppress_fields_and_pairs()
192 requests.post(url, json = command_list)