def test_read_evg_config_file_order(self): with patch("os.path.isfile", return_value=False) as mock_isfile,\ patch("os.path.expanduser", side_effect=(lambda path: path)): self.assertIsNone(evergreen.read_evg_config()) self.assertEqual(mock_isfile.call_count, len(evergreen.EVERGREEN_FILES)) calls = [call(evg_file) for evg_file in evergreen.EVERGREEN_FILES] mock_isfile.assert_has_calls(calls)
def test_read_evg_config(self): evg_yaml = "data1: val1\ndata2: val2" with patch("os.path.isfile", return_value=True),\ patch(EVERGREEN + ".open", mock_open(read_data=evg_yaml)): evg_config = evergreen.read_evg_config() self.assertEqual(evg_config["data1"], "val1") self.assertEqual(evg_config["data2"], "val2")
def test_read_evg_config(self): evg_yaml = "data1: val1\ndata2: val2" with patch("os.path.isfile", return_value=True),\ patch(EVERGREEN + ".open", mock_open(read_data=evg_yaml)): evg_config = evergreen.read_evg_config() self.assertEqual(evg_config["data1"], "val1") self.assertEqual(evg_config["data2"], "val2")
def find_last_activated_task(revisions, variant, branch_name): """Get the git hash of the most recently activated build before this one.""" project = "mongodb-mongo-" + branch_name build_prefix = "mongodb_mongo_" + branch_name + "_" + variant.replace( "-", "_") evg_cfg = evergreen_client.read_evg_config() if evg_cfg is not None and "api_server_host" in evg_cfg: api_server = "{url.scheme}://{url.netloc}".format( url=urllib.parse.urlparse(evg_cfg["api_server_host"])) else: api_server = API_SERVER_DEFAULT api_prefix = api_server + API_REST_PREFIX for githash in revisions: url = "{}projects/{}/revisions/{}".format(api_prefix, project, githash) response = requests.get(url) revision_data = response.json() try: for build in revision_data["builds"]: if build.startswith(build_prefix): url = "{}builds/{}".format(api_prefix, build) build_resp = requests.get(url) build_data = build_resp.json() if build_data["activated"]: return build_data["revision"] except: # pylint: disable=bare-except # Sometimes build data is incomplete, as was the related build. pass return None
def find_last_activated_task(revisions, variant, branch_name): """Get the git hash of the most recently activated build before this one.""" project = "mongodb-mongo-" + branch_name build_prefix = "mongodb_mongo_" + branch_name + "_" + variant.replace("-", "_") evg_cfg = evergreen_client.read_evg_config() if evg_cfg is not None and "api_server_host" in evg_cfg: api_server = "{url.scheme}://{url.netloc}".format( url=urllib.parse.urlparse(evg_cfg["api_server_host"])) else: api_server = API_SERVER_DEFAULT api_prefix = api_server + API_REST_PREFIX for githash in revisions: url = "{}projects/{}/revisions/{}".format(api_prefix, project, githash) response = requests.get(url) revision_data = response.json() try: for build in revision_data["builds"]: if build.startswith(build_prefix): url = "{}builds/{}".format(api_prefix, build) build_resp = requests.get(url) build_data = build_resp.json() if build_data["activated"]: return build_data["revision"] except: # pylint: disable=bare-except # Sometimes build data is incomplete, as was the related build. pass return None
def test_read_evg_config_file_order(self): with patch("os.path.isfile", return_value=False) as mock_isfile,\ patch("os.path.expanduser", side_effect=(lambda path: path)): self.assertIsNone(evergreen.read_evg_config()) self.assertEqual(mock_isfile.call_count, len(evergreen.EVERGREEN_FILES)) calls = [call(evg_file) for evg_file in evergreen.EVERGREEN_FILES] mock_isfile.assert_has_calls(calls)
def test_read_evg_config_last_file(self): evg_files = {"path1": False, "path2": False, "path3": True} evg_paths = ["path1", "path2", "path3"] evg_yaml = "data1: val1\ndata2: val2" with patch("os.path.isfile", lambda path: evg_files[path]),\ patch(EVERGREEN + ".open", mock_open(read_data=evg_yaml)) as mock_openfile,\ patch(EVERGREEN + ".EVERGREEN_FILES", evg_paths): evg_config = evergreen.read_evg_config() mock_openfile.assert_called_once_with("path3", "r") self.assertEqual(evg_config["data1"], "val1") self.assertEqual(evg_config["data2"], "val2")
def test_read_evg_config_last_file(self): evg_files = {"path1": False, "path2": False, "path3": True} evg_paths = ["path1", "path2", "path3"] evg_yaml = "data1: val1\ndata2: val2" with patch("os.path.isfile", lambda path: evg_files[path]),\ patch(EVERGREEN + ".open", mock_open(read_data=evg_yaml)) as mock_openfile,\ patch(EVERGREEN + ".EVERGREEN_FILES", evg_paths): evg_config = evergreen.read_evg_config() mock_openfile.assert_called_once_with("path3", "r") self.assertEqual(evg_config["data1"], "val1") self.assertEqual(evg_config["data2"], "val2")
def test_read_evg_config_file_not_found(self): with patch("os.path.isfile", return_value=False): self.assertIsNone(evergreen.read_evg_config())
def test_read_evg_config_file_not_found(self): with patch("os.path.isfile", return_value=False): self.assertIsNone(evergreen.read_evg_config())