Skip to content
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

Validate/test all default configs #1268

Merged
merged 13 commits into from
Apr 25, 2022
Merged

Validate/test all default configs #1268

merged 13 commits into from
Apr 25, 2022

Conversation

MisterTimn
Copy link
Contributor

πŸ“ Related issues

#354

✍️ Description

A bash script has been added /test/deploy/validate-configs.sh
This script will test run CSS with all the different default configs by looping over config/*.json
For https (example-https-file.json and https-cli-file.json) certs are set (through cli params or config file overwrites) and base URL is changed.

This script is run in the test-configs job. The job has a tenforce/virtuoso service for sparql config validation and also generates a self-signed cert/key for https. All configs get tested, in case of failure the logs from CSS get printed and the script moves on to the next config. At the end an overview printout is provided:

image

If one of the tests has failed, the overall job will fail.

Improvements

Conditional command changes

Additional exceptions like in the case of https can be set up but this might become cumbersome in the future as configs get added or changed. Perhaps we might move to a solution where default configs are accompanied with an entry in a separate validation config file that provides a string to append to the community-solid-server command. With the addition #1264 and dynamic CLI parameters, we can also enforce all future configs to have parameters that allow it to be run without editing config files (like in the case of example-https-file.json).

Validation / deployment testing / config testing?

Right now, the job name is test-configs and the script is called validate-configs, I'm not sure how we best name this step and where we position it in the pipeline. It's more a form of deployment testing with different configs than a true test...

βœ… PR check list

Before this pull request can be merged, a core maintainer will check whether

  • this PR is labeled with the correct semver label
    • semver.patch: Backwards compatible bug fixes.
    • semver.minor: Backwards compatible feature additions.
    • semver.major: Breaking changes. This includes changing interfaces or configuration behaviour.
  • the correct branch is targeted. Patch updates can target main, other changes should target the latest versions/* branch.
  • the RELEASE_NOTES.md document in case of relevant feature or config changes.
  • any relevant documentation was updated to reflect the changes in this PR.

@MisterTimn MisterTimn added the semver.patch Does not require a minor or major version bump label Apr 19, 2022
@MisterTimn MisterTimn changed the title Chore/test deploy configs Validate/test all default configs Apr 19, 2022
@RubenVerborgh
Copy link
Member

Great!

Is this the right target branch though? I see a couple of unrelated commits.

@MisterTimn
Copy link
Contributor Author

MisterTimn commented Apr 20, 2022

Is this the right target branch though? I see a couple of unrelated commits.

Oh, yea I rebased off the version/4.0.0 branch before opening the PR but then targeted main. I think this best targets main since its unrelated to the CSS code itself, maybe after the 4.0.0 release this can be cleaned up.

EDIT: fixed with rebase off main after release

node-version: '16.x'
- name: Check out repository
uses: actions/checkout@v3
- name: Generate certificates https config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: Generate certificates https config
- name: Generate certificates for HTTPS configurations

test/deploy/validate-configs.sh Show resolved Hide resolved
Comment on lines 26 to 31
if [[ $CONFIG_NAME =~ "https" ]]; then
sed -i -E "s/(\W+\"options_key\".*\").+(\".*)/\1server.key\2/" $CONFIG_PATH
sed -i -E "s/(\W+\"options_cert\".*\").+(\".*)/\1server.cert\2/" $CONFIG_PATH
CSS_OPTS="$CSS_OPTS -b https://localhost:8888 --httpsKey server.key --httpsCert server.cert"
CURL_STATEMENT='-k https://localhost:8888'
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have 2 separate if-statements for the 2 different HTTPS configs so only one of them gets the CLI params, and only one of them gets the changed config. You can also changes the paths in example-https-file.json should that make testing easier.

echo "----------------------------------------"
echo -e $SUCCESSES
echo -e $FAILURES
exit $VALIDATION_FAILURE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing EOL.

test/deploy/validate-configs.sh Show resolved Hide resolved
test/deploy/validate-configs.sh Show resolved Hide resolved
Comment on lines 38 to 51
FAILURE=1
if [ -z $PID ]; then
echo "$TEST_NAME($CONFIG_NAME) - FAILURE: Server did not start"
cat logs/$CONFIG_NAME
else
echo "$TEST_NAME($CONFIG_NAME) - Attempting HTTP access to the server"
for i in {1..20}; do
sleep 1
if curl -s -f $CURL_STATEMENT > logs/$CONFIG_NAME-curl; then
echo "$TEST_NAME($CONFIG_NAME) - SUCCESS: server reached (after ~${i}s)"
FAILURE=0
break
fi
done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since writing this I found https://stackoverflow.com/a/71522504/476820

Comment on lines 86 to 87
echo -e $SUCCESSES
echo -e $FAILURES
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brutal honesty there.

@MisterTimn
Copy link
Contributor Author

The script can now be handed one or multiple arguments, either full path, name, name.json or config/name (see example below).

$ npm run test:deploy default file.json config/example-https-file config/https-file-cli.json

> @solid/community-server@4.0.0 test:deploy
> test/deploy/validate-configs.sh "default" "file.json" "config/example-https-file" "config/https-file-cli.json"

Deployment testing 4 configs
 - config/default.json
 - config/file.json
 - config/example-https-file.json
 - config/https-file-cli.json

No arguments will start test for all configs.

$ npm run test:deploy

> @solid/community-server@4.0.0 test:deploy
> test/deploy/validate-configs.sh

Deployment testing all configs!
 - config/default.json
 - config/dynamic.json
 - config/example-https-file.json
 - config/file-no-setup.json
 - config/file.json
 - config/https-file-cli.json
 - config/memory-subdomains.json
 - config/path-routing.json
 - config/quota-file.json
 - config/restrict-idp.json
 - config/sparql-endpoint-no-setup.json
 - config/sparql-endpoint.json
 - config/sparql-file-storage.json

Added -f argument to css run with a folder for automated cleanup of all files after tests, so it can be used locally.

! When you run locally, sparql configs will fail unless you have an endpoint on https://localhost:4000/sparql

Certificate generation was moved inside the script (instead of from CI run) to allow local deploy:test of https (now it will get generated twice in case all configs are run, don't think this is an issue but might be better to generate at start script (not in the https conditional)

The example-https-file gets copied and placed back so original values are restored. Alternatively, we just change the paths in the file like @joachimvh suggested, but maybe best to keep it in a dir still (to indicate clearly it needs a path). Something like ssl/server.key, then either create/remove that folder everytime or leave it.

Perhaps I should look into writing some small Developer docs on what to do/check when new default configs get added?

@MisterTimn
Copy link
Contributor Author

Im seeing the unit tests on ubuntu fail because they are running deploy:test as well. Remove this step from all CI unit tests as we can depend on the separate deploy-configs job for this?

@RubenVerborgh
Copy link
Member

Im seeing the unit tests on ubuntu fail because they are running deploy:test as well. Remove this step from all CI unit tests as we can depend on the separate deploy-configs job for this?

Absolutely, yes!

Copy link
Member

@RubenVerborgh RubenVerborgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super cool stuff!

.github/workflows/ci.yml Show resolved Hide resolved

TEST_NAME="Deployment testing"
declare -a CONFIG_ARRAY
if [[ $# -gt 0 ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments perhaps regarding expected arguments?

# Script to validate the packaged module and configs

# Ensure our workdir is that of the project root
cd "${0%/*}/../.." || exit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exit with warning / error code?

test/deploy/validate-configs.sh Outdated Show resolved Hide resolved
test/deploy/validate-configs.sh Outdated Show resolved Hide resolved
test/deploy/validate-configs.sh Outdated Show resolved Hide resolved
test/deploy/validate-configs.sh Outdated Show resolved Hide resolved
test/deploy/validate-configs.sh Outdated Show resolved Hide resolved
test/deploy/validate-configs.sh Outdated Show resolved Hide resolved
test/deploy/validate-configs.sh Outdated Show resolved Hide resolved
test/deploy/validate-configs.sh Outdated Show resolved Hide resolved
@MisterTimn
Copy link
Contributor Author

MisterTimn commented Apr 25, 2022

Requested changes are implemented

  • All files needed are generated/cleaned from test/tmp folder which is already in gitignore
  • test:deploy only called in its separate job and needs updated
  • fixed an issue with parameter expansion
  • Now only takes full config path as optional parameter (relative from project directory or absolute)

@RubenVerborgh
Copy link
Member

So nice to see this pass. Great work! @joachimvh Let's make test-configs mandatory in GitHub after this is merged.

@RubenVerborgh
Copy link
Member

@joachimvh Do we have graceful shutdown instead of kill? Like a HUP? Or is this the safe way?

@joachimvh
Copy link
Member

@joachimvh Do we have graceful shutdown instead of kill? Like a HUP? Or is this the safe way?

We don't. The only way to gracefully shutdown is if you start the server through code.

@joachimvh joachimvh merged commit 6dd77cf into main Apr 25, 2022
@joachimvh joachimvh deleted the chore/test-deploy-configs branch April 25, 2022 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver.patch Does not require a minor or major version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants