@@ -10,11 +10,17 @@ Library Collections
1010Suite Setup Setup
1111Suite Teardown Teardown
1212
13- Test Tags configuration etcd restart slow
13+ Test Tags etcd
1414
1515
1616*** Variables ***
1717${ETCD_SYSTEMD_UNIT } microshift-etcd.scope
18+ ${ETCD_CA_CERT } /var/lib/microshift/certs/etcd-signer/ca.crt
19+ ${ETCD_CLIENT_CERT } /var/lib/microshift/certs/etcd-signer/apiserver-etcd-client/client.crt
20+ ${ETCD_CLIENT_KEY } /var/lib/microshift/certs/etcd-signer/apiserver-etcd-client/client.key
21+ ${ETCD_ENDPOINT } https://localhost:2379
22+ ${ETCDCTL_BIN } /tmp/etcdctl
23+ ${ETCDCTL_CMD } ${ETCDCTL_BIN } --cacert=${ETCD_CA_CERT } --cert=${ETCD_CLIENT_CERT } --key=${ETCD_CLIENT_KEY } --endpoints=${ETCD_ENDPOINT }
1824${MEMLIMIT256 } SEPARATOR=\n
1925... ---
2026... etcd:
@@ -26,17 +32,53 @@ ${MEMLIMIT0} SEPARATOR=\n
2632
2733
2834*** Test Cases ***
35+ Etcd Database Defragment Manually
36+ [Documentation] Verify that etcd database can be manually defragmented
37+ ... using etcdctl and the database size does not grow.
38+ ${size_before } = Get Etcd Database Size
39+ Command Should Work ${ETCDCTL_CMD } defrag
40+ ${size_after } = Get Etcd Database Size
41+ Should Be True ${size_after } <= ${size_before }
42+ ... msg=DB size after defrag (${size_after } ) should not exceed size before (${size_before } )
43+ [Teardown] Command Should Work ${ETCDCTL_CMD } alarm disarm
44+
45+ Etcd Runs As Transient Systemd Scope Unit
46+ [Documentation] Verify that etcd runs as a transient systemd scope unit
47+ ... managed by MicroShift with the expected systemd wiring.
48+ Systemctl Check Service SubState ${ETCD_SYSTEMD_UNIT } running
49+ ${transient } = Get Systemd Setting ${ETCD_SYSTEMD_UNIT } Transient
50+ Should Be Equal As Strings ${transient } yes
51+ ${pid } = MicroShift Etcd Process ID
52+ Should Not Be Empty ${pid }
53+ ${binds_to } = Get Systemd Setting ${ETCD_SYSTEMD_UNIT } BindsTo
54+ Should Contain ${binds_to } microshift.service
55+ ${before } = Get Systemd Setting ${ETCD_SYSTEMD_UNIT } Before
56+ Should Contain ${before } microshift.service
57+
58+ Etcd Scope Follows MicroShift Lifecycle
59+ [Documentation] Verify that etcd scope stops with MicroShift and restarts with it.
60+ [Tags] restart slow
61+ Stop MicroShift
62+ Wait Until Etcd Scope Is Inactive
63+ Start MicroShift
64+ Wait For MicroShift
65+ Systemctl Check Service SubState ${ETCD_SYSTEMD_UNIT } running
66+ [Teardown] Run Keywords Start MicroShift AND Wait For MicroShift
67+
2968Set MemoryHigh Limit Unlimited
3069 [Documentation] The default configuration should not limit RAM
3170 ...
3271 ... Since we cannot assume that the default configuration file is
3372 ... being used, the test explicitly configures a '0' limit, which
3473 ... is equivalent to not having any configuration at all.
74+ [Tags] configuration restart slow
3575 [Setup] Setup With Custom Config ${MEMLIMIT0 }
3676 Expect MemoryHigh infinity
77+ [Teardown] Restore Default Config
3778
3879Set MemoryHigh Limit 256MB
3980 [Documentation] Set the memory limit for etcd to 256MB and ensure it takes effect
81+ [Tags] configuration restart slow
4082 [Setup] Setup With Custom Config ${MEMLIMIT256 }
4183 # Expecting the setting to be 256 * 1024 * 1024
4284 Expect MemoryHigh 268435456
4991 Check Required Env Variables
5092 Login MicroShift Host
5193 Setup Kubeconfig # for readiness checks
94+ Install Etcdctl
5295
5396Teardown
5497 [Documentation] Test suite teardown
@@ -70,7 +113,38 @@ Setup With Custom Config
70113Expect MemoryHigh
71114 [Documentation] Verify that the MemoryHigh setting for etcd matches the expected value
72115 [Arguments] ${expected }
73- ${actual } = Get Systemd Setting microshift-etcd.scope MemoryHigh
116+ ${actual } = Get Systemd Setting ${ ETCD_SYSTEMD_UNIT } MemoryHigh
74117 # Using integer comparison is complicated here because sometimes
75118 # the returned or expected value is 'infinity'.
76119 Should Be Equal ${expected } ${actual }
120+
121+ Etcd Scope Is Inactive
122+ [Documentation] Check that the etcd scope unit is not active.
123+ ... Transient scopes disappear when stopped, so is-active returns
124+ ... "inactive" or an error.
125+ ${stdout } ${rc } = Execute Command
126+ ... systemctl is-active ${ETCD_SYSTEMD_UNIT }
127+ ... sudo=True return_rc=True
128+ Should Not Be Equal As Strings ${stdout.strip() } active
129+
130+ Wait Until Etcd Scope Is Inactive
131+ [Documentation] Wait for the etcd scope to become inactive
132+ Wait Until Keyword Succeeds 30x 5s
133+ ... Etcd Scope Is Inactive
134+
135+ Install Etcdctl
136+ [Documentation] Download etcdctl from GitHub to /tmp.
137+ ... Extracts the etcd version from microshift-etcd and downloads the matching release.
138+ ${etcd_ver } = Command Should Work
139+ ... microshift-etcd version 2>&1 | sed -n 's/.*Base etcd Version: //p'
140+ ${arch } = Command Should Work uname -m
141+ ${arch_suffix } = Set Variable If '${arch } ' == 'aarch64' arm64 amd64
142+ Command Should Work
143+ ... bash -c 'curl -sL https://github.com/etcd-io/etcd/releases/download/v${etcd_ver } /etcd-v${etcd_ver } -linux-${arch_suffix } .tar.gz | tar -xz -C /tmp --strip-components\=1 etcd-v${etcd_ver } -linux-${arch_suffix } /etcdctl'
144+
145+ Get Etcd Database Size
146+ [Documentation] Return the current etcd database size in bytes
147+ ${output } = Command Should Work ${ETCDCTL_CMD } endpoint status --write-out\=json
148+ ${size } = Command Should Work
149+ ... echo '${output } ' | python3 -c "import sys,json; print(json.load(sys.stdin)[0]['Status']['dbSize'])"
150+ RETURN ${size }
0 commit comments