You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

001_migration.robot 3.4KB

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