Skip to content

Commit

Permalink
use libs
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Jan 3, 2025
1 parent c038bae commit 9daeb7e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .evergreen/mongosh_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _get_latest_version_git():
shlex.split(cmd), cwd=path, stderr=subprocess.PIPE
)
for line in reversed(output.decode("utf-8").splitlines()):
if re.match("^v\d+\.\d+\.\d+$", line):
if re.match(r"^v\d+\.\d+\.\d+$", line):
print("Found version", line, file=sys.stderr)
return line.replace("v", "").strip()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,22 @@
import shlex
import shutil
import socket
import subprocess
import sys
import time
import urllib.error
import urllib.request
from datetime import datetime
from pathlib import Path

from mongo_orchestration.server import main as mongo_orchestration
from mongodl import main as mongodl
from mongosh_dl import main as mongosh_dl

# Get global values.
HERE = Path(__file__).absolute().parent
EVG_PATH = HERE.parent
DRIVERS_TOOLS = EVG_PATH.parent


def run_command(args, **kwargs):
if isinstance(args, str):
args = shlex.split(args)
args = [sys.executable, "-m", *args]
kwargs.setdefault("stderr", subprocess.PIPE)
try:
subprocess.run(args, check=True, **kwargs)
except subprocess.CalledProcessError as e:
if e.stderr:
print("stderr:", e.stderr.decode("utf8"))
raise e


def get_options():
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
Expand Down Expand Up @@ -166,7 +155,6 @@ def run(opts):

# Clean up previous files.
mdb_binaries = Path(opts.mongodb_binaries)
mdb_binaries = str(mdb_binaries).replace(os.sep, "/")
shutil.rmtree(mdb_binaries, ignore_errors=True)

# The evergreen directory to path.
Expand All @@ -176,19 +164,18 @@ def run(opts):
dl_start = datetime.now()
version = opts.version
cache_dir = DRIVERS_TOOLS / ".local/cache"
cache_dir = str(cache_dir).replace(os.sep, "/")
args = f"mongodl --out {mdb_binaries} --cache-dir {cache_dir} --version {version}"
args = f"--out {mdb_binaries} --cache-dir {cache_dir} --version {version}"
args += " --strip-path-components 2 --component archive"
print(f"Downloading mongodb {version}...")
run_command(args)
mongodl(shlex.split(args))
print(f"Downloading mongodb {version}... done.")

# Download legacy shell
if opts.install_legacy_shell:
args = f"mongodl --out {mdb_binaries} --cache-dir {cache_dir} --version 5.0"
args = f"--out {mdb_binaries} --cache-dir {cache_dir} --version 5.0"
args += " --strip-path-components 2 --component shell"
print("Downloading legacy shell...")
run_command(args)
mongodl(shlex.split(args))
print("Downloading legacy shell... done.")

# Download crypt shared.
Expand All @@ -201,10 +188,10 @@ def run(opts):
crypt_shared_version = "latest"
else:
crypt_shared_version = version
args = f"mongodl --out {mdb_binaries} --cache-dir {cache_dir} --version {crypt_shared_version}"
args = f"--out {mdb_binaries} --cache-dir {cache_dir} --version {crypt_shared_version}"
args += " --strip-path-components 1 --component crypt_shared"
print("Downloading crypt_shared...")
run_command(args)
mongodl(shlex.split(args))
print("Downloading crypt_shared... done.")
crypt_shared_path = None
for fname in os.listdir(mdb_binaries):
Expand All @@ -217,9 +204,9 @@ def run(opts):
Path("mo-expansion.sh").write_text(crypt_text.replace(": ", "="))

# Download mongosh
args = f"mongosh_dl --out {mdb_binaries} --strip-path-components 2"
args = f"--out {mdb_binaries} --strip-path-components 2"
print("Downloading mongosh...")
run_command(args)
mongosh_dl(shlex.split(args))
print("Downloading mongosh... done.")

dl_end = datetime.now()
Expand Down Expand Up @@ -338,7 +325,6 @@ def start(opts):
mdb_binaries = Path(opts.mongodb_binaries)
config = dict(releases=dict(default=str(mdb_binaries)))
mo_config.write_text(json.dumps(config, indent=2))
mo_config = str(mo_config).replace(os.sep, "/")

# Copy client certificates on Windows.
if os.name == "nt":
Expand All @@ -349,15 +335,15 @@ def start(opts):
mo_start = datetime.now()

# Start the process.
args = f"mongo_orchestration.server -e default -f {mo_config} --socket-timeout-ms=60000 --bind=127.0.0.1 --enable-majority-read-concern"
args = f"-e default -f {mo_config} --socket-timeout-ms=60000 --bind=127.0.0.1 --enable-majority-read-concern"
if os.name == "nt":
args = +"-s wsgiref"
args += " start"
output_file = mo_home / "out.log"
output_fid = output_file.open("w")

print("Starting mongo-orchestration...")
run_command(args, stderr=subprocess.STDOUT, stdout=output_fid)
mongo_orchestration(shlex.split(args))

# Wait for the server to be available.
attempt = 0
Expand All @@ -369,8 +355,6 @@ def start(opts):
except ConnectionRefusedError:
if (datetime.now() - mo_start).seconds > 120:
stop()
output_fid.close()
print(output_file.read_text())
raise TimeoutError(
"Failed to start cluster, see out.log and server.log"
) from None
Expand All @@ -384,7 +368,7 @@ def start(opts):

def stop(_):
print("Stopping mongo-orchestration...")
run_command(["mongo_orchestration.server", "stop"])
mongo_orchestration(["stop"])
print("Stopping mongo-orchestration... done.")


Expand Down
6 changes: 3 additions & 3 deletions .evergreen/orchestration/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: Implementation :: CPython",
]
dependencies = ["drivers-evergreen-tools @ {root:parent:uri}", "mongo-orchestration"]
dependencies = ["drivers-evergreen-tools @ {root:parent:uri}", "mongo-orchestration >= 0.11"]

[project.scripts]
orchestration = "drivers-orchestration:main"
drivers-orchestration = "drivers_orchestration:main"

[tool.hatch.build]
include = ["drivers-orchestration.py"]
include = ["drivers_orchestration.py"]

[tool.hatch.metadata]
allow-direct-references=true

0 comments on commit 9daeb7e

Please sign in to comment.