summaryrefslogtreecommitdiff
path: root/pytests
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2019-05-16 14:52:24 -0400
committerMax Hirschhorn <max.hirschhorn@mongodb.com>2019-05-16 14:52:24 -0400
commita48102efbc35b8c622eb72599c5eb3fa3c47c430 (patch)
treede1c6b22155ea0865c15e54fd20a4dc10d536cff /pytests
parent8ab4e38d8ad3eb6901f79dfbd67b8b2cf6646c2d (diff)
downloadmongo-a48102efbc35b8c622eb72599c5eb3fa3c47c430.tar.gz
SERVER-41109 Migrate powercycle scripts over to Python 3.
Diffstat (limited to 'pytests')
-rwxr-xr-xpytests/powertest.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/pytests/powertest.py b/pytests/powertest.py
index 944002c12c2..5c380c2cd97 100755
--- a/pytests/powertest.py
+++ b/pytests/powertest.py
@@ -10,14 +10,12 @@ Note - the remote hosts should be running bash shell (this script may fail other
There are no assumptions on the server what is the current deployment of MongoDB.
For Windows the assumption is that Cygwin is installed.
The server needs these utilities:
- - python 2.7 or higher
+ - python 3.7 or higher
- sshd
- rsync
This script will either download a MongoDB tarball or use an existing setup.
"""
-from __future__ import print_function
-
import atexit
import collections
import copy
@@ -43,7 +41,7 @@ import tempfile
import threading
import time
import traceback
-import urlparse
+import urllib.parse
import zipfile
import subprocess
@@ -242,7 +240,7 @@ def kill_process(parent, kill_children=True):
# accurate notion of the creation time.
procs = parent.children(recursive=True) if kill_children else []
except psutil.NoSuchProcess:
- LOGGER.warn("Could not kill process %d, as it no longer exists", parent.pid)
+ LOGGER.warning("Could not kill process %d, as it no longer exists", parent.pid)
return 0
procs.append(parent)
@@ -252,7 +250,7 @@ def kill_process(parent, kill_children=True):
LOGGER.debug("Killing process '%s' pid %d", proc.name(), proc.pid)
proc.kill()
except psutil.NoSuchProcess:
- LOGGER.warn("Could not kill process %d, as it no longer exists", proc.pid)
+ LOGGER.warning("Could not kill process %d, as it no longer exists", proc.pid)
_, alive = psutil.wait_procs(procs, timeout=30, callback=None)
if alive:
@@ -375,6 +373,7 @@ def execute_cmd(cmd, use_file=False):
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, _ = proc.communicate()
+ output = output.decode("utf-8", "replace")
error_code = proc.returncode
if error_code:
output = "Error executing cmd {}: {}".format(cmd, output)
@@ -592,7 +591,7 @@ def install_mongod(bin_dir=None, tarball_url="latest", root_dir=None):
elif _IS_LINUX:
tarball_url = "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-latest.tgz"
- tarball = os.path.split(urlparse.urlsplit(tarball_url).path)[-1]
+ tarball = os.path.split(urllib.parse.urlsplit(tarball_url).path)[-1]
download_file(tarball_url, tarball)
install_tarball(tarball, root_dir)
chmod_x_binaries(get_bin_dir(root_dir))
@@ -611,7 +610,9 @@ def get_boot_datetime(uptime_string):
"""
match = re.search(r"last booted (.*), up", uptime_string)
if match:
- return datetime.datetime(*map(int, map(float, re.split("[ :-]", match.groups()[0]))))
+ return datetime.datetime(
+ *list(map(int, list(map(float, re.split("[ :-]",
+ match.groups()[0]))))))
return -1
@@ -673,7 +674,8 @@ class NamedTempFile(object):
LOGGER.debug("Creating temporary directory %s", directory)
os.makedirs(directory)
cls._DIR_LIST.append(directory)
- temp_file = tempfile.NamedTemporaryFile(suffix=suffix, dir=directory, delete=False)
+ temp_file = tempfile.NamedTemporaryFile(mode="w+", suffix=suffix, dir=directory,
+ delete=False)
cls._FILE_MAP[temp_file.name] = temp_file
return temp_file.name
@@ -696,7 +698,7 @@ class NamedTempFile(object):
try:
os.remove(name)
except (IOError, OSError) as err:
- LOGGER.warn("Unable to delete temporary file %s with error %s", name, err)
+ LOGGER.warning("Unable to delete temporary file %s with error %s", name, err)
if not os.path.exists(name):
del cls._FILE_MAP[name]
@@ -712,7 +714,7 @@ class NamedTempFile(object):
try:
shutil.rmtree(directory)
except (IOError, OSError) as err:
- LOGGER.warn("Unable to delete temporary directory %s with error %s", directory, err)
+ LOGGER.warning("Unable to delete temporary directory %s with error %s", directory, err)
if not os.path.exists(directory):
cls._DIR_LIST.remove(directory)
@@ -818,7 +820,7 @@ class WindowsService(object):
def create(self):
"""Create service, if not installed. Return (code, output) tuple."""
- if self.status() in self._states.values():
+ if self.status() in list(self._states.values()):
return 1, "Service '{}' already installed, status: {}".format(self.name, self.status())
try:
win32serviceutil.InstallService(pythonClassString="Service.{}".format(
@@ -1290,7 +1292,7 @@ def remote_handler(options, operations): # pylint: disable=too-many-branches,to
ret = mongo.admin.command("setFeatureCompatibilityVersion", options.fcv_version)
ret = 0 if ret["ok"] == 1 else 1
except pymongo.errors.OperationFailure as err:
- LOGGER.error(err.message)
+ LOGGER.error("%s", err)
ret = err.code
elif operation == "remove_lock_file":
@@ -1300,7 +1302,8 @@ def remote_handler(options, operations): # pylint: disable=too-many-branches,to
try:
os.remove(lock_file)
except (IOError, OSError) as err:
- LOGGER.warn("Unable to delete mongod lockfile %s with error %s", lock_file, err)
+ LOGGER.warning("Unable to delete mongod lockfile %s with error %s", lock_file,
+ err)
ret = err.code
else:
@@ -1570,14 +1573,15 @@ def mongo_seed_docs(mongo, db_name, coll_name, num_docs):
def rand_string(max_length=1024):
"""Return random string of random length."""
- return ''.join(random.choice(string.letters) for _ in range(random.randint(1, max_length)))
+ return ''.join(
+ random.choice(string.ascii_letters) for _ in range(random.randint(1, max_length)))
LOGGER.info("Seeding DB '%s' collection '%s' with %d documents, %d already exist", db_name,
coll_name, num_docs, mongo[db_name][coll_name].count())
random.seed()
base_num = 100000
bulk_num = min(num_docs, 10000)
- bulk_loops = num_docs / bulk_num
+ bulk_loops = num_docs // bulk_num
for _ in range(bulk_loops):
num_coll_docs = mongo[db_name][coll_name].count()
if num_coll_docs >= num_docs:
@@ -1638,7 +1642,7 @@ def new_resmoke_config(config_file, new_config_file, test_data, eval_str=""):
}
}
with open(config_file, "r") as yaml_stream:
- config = yaml.load(yaml_stream)
+ config = yaml.safe_load(yaml_stream)
config.update(new_config)
with open(new_config_file, "w") as yaml_stream:
yaml.safe_dump(config, yaml_stream)