def __init__(self, service_name, shard): address, port = get_cms_config()["core_services"][service_name][shard] self.service_name = service_name self.shard = shard self.address = address self.port = port
def _check_service(self): """Health checker for services and servers.""" rs = RemoteService(self.service_name, self.shard) reply = rs.call("echo", {"string": "hello"}) if reply["__data"] != "hello": raise FrameworkException("Strange response from service.") # In case it is a server, we also check HTTP is serving. if self.service_name == "AdminWebServer": port = get_cms_config()["admin_listen_port"] elif self.service_name == "ContestWebServer": port = get_cms_config()["contest_listen_port"][self.shard] else: return sock = socket.socket() sock.connect(("127.0.0.1", port)) sock.close()
def load_cms_conf(): try: git_root = subprocess.check_output( "git rev-parse --show-toplevel", shell=True, stderr=io.open(os.devnull, "wb")).decode('utf-8').strip() except subprocess.CalledProcessError: git_root = None CONFIG["TEST_DIR"] = git_root CONFIG["CONFIG_PATH"] = "%s/config/cms.conf" % CONFIG["TEST_DIR"] if CONFIG["TEST_DIR"] is None: CONFIG["CONFIG_PATH"] = "/usr/local/etc/cms.conf" return get_cms_config()
def load_cms_conf(): try: git_root = subprocess.check_output( "git rev-parse --show-toplevel", shell=True, stderr=io.open(os.devnull, "wb")).strip() except subprocess.CalledProcessError: git_root = None CONFIG["TEST_DIR"] = git_root CONFIG["CONFIG_PATH"] = "%s/config/cms.conf" % CONFIG["TEST_DIR"] if CONFIG["TEST_DIR"] is None: CONFIG["CONFIG_PATH"] = "/usr/local/etc/cms.conf" return get_cms_config()
def main(): parser = ArgumentParser(description="Runs the CMS functional test suite.") parser.add_argument("regex", action="store", type=utf8_decoder, nargs='*', metavar="regex", help="a regex to match to run a subset of tests") parser.add_argument("-l", "--languages", action="store", type=utf8_decoder, default="", help="a comma-separated list of languages to test") parser.add_argument("-c", "--contest", action="store", type=utf8_decoder, help="use an existing contest (and the tasks in it)") parser.add_argument( "-r", "--retry-failed", action="store_true", help="only run failed tests from the previous run (stored in %s)" % FAILED_TEST_FILENAME) parser.add_argument( "-n", "--dry-run", action="store_true", help="show what tests would be run, but do not run them") parser.add_argument( "-v", "--verbose", action="count", help="print debug information (use multiple times for more)") args = parser.parse_args() CONFIG["VERBOSITY"] = args.verbose start_time = datetime.datetime.now() # Pre-process our command-line arugments to figure out which tests to run. regexes = [re.compile(s) for s in args.regex] if args.languages: languages = frozenset(args.languages.split(',')) else: languages = frozenset() if args.retry_failed: test_list = load_failed_tests() else: test_list = get_all_tests() test_list = filter_testcases(test_list, regexes, languages) if not test_list: info("There are no tests to run! (was your filter too restrictive?)") return 0 if args.dry_run: for t in test_list: print(t[0].name, t[1]) return 0 if args.retry_failed: info("Re-running %d failed tests from last run." % len(test_list)) # Load config from cms.conf. try: git_root = subprocess.check_output("git rev-parse --show-toplevel", shell=True, stderr=io.open(os.devnull, "wb")).strip() except subprocess.CalledProcessError: git_root = None CONFIG["TEST_DIR"] = git_root CONFIG["CONFIG_PATH"] = "%s/config/cms.conf" % CONFIG["TEST_DIR"] if CONFIG["TEST_DIR"] is None: CONFIG["CONFIG_PATH"] = "/usr/local/etc/cms.conf" cms_config = get_cms_config() if not config_is_usable(cms_config): return 1 if CONFIG["TEST_DIR"] is not None: # Set up our expected environment. os.chdir("%(TEST_DIR)s" % CONFIG) os.environ["PYTHONPATH"] = "%(TEST_DIR)s" % CONFIG # Clear out any old coverage data. info("Clearing old coverage data.") sh("python-coverage erase") # Fire us up! start_generic_services() if args.contest is None: contest_id = create_contest() else: contest_id = int(args.contest) user_id = create_or_get_user(contest_id) start_contest(contest_id) # Run all of our test cases. passed, test_results = run_testcases(contest_id, user_id, test_list) # And good night! shutdown_services() combine_coverage() print(test_results) end_time = datetime.datetime.now() print(time_difference(start_time, end_time)) if passed: return 0 else: return 1
def main(): parser = ArgumentParser(description="Runs the CMS test suite.") parser.add_argument("regex", metavar="regex", type=str, nargs='*', help="a regex to match to run a subset of tests") parser.add_argument("-l", "--languages", type=str, action="store", default="", help="a comma-separated list of languages to test") parser.add_argument("-r", "--retry-failed", action="store_true", help="only run failed tests from the previous run (stored in %s)" % FAILED_TEST_FILENAME) parser.add_argument("-v", "--verbose", action="count", help="print debug information (use multiple times for more)") args = parser.parse_args() CONFIG["VERBOSITY"] = args.verbose start_time = datetime.datetime.now() # Pre-process our command-line arugments to figure out which tests to run. regexes = [re.compile(s) for s in args.regex] if args.languages: languages = frozenset(args.languages.split(',')) else: languages = frozenset() if args.retry_failed: test_list = load_failed_tests() else: test_list = get_all_tests() test_list = filter_testcases(test_list, regexes, languages) if not test_list: info("There are no tests to run! (was your filter too restrictive?)") return 0 if args.retry_failed: info("Re-running %d failed tests from last run." % len(test_list)) # Load config from cms.conf. try: git_root = subprocess.check_output( "git rev-parse --show-toplevel", shell=True, stderr=open(os.devnull, "w")).strip() except subprocess.CalledProcessError: git_root = None CONFIG["TEST_DIR"] = git_root CONFIG["CONFIG_PATH"] = "%s/examples/cms.conf" % CONFIG["TEST_DIR"] if CONFIG["TEST_DIR"] is None: CONFIG["CONFIG_PATH"] = "/usr/local/etc/cms.conf" cms_config = get_cms_config() if not config_is_usable(cms_config): return 1 if CONFIG["TEST_DIR"] is not None: # Set up our expected environment. os.chdir("%(TEST_DIR)s" % CONFIG) os.environ["PYTHONPATH"] = "%(TEST_DIR)s" % CONFIG # Clear out any old coverage data. info("Clearing old coverage data.") sh("python-coverage erase") # Fire us up! start_generic_services() contest_id = create_contest() user_id = create_a_user(contest_id) # Run all of our test cases. test_results = run_testcases(contest_id, user_id, test_list) # And good night! shutdown_services() combine_coverage() print test_results end_time = datetime.datetime.now() print time_difference(start_time, end_time)
def _check_ranking_web_server(self): """Health checker for RWS.""" url = urlsplit(get_cms_config()["rankings"][0]) sock = socket.socket() sock.connect((url.hostname, url.port)) sock.close()