Skip to content

Commit

Permalink
More work towards fixing the selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meatballhat committed Jun 23, 2020
1 parent 657475a commit 8ee63bb
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 58 deletions.
10 changes: 2 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
build/
dist/
notebooks*/
*/node_modules/
*.egg-info/
.eggs/
*.pyc
.git/
*
!Pipfile*
12 changes: 9 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ jobs:
- run: make install
- run: make lint
- run: make test
# - run: make image${{ matrix.python-version }}
# - run: make -C selenium build
# - run: make test-selenium
- if: false
name: currently busted selenium test stuff
run: >
make image${{ matrix.python-version }}
make -C selenium build
make -C selenium clean
make -C selenium test-env-up
make -C selenium jupyter-up
make -C selenium test
distributions:
needs: test
runs-on: ubuntu-latest
Expand Down
26 changes: 19 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@ LABEL maintainer="RStudio Connect <[email protected]>"
ARG NB_UID
ARG NB_GID
ARG PY_VERSION
RUN apt-get update -qq \
&& apt-get install -y make
RUN apt-get update -qq && \
apt-get install -y make curl xz-utils git && \
curl -fsSL "https://nodejs.org/dist/v12.18.1/node-v12.18.1-linux-x64.tar.xz" | \
tar --strip-components=1 -C /usr/local -xJf - && \
npm install -g yarn

RUN getent group ${NB_GID} || groupadd -g ${NB_GID} builder
RUN useradd --password password \
--create-home \
--home-dir /home/builder \
--uid ${NB_UID} \
--gid ${NB_GID} \
builder

RUN conda update conda
builder && \
mkdir -p /rsconnect_jupyter && \
chown ${NB_UID}:${NB_GID} /rsconnect_jupyter

USER ${NB_UID}:${NB_GID}
RUN bash -c 'cd /home/builder \
&& conda create --yes --channel conda-forge --name py${PY_VERSION/./} python=${PY_VERSION} jupyter numpy matplotlib setuptools pip pipenv'
WORKDIR /rsconnect_jupyter
ENV WORKON_HOME=/home/builder \
PIPENV_DONT_LOAD_ENV=1 \
PIPENV_SHELL=/bin/bash \
PATH=/home/builder/.local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
COPY Pipfile Pipfile
COPY Pipfile.lock Pipfile.lock
RUN python -m pip install -I -U pip pipenv && \
pipenv install --dev --python=/usr/local/bin/python && \
rm -vf Pipfile*
22 changes: 2 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,19 @@ image%:
docker build \
--tag $(IMAGE)$* \
--file Dockerfile \
--build-arg BASE_IMAGE=continuumio/miniconda:4.4.10 \
--build-arg BASE_IMAGE=python:$*-slim \
--build-arg NB_UID=$(NB_UID) \
--build-arg NB_GID=$(NB_GID) \
--build-arg PY_VERSION=$* \
.

.PHONY: launch
launch:
docker run --rm -i -t \
-v $(CURDIR)/notebooks$(PY_VERSION):/notebooks \
-v $(CURDIR):/rsconnect_jupyter \
-e NB_UID=$(NB_UID) \
-e NB_GID=$(NB_GID) \
-e PY_VERSION=$(PY_VERSION) \
-p :$(PORT):9999 \
$(DOCKER_IMAGE) \
/rsconnect_jupyter/run.sh $(TARGET)


notebook%:
make DOCKER_IMAGE=$(IMAGE)$* PY_VERSION=$* TARGET=run launch

.PHONY: all-tests
all-tests: test2.7 test3.5 test3.6 test3.7 test3.8

.PHONY: test
test: version-frontend
pipenv run pytest -vv --cov=rsconnect_jupyter tests/

test%: version-frontend
make DOCKER_IMAGE=rstudio/rsconnect-jupyter-py$* PY_VERSION=$* TARGET=test launch

.PHONY: test-selenium
test-selenium:
$(MAKE) -C selenium clean test-env-up jupyter-up test || EXITCODE=$$? ; \
Expand All @@ -79,6 +60,7 @@ run: install
.PHONY: install
install: yarn
pipenv install --dev
$(MAKE) version-frontend
pipenv run pip install -e .
pipenv run jupyter-nbextension install --symlink --user --py rsconnect_jupyter
pipenv run jupyter-nbextension enable --py rsconnect_jupyter
Expand Down
14 changes: 11 additions & 3 deletions mock_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
from pprint import pprint

# noinspection PyPackageRequirements
from flask import Flask, Blueprint, abort, after_this_request, g, request, url_for, jsonify
from flask import (
Flask,
Blueprint,
abort,
after_this_request,
g,
request,
url_for,
jsonify,
)


def error(code, reason):
Expand Down Expand Up @@ -307,8 +316,7 @@ def get_task(task):
@api.route("server_settings")
@json
def server_settings():
# for our purposes, any non-error response will do
return {}
return {"not_empty": True}


# noinspection PyUnresolvedReferences
Expand Down
11 changes: 11 additions & 0 deletions rsconnect_jupyter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ def post(self, action):
disable_tls_check = data["disable_tls_check"]
cadata = data.get("cadata", None)

self.log.warning(
"server_address=%r api_key=%r disable_tls_check=%r cadata=%r",
server_address,
api_key,
disable_tls_check,
cadata,
)
canonical_address = None
result = None
try:
canonical_address, result = test_server(
RSConnectServer(server_address, api_key, disable_tls_check, cadata)
Expand All @@ -96,6 +105,8 @@ def post(self, action):
+ u' upload it using "Upload TLS Certificate Bundle" below.',
)
except Exception as err:
self.log.exception("Unable to verify that the provided server is running RStudio Connect")
self.log.warning("canonical_address=%r result=%r", canonical_address, result)
raise web.HTTPError(
400, u"Unable to verify that the provided server is running RStudio Connect: %s" % err,
)
Expand Down
31 changes: 14 additions & 17 deletions selenium/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SCALE_FIREFOX=${SCALE}
SCALE_CHROME=${SCALE}
SELENIUM_VERSION=3.8.1-dubnium
TMP_PIPE=tmp.pipe
TRE_IMAGE?=rstudio/checkrs-tew:0.1.0
TRE_IMAGE?=rstudio/checkrs-tew:0.3.2

# Allocate a tty and keep stdin open when running locally
# Jenkins nodes don't have input tty, so we set this to ""
Expand All @@ -46,7 +46,7 @@ DOCKER_RUN_COMMAND=docker run --rm --init \
--network=$(NETWORK) \
--volume=$(CURDIR)/..:${RSCONNECT_DIR} \
--volume=$(CURDIR)/../notebooks$(PY_VERSION):${NOTEBOOKS_DIR} \
--user=`id -u`:`id -g` \
--user=$(NB_UID):$(NB_GID) \
--workdir=${RSCONNECT_DIR}/selenium \
${TRE_IMAGE}

Expand Down Expand Up @@ -82,8 +82,8 @@ build-mock-connect:
docker build -t ${CONNECT_IMAGE} ${CONNECT_DOCKERFILE_DIR}

clean:
rm -f *.png *.log *.xml ${TMP_PIPE};
rm -rf .pytest_cache;
rm -f *.png *.log *.xml ${TMP_PIPE}
rm -rf .pytest_cache

distclean: clean

Expand Down Expand Up @@ -123,7 +123,7 @@ wait-for-systems-up:
--name=systemstat \
--network=$(NETWORK) \
--volume=${CURDIR}/..:${RSCONNECT_DIR} \
--user=`id -u`:`id -g` \
--user=$(NB_UID):$(NB_GID) \
--workdir=${RSCONNECT_DIR}/selenium \
${TRE_IMAGE} \
./wait_for_systems_up.sh \
Expand Down Expand Up @@ -156,7 +156,7 @@ network-up:
@if [ "${NETWORK_EXISTS}" = "1" ] ; then \
echo "Creating network: ${NETWORK}"; \
docker network create --driver bridge ${NETWORK} ; \
fi;
fi

network-down: connect-down grid-down
$(eval NETWORK_EXISTS=$(shell docker network inspect ${NETWORK} > /dev/null 2>&1 && echo 0 || echo 1))
Expand All @@ -167,13 +167,10 @@ network-down: connect-down grid-down
done; \
echo "Removing network: ${NETWORK}"; \
docker network rm ${NETWORK}; \
fi;

# I think we need TINI_SUBREAPER set because we are using --init, but run.sh
# calls a make command which launches another command.
fi

jupyter-up:
@echo -n "Creating ${JUPYTER_HOST} ..."
@echo "Creating ${JUPYTER_HOST} ..."
@docker run --rm -d --init \
${DOCKER_TTY_FLAGS} \
--name=${JUPYTER_HOST} \
Expand All @@ -187,21 +184,21 @@ jupyter-up:
--publish=:${JUPYTER_PORT}:${JUPYTER_PORT} \
--workdir=${RSCONNECT_DIR} \
$(JUPYTER_IMAGE) \
${RSCONNECT_DIR}/run.sh run \
make -C ${RSCONNECT_DIR} run \
1>/dev/null
@docker logs -f ${JUPYTER_HOST} > ${JUPYTER_LOG} &
@echo " done"

jupyter-down:
$(eval JUPYTER_EXISTS=$(shell docker container inspect ${JUPYTER_HOST} > /dev/null 2>&1 && echo 0 || echo 1))
@if [ "${JUPYTER_EXISTS}" = "0" ] ; then \
echo -n "Stopping ${JUPYTER_HOST} ..."; \
echo "Stopping ${JUPYTER_HOST} ..."; \
docker stop ${JUPYTER_HOST} 1>/dev/null; \
echo " done"; \
fi;
fi

connect-up:
@echo -n "Creating ${CONNECT_HOST} ..."
@echo "Creating ${CONNECT_HOST} ..."
@docker run --rm -d --init \
${DOCKER_TTY_FLAGS} \
--name=${CONNECT_HOST} \
Expand All @@ -219,10 +216,10 @@ connect-up:
connect-down:
$(eval CONNECT_EXISTS=$(shell docker container inspect ${CONNECT_HOST} > /dev/null 2>&1 && echo 0 || echo 1))
@if [ "${CONNECT_EXISTS}" = "0" ] ; then \
echo -n "Stopping ${CONNECT_HOST} ..."; \
echo "Stopping ${CONNECT_HOST} ..."; \
docker stop ${CONNECT_HOST} 1>/dev/null; \
echo " done"; \
fi;
fi


.PHONY: all
Expand Down

0 comments on commit 8ee63bb

Please sign in to comment.