cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
test_cfsp_module.py
Go to the documentation of this file.
1 # /*******************************************************************************
2 # * Copyright 2016 -- 2022 IBM Corporation
3 # *
4 # * Licensed under the Apache License, Version 2.0 (the "License");
5 # * you may not use this file except in compliance with the License.
6 # * You may obtain a copy of the License at
7 # *
8 # * http://www.apache.org/licenses/LICENSE-2.0
9 # *
10 # * Unless required by applicable law or agreed to in writing, software
11 # * distributed under the License is distributed on an "AS IS" BASIS,
12 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # * See the License for the specific language governing permissions and
14 # * limitations under the License.
15 # *******************************************************************************/
16 
17 # *
18 # * cloudFPGA
19 # * Copyright IBM Research, All Rights Reserved
20 # * =============================================
21 # * Created: Sep. 2020
22 # * Authors: FAB, WEI, NGL, DID
23 # *
24 # * Description:
25 # * A test example of cFSP Python module.
26 # *
27 # *
28 
29 import sys
30 from docopt import docopt
31 
32 # make sure cFSPlib's folder is in the PYTHONPATH, or add a line as below
33 sys.path.append("../")
34 
35 from cFSPlib import cFSP
36 
37 retval=0
38 num_tests=16
39 
40 # Create a variable of class cFSP docopt.
41 # This variable will be populated with the options we need to pass to the callable cFSP module
42 args=docopt(cFSP.__doc__)
43 
44 
45 
46 
49 print("############# Start testing: help ###############\n")
50 args['<command>'] = 'help'
51 args['<args>'] = ['']
52 cFSP.main(args)
53 retval=retval+1
54 print("############# End testing: help ###############\n\n")
55 
56 
57 
58 
61 print("############# Start testing: user load ###############\n")
62 args['<command>'] = 'user'
63 args['<args>'] = ['load']
64 cFSP.main(args)
65 retval=retval+1
66 print("############# End testing: user load ###############\n\n")
67 
68 print("############# Start testing: user show ###############\n")
69 args['<command>'] = 'user'
70 args['<args>'] = ['show']
71 cFSP.main(args)
72 retval=retval+1
73 print("############# End testing: user show ###############\n\n")
74 
75 
76 
77 
80 print("############# Start testing: get instance ###############\n")
81 args['<command>'] = 'instance'
82 args['<args>'] = ['get']
83 cfrm_response=cFSP.main(args)
84 print(cfrm_response)
85 retval=retval+1
86 print("############# End testing: get instance ###############\n\n")
87 
88 print("############# Start testing: post instance ###############\n")
89 args['<command>'] = 'instance'
90 args['<args>'] = ['post']
91 args['--image_id'] = ['74462cd5-20e3-4228-a47d-258b7e5e583a']
92 cfrm_response=cFSP.main(args)
93 print(cfrm_response)
94 instance_id=cfrm_response.instance_id
95 print("INFO: The new instance has id : " + str(instance_id))
96 retval=retval+1
97 print("############# End testing: post instance ###############\n\n")
98 
99 print("############# Start testing: restart instance ###############\n")
100 args['<command>'] = 'instance'
101 args['<args>'] = ['restart', str(instance_id)]
102 cfrm_response=cFSP.main(args)
103 print(cfrm_response)
104 retval=retval+1
105 print("############# End testing: restart instance ###############\n\n")
106 
107 print("############# Start testing: debug instance ###############\n")
108 args['<command>'] = 'debug'
109 args['<args>'] = ['get', 'flight_recorder_data', 'instance', str(instance_id)]
110 cfrm_response=cFSP.main(args)
111 print(cfrm_response)
112 retval=retval+1
113 print("############# End testing: debug instance ###############\n\n")
114 
115 print("############# Start testing: delete instance ###############\n")
116 args['<command>'] = 'instance'
117 args['<args>'] = ['delete', str(instance_id)]
118 cfrm_response=cFSP.main(args)
119 print(cfrm_response)
120 retval=retval+1
121 print("############# End testing: delete instance ###############\n\n")
122 
123 
124 
125 
128 print("############# Start testing: get image ###############\n")
129 args['<command>'] = 'image'
130 args['<args>'] = ['get']
131 cfrm_response=cFSP.main(args)
132 print(cfrm_response)
133 retval=retval+1
134 print("############# End testing: get image ###############\n\n")
135 
136 print("############# Start testing: post image ###############\n")
137 args['<command>'] = 'image'
138 args['<args>'] = ['post']
139 args['--image_file'] = './4_topFMKU60_impl_monolithic.bit' # ensure this file exists
140 cfrm_response=cFSP.main(args)
141 print(cfrm_response)
142 print("INFO: The uploaded image has id : " + str(cfrm_response.id))
143 retval=retval+1
144 print("############# End testing: post image ###############\n\n")
145 
146 print("############# Start testing: delete image ###############\n")
147 args['<command>'] = 'image'
148 args['<args>'] = ['delete', str(cfrm_response.id)]
149 cfrm_response=cFSP.main(args)
150 print(cfrm_response)
151 retval=retval+1
152 print("############# End testing: delete image ###############\n\n")
153 
154 
155 
156 
159 print("############# Start testing: get cluster ###############\n")
160 args['<command>'] = 'cluster'
161 args['<args>'] = ['get']
162 cfrm_response=cFSP.main(args)
163 print(cfrm_response)
164 retval=retval+1
165 print("############# End testing: get cluster ###############\n\n")
166 
167 print("############# Start testing: post_cluster ###############\n")
168 args['<command>'] = 'cluster'
169 args['<args>'] = ['post']
170 args['--image_id'] = ['74462cd5-20e3-4228-a47d-258b7e5e583a']
171 args['--node_ip'] = ['10.12.2.100']
172 cfrm_response=cFSP.main(args)
173 print(cfrm_response)
174 cluster_id = cfrm_response.cluster_id
175 print("INFO: The new cluster has id : " + str(cluster_id))
176 retval=retval+1
177 print("############# End testing: post_cluster ###############\n\n")
178 
179 print("############# Start testing: restart cluster ###############\n")
180 args['<command>'] = 'cluster'
181 args['<args>'] = ['restart', str(cluster_id)]
182 cfrm_response=cFSP.main(args)
183 print(cfrm_response)
184 retval=retval+1
185 print("############# End testing: restart cluster ###############\n\n")
186 
187 print("############# Start testing: debug cluster ###############\n")
188 args['<command>'] = 'debug'
189 args['<args>'] = ['get', 'flight_recorder_data', 'cluster', str(cluster_id)]
190 cfrm_response=cFSP.main(args)
191 print(cfrm_response)
192 retval=retval+1
193 print("############# End testing: debug cluster ###############\n\n")
194 
195 print("############# Start testing: delete cluster ###############\n")
196 args['<command>'] = 'cluster'
197 args['<args>'] = ['delete', str(cluster_id)]
198 cfrm_response=cFSP.main(args)
199 print(cfrm_response)
200 retval=retval+1
201 print("############# End testing: delete cluster ###############\n\n")
202 
203 
204 
205 
208 if (retval==num_tests):
209  print("INFO: Succesfully completed " + str(num_tests) + " tests!")
210  exit(0)
211 else:
212  print("ERROR: Only " + str(retval) + " tests out of " + str(num_tests) + " completed succesfully.")
213  exit(-1)
214