fake_daqapp_rest
drunc.apps.fake_daqapp_rest
This is a fake DAQ application that doesn't do anything, but should talk in the same way to the run control.
It is primarily used for the testing of the Run Control.
Classes
AppCommand
Bases: Resource
Flask interface for the fake daq app.
Receives the commands from the command facility and passes them to the AppState to be executed, and sends the response back to the response listener.
Methods:
pass_daq_app(daq_app)
classmethod
Interface to pass the daq_app instance to the Flask resource, since Flask doesn't allow to pass arguments to the resource constructor.
Source code in drunc/apps/fake_daqapp_rest.py
post()
Endpoint to receive commands from the command facility. The command data should be sent in a JSON format, with the following structure: { "id": "command_id", "entry_state": "state the app should be in to execute the command, or *", "exit_state": "state the app will be in after executing the command", "data": { optional parameters: "execution-time": "time the command should take to execute", "seg_fault": "app will exit with this code to simulate a failure", "throw": "app will throw an exception to simulate a failure" } }
Source code in drunc/apps/fake_daqapp_rest.py
AppState(app_name)
Tracks state of the apps, and simulates the behaviour of daq_applicaitons with stateful commands.
Initialize the app state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The name of the app, used for logging and in the responses |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in drunc/apps/fake_daqapp_rest.py
Methods:
execute_command(req_data, answer_port, answer_host, remote_host)
Execute a command received from the command facility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
req_data
|
dict
|
The data received in the command, should contain at least the following keys: - id: The id of the command, used for logging and in the responses - entry_state: The state the app should be in to execute the command, or "*" to ignore the state - exit_state: The state the app will be in after executing the command - data: A dictionary with additional data for the command, can contain: - execution-time: An integer with the time the command should take to execute, in seconds - seg_fault: An integer that if present will cause the app to exit with that code - throw: If present, the app will throw an exception instead of executing the command |
required |
answer_port
|
str
|
The port to send the response to |
required |
answer_host
|
str | None
|
The host to send the response to, if None, the remote_host will be used |
required |
remote_host
|
str
|
The host that sent the command, used for logging and as a fallback for the answer_host |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Response |
Response
|
A Flask response object with the result of the command execution |
Source code in drunc/apps/fake_daqapp_rest.py
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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
send_response_to_response_listener(address, txt, success=True, data=None)
Send a response to the response listener.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
The address of the response listener |
required |
txt
|
str
|
The text to send in the response |
required |
success
|
bool
|
Whether the command was executed successfully or not |
True
|
data
|
dict
|
Additional data to send in the response |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in drunc/apps/fake_daqapp_rest.py
CommandRequest
Bases: TypedDict
Expected structure for incoming DAQ application command requests.
Functions:
get_address(hostname)
Gets a new address for the application, by finding an available port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The hostname to use in the address |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
URI with the given hostname and a new available port |
Source code in drunc/apps/fake_daqapp_rest.py
index()
Endpoint to check if the app is running, can be used in the tests to wait for the app to be ready before sending commands to it.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string indicating the app is running. |
Source code in drunc/apps/fake_daqapp_rest.py
update_connectivity_service(name, connectivity_service, interval, url)
Function to continuously update the connectivity service with the address of the app, to simulate the behaviour of a real DAQ application that is continuously publishing its address to the connectivity service. This is necessary for the Run Control to be able to send commands to the app, since the Run Control gets the address of the app from the connectivity service. The function runs in a separate thread to not block the main thread of the app, which is running the Flask app to receive commands from the command facility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the publishing app |
required |
connectivity_service
|
ConnectivityServiceClient
|
the client to publish to the connectivity service |
required |
interval
|
int
|
Interval in seconds to update the connectivity service |
required |
url
|
str
|
The app address to publish to the connectivity service |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |