Skip to content

CI/TST: Use CI moto service instead of subprocess #44612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d97aebe
WIP: CI/TST: Use CI moto service instead of subprocess
mroeschke Nov 25, 2021
1997621
Use importorskip, hardcode CI service
mroeschke Nov 25, 2021
42f8a8e
Merge remote-tracking branch 'upstream/master' into ci/service/moto
mroeschke Nov 25, 2021
f6556fe
Add moto to database
mroeschke Nov 25, 2021
463580e
Maybe fix resource format for azure?
mroeschke Nov 25, 2021
f12c148
Merge remote-tracking branch 'upstream/master' into ci/service/moto
mroeschke Nov 26, 2021
29f7025
Set environment variables still due to botocore?
mroeschke Nov 26, 2021
26fdc3a
Move resource to top level
mroeschke Nov 26, 2021
8ce202e
Reorder pytest.importerskip
mroeschke Nov 26, 2021
6f17000
Define azure service in template
mroeschke Nov 26, 2021
edc8841
Remove moto & flask from CI, add support back for local running
mroeschke Nov 26, 2021
fe97638
Apparently templates do not support resources
mroeschke Nov 26, 2021
08a20cc
Dont use service for macOS on azure
mroeschke Nov 26, 2021
c7b07a7
Merge remote-tracking branch 'upstream/master' into ci/service/moto
mroeschke Nov 27, 2021
6f8c273
Revert for window and mac
mroeschke Nov 27, 2021
ef4b020
Add back deps for windows, ignore for circleci
mroeschke Nov 27, 2021
9693baa
Add boto3 to run s3_resource tests
mroeschke Nov 27, 2021
70a20d8
Have fixture yield, don't run on windows
mroeschke Nov 27, 2021
762a79b
Add service to arraymanager test
mroeschke Nov 27, 2021
047a7fd
Merge remote-tracking branch 'upstream/master' into ci/service/moto
mroeschke Nov 28, 2021
129a9f2
Merge remote-tracking branch 'upstream/master' into ci/service/moto
mroeschke Nov 28, 2021
09481d5
Add comments and remove url
mroeschke Nov 28, 2021
c2eed39
Be very explicit just in case the dependencies get added to the build
mroeschke Nov 29, 2021
08605ff
Merge remote-tracking branch 'upstream/master' into ci/service/moto
mroeschke Dec 1, 2021
9b85e2e
Merge remote-tracking branch 'upstream/master' into ci/service/moto
mroeschke Dec 1, 2021
9f60277
Merge remote-tracking branch 'upstream/master' into ci/service/moto
mroeschke Dec 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ jobs:
data_manager:
name: Test experimental data manager
runs-on: ubuntu-latest
services:
moto:
image: motoserver/moto
env:
AWS_ACCESS_KEY_ID: foobar_key
AWS_SECRET_ACCESS_KEY: foobar_secret
ports:
- 5000:5000
strategy:
matrix:
pattern: ["not slow and not network and not clipboard", "slow"]
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ jobs:
ports:
- 5432:5432

moto:
image: motoserver/moto
env:
AWS_ACCESS_KEY_ID: foobar_key
AWS_SECRET_ACCESS_KEY: foobar_secret
ports:
- 5000:5000

steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ jobs:
# https://github.community/t/concurrecy-not-work-for-push/183068/7
group: ${{ github.event_name == 'push' && github.run_number || github.ref }}-${{ matrix.settings[0] }}
cancel-in-progress: true
services:
moto:
image: motoserver/moto
env:
AWS_ACCESS_KEY_ID: foobar_key
AWS_SECRET_ACCESS_KEY: foobar_secret
ports:
- 5000:5000

steps:
- name: Checkout
Expand Down
2 changes: 0 additions & 2 deletions ci/deps/actions-38-db-min.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ dependencies:
- xlrd
- xlsxwriter
- xlwt
- moto
- flask

# sql
- psycopg2=2.8.4
Expand Down
3 changes: 1 addition & 2 deletions ci/deps/actions-38-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
# pandas dependencies
- aiobotocore<2.0.0
- beautifulsoup4
- boto3
- botocore>=1.11
- dask
- fastparquet>=0.4.0
Expand All @@ -22,8 +23,6 @@ dependencies:
- geopandas
- html5lib
- matplotlib
- moto>=1.3.14
- flask
- nomkl
- numexpr
- numpy=1.18
Expand Down
3 changes: 0 additions & 3 deletions ci/deps/actions-38-locale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ dependencies:

# pandas dependencies
- beautifulsoup4
- flask
- html5lib
- ipython
- jinja2
- jedi
- lxml
- matplotlib<3.3.0
- moto
- nomkl
- numexpr
- numpy<1.20 # GH#39541 compat with pyarrow<3
Expand All @@ -34,7 +32,6 @@ dependencies:
- xlrd
- xlsxwriter
- xlwt
- moto
- pyarrow=1.0.1
- pip
- pip:
Expand Down
4 changes: 1 addition & 3 deletions ci/deps/actions-38-slow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:

# pandas dependencies
- beautifulsoup4
- boto3
- fsspec>=0.7.4
- html5lib
- lxml
Expand All @@ -27,12 +28,9 @@ dependencies:
- python-dateutil
- pytz
- s3fs>=0.4.0
- moto>=1.3.14
- scipy
- sqlalchemy
- xlrd
- xlsxwriter
- xlwt
- moto
- flask
- numba
3 changes: 1 addition & 2 deletions ci/deps/actions-39-slow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ dependencies:
# pandas dependencies
- beautifulsoup4
- bottleneck
- boto3
- fsspec>=0.8.0
- gcsfs
- html5lib
- jinja2
- lxml
- matplotlib
- moto>=1.3.14
- flask
- numba
- numexpr
- numpy
Expand Down
3 changes: 1 addition & 2 deletions ci/deps/actions-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ dependencies:
# pandas dependencies
- beautifulsoup4
- bottleneck
- boto3
- fsspec>=0.8.0
- gcsfs
- html5lib
- jinja2
- lxml
- matplotlib
- moto>=1.3.14
- flask
- numba
- numexpr
- numpy
Expand Down
2 changes: 0 additions & 2 deletions ci/deps/azure-windows-38.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ dependencies:
- blosc
- bottleneck
- fastparquet>=0.4.0
- flask
- fsspec>=0.8.0
- matplotlib=3.3.2
- moto>=1.3.14
- numba
- numexpr
- numpy=1.18
Expand Down
2 changes: 0 additions & 2 deletions ci/deps/azure-windows-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ dependencies:
- jinja2
- lxml
- matplotlib
- moto>=1.3.14
- flask
- numba
- numexpr
- numpy
Expand Down
95 changes: 56 additions & 39 deletions pandas/tests/io/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import logging
import os
import shlex
import subprocess
import time

import pytest

from pandas.compat import (
is_platform_arm,
is_platform_mac,
is_platform_windows,
)

import pandas._testing as tm

from pandas.io.parsers import read_csv
Expand Down Expand Up @@ -35,60 +40,72 @@ def feather_file(datapath):


@pytest.fixture
def s3so(worker_id):
worker_id = "5" if worker_id == "master" else worker_id.lstrip("gw")
return {"client_kwargs": {"endpoint_url": f"http://127.0.0.1:555{worker_id}/"}}
def s3so():
return {"client_kwargs": {"endpoint_url": "http://localhost:5000/"}}


@pytest.fixture(scope="session")
def s3_base(worker_id):
"""
Fixture for mocking S3 interaction.

Sets up moto server in separate process
Sets up moto server in separate process locally
Return url for motoserver/moto CI service
"""
pytest.importorskip("s3fs")
pytest.importorskip("boto3")
requests = pytest.importorskip("requests")
logging.getLogger("requests").disabled = True

with tm.ensure_safe_environment_variables():
# temporary workaround as moto fails for botocore >= 1.11 otherwise,
# see https://github.com/spulec/moto/issues/1924 & 1952
os.environ.setdefault("AWS_ACCESS_KEY_ID", "foobar_key")
os.environ.setdefault("AWS_SECRET_ACCESS_KEY", "foobar_secret")

pytest.importorskip("moto", minversion="1.3.14")
pytest.importorskip("flask") # server mode needs flask too

# Launching moto in server mode, i.e., as a separate process
# with an S3 endpoint on localhost

worker_id = "5" if worker_id == "master" else worker_id.lstrip("gw")
endpoint_port = f"555{worker_id}"
endpoint_uri = f"http://127.0.0.1:{endpoint_port}/"

# pipe to null to avoid logging in terminal
with subprocess.Popen(
shlex.split(f"moto_server s3 -p {endpoint_port}"),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
) as proc:

timeout = 5
while timeout > 0:
try:
# OK to go once server is accepting connections
r = requests.get(endpoint_uri)
if r.ok:
break
except Exception:
pass
timeout -= 0.1
time.sleep(0.1)
yield endpoint_uri

proc.terminate()
if os.environ.get("PANDAS_CI", "0") == "1":
if is_platform_arm() or is_platform_mac() or is_platform_windows():
# NOT RUN on Windows/MacOS/ARM, only Ubuntu
# - subprocess in CI can cause timeouts
# - Azure pipelines/Github Actions do not support
# container services for the above OSs
# - CircleCI will probably hit the Docker rate pull limit
pytest.skip(
"S3 tests do not have a corresponding service in "
"Windows, MacOS or ARM platforms"
)
else:
yield "http://localhost:5000"
else:
requests = pytest.importorskip("requests")
pytest.importorskip("moto", minversion="1.3.14")
pytest.importorskip("flask") # server mode needs flask too

# Launching moto in server mode, i.e., as a separate process
# with an S3 endpoint on localhost

worker_id = "5" if worker_id == "master" else worker_id.lstrip("gw")
endpoint_port = f"555{worker_id}"
endpoint_uri = f"http://127.0.0.1:{endpoint_port}/"

# pipe to null to avoid logging in terminal
with subprocess.Popen(
shlex.split(f"moto_server s3 -p {endpoint_port}"),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
) as proc:

timeout = 5
while timeout > 0:
try:
# OK to go once server is accepting connections
r = requests.get(endpoint_uri)
if r.ok:
break
except Exception:
pass
timeout -= 0.1
time.sleep(0.1)
yield endpoint_uri

proc.terminate()


@pytest.fixture()
Expand Down