mocked_env
ConnectionFailureConfig
Configuration class for different types of connection failures. This allows users to configure specific failure scenarios similar to the responses library.
Source code in src/paramiko_mock/mocked_env.py
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 | |
authentication_failure()
staticmethod
Create an authentication failure (AuthenticationException)
Source code in src/paramiko_mock/mocked_env.py
38 39 40 41 | |
connection_refused()
staticmethod
Create a connection refused failure
Source code in src/paramiko_mock/mocked_env.py
43 44 45 46 | |
custom_exception(exception)
staticmethod
Create a custom exception
Source code in src/paramiko_mock/mocked_env.py
68 69 70 71 | |
dns_failure(hostname=None)
staticmethod
Create a DNS resolution failure (socket.gaierror)
Source code in src/paramiko_mock/mocked_env.py
26 27 28 29 30 31 | |
timeout_failure()
staticmethod
Create a connection timeout failure (TimeoutError)
Source code in src/paramiko_mock/mocked_env.py
33 34 35 36 | |
ParamikoMockEnviron
This class is the Coordinator for the ParamikoMock environment. It stores information about the remote devices and the local filesystem.
Source code in src/paramiko_mock/mocked_env.py
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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
add_local_file(path, file_mock)
add_local_file is a method that adds a mock file to the local
filesystem.
- path: The path of the file.
- file_mock: The mock file to add.
Source code in src/paramiko_mock/mocked_env.py
221 222 223 224 225 226 227 228 229 | |
add_mock_file_for_host(host, port, path, file_mock)
add_mock_file_for_host is a method that adds a mock file to the remote
filesystem for a specific host.
- host: The hostname of the remote device.
- port: The port of the remote device.
- path: The path of the file.
- file_mock: The mock file to add.
Source code in src/paramiko_mock/mocked_env.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
add_responses_for_host(host, port, responses, username=None, password=None, connection_failure=None)
add_responses_for_host is a method that adds responses for a remote
device. Effectively, it creates a new MockRemoteDevice object and stores
it in the environment.
- host: The hostname of the remote device.
- port: The port of the remote device.
- responses: A dictionary that maps commands to responses.
- username: The username for the remote device (optional)
- password: The password for the remote device (optional)
- connection_failure: An exception to raise during connection (optional)
Source code in src/paramiko_mock/mocked_env.py
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 | |
assert_command_executed_on_index(host, port, command, index)
assert_command_executed_on_index is a method that asserts that a
command was executed on a specific index
- host: The hostname of the remote device.
- port: The port of the remote device.
- command: The command to assert.
- index: The index to assert.
Raises: AssertionError if the command was not executed on the index.
Source code in src/paramiko_mock/mocked_env.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
assert_command_was_executed(host, port, command)
assert_command_was_executed is a method that asserts that a command
was executed
- host: The hostname of the remote device.
- port: The port of the remote device.
- command: The command to assert.
Raises: AssertionError if the command was not executed.
Source code in src/paramiko_mock/mocked_env.py
252 253 254 255 256 257 258 259 260 261 262 263 264 | |
assert_command_was_not_executed(host, port, command)
assert_command_was_not_executed is a method that asserts that a
command was not executed
- host: The hostname of the remote device.
- port: The port of the remote device.
- command: The command to assert.
Raises: AssertionError if the command was executed
Source code in src/paramiko_mock/mocked_env.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
cleanup_environment()
cleanup_environment is a method that clears the environment.
Source code in src/paramiko_mock/mocked_env.py
168 169 170 171 172 173 174 | |
get_local_file(path)
get_local_file is a method that retrieves a mock file from the local
filesystem.
- path: The path of the file.
Returns: The mock file.
Source code in src/paramiko_mock/mocked_env.py
240 241 242 243 244 245 246 247 248 249 | |
get_mock_file_for_host(host, port, path)
get_mock_file_for_host is a method that retrieves a mock file from the
remote filesystem for a specific host.
- host: The hostname of the remote device.
- port: The port of the remote device.
- path: The path of the file.
Returns: The mock file.
Source code in src/paramiko_mock/mocked_env.py
207 208 209 210 211 212 213 214 215 216 217 218 219 | |
get_remote_device(host)
get_remote_device is a method that retrieves a remote device from the
environment.
- host: The hostname of the remote device. Returns: The remote device.
Note: This method is protected and should not be used outside of the package. (We cannot guarantee that this method will not change in the future)
Source code in src/paramiko_mock/mocked_env.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
remove_local_file(path)
remove_local_file is a method that removes a mock file from the local
filesystem.
- path: The path of the file.
Source code in src/paramiko_mock/mocked_env.py
231 232 233 234 235 236 237 238 | |
remove_mock_file_for_host(host, port, path)
remove_mock_file_for_host is a method that removes a mock file from the
remote filesystem for a specific host.
- host: The hostname of the remote device.
- port: The port of the remote device.
- path: The path of the file.
Source code in src/paramiko_mock/mocked_env.py
195 196 197 198 199 200 201 202 203 204 205 | |
setup_authentication_failure(host, port=22)
Set up an authentication failure for a host.
- host: The hostname to fail authentication for
- port: The port (default: 22)
Source code in src/paramiko_mock/mocked_env.py
332 333 334 335 336 337 338 339 340 341 342 | |
setup_badhost_failure(host, port, custom_got_key=None, custom_pkey=None)
Set up a custom exception failure for a host.
- host: The hostname to fail for
- port: The port
- exception: The custom exception to raise
Source code in src/paramiko_mock/mocked_env.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
setup_connection_refused(host, port=22)
Set up a connection refused failure for a host.
- host: The hostname to refuse connection for
- port: The port (default: 22)
Source code in src/paramiko_mock/mocked_env.py
344 345 346 347 348 349 350 351 352 353 354 | |
setup_custom_failure(host, port, exception)
Set up a custom exception failure for a host.
- host: The hostname to fail for
- port: The port
- exception: The custom exception to raise
Source code in src/paramiko_mock/mocked_env.py
356 357 358 359 360 361 362 363 364 365 366 367 | |
setup_dns_failure(host, port=22, hostname=None)
Set up a DNS resolution failure for a host.
- host: The hostname to fail DNS resolution for
- port: The port (default: 22)
- hostname: Optional custom hostname for the error message
Source code in src/paramiko_mock/mocked_env.py
307 308 309 310 311 312 313 314 315 316 317 318 | |
setup_timeout_failure(host, port=22)
Set up a connection timeout failure for a host.
- host: The hostname to timeout for
- port: The port (default: 22)
Source code in src/paramiko_mock/mocked_env.py
320 321 322 323 324 325 326 327 328 329 330 | |