Debian Codegraph @

test/functional/cases/210_clickhouse/001_migration.robot

raw
1 *** Settings ***
2 Documentation Checks if rspamd is able to upgrade migration schema from v0 (very initial) to v2
3 Test Setup Clickhouse Setup
4 Test Teardown Clickhosue Teardown
5 Variables ${RSPAMD_TESTDIR}/lib/vars.py
6 Library ${RSPAMD_TESTDIR}/lib/rspamd.py
7 Library clickhouse.py
8 Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot
9
10 *** Variables ***
11 ${CONFIG} ${RSPAMD_TESTDIR}/configs/clickhouse.conf
12 ${RSPAMD_SCOPE} Suite
13 ${CLICKHOUSE_PORT} ${18123}
14
15 *** Test Cases ***
16 # Usually broken
17 #Migration
18 #Initial schema
19 # Prepare rspamd
20 # Sleep 2 #TODO: replace this check with waiting until migration finishes
21 # Column should exist rspamd Symbols.Scores
22 # Column should exist rspamd Attachments.Digest
23 # Column should exist rspamd Symbols.Scores
24 # Schema version should be 3
25 # Upload new schema ${RSPAMD_TESTDIR}/data/initial_schema/schema.sql
26 # Insert data rspamd ${RSPAMD_TESTDIR}/data/initial_schema/data.rspamd.sql
27 # Insert data rspamd_asn ${RSPAMD_TESTDIR}/data/initial_schema/data.rspamd_asn.sql
28 # Insert data rspamd_urls ${RSPAMD_TESTDIR}/data/initial_schema/data.rspamd_urls.sql
29 # Insert data rspamd_emails ${RSPAMD_TESTDIR}/data/initial_schema/data.rspamd_emails.sql
30 # Insert data rspamd_symbols ${RSPAMD_TESTDIR}/data/initial_schema/data.rspamd_symbols.sql
31 # Insert data rspamd_attachments ${RSPAMD_TESTDIR}/data/initial_schema/data.rspamd_attachments.sql
32 # Prepare rspamd
33 # Sleep 2 #TODO: replace this check with waiting until migration finishes
34 # Column should exist rspamd Symbols.Scores
35 # Column should exist rspamd Attachments.Digest
36 # Column should exist rspamd Symbols.Scores
37 # # Added in schema version 7
38 # Column should exist rspamd Helo
39 # Column should exist rspamd SMTPRecipients
40 # # Added in schema version 8
41 # Column should exist rspamd Groups.Scores
42 # Schema version should be 8
43
44 # Eventually broken
45 #Retention
46 # Upload new schema ${RSPAMD_TESTDIR}/data/schema_2/schema.sql
47 # Insert data rspamd ${RSPAMD_TESTDIR}/data/schema_2/data.rspamd.sql
48 # Assert rows count rspamd 56
49 # Prepare rspamd
50 # Sleep 2 #TODO: replace this check with waiting until migration finishes
51 # Assert rows count rspamd 30
52
53 *** Keywords ***
54 Clickhouse Setup
55 ${RSPAMD_TMPDIR} = Make Temporary Directory
56 Set Suite Variable ${RSPAMD_TMPDIR}
57 Set Directory Ownership ${RSPAMD_TMPDIR} ${RSPAMD_USER} ${RSPAMD_GROUP}
58 ${template} = Get File ${RSPAMD_TESTDIR}/configs/clickhouse-config.xml
59 ${config} = Replace Variables ${template}
60 Create File ${RSPAMD_TMPDIR}/clickhouse-config.xml ${config}
61 Copy File ${RSPAMD_TESTDIR}/configs/clickhouse-users.xml ${RSPAMD_TMPDIR}/users.xml
62 Create Directory ${RSPAMD_TMPDIR}/clickhouse
63 Set Directory Ownership ${RSPAMD_TMPDIR}/clickhouse clickhouse clickhouse
64 ${result} = Run Process su -s /bin/sh clickhouse -c
65 ... clickhouse-server --daemon --config-file\=${RSPAMD_TMPDIR}/clickhouse-config.xml --pid-file\=${RSPAMD_TMPDIR}/clickhouse/clickhouse.pid
66 IF ${result.rc} != 0
67 Log ${result.stderr}
68 END
69 Should Be Equal As Integers ${result.rc} 0
70 Wait Until Keyword Succeeds 5 sec 50 ms TCP Connect localhost ${CLICKHOUSE_PORT}
71 Set Suite Variable ${RSPAMD_TMPDIR} ${RSPAMD_TMPDIR}
72
73 Clickhosue Teardown
74 # Sleep 30
75 ${clickhouse_pid} = Get File ${RSPAMD_TMPDIR}/clickhouse/clickhouse.pid
76 Shutdown Process With Children ${clickhouse_pid}
77 Log File ${RSPAMD_TMPDIR}/clickhouse/clickhouse-server.err.log
78 Rspamd Teardown
79
80 Prepare rspamd
81 &{d} = Run Rspamd CONFIG=${RSPAMD_TESTDIR}/configs/clickhouse.conf TMPDIR=${RSPAMD_TMPDIR}
82 ${keys} = Get Dictionary Keys ${d}
83 FOR ${i} IN @{keys}
84 IF '${RSPAMD_SCOPE}' == 'Suite'
85 Set Suite Variable ${${i}} ${d}[${i}]
86 ELSE IF '${RSPAMD_SCOPE}' == 'Test'
87 Set Test Variable ${${i}} ${d}[${i}]
88 ELSE
89 Fail 'RSPAMD_SCOPE must be Test or Suite'
90 END
91 END