Skip to content

Commit

Permalink
Integration test for bluechi-is-online node --wait
Browse files Browse the repository at this point in the history
1. Start agent and verify --wait option returns 0 immediately.
2. Stop agent and verify --wait returns 1 after wait time is expired.
3. Stop agent, run 'bluechi-is-online node --wait' start agent and verify --wait returns 0 before the wait time expires.

Fixes: #1019
Signed-off-by: Dana Orr <[email protected]>
  • Loading branch information
DanaOrr authored and mkemel committed Jan 21, 2025
1 parent 4decef2 commit 4deaab9
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/bluechi_test/bluechi_is_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ def agent_is_online(self, wait: int = None) -> bool:
)
return result == 0

def node_is_online(self, node_name: str) -> bool:
def node_is_online(self, node_name: str, wait: int = None) -> bool:
cmd = ["node", node_name]

if wait:
cmd.extend(["--wait", str(wait)])

result, output = self.run(
"Checking controller status.",
f"node {node_name}",
" ".join(cmd),
False,
0,
)
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/tier0/bluechi-is-online-node-wait/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
summary: test bluechi-is-online node --wait command
id: 0fcb263e-8e6b-493d-91c7-e02da39737f0
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#
# Copyright Contributors to the Eclipse BlueChi project
#
# SPDX-License-Identifier: LGPL-2.1-or-later
import logging
import threading
import time
from typing import Dict

from bluechi_test.bluechi_is_online import BluechiIsOnline
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
from bluechi_test.test import BluechiTest
from bluechi_test.util import Timeout, get_test_env_value_int

LOGGER = logging.getLogger(__name__)

NODE_FOO = "node-foo"
IMMEDIATE_RETURN_TIMEOUT_MS = get_test_env_value_int("IMMEDIATE_RETURN_TIMEOUT", 1000)
WAIT_PARAM_VALUE_MS = get_test_env_value_int("WAIT_PARAM_VALUE", 5000)
SLEEP_DURATION = get_test_env_value_int("SLEEP_DURATION", 2)


class ResultFuture:
def __init__(self):
self.result = None
self.output = ""


def check_node(
bluechi_is_online: BluechiIsOnline,
wait_time: int,
future: ResultFuture,
):
future.result = bluechi_is_online.node_is_online(
NODE_FOO,
wait_time,
)


def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):

node_foo = nodes[NODE_FOO]

# Test 1: Start agent and verify --wait option returns 0 immediately
LOGGER.debug(
f"Starting test number 1 - agent for node {NODE_FOO} should be online."
)
with Timeout(
IMMEDIATE_RETURN_TIMEOUT_MS, "bluechi-is-online didn't return immediately"
):
assert ctrl.bluechi_is_online.node_is_online(NODE_FOO, wait=WAIT_PARAM_VALUE_MS)

# Test 2: Stop agent and verify node --wait returns 1 after wait time is expired
node_foo.systemctl.stop_unit("bluechi-agent")
assert node_foo.wait_for_unit_state_to_be("bluechi-agent", "inactive")
LOGGER.debug(
f"Starting test number 2 - agent for node {NODE_FOO} should remain offline."
)

start_time = time.time()
result = ctrl.bluechi_is_online.node_is_online(NODE_FOO, wait=WAIT_PARAM_VALUE_MS)
assert (
not result
), f"Expected bluechi-is-online with node --wait={WAIT_PARAM_VALUE_MS} to return an error"
assert (
time.time() - start_time > WAIT_PARAM_VALUE_MS / 1000
), "Expected around 5 second for bluechi-is-online to exit"

# Test 3: Stop agent, run 'bluechi-is-online node --wait', start agent and verify --wait returns 0 before the
# wait time expires
LOGGER.debug(
"Starting test number 3, ensure agent is inactive before starting `bluechi-is-online`."
)
with Timeout(WAIT_PARAM_VALUE_MS, "Timeout during Test 3"):
result_future_wait = ResultFuture()
start_time = time.time()
LOGGER.debug("Starting `bluechi-is-online` thread with wait time of 5 seconds.")
check_thread_wait = threading.Thread(
target=check_node,
args=(
ctrl.bluechi_is_online,
WAIT_PARAM_VALUE_MS,
result_future_wait,
),
)
check_thread_wait.start()
time.sleep(SLEEP_DURATION)
node_foo.systemctl.start_unit("bluechi-agent")
assert node_foo.wait_for_unit_state_to_be("bluechi-agent", "active")
LOGGER.debug("Agent confirmed active after starting.")

check_thread_wait.join()
elapsed_time = time.time() - start_time
LOGGER.debug(
f"Test 3 result: {result_future_wait.result}, Elapsed time: {elapsed_time:.2f} seconds"
)
assert (
result_future_wait.result
), f"Expected agent for node {NODE_FOO} to come online before wait expired"
assert (
elapsed_time < WAIT_PARAM_VALUE_MS / 1000
), "bluechi-is-online didn't finish before wait timeout"


def test_bluechi_is_online_agent_wait(
bluechi_test: BluechiTest,
bluechi_node_default_config: BluechiAgentConfig,
bluechi_ctrl_default_config: BluechiControllerConfig,
):
node_bar_cfg = bluechi_node_default_config.deep_copy()
node_bar_cfg.node_name = NODE_FOO

bluechi_ctrl_default_config.allowed_node_names = [NODE_FOO]

bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
bluechi_test.add_bluechi_agent_config(node_bar_cfg)

bluechi_test.run(exec)

2 comments on commit 4deaab9

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

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

@mkemel
Copy link
Member

@mkemel mkemel commented on 4deaab9 Jan 24, 2025

Choose a reason for hiding this comment

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

@mwperina
The weirdest thing is that i386 builds failed for two commits, but for different reasons.

  1. https://copr.fedorainfracloud.org/coprs/g/centos-automotive-sig/bluechi-snapshot/build/8518805/
    https://download.copr.fedorainfracloud.org/results/@centos-automotive-sig/bluechi-snapshot/fedora-rawhide-i386/08518805-bluechi/builder-live.log.gz
    Failed on some build warning, which you don't see in other builds, on 2 year old line:
gcc -Isrc/libbluechi/libbluechi.a.p -Isrc/libbluechi -I../src/libbluechi -Isrc -I../src -Isubprojects/inih -I../subprojects/inih -Isubprojects/hashmap.c -I../subprojects/hashmap.c -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=gnu17 -include config.h -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m32 -march=i686 -mtune=generic -msse2 -mfpmath=sse -mstackrealign -fasynchronous-unwind-tables -fstack-clash-protection -fPIC -DINI_STOP_ON_FIRST_ERROR=1 -DINI_MAX_LINE=520 -Wno-cast-function-type -MD -MQ src/libbluechi/libbluechi.a.p/bus_utils.c.o -MF src/libbluechi/libbluechi.a.p/bus_utils.c.o.d -o src/libbluechi/libbluechi.a.p/bus_utils.c.o -c ../src/libbluechi/bus/utils.c
../src/libbluechi/bus/utils.c: In function ‘hexchar’:
../src/libbluechi/bus/utils.c:254:39: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
  254 |         static const char table[16] = "0123456789abcdef";
      |                                       ^~~~~~~~~~~~~~~~~~
  1. https://copr.fedorainfracloud.org/coprs/g/centos-automotive-sig/bluechi-snapshot/build/8556989/
    https://download.copr.fedorainfracloud.org/results/@centos-automotive-sig/bluechi-snapshot/fedora-rawhide-i386/08556989-bluechi/builder-live.log.gz
    Gets 404s on repo mirrors.
Start: installing minimal buildroot with dnf5
Updating and loading repositories:
 Copr repository                        100% |  44.7 KiB/s |   1.5 KiB |  00m00s
 local                                  100% |  37.1 KiB/s |   8.2 KiB |  00m00s
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Librepo error: Yum repo downloading error: Downloading error(s): repodata/32
Failed to download metadata (baseurl: "https://kojipkgs.fedoraproject.org/repos/rawhide/latest/i386/") for repository "local"
 Librepo error: Yum repo downloading error: Downloading error(s): repodata/3290428df24a3e19696aa9913f3d3bb49e4e52cdf7ff41f67365521902202a48-primary.xml.zst - Cannot download, all mirrors were already tried without success
WARNING: DNF5 command failed, retrying, attempt #2, sleeping 10s
Updating and loading repositories:
 Copr repository                        100% |  23.4 KiB/s |   1.5 KiB |  00m00s
 local                                  100% |  77.7 KiB/s |   8.2 KiB |  00m00s
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Librepo error: Yum repo downloading error: Downloading error(s): repodata/32
Failed to download metadata (baseurl: "https://kojipkgs.fedoraproject.org/repos/rawhide/latest/i386/") for repository "local"
 Librepo error: Yum repo downloading error: Downloading error(s): repodata/3290428df24a3e19696aa9913f3d3bb49e4e52cdf7ff41f67365521902202a48-primary.xml.zst - Cannot download, all mirrors were already tried without success
WARNING: DNF5 command failed, retrying, attempt #3, sleeping 10s
Updating and loading repositories:
 Copr repository                        100% |   9.4 KiB/s |   1.5 KiB |  00m00s
 local                                  100% |  79.3 KiB/s |   8.2 KiB |  00m00s
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Librepo error: Yum repo downloading error: Downloading error(s): repodata/32
Failed to download metadata (baseurl: "https://kojipkgs.fedoraproject.org/repos/rawhide/latest/i386/") for repository "local"
 Librepo error: Yum repo downloading error: Downloading error(s): repodata/3290428df24a3e19696aa9913f3d3bb49e4e52cdf7ff41f67365521902202a48-primary.xml.zst - Cannot download, all mirrors were already tried without success
INFO: chroot_scan: 1 files copied to /var/lib/copr-rpmbuild/results/chroot_scan
INFO: /var/lib/mock/fedora-rawhide-i686-1737486829.414189/root/var/log/dnf5.log
INFO: chroot_scan: creating tarball /var/lib/copr-rpmbuild/results/chroot_scan.tar.gz
/bin/tar: Removing leading `/' from member names
ERROR: Exception(/var/lib/copr-rpmbuild/workspace/workdir-f6d4nn93/bluechi/bluechi.spec) Config(fedora-rawhide-i686) 0 minutes 26 seconds
INFO: Results and/or logs in: /var/lib/copr-rpmbuild/results
INFO: Cleaning up build root ('cleanup_on_failure=True')
Start: clean chroot
INFO: unmounting tmpfs.
Finish: clean chroot
ERROR: Command failed: 
 # /usr/bin/systemd-nspawn -q -M eb85ad26f8e44252aeaec1d8918e6ed8 -D /var/lib/mock/fedora-rawhide-i686-bootstrap-1737486829.414189/root -a --capability=cap_ipc_lock --rlimit=RLIMIT_NOFILE=10240 --capability=cap_ipc_lock --bind=/tmp/mock-resolv.cogezmxr:/etc/resolv.conf --console=pipe --setenv=TERM=vt100 --setenv=SHELL=/bin/bash --setenv=HOME=/var/lib/mock/fedora-rawhide-i686-1737486829.414189/root/installation-homedir --setenv=HOSTNAME=mock --setenv=PATH=/usr/bin:/bin:/usr/sbin:/sbin '--setenv=PROMPT_COMMAND=printf "\033]0;<mock-chroot>\007"' '--setenv=PS1=<mock-chroot> \s-\v\$ ' --setenv=LANG=C.UTF-8 --setenv=LC_MESSAGES=C.UTF-8 --setenv=SYSTEMD_NSPAWN_TMPFS_TMP=0 --setenv=SYSTEMD_SECCOMP=0 --resolv-conf=off /usr/bin/dnf5 --installroot /var/lib/mock/fedora-rawhide-i686-1737486829.414189/root/ --releasever 43 install @build --setopt=deltarpm=False --setopt=allow_vendor_change=yes --allowerasing --setopt=tsflags=nocontexts --setopt=tsflags=nocontexts --setopt=tsflags=nocontexts
Updating and loading repositories:
 Copr repository                        100% |   9.4 KiB/s |   1.5 KiB |  00m00s
 local                                  100% |  79.3 KiB/s |   8.2 KiB |  00m00s
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Status code: 404 for https://kojipkgs.fedoraproject.org/repos/rawhide/latest
>>> Librepo error: Yum repo downloading error: Downloading error(s): repodata/32
Failed to download metadata (baseurl: "https://kojipkgs.fedoraproject.org/repos/rawhide/latest/i386/") for repository "local"
 Librepo error: Yum repo downloading error: Downloading error(s): repodata/3290428df24a3e19696aa9913f3d3bb49e4e52cdf7ff41f67365521902202a48-primary.xml.zst - Cannot download, all mirrors were already tried without success

Copr build error: Build failed

Seems like some copr glitches, let's see if we get something of that sort in the future.

Please sign in to comment.