Skip to content

Commit

Permalink
MongoDB versions list update (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekarademir authored Oct 4, 2022
1 parent f656d5f commit e3bc157
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 72 deletions.
61 changes: 33 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[![PyPI
version](https://badge.fury.io/py/pymongo-inmemory.svg)](https://badge.fury.io/py/pymongo-inmemory)
[ [PyPI](https://pypi.org/project/pymongo-inmemory/) ][ [GitHub](https://github.com/kaizendorks/pymongo_inmemory) ][ [BETA Docs](https://kaizendorks.github.io/pymongo_inmemory/)]

# pymongo_inmemory
A mongo mocking library with an ephemeral MongoDB running in memory.

## What's new?
### v0.2.10
* Updated MongoDB version list.
* With 6.0 versions, there is support of MacOS running on ARM arch.

## Installation
```bash
pip install pymongo-inmemory
Expand Down Expand Up @@ -69,32 +73,33 @@ them to set as `mongo_version` at `major.minor` level.
Note that, not all `major.minor.patch` level is available for all OS versions. For exact patch level range, either see
release pages of MongoDB or have a look at the internal [URL bank](pymongo_inmemory/downloader/_patterns.py).

| `operating_system` | `os_version` | MongoDB versions (`major.minor`)|
|-|-|-|
|`osx`|`generic`*| `2.6`, `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
|`windows`|`generic`*| `2.6`, `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
|`linux`|`generic`*| `2.6`, `3.0`, `3.2`, `3.4`, `3.6`, `4.0`|
|`amazon`|`1`| `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
|`amazon`|`2`| `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
|`debian`|`7`| `3.0`, `3.2`, `3.4`, `3.6`|
|`debian`|`8`| `3.2`, `3.4`, `3.6`, `4.0`|
|`debian`|`9`| `3.6`, `4.0`, `4.2`, `4.4`, `4.5`, `4.6`, `5.0`|
|`debian`|`10`| `4.2`, `4.4`, `4.5`, `4.6`, `5.0`|
|`debian`|`11`| `5.0`|
|`rhel`|`5`| `3.0`, `3.2`|
|`rhel`|`6`| `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`|
|`rhel`|`7`| `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
|`rhel`|`8`| `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
|`suse`|`11`| `3.0`, `3.2`, `3.4`, `3.6`|
|`suse`|`12`| `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
|`suse`|`15`| `4.2`, `4.4`, `5.0`|
|`ubuntu`|`12`| `3.0`, `3.2`, `3.4`, `3.6`|
|`ubuntu`|`14`| `3.0`, `3.2`, `3.4`, `3.6`, `4.0`|
|`ubuntu`|`16`| `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`|
|`ubuntu`|`18`| `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
|`ubuntu`|`20`| `4.4`, `5.0`|
|`sunos`|`5`| `2.6`, `3.0`, `3.2`, `3.4`|
||||
|| `operating_system` | `os_version` | MongoDB versions (`major.minor`)|
|-|-|-|-|
||`osx`|`generic`*| `2.6`, `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`, `6.0`|
|**NEW**|`macos`|`arm`| `6.0`|
||`windows`|`generic`*| `2.6`, `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
||`linux`|`generic`*| `2.6`, `3.0`, `3.2`, `3.4`, `3.6`, `4.0`|
||`amazon`|`1`| `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
||`amazon`|`2`| `3.6`, `4.0`, `4.2`, `4.4`, `5.0`, `6.0`|
||`debian`|`7`| `3.0`, `3.2`, `3.4`, `3.6`|
||`debian`|`8`| `3.2`, `3.4`, `3.6`, `4.0`|
||`debian`|`9`| `3.6`, `4.0`, `4.2`, `4.4`, `4.5`, `4.6`, `5.0`|
||`debian`|`10`| `4.2`, `4.4`, `4.5`, `4.6`, `5.0`, `6.0`|
||`debian`|`11`| `5.0`, `6.0`|
||`rhel`|`5`| `3.0`, `3.2`|
||`rhel`|`6`| `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`|
||`rhel`|`7`| `3.0`, `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`, `6.0`|
||`rhel`|`8`| `3.6`, `4.0`, `4.2`, `4.4`, `5.0`, `6.0`|
||`suse`|`11`| `3.0`, `3.2`, `3.4`, `3.6`|
||`suse`|`12`| `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`, `5.0`, `6.0`|
||`suse`|`15`| `4.2`, `4.4`, `5.0`, `6.0`|
||`ubuntu`|`12`| `3.0`, `3.2`, `3.4`, `3.6`|
||`ubuntu`|`14`| `3.0`, `3.2`, `3.4`, `3.6`, `4.0`|
||`ubuntu`|`16`| `3.2`, `3.4`, `3.6`, `4.0`, `4.2`, `4.4`|
||`ubuntu`|`18`| `3.6`, `4.0`, `4.2`, `4.4`, `5.0`|
||`ubuntu`|`20`| `4.4`, `5.0`|
||`sunos`|`5`| `2.6`, `3.0`, `3.2`, `3.4`|
|||||

****Note:*** No need to specify `generic`, as it will be chosen automatically since it's the only version for that OS.

Expand Down
106 changes: 92 additions & 14 deletions pymongo_inmemory/downloader/_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@
"3.4-ubuntu12": list(range(8)) + list(range(9, 15)),
"3.4-sunos5": list(range(6)),
"3.4-debian7": list(range(8)) + list(range(9, 16)),
"3.6": list(range(23)),
"3.6": list(range(24)),
"3.6-suse11": list(range(3)),
"3.6-ubuntu18": list(range(20, 23)),
"3.6-ubuntu14": list(range(13)) + list(range(14, 23)),
"3.6-ubuntu18": list(range(20, 24)),
"3.6-ubuntu14": list(range(13)) + list(range(14, 24)),
"3.6-ubuntu12": list(range(4)),
"3.6-rhel8": list(range(17, 23)),
"3.6-debian9": list(range(5, 23)),
"3.6-rhel8": list(range(17, 24)),
"3.6-debian9": list(range(5, 24)),
"3.6-debian7": list(range(6)),
"3.6-amazon2": [22],
"3.6-amazon2": list(range(22, 24)),
"4.0": list(range(29)),
"4.0-rhel8": list(range(14, 29)),
"4.0-ubuntu14": list(range(10)) + list(range(12, 29)),
"4.0-ubuntu18": list(range(1, 29)),
"4.2": list(range(4)) + list(range(5, 20)),
"4.2-suse15": list(range(1, 4)) + list(range(5, 20)),
"4.2-rhel8": list(range(1, 4)) + list(range(5, 20)),
"4.2-debian10": list(range(1, 4)) + list(range(5, 20)),
"4.4": list(range(14)),
"5.0": list(range(9)),
"5.0-debian11": list(range(8, 9)),
"4.2": list(range(4)) + list(range(5, 24)),
"4.2-suse15": list(range(1, 4)) + list(range(5, 24)),
"4.2-rhel8": list(range(1, 4)) + list(range(5, 24)),
"4.2-debian10": list(range(1, 4)) + list(range(5, 24)),
"4.4": list(range(18)),
"5.0": list(range(14)),
"5.0-debian11": list(range(8, 14)),
"6.0": list(range(3)),
}

PATTERNS = {
Expand All @@ -46,6 +47,7 @@
"osx": "https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-{}.tgz",
"osx-ssl": "https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-{}.tgz",
"macos": "https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-{}.tgz",
"macos-arm": "https://fastdl.mongodb.org/osx/mongodb-macos-arm64-{}.tgz",
"linux": "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-{}.tgz",
"ubuntu20": "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-{}.tgz", # noqa E501
"ubuntu18": "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-{}.tgz", # noqa E501
Expand Down Expand Up @@ -140,6 +142,12 @@
"url": PATTERNS["amazon2"],
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["amazon2"],
},
},
},
},
"debian": {
Expand Down Expand Up @@ -230,6 +238,12 @@
"url": PATTERNS["debian10"],
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["debian10"],
},
},
},
"11": {
5: {
Expand All @@ -238,6 +252,12 @@
"url": PATTERNS["debian11"],
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["debian11"],
},
},
},
},
"rhel": {
Expand Down Expand Up @@ -326,6 +346,12 @@
"url": PATTERNS["rhel7"],
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["rhel7"],
},
},
},
"8": {
3: {
Expand Down Expand Up @@ -353,7 +379,13 @@
"patches": PATCH_RANGE["5.0"],
"url": PATTERNS["rhel8"],
},
}
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["rhel8"],
},
},
},
},
"suse": {
Expand Down Expand Up @@ -412,6 +444,12 @@
"url": PATTERNS["suse12"],
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["suse12"],
},
},
},
"15": {
4: {
Expand All @@ -430,6 +468,12 @@
"url": PATTERNS["suse15"],
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["suse15"],
},
},
},
},
"ubuntu": {
Expand Down Expand Up @@ -536,6 +580,12 @@
"url": PATTERNS["ubuntu18"],
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["ubuntu18"],
},
},
},
"20": {
4: {
Expand All @@ -550,6 +600,12 @@
"url": PATTERNS["ubuntu20"],
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["ubuntu20"],
},
},
},
},
"linux": {
Expand Down Expand Up @@ -632,6 +688,22 @@
"url": PATTERNS["macos"],
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["macos"],
},
},
},
},
"macos": {
"arm": {
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["macos-arm"],
},
},
},
},
"sunos": {
Expand Down Expand Up @@ -704,6 +776,12 @@
"url": PATTERNS["windows-x86_64"]
},
},
6: {
0: {
"patches": PATCH_RANGE["6.0"],
"url": PATTERNS["windows-x86_64"]
},
},
},
},
}
57 changes: 32 additions & 25 deletions pymongo_inmemory/mongod.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import threading
from tempfile import TemporaryDirectory

import pymongo

from ._utils import conf, find_open_port
from .downloader import download

Expand Down Expand Up @@ -87,8 +89,11 @@ def __init__(self):

self._bin_folder = download()
self._proc = None
self._mongod_port = None
self._mongod_ip = None
self._connection_string = None

self.config = MongodConfig()
self.data_folder = TemporaryDirectory(prefix="pymongoim")
self._client = pymongo.MongoClient(self.connection_string)

def __enter__(self):
self.start()
Expand All @@ -98,11 +103,6 @@ def __exit__(self, *args):
self.stop()

def start(self):
mongod_config = MongodConfig()
self._mongod_port = mongod_config.port
self._mongod_ip = mongod_config.local_address
self.data_folder = TemporaryDirectory(prefix="pymongoim")

while self.is_locked:
logger.warning((
"Lock file found, possibly another mock server is running. "
Expand All @@ -117,9 +117,9 @@ def start(self):
os.path.join(self._bin_folder, "mongod"),
"--dbpath", self.data_folder.name,
"--logpath", self.log_path,
"--port", self._mongod_port,
"--bind_ip", self._mongod_ip,
"--storageEngine", mongod_config.engine,
"--port", self.config.port,
"--bind_ip", self.config.local_address,
"--storageEngine", self.config.engine,
]
logger.debug(boot_command)
self._proc = subprocess.Popen(boot_command)
Expand All @@ -139,35 +139,42 @@ def stop(self):

@property
def connection_string(self):
if self._mongod_ip is not None and self._mongod_port is not None:
return "mongodb://{host}:{port}".format(
host=self._mongod_ip,
port=self._mongod_port
if self._connection_string is not None:
return self._connection_string

if (
self.config.local_address is not None
and self.config.port is not None
):
self._connection_string = "mongodb://{host}:{port}".format(
host=self.config.local_address,
port=self.config.port
)
else:
return None
self._connection_string = None

return self._connection_string

@property
def is_locked(self):
return os.path.exists(os.path.join(self.data_folder.name, "mongod.lock"))

@property
def is_healthy(self):
healthcheck = [
os.path.join(self._bin_folder, "mongo"),
self.connection_string,
"--quiet",
"--eval", "db.serverStatus().uptime"
]
db = self._client["admin"]
status = db.command("serverStatus")
try:
logger.debug("Getting status")
uptime = _last_line(subprocess.check_output(healthcheck))
uptime = int(status["uptime"])
except subprocess.CalledProcessError:
logger.debug("Status: Not running")
return False
else:
if uptime > 0:
logger.debug("Status: Running for {} secs".format(uptime))
version = status["version"]
logger.debug(
"Status: MongoDB {} running for {} secs".format(version, uptime)
)
return True
else:
logger.debug("Status: Just started.")
Expand All @@ -176,8 +183,8 @@ def is_healthy(self):
def mongodump(self, database, collection):
dump_command = [
os.path.join(self._bin_folder, "mongodump"),
"--host", self._mongod_ip,
"--port", self._mongod_port,
"--host", self.config.local_address,
"--port", self.config.port,
"--out", "-",
"--db", database,
"--collection", collection,
Expand Down
Loading

0 comments on commit e3bc157

Please sign in to comment.