Commit b068b908 authored by Xavier Thompson's avatar Xavier Thompson

test_slapproxy: Explain how to upgrade migration tests

Add `README.md` instructions explaining how to adapt the migration
tests after upgrading the proxy database version.
parent e0a747ab
# How to update tests after database version upgrade ?
You've just updated the version of the database in `slapos/proxy/schema.sql`,
and you need to update the tests. You're in the right place!
Let's call `XX` the current version number and `YY` the new version.
Let's call `UU` the version number before `XX`.
## Prerequisites
A SlapOS node in which command `slapos` uses version `XX` of the database.
- e.g. a Theia in which you're locally developping `slapos.core`
A Python virtual environment in which the `slapos.core` egg is installed
from the local repository with your changes, including the version upgrade
to `YY`.
For example, beside the `slapos.core` repository
```
$ python3 -m venv pyenv
$ source pyenv/bin/activate
(pyenv) $ cd slapos.core
(pyenv) $ pip install -e .
(pyenv) $ deactivate
$
```
The command `pip install -e <path>` installs the egg from sources at `<path>`
in editable mode, so that any change the source code is immediately taken
into account.
This provides a `slapos` command that uses version `YY` of the database
(assuming `slapos/proxy/schema.sql` has been updated in the source code)
whenever the virtual environment is activated.
## In `test_slapproxy.py`
- In `_MigrationTestCase`, update `current_version` from `XX` to `YY`.
- Add a `TestMigrateVersionXXToLatest` test case (see the existing ones).
- If tables were added in version `XX`, adjust the `initial_table_list`.
## In `test_slapproxy/`
Go to `test_slapproxy/` (assuming you are at the root of `slapos.core`):
```
$ cd slapos/tests/test_slapproxy
```
With the Python virtual environment deactivated, run:
```
$ ./generate_dump.sh computer database_dump_version_UU.sql database_dump_version_XX.sql
```
This will call `slapos proxy start` with the `slapos` that uses version `XX`,
load the `database_dump_version_UU.sql` and migrate it to version `XX`, and
then dump it into a new file `database_dump_version_XX.sql`.
Now activate the virtual environment and run:
```
(pyenv) $ ./generate_dump.sh slaprunner database_dump_version_current.sql database_dump_version_current.sql
```
This will call `slapos proxy start` with `slapos` from the virtual environment
which has version `YY`, load `database_dump_version_current.sql` which is in
version `XX`, migrate it to `YY`, and then dump it back overwriting the file.
......@@ -42,12 +42,6 @@ sqlite3 ${TMPD}/proxy.db < $DUMP_BEFORE
slapos proxy start --cfg ${TMPD}/slapos.cfg &
# If you are running tests locally and you want to refer to the slapos being tested,
# you can use the test python executable in this way:
# cd ../../..
# python -m slapos.cli.entry proxy start --cfg ${TMPD}/slapos.cfg &
# cd -
SLAPOS_PROXY_PID=$!
curl --silent --retry-connrefused --retry 3 http://127.0.0.1:${PORT}/getComputerInformation?computer_id=$COMPUTER_ID
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment