This class defines the functions necessary to launch a task in the CLI unit tests.
| 312 | |
| 313 | |
| 314 | class Task(Executable): |
| 315 | """ |
| 316 | This class defines the functions necessary to launch a task in |
| 317 | the CLI unit tests. |
| 318 | """ |
| 319 | count = 0 |
| 320 | |
| 321 | def __init__(self, flags=None): |
| 322 | super(Task, self).__init__() |
| 323 | |
| 324 | if flags is None: |
| 325 | flags = {} |
| 326 | |
| 327 | if "master" not in flags: |
| 328 | flags["master"] = "{ip}:{port}".format( |
| 329 | ip=TEST_MASTER_IP, |
| 330 | port=TEST_MASTER_PORT) |
| 331 | if "name" not in flags: |
| 332 | flags["name"] = "task-{id}".format(id=Task.count) |
| 333 | if "command" not in flags: |
| 334 | raise CLIException("No command supplied when creating task") |
| 335 | |
| 336 | self.flags = flags |
| 337 | self.name = flags["name"] |
| 338 | self.executable = os.path.join( |
| 339 | CLITestCase.MESOS_BUILD_DIR, |
| 340 | "src", |
| 341 | "mesos-execute") |
| 342 | |
| 343 | def __wait_for_containers(self, condition, timeout=TIMEOUT): |
| 344 | """ |
| 345 | Wait for the agent's '/containers' endpoint |
| 346 | to return data subject to 'condition'. |
| 347 | """ |
| 348 | try: |
| 349 | data = http.get_json(self.flags["master"], "slaves") |
| 350 | except Exception as exception: |
| 351 | raise CLIException("Could not get '/slaves' endpoint" |
| 352 | " as JSON: {error}" |
| 353 | .format(error=exception)) |
| 354 | |
| 355 | if len(data["slaves"]) != 1: |
| 356 | raise CLIException("More than one agent detected when" |
| 357 | " reading from '/slaves' endpoint") |
| 358 | |
| 359 | try: |
| 360 | agent = parse.parse( |
| 361 | "slave({id})@{addr}", |
| 362 | data["slaves"][0]["pid"]) |
| 363 | except Exception as exception: |
| 364 | raise CLIException("Unable to parse agent info: {error}" |
| 365 | .format(error=exception)) |
| 366 | |
| 367 | try: |
| 368 | data = http.get_json( |
| 369 | agent["addr"], |
| 370 | "containers", |
| 371 | condition, |
no outgoing calls