Skip to content

Commit

Permalink
Use certifi to workaround outdated CACert issue on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantmital committed Apr 10, 2020
1 parent 52d105e commit f17693c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
10 changes: 3 additions & 7 deletions astrolabe/spec_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
from astrolabe.poller import BooleanCallablePoller
from astrolabe.utils import (
assert_subset, encode_cdata, get_cluster_name,
get_test_name_from_spec_file, SingleTestXUnitLogger, Timer)
get_test_name_from_spec_file, load_test_data, SingleTestXUnitLogger,
Timer)


LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -157,12 +158,7 @@ def run(self, persist_cluster=False):
LOGGER.info("Loading test data on cluster {!r}".format(
self.cluster_name))
connection_string = self.get_connection_string()
client = MongoClient(connection_string, w="majority")
coll = client.get_database(
self.spec.driverWorkload.database).get_collection(
self.spec.driverWorkload.collection)
coll.drop()
coll.insert_many(test_data)
load_test_data(connection_string, self.spec.driverWorkload)
LOGGER.info("Successfully loaded test data on cluster {!r}".format(
self.cluster_name))

Expand Down
19 changes: 19 additions & 0 deletions astrolabe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import click
import junitparser

from pymongo import MongoClient


class ClickLogHandler(logging.Handler):
"""Handler for print log statements via Click's echo functionality."""
Expand Down Expand Up @@ -116,3 +118,20 @@ def get_cluster_name(test_name, name_salt):
name_hash = sha256(test_name.encode('utf-8'))
name_hash.update(name_salt.encode('utf-8'))
return name_hash.hexdigest()[:10]


def load_test_data(connection_string, driver_workload):
"""Insert the test data into the cluster."""
kwargs = {'w': "majority"}
try:
import certifi
kwargs['tlsCAFile'] = certifi.where()
except ImportError:
pass

client = MongoClient(connection_string, **kwargs)
coll = client.get_database(
driver_workload.database).get_collection(
driver_workload.collection)
coll.drop()
coll.insert(driver_workload.testData)
20 changes: 12 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import os
import sys

from setuptools import setup

Expand All @@ -21,6 +22,16 @@
readme_content = ''


# Dynamically generate requirements.
install_requires = [
'click>=7,<8', 'requests>=2,<3',
'pymongo>=3.10,<4', 'dnspython>=1.16,<2',
'pyyaml>=5,<6', 'tabulate>=0.8,<0.9',
'junitparser>=1,<2']
if sys.platform in ("win32", "cygwin"):
install_requires.append("certifi")


setup(
name='astrolabe',
version=version['__version__'],
Expand All @@ -34,14 +45,7 @@
license="Apache License, Version 2.0",
python_requires=">=3.5",
packages=["atlasclient", "astrolabe"],
install_requires=[
'click>=7,<8',
'requests>=2,<3',
'pymongo>=3.10,<4',
'dnspython>=1.16,<2',
'pyyaml>=5,<6',
'tabulate>=0.8,<0.9',
'junitparser>=1,<2'],
install_requires=install_requires,
entry_points={
'console_scripts': ['astrolabe=astrolabe.cli:cli']},
classifiers=[
Expand Down

0 comments on commit f17693c

Please sign in to comment.