From 38d98961f10ce117abc1e12c960c457da87d49c8 Mon Sep 17 00:00:00 2001 From: nicholasyang Date: Thu, 13 Feb 2025 11:17:43 +0800 Subject: [PATCH] Dev: behave: add functional tests for pre-migration checks (jsc#PED-8252) --- .github/workflows/crmsh-ci.yml | 15 +++ codecov.yml | 4 +- data-manifest | 1 + test/features/migration.feature | 102 +++++++++++++++++++++ test/features/steps/step_implementation.py | 12 ++- test/run-functional-tests | 2 - 6 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 test/features/migration.feature diff --git a/.github/workflows/crmsh-ci.yml b/.github/workflows/crmsh-ci.yml index 0bfe67ce8..6dc6b8978 100644 --- a/.github/workflows/crmsh-ci.yml +++ b/.github/workflows/crmsh-ci.yml @@ -415,6 +415,21 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} flags: integration + functional_test_migration: + runs-on: ubuntu-24.04 + timeout-minutes: 40 + steps: + - uses: actions/checkout@v4 + - name: functional test for migration + run: | + echo '{ "exec-opts": ["native.cgroupdriver=systemd"] }' | sudo tee /etc/docker/daemon.json + sudo systemctl restart docker.service + $CONTAINER_SCRIPT `$GET_INDEX_OF migration` && $CONTAINER_SCRIPT -d && $CONTAINER_SCRIPT -u `$GET_INDEX_OF migration` + - uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: integration + original_regression_test: runs-on: ubuntu-24.04 timeout-minutes: 40 diff --git a/codecov.yml b/codecov.yml index 47000a652..9c67c4c4a 100644 --- a/codecov.yml +++ b/codecov.yml @@ -8,7 +8,7 @@ coverage: threshold: 0.35% codecov: notify: - after_n_builds: 28 + after_n_builds: 29 comment: - after_n_builds: 28 + after_n_builds: 29 layout: "condensed_header, flags, files, condensed_footer" diff --git a/data-manifest b/data-manifest index 740711f92..ce5f25d4d 100644 --- a/data-manifest +++ b/data-manifest @@ -83,6 +83,7 @@ test/features/environment.py test/features/geo_setup.feature test/features/gfs2.feature test/features/healthcheck.feature +test/features/migration.feature test/features/ocfs2.feature test/features/qdevice_options.feature test/features/qdevice_setup_remove.feature diff --git a/test/features/migration.feature b/test/features/migration.feature new file mode 100644 index 000000000..b6a60a923 --- /dev/null +++ b/test/features/migration.feature @@ -0,0 +1,102 @@ +# vim: sw=2 sts=2 +Feature: migration + + Test migration and pre-migration checks + Need nodes: hanode1 hanode2 + + Scenario: Run pre-migration checks when cluster services are running. + Given Cluster service is "stopped" on "hanode1" + And Cluster service is "stopped" on "hanode2" + And Run "crm cluster init -y -N hanode2" OK on "hanode1" + When Try "crm cluster health sles16" on "hanode1" + Then Expected return code is "1" + And Expected "[FAIL] Cluster services are running" in stdout + + Scenario: Run pre-migration checks with cluster services stopped. + When Run "crm cluster stop --all" on "hanode1" + And Run "crm cluster stop --all" on "hanode2" + And Try "crm cluster health sles16" on "hanode1" + Then Expected return code is "0" + + Scenario: Should run fixes. + When Try "crm cluster health sles16 --fix" on "hanode1" + Then Expected return code is "0" + + Scenario: run pre-migration checks against corosync.conf generated in crmsh-4.6 + When Run "rm -f /etc/corosync/corosync.conf" on "hanode1" + And Write multi lines to file "/etc/corosync/corosync.conf" on "hanode1" + """ + # Please read the corosync.conf.5 manual page + totem { + version: 2 + cluster_name: hacluster + clear_node_high_bit: yes + interface { + ringnumber: 0 + mcastport: 5405 + ttl: 1 + } + + transport: udpu + crypto_hash: sha1 + crypto_cipher: aes256 + token: 5000 + join: 60 + max_messages: 20 + token_retransmits_before_loss_const: 10 + } + + logging { + fileline: off + to_stderr: no + to_logfile: yes + logfile: /var/log/cluster/corosync.log + to_syslog: yes + debug: off + timestamp: on + logger_subsys { + subsys: QUORUM + debug: off + } + + } + + quorum { + + # Enable and configure quorum subsystem (default: off) + # see also corosync.conf.5 and votequorum.5 + provider: corosync_votequorum + expected_votes: 2 + two_node: 1 + } + + nodelist { + node { + ring0_addr: @hanode1.ip.0 + name: hanode1 + nodeid: 1 + } + + node { + ring0_addr: @hanode2.ip.0 + name: hanode2 + nodeid: 2 + } + + } + """ + And Run "crm cluster copy /etc/corosync/corosync.conf" on "hanode1" + And Try "crm cluster health sles16" on "hanode1" + Then Expected return code is "0" + And Expect stdout contains snippets ["[PASS] This cluster is good to migrate to SLES 16.", "[INFO] Please run \"crm cluster health sles16 --fix\" on on any one of above nodes.", "[WARN] Corosync transport \"udpu\" will be deprecated in corosync 3. Please use knet.", "----- localhost -----", "----- hanode2 -----"]. + + Scenario: Run fixes against corosync.conf generated in crmsh-4.6 + When Try "crm cluster health sles16 --fix" on "hanode1" + Then Expected return code is "0" + + Scenario: Run pre-migration checks when some of the nodes are offline. + When Run "systemctl stop sshd" on "hanode2" + And Try "crm cluster health sles16" on "hanode1" + Then Expected return code is "1" + And Expect stdout contains snippets ["Cannot create SSH connection to", "----- localhost -----", "----- hanode2 -----"]. + diff --git a/test/features/steps/step_implementation.py b/test/features/steps/step_implementation.py index b87b52c31..7408a57d3 100644 --- a/test/features/steps/step_implementation.py +++ b/test/features/steps/step_implementation.py @@ -1,3 +1,4 @@ +import ast import re import time import os @@ -18,8 +19,8 @@ def _parse_str(text): - return text[1:-1].encode('utf-8').decode('unicode_escape') -_parse_str.pattern='".*"' + return ast.literal_eval(text) +_parse_str.pattern='"([^"]|\\")*?"' behave.use_step_matcher("cfparse") @@ -170,6 +171,13 @@ def step_impl(context, msg): context.stderr = None +@then('Expect stdout contains snippets [{snippets:str+}].') +def step_impl(context, snippets): + for snippet in snippets: + assert_in(snippet, context.stdout) + context.stdout = None + + @then('Expected regex "{reg_str}" in stdout') def step_impl(context, reg_str): res = re.search(reg_str, context.stdout) diff --git a/test/run-functional-tests b/test/run-functional-tests index dbdc25545..20dfb2018 100755 --- a/test/run-functional-tests +++ b/test/run-functional-tests @@ -228,8 +228,6 @@ deploy_ha_node() { create_node() { - info "Loading container image $CONTAINER_IMAGE..." - echo 16777216 > /proc/sys/net/core/rmem_max echo 16777216 > /proc/sys/net/core/wmem_max info "Create ha specific container networks..."