|
2 | 2 |
|
3 | 3 | # This SConscript describes build and install rules for the Mongo C++ driver and associated exmaple |
4 | 4 | # programs. |
5 | | -import os |
| 5 | +import buildscripts.git |
6 | 6 | import httplib |
7 | | -import urllib |
8 | 7 | import json |
| 8 | +import os |
9 | 9 | import re |
10 | 10 | import time |
11 | | -import buildscripts.git |
| 11 | +import urllib |
12 | 12 |
|
13 | 13 | Import('env has_option get_option') |
14 | 14 | Import('nix linux darwin windows') |
@@ -545,74 +545,92 @@ clientEnv.Alias('build-examples', clientTestPrograms) |
545 | 545 |
|
546 | 546 | clientTestProgramInstalls = staticClientProgramInstalls + sharedClientProgramInstalls |
547 | 547 |
|
548 | | -# TODO: Make this more Scons-like with an action target that causes |
549 | | -# a server to come into being and then have each test depend on it. |
550 | | -orchestration_uri = "%s:%s" % (clientEnv.GetOption("mongo-orchestration-host"), |
551 | | - clientEnv.GetOption("mongo-orchestration-port")) |
552 | | -json_headers = { "Content-Type": "application/json" } |
553 | | - |
554 | | -params = json.dumps({ |
555 | | - "id": "standalone", |
556 | | - "name": "mongod", |
557 | | - "preset": clientEnv.GetOption("mongo-orchestration-preset") |
558 | | -}) |
559 | | - |
560 | | -# Check if a standalone mongod is already up, resetting if it is |
561 | | -MO_MAX_RETRIES = 10 |
562 | | -for attempt in range(1, MO_MAX_RETRIES+1): |
563 | | - |
564 | | - if attempt > 1: |
565 | | - # don't sleep before first attempt |
566 | | - time.sleep(1) |
567 | | - |
568 | | - try: |
569 | | - conn = httplib.HTTPConnection(orchestration_uri, timeout=30) |
570 | | - conn.request("GET", "/servers/standalone", headers=json_headers) |
571 | | - response = conn.getresponse() |
572 | | - message = response.read() |
573 | | - |
574 | | - except IOError: |
575 | | - print("Cannot connect to Mongo Orchestration at %s on attempt %d. %d attempts remaining..." |
576 | | - % (orchestration_uri, attempt, MO_MAX_RETRIES - (attempt))) |
577 | | - continue |
| 548 | +mongoDBUri = str() |
| 549 | +def getMongoDBUri(): |
| 550 | + return mongoDBUri |
| 551 | +clientEnv['getMongoDBUri'] = getMongoDBUri |
578 | 552 |
|
579 | | - if (response.status == 404): |
580 | | - print("No standalone started, starting one now...") |
581 | | - post_conn = httplib.HTTPConnection(orchestration_uri, timeout=30) |
582 | | - post_conn.request("POST", "/servers", params, json_headers) |
583 | | - continue |
584 | | - elif (response.status/100 != 2): |
585 | | - print("Mongo Orchestration had an error with code %s" % response.status) |
586 | | - if message: |
587 | | - print("\tmessage from MO: %s", message) |
588 | | - continue |
| 553 | +def setupMongoOrchestration(target, source, env): |
| 554 | + |
| 555 | + orchestration_uri = "%s:%s" % (env.GetOption("mongo-orchestration-host"), |
| 556 | + env.GetOption("mongo-orchestration-port")) |
| 557 | + json_headers = { "Content-Type": "application/json" } |
| 558 | + |
| 559 | + params = json.dumps({ |
| 560 | + "id": "standalone", |
| 561 | + "name": "mongod", |
| 562 | + "preset": env.GetOption("mongo-orchestration-preset") |
| 563 | + }) |
| 564 | + |
| 565 | + # Check if a standalone mongod is already up, resetting if it is |
| 566 | + MO_MAX_RETRIES = 10 |
| 567 | + for attempt in range(1, MO_MAX_RETRIES+1): |
589 | 568 |
|
590 | | - # Grab the port from the response -- use it in the tests |
591 | | - decoded_response = json.loads(message) |
592 | | - mongodb_uri = decoded_response['mongodb_uri'] |
| 569 | + if attempt > 1: |
| 570 | + # don't sleep before first attempt |
| 571 | + time.sleep(1) |
593 | 572 |
|
594 | | - for clientTest in clientTestProgramInstalls: |
| 573 | + try: |
| 574 | + conn = httplib.HTTPConnection(orchestration_uri, timeout=30) |
| 575 | + conn.request("GET", "/servers/standalone", headers=json_headers) |
| 576 | + response = conn.getresponse() |
| 577 | + message = response.read() |
595 | 578 |
|
596 | | - # On windows, the installs also install PDB files, which we end up picking up. |
597 | | - # Obviously, we can't run those, so filter them out. Lets hope nobody creates |
598 | | - # a new client test with pdb in the name. |
599 | | - if clientTest.abspath.endswith('.pdb'): |
| 579 | + except IOError: |
| 580 | + print("Cannot connect to Mongo Orchestration at %s on attempt %d. %d attempts remaining..." |
| 581 | + % (orchestration_uri, attempt, MO_MAX_RETRIES - (attempt))) |
600 | 582 | continue |
601 | 583 |
|
602 | | - # the rsExample test needs a replica set to talk to. The old smokeClient never tested it |
603 | | - # The old smoke subsystem did test authTest, not sure why it isn't working now. |
604 | | - if 'rsExample' in clientTest.abspath: |
| 584 | + if (response.status == 404): |
| 585 | + print("No standalone started, starting one now...") |
| 586 | + post_conn = httplib.HTTPConnection(orchestration_uri, timeout=30) |
| 587 | + post_conn.request("POST", "/servers", params, json_headers) |
| 588 | + continue |
| 589 | + elif (response.status/100 != 2): |
| 590 | + print("Mongo Orchestration had an error with code %s" % response.status) |
| 591 | + if message: |
| 592 | + print("\tmessage from MO: %s", message) |
605 | 593 | continue |
606 | 594 |
|
607 | | - clientEnv.AlwaysBuild( |
608 | | - clientEnv.Alias( |
609 | | - 'examples', |
610 | | - [clientTest], |
611 | | - "%s %s" % (clientTest.abspath, mongodb_uri) |
612 | | - ) |
613 | | - ) |
| 595 | + # Grab the port from the response -- use it in the tests |
| 596 | + decoded_response = json.loads(message) |
| 597 | + |
| 598 | + global mongoDBUri |
| 599 | + mongoDBUri = decoded_response['mongodb_uri'] |
| 600 | + |
| 601 | + # The last attempt succeeded so we don't need to keep trying |
| 602 | + break |
| 603 | + |
| 604 | +clientEnv.Alias('setup-mongo-orchestration', |
| 605 | + clientEnv.Command( |
| 606 | + target="#setup-mongo-orchestration", |
| 607 | + source=[], |
| 608 | + action=clientEnv.Action( |
| 609 | + setupMongoOrchestration, |
| 610 | + cmdstr="Configuring MongoOrchestration for Examples") |
| 611 | + )) |
| 612 | + |
| 613 | +for clientTest in clientTestProgramInstalls: |
| 614 | + |
| 615 | + # On windows, the installs also install PDB files, which we end up picking up. |
| 616 | + # Obviously, we can't run those, so filter them out. Lets hope nobody creates |
| 617 | + # a new client test with pdb in the name. |
| 618 | + if clientTest.abspath.endswith('.pdb'): |
| 619 | + continue |
| 620 | + |
| 621 | + # the rsExample test needs a replica set to talk to. The old smokeClient never tested it |
| 622 | + # The old smoke subsystem did test authTest, not sure why it isn't working now. |
| 623 | + if 'rsExample' in clientTest.abspath: |
| 624 | + continue |
| 625 | + |
| 626 | + command = clientEnv.Command( |
| 627 | + target="${SOURCE}-run", |
| 628 | + source=[clientTest], |
| 629 | + action="$SOURCE ${getMongoDBUri()}") |
614 | 630 |
|
615 | | - # The last attempt succeeded so we don't need to keep trying |
616 | | - break |
| 631 | + clientEnv.SideEffect("#example-running", command) |
| 632 | + clientEnv.AlwaysBuild(command) |
| 633 | + clientEnv.Depends(command, 'setup-mongo-orchestration') |
| 634 | + clientEnv.Alias('examples', command) |
617 | 635 |
|
618 | 636 | clientEnv.Alias('install-examples', clientTestProgramInstalls) |
0 commit comments