chore(ci): Update migrate guide for testing. Monitor for URLs that the container tries to open in a browser and then open them in the host.
parent
8b590068d0
commit
838d615692
|
@ -1,6 +1,6 @@
|
|||
# If you're running tests in a container that doesn't support TTY (docker run -t), you can use monitor-tests.sh to open URLs in the host's browser.
|
||||
# Your test needs to redirect the URL to the test/urls.txt file--for example:
|
||||
# influxctl database update /dev/null > test/urls.txt
|
||||
# ./test/src/monitor-tests.sh start
|
||||
sh ./test/src/monitor-tests.sh start
|
||||
npx lint-staged --relative
|
||||
# ./test/src/monitor-tests.sh kill
|
||||
sh ./test/src/monitor-tests.sh stop
|
||||
|
|
|
@ -48,14 +48,20 @@ function pytestStagedContent(paths, productPath) {
|
|||
// Instead of the plugin, we could use a placeholder test that always or conditionally passes.
|
||||
// Whether tests pass or fail, the container is removed,
|
||||
// but the CONTENT container and associated volume will remain until the next run.
|
||||
// Note: TTY is required for the container to open influxctl OAuth URLs in the host browser.
|
||||
// Note: Run the container with TTY to open influxctl OAuth URLs in the host browser.
|
||||
// Run pytest with:
|
||||
// -s to make pytest output log info during the test (instead of after).
|
||||
// --suppress-no-test-exit-code to suppress exit code 5 (no tests collected).
|
||||
// --exitfirst to stop after the first failure.
|
||||
// --codeblocks to test code blocks in markdown files.
|
||||
// Run
|
||||
`docker run --tty=true --label tag=influxdata-docs --label stage=test \
|
||||
--name ${TEST} \
|
||||
--env-file ${productPath}/.env.test \
|
||||
--volumes-from ${CONTENT} \
|
||||
--mount type=bind,src=./test/shared,dst=/shared \
|
||||
--mount type=volume,source=test-tmp,target=/app/iot-starter \
|
||||
influxdata-docs/pytest --codeblocks --suppress-no-test-exit-code --exitfirst ${productPath}/`,
|
||||
influxdata-docs/pytest -s --codeblocks --suppress-no-test-exit-code --exitfirst ${productPath}/`,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -26,10 +26,9 @@ ENV PYTHONUNBUFFERED=1
|
|||
|
||||
WORKDIR /app
|
||||
|
||||
# Create a mock xdg-open script` to prevent the test suite from attempting to open a browser (for example, during influxctl OAuth2 authentication), and instead execute the host-open script.
|
||||
# Create a mock xdg-open script` to prevent the test suite from attempting to open a browser (for example, during influxctl OAuth2 authentication).
|
||||
RUN echo '#!/bin/bash' > /usr/local/bin/xdg-open \
|
||||
&& echo 'echo "$1" > /shared/urls.txt' >> /usr/local/bin/xdg-open \
|
||||
&& echo 'echo "$1" >> /shared/host_open.log' >> /usr/local/bin/xdg-open \
|
||||
&& chmod +x /usr/local/bin/xdg-open
|
||||
|
||||
# Some Python test dependencies (pytest-dotenv and pytest-codeblocks) aren't
|
||||
|
|
|
@ -60,7 +60,7 @@ The simplest way to do this is to directly modify the line protocol exported in
|
|||
|
||||
For example, the following line protocol includes both a tag and field named `temp`.
|
||||
|
||||
```
|
||||
```text
|
||||
home,room=Kitchen,temp=F co=0i,hum=56.6,temp=71.0 1672531200000000000
|
||||
```
|
||||
|
||||
|
@ -143,13 +143,13 @@ the [exported line protocol](#migrate-data-step-1) to group certain fields into
|
|||
unique measurements.
|
||||
For example:
|
||||
|
||||
```
|
||||
```text
|
||||
example-measurement field1=0,field2=0,field3=0,field4=0,field5=0,field6=0,field7=0,field8=0 1672531200000000000
|
||||
```
|
||||
|
||||
Would become:
|
||||
|
||||
```
|
||||
```text
|
||||
new-measurement-1 field1=0,field2=0,field3=0,field4=0 1672531200000000000
|
||||
new-measurement-2 field5=0,field6=0,field7=0,field8=0 1672531200000000000
|
||||
```
|
||||
|
@ -209,6 +209,9 @@ databases.
|
|||
{{% /note %}}
|
||||
|
||||
##### Export all data in a database and retention policy to a file
|
||||
|
||||
<!--pytest.mark.xfail-->
|
||||
|
||||
```sh
|
||||
influx_inspect export \
|
||||
-lponly \
|
||||
|
@ -221,6 +224,8 @@ databases.
|
|||
{{< expand-wrapper >}}
|
||||
{{% expand "Export all data to a file" %}}
|
||||
|
||||
<!--pytest.mark.xfail-->
|
||||
|
||||
```sh
|
||||
influx_inspect export \
|
||||
-lponly \
|
||||
|
@ -231,6 +236,8 @@ influx_inspect export \
|
|||
|
||||
{{% expand "Export all data to a compressed file" %}}
|
||||
|
||||
<!--pytest.mark.xfail-->
|
||||
|
||||
```sh
|
||||
influx_inspect export \
|
||||
-lponly \
|
||||
|
@ -242,6 +249,8 @@ influx_inspect export \
|
|||
|
||||
{{% expand "Export data within time bounds to a file" %}}
|
||||
|
||||
<!--pytest.mark.xfail-->
|
||||
|
||||
```sh
|
||||
influx_inspect export \
|
||||
-lponly \
|
||||
|
@ -254,6 +263,8 @@ influx_inspect export \
|
|||
|
||||
{{% expand "Export a database and all its retention policies to a file" %}}
|
||||
|
||||
<!--pytest.mark.xfail-->
|
||||
|
||||
```sh
|
||||
influx_inspect export \
|
||||
-lponly \
|
||||
|
@ -265,6 +276,8 @@ influx_inspect export \
|
|||
|
||||
{{% expand "Export a specific database and retention policy to a file" %}}
|
||||
|
||||
<!--pytest.mark.xfail-->
|
||||
|
||||
```sh
|
||||
influx_inspect export \
|
||||
-lponly \
|
||||
|
@ -277,6 +290,8 @@ influx_inspect export \
|
|||
|
||||
{{% expand "Export all data from _non-default_ `data` and `wal` directories" %}}
|
||||
|
||||
<!--pytest.mark.xfail-->
|
||||
|
||||
```sh
|
||||
influx_inspect export \
|
||||
-lponly \
|
||||
|
@ -329,6 +344,9 @@ You would create the following InfluxDB {{< current-version >}} databases:
|
|||
(default is infinite)
|
||||
- Database name _(see [Database naming restrictions](#database-naming-restrictions))_
|
||||
|
||||
<!--Skip tests for dataase create and delete: namespaces aren't reusable-->
|
||||
<!--pytest.mark.skip-->
|
||||
|
||||
```sh
|
||||
influxctl database create --retention-period 30d <DATABASE_NAME>
|
||||
```
|
||||
|
|
|
@ -3,20 +3,20 @@
|
|||
## This script is meant to be run on the host and monitors a file for URLs written by a container.
|
||||
|
||||
# The file to monitor for URLs written by the container.
|
||||
FILE="./test/shared/urls.txt"
|
||||
URL_FILE="./test/shared/urls.txt"
|
||||
# Define the URL pattern for OAuth2 authorization.
|
||||
OAUTH_PATTERN='https://auth\.influxdata\.com/activate\?user_code=[A-Z]{1,8}-[A-Z]{1,8}'
|
||||
|
||||
# Loop indefinitely
|
||||
while true; do
|
||||
if [ -f "$FILE" ]; then
|
||||
if [ -f "$URL_FILE" ]; then
|
||||
# Extract an OAuth2 authorization URL from the file
|
||||
URL=$(grep -Eo "$OAUTH_PATTERN" "$FILE")
|
||||
URL=$(grep -Eo "$OAUTH_PATTERN" "$URL_FILE")
|
||||
if [ "$URL" ]; then
|
||||
# Open the URL in the default browser
|
||||
open "$URL"
|
||||
# Clear the file to indicate the URL has been handled
|
||||
> "$FILE"
|
||||
> "$URL_FILE"
|
||||
fi
|
||||
fi
|
||||
sleep 1
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
pid_file=./test/monitor_urls_pid
|
||||
function start {
|
||||
./test/src/monitor-container-urls.sh & echo $! > ./test/monitor_urls_pid
|
||||
./test/src/monitor-container-urls.sh & echo $! >> "$pid_file"
|
||||
}
|
||||
|
||||
function kill_process {
|
||||
PID=$(cat ./test/monitor_urls_pid) && kill -9 $PID && rm ./test/monitor_urls_pid
|
||||
function kill_processes {
|
||||
# Kill all processes in the monitor_urls_pid file
|
||||
echo "Cleaning up monitor-container-urls processes..."
|
||||
while read -r PID; do
|
||||
kill $PID 2>/dev/null; ps -p $PID > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
sed -i '' "/$PID/d" "$pid_file"
|
||||
echo "Successfully stopped monitor-container-urls process $PID"
|
||||
else
|
||||
# Leave it in the file to try stopping it again next time
|
||||
# and output the error message
|
||||
echo "Failed to stop monitor-container-urls process $PID"
|
||||
fi
|
||||
done < "$pid_file"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start) start ;;
|
||||
kill) kill_process ;;
|
||||
*) echo "Usage: $0 {start|kill}" ;;
|
||||
stop) kill_processes ;;
|
||||
*) echo "Usage: $0 {start|stop}" ;;
|
||||
esac
|
|
@ -8,4 +8,10 @@ python_classes = *Test
|
|||
# Collect all functions.
|
||||
python_functions = *
|
||||
|
||||
filterwarnings = ignore::pytest.PytestReturnNotNoneWarning
|
||||
filterwarnings = ignore::pytest.PytestReturnNotNoneWarning
|
||||
# Log settings.
|
||||
log_file = /shared/tests_run.log
|
||||
log_file_date_format = %Y-%m-%d %H:%M:%S
|
||||
log_file_format = %(asctime)s - %(name)s %(levelname)s %(message)s
|
||||
# INFO level log messages for extracting authentication URLs output during tests.
|
||||
log_file_level = INFO
|
Loading…
Reference in New Issue