-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathcreate_chamberview.py
More file actions
executable file
·311 lines (255 loc) · 11.6 KB
/
create_chamberview.py
File metadata and controls
executable file
·311 lines (255 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/usr/bin/env python3
"""
NAME: create_chamberview.py
PURPOSE: This script creates a scenario in which stations,bridged-AP,vap,etc can be created and upstream, upstream-dhcp,
uplink-nat can be configured in chamber view.
EXAMPLE:
EXAMPLE-1:
./create_chamberview.py -m "localhost" -o "8080" -cs "scenario_name"
--line "Resource=1.1 Profile=STA-AC Amount=1 Uses-1=wiphy0 Uses-2=AUTO Freq=-1
DUT=Test DUT_Radio=Radio-1 Traffic=http VLAN=NA"
--line "Resource=1.1 Profile=upstream Amount=1 Uses-1=eth1 Uses-2=AUTO Freq=-1
DUT=Test DUT_Radio=Radio-1 Traffic=http VLAN=NA"
EXAMPLE-2:
./create_chamberview.py -m "localhost" -o "8080" -cs "scenario_name"
--raw_line "profile_link 1.1 STA-AC 10 'DUT: temp Radio-1' tcp-dl-6m-vi wiphy0,AUTO -1"
--raw_line "profile_link 1.1 upstream 1 'DUT: temp Radio-1' tcp-dl-6m-vi eth1,AUTO -1"
SCRIPT_CLASSIFICATION : Creation
SCRIPT_CATEGORIES: Functional
NOTES:
To Run this script gui should be opened with
path: cd LANforgeGUI_5.4.3 (5.4.3 can be changed with GUI version)
pwd (Output : /home/lanforge/LANforgeGUI_5.4.3)
./lfclient.bash -cli-socket 3990
Scenario names should be different, for each run of this script.
in case of same scenario name scenario will be appended to the same name.
You should see build scenario with the given arguments at the end of this script.
To verify this:
open Chamber View -> Manage scenario
STATUS: Functional
VERIFIED_ON: 31-JULy-2023
Build version - 5.4.6
kernel version - 6.2.16+
LICENSE:
Free to distribute and modify. LANforge systems must be licensed.
Copyright 2023 Candela Technologies Inc
INCLUDE_IN_README: False
"""
import sys
import os
import importlib
import argparse
import time
import shlex
import logging
logger = logging.getLogger(__name__)
if sys.version_info[0] != 3:
print("This script requires Python 3")
exit(1)
sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../")))
cv_test_manager = importlib.import_module("py-json.cv_test_manager")
cv_test = cv_test_manager.cv_test
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
class CreateChamberview(cv_test):
def __init__(self,
lfmgr="localhost",
port="8080",
_debug_on=False,
):
super().__init__(
lfclient_host=lfmgr,
lfclient_port=port,
debug_=_debug_on
)
self.lfmgr = lfmgr
self.port = port
def clean_cv_scenario(
self,
cv_type="Network-Connectivity",
scenario_name=None):
self.rm_cv_text_blob(cv_type, scenario_name)
def setup(self,
create_scenario="",
line="",
raw_line=None):
if raw_line:
logger.info("creating %s scenario using raw lines" % create_scenario)
for create_lines in raw_line:
ln = create_lines[0]
# print("ln: %s" % (ln))
self.pass_raw_lines_to_cv(create_scenario, ln)
# check for lines
if line:
scenario_name = create_scenario
line = line
Resource = "1.1"
Profile = "STA-AC"
Amount = "1"
DUT = "DUT"
DUT_Radio = "Radio-1"
Uses1 = "wiphy0"
Uses2 = "AUTO"
Traffic = "http"
Freq = "-1"
VLAN = ""
# print("line: ")
# pprint(line)
for item in line:
# print("item: ")
# pprint(item)
for sub_item in shlex.split(item[0]):
# print("sub-item: ")
# pprint(sub_item)
sub_item = sub_item.split("=")
if sub_item[0] == "Resource" or str(
sub_item[0]) == "Res" or sub_item[0] == "R":
Resource = sub_item[1]
elif sub_item[0] == "Profile" or sub_item[0] == "Prof" or sub_item[0] == "P":
Profile = sub_item[1]
elif sub_item[0] == "Amount" or sub_item[0] == "Sta" or sub_item[0] == "A":
Amount = sub_item[1]
elif sub_item[0] == "Uses-1" or sub_item[0] == "U1" or sub_item[0] == "U-1":
Uses1 = sub_item[1]
elif sub_item[0] == "Uses-2" or sub_item[0] == "U2" or sub_item[0] == "U-2":
Uses2 = sub_item[1]
elif sub_item[0] == "Freq" or sub_item[0] == "Freq" or sub_item[0] == "F":
Freq = sub_item[1]
elif sub_item[0] == "DUT" or sub_item[0] == "dut" or sub_item[0] == "D":
DUT = sub_item[1]
elif sub_item[0] == "DUT_Radio" or sub_item[0] == "dr" or sub_item[0] == "DR":
DUT_Radio = sub_item[1]
elif sub_item[0] == "Traffic" or sub_item[0] == "Traf" or sub_item[0] == "T":
Traffic = sub_item[1]
elif sub_item[0] == "VLAN" or sub_item[0] == "Vlan" or sub_item[0] == "V":
VLAN = sub_item[1]
else:
logger.critical("ERROR: Unknown line argument -:%s:-" % (sub_item[0]))
logger.critical("Un-supported line argument")
raise ValueError("Un-supported line argument") # Bad user input, terminate script.
continue
self.add_text_blob_line(scenario_name,
Resource,
Profile,
Amount,
DUT,
DUT_Radio,
Uses1,
Uses2,
Traffic,
Freq,
VLAN
) # To manage scenario
if not line and not raw_line:
logger.critical("scenario creation failed")
raise Exception("scenario creation failed")
return True
def build(self, scenario_name):
self.sync_cv() # chamberview sync
time.sleep(2)
self.apply_cv_scenario(scenario_name) # Apply scenario
self.show_text_blob(None, None, False) # Show changes on GUI
self.apply_cv_scenario(scenario_name) # Apply scenario
self.build_cv_scenario() # build scenario
tries = 0
while True:
self.get_popup_info_and_close()
if not self.get_cv_is_built():
# It can take a while to build a large scenario, so wait-time
# is currently max of 5 minutes.
logger.info("Waiting %i/300 for Chamber-View to be built." % tries)
tries += 1
if tries > 300:
self._fail("Waiting %i/300 for Chamber-View to be built." % tries)
break
time.sleep(1)
else:
self._pass("completed building %s scenario" % scenario_name)
break
def main():
help_summary = '''\
This script creates a scenario in which stations,bridged-AP,vap,etc can be created and upstream, upstream-dhcp, uplink-nat can be configured in chamber view.
'''
parser = cv_test.create_basic_argparse(
prog='create_chamberview.py',
formatter_class=argparse.RawTextHelpFormatter,
description="""
NAME: create_chamberview.py
PURPOSE: This script creates a scenario in which stations,bridged-AP,vap,etc can be created and upstream, upstream-dhcp,
uplink-nat can be configured in chamber view.
EXAMPLE:
EXAMPLE-1:
./create_chamberview.py -m "localhost" -o "8080" -cs "scenario_name"
--line "Resource=1.1 Profile=STA-AC Amount=1 Uses-1=wiphy0 Uses-2=AUTO Freq=-1
DUT=Test DUT_Radio=Radio-1 Traffic=http VLAN=NA"
--line "Resource=1.1 Profile=upstream Amount=1 Uses-1=eth1 Uses-2=AUTO Freq=-1
DUT=Test DUT_Radio=Radio-1 Traffic=http VLAN=NA"
EXAMPLE-2:
./create_chamberview.py -m "localhost" -o "8080" -cs "scenario_name"
--raw_line "profile_link 1.1 STA-AC 10 'DUT: temp Radio-1' tcp-dl-6m-vi wiphy0,AUTO -1"
--raw_line "profile_link 1.1 upstream 1 'DUT: temp Radio-1' tcp-dl-6m-vi eth1,AUTO -1"
SCRIPT_CLASSIFICATION : Creation
SCRIPT_CATEGORIES: Functional
NOTES:
To Run this script gui should be opened with
path: cd LANforgeGUI_5.4.3 (5.4.3 can be changed with GUI version)
pwd (Output : /home/lanforge/LANforgeGUI_5.4.3)
./lfclient.bash -cli-socket 3990
Scenario names should be different, for each run of this script.
in case of same scenario name scenario will be appended to the same name.
You should see build scenario with the given arguments at the end of this script.
To verify this:
open Chamber View -> Manage scenario
STATUS: Functional
VERIFIED_ON: 31-JULy-2023
Build version - 5.4.6
kernel version - 6.2.16+
LICENSE:
Free to distribute and modify. LANforge systems must be licensed.
Copyright 2023 Candela Technologies Inc
INCLUDE_IN_README: False
""")
parser.add_argument(
"-cs",
"--create_scenario",
"--create_lf_scenario",
type=str,
help="name of scenario to be created and saved in lanforge database. See further notes section for more details.")
parser.add_argument("-l", "--line", action='append', nargs='+',
help="line number", default=[])
parser.add_argument("-rl", "--raw_line", action='append', nargs=1,
help="raw lines", default=[])
parser.add_argument(
"-ds",
"--delete_scenario",
default=False,
action='store_true',
help="delete existing scenario with same name as given in 'create-scenario' argument. See 'further notes' section for more details. (by default: False)")
args = parser.parse_args()
if args.help_summary:
print(help_summary)
exit(0)
logger_config = lf_logger_config.lf_logger_config()
# set the logger level to requested value
logger_config.set_level(level=args.log_level)
logger_config.set_json(json_file=args.lf_logger_config_json)
Create_Chamberview = CreateChamberview(lfmgr=args.mgr,
_debug_on=args.debug,
port=args.mgr_port,
)
if args.delete_scenario:
Create_Chamberview.clean_cv_scenario(
cv_type="Network-Connectivity",
scenario_name=args.create_scenario)
Create_Chamberview.setup(create_scenario=args.create_scenario,
line=args.line,
raw_line=args.raw_line)
Create_Chamberview.build(args.create_scenario)
# TODO: Build the scenario (cv click the 'Build Scenario' button, wait until build has completed
# TODO: Find and admin up all wlan* and sta* ports,
# TODO: Verify they admin up and get IP address.
if Create_Chamberview.passes():
Create_Chamberview.exit_success()
else:
Create_Chamberview.exit_fail()
if __name__ == "__main__":
main()