Skip to content

Commit b10d6d5

Browse files
committed
glusterfs: Don't uninstall glusterfs tools when SR couldn't be destroyed
Signed-off-by: Antoine Bartuccio <[email protected]>
1 parent a71b5e5 commit b10d6d5

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

tests/storage/glusterfs/conftest.py

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import pytest
22

33
import logging
4+
from dataclasses import dataclass
45

56
from lib.common import exec_nofail, raise_errors, setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
67
from lib.netutil import is_ipv6
78

9+
from typing import TYPE_CHECKING
10+
11+
if TYPE_CHECKING:
12+
from lib.host import Host
13+
from lib.pool import Pool
14+
from lib.sr import SR
15+
816
# explicit import for package-scope fixtures
917
from pkgfixtures import pool_with_saved_yum_state
1018

1119
GLUSTERFS_PORTS = [('24007', 'tcp'), ('49152:49251', 'tcp')]
1220

21+
@dataclass
22+
class GlusterFsConfig:
23+
uninstall_glusterfs: bool = True
24+
1325
def _setup_host_with_glusterfs(host):
1426
for service in ['iptables', 'ip6tables']:
1527
host.ssh(['cp', '/etc/sysconfig/%s' % service, '/etc/sysconfig/%s.orig' % service])
@@ -30,13 +42,18 @@ def _setup_host_with_glusterfs(host):
3042

3143
host.ssh(['systemctl', 'enable', '--now', 'glusterd.service'])
3244

33-
def _teardown_host_with_glusterfs(host):
45+
def _uninstall_host_glusterfs(host: 'Host'):
3446
errors = []
3547
errors += exec_nofail(lambda: host.ssh(['systemctl', 'disable', '--now', 'glusterd.service']))
3648

3749
# Remove any remaining gluster-related data to avoid issues in future test runs
3850
errors += exec_nofail(lambda: host.ssh(['rm', '-rf', '/var/lib/glusterd']))
3951

52+
raise_errors(errors)
53+
54+
def _restore_host_iptables(host: 'Host'):
55+
errors = []
56+
4057
iptables = 'ip6tables' if is_ipv6(host.hostname_or_ip) else 'iptables'
4158
for h in host.pool.hosts:
4259
hostname_or_ip = h.hostname_or_ip
@@ -56,7 +73,7 @@ def _teardown_host_with_glusterfs(host):
5673
raise_errors(errors)
5774

5875
@pytest.fixture(scope='package')
59-
def pool_without_glusterfs(host):
76+
def pool_without_glusterfs(host: 'Host'):
6077
for h in host.pool.hosts:
6178
if h.file_exists('/usr/sbin/glusterd'):
6279
raise Exception(
@@ -65,11 +82,31 @@ def pool_without_glusterfs(host):
6582
yield host.pool
6683

6784
@pytest.fixture(scope='package')
68-
def pool_with_glusterfs(pool_without_glusterfs, pool_with_saved_yum_state):
85+
def _glusterfs_config():
86+
return GlusterFsConfig()
87+
88+
@pytest.fixture(scope='package')
89+
def pool_with_glusterfs(
90+
pool_without_glusterfs: 'Pool',
91+
pool_with_saved_yum_state: 'Pool',
92+
_glusterfs_config: GlusterFsConfig
93+
):
94+
95+
def _host_rollback(host: 'Host'):
96+
_uninstall_host_glusterfs(host)
97+
_restore_host_iptables(host)
98+
99+
def _disable_yum_rollback(host: 'Host'):
100+
host.saved_rollback_id = None
101+
69102
pool = pool_with_saved_yum_state
70-
pool.exec_on_hosts_on_error_rollback(_setup_host_with_glusterfs, _teardown_host_with_glusterfs)
103+
pool.exec_on_hosts_on_error_rollback(_setup_host_with_glusterfs, _host_rollback)
71104
yield pool
72-
pool.exec_on_hosts_on_error_continue(_teardown_host_with_glusterfs)
105+
if _glusterfs_config.uninstall_glusterfs:
106+
pool.exec_on_hosts_on_error_continue(_uninstall_host_glusterfs)
107+
else:
108+
pool.exec_on_hosts_on_error_continue(_disable_yum_rollback)
109+
pool.exec_on_hosts_on_error_continue(_restore_host_iptables)
73110

74111
@pytest.fixture(scope='package')
75112
def gluster_disk(pool_with_unused_512B_disk, unused_512B_disks):
@@ -184,13 +221,23 @@ def glusterfs_device_config(host):
184221
}
185222

186223
@pytest.fixture(scope='package')
187-
def glusterfs_sr(host, pool_with_glusterfs, gluster_volume_started, glusterfs_device_config):
224+
def glusterfs_sr(
225+
host: 'Host',
226+
pool_with_glusterfs: 'Pool',
227+
gluster_volume_started: None,
228+
glusterfs_device_config,
229+
_glusterfs_config: GlusterFsConfig
230+
):
188231
""" A GlusterFS SR on first host. """
189232
# Create the SR
190233
sr = host.sr_create('glusterfs', "GlusterFS-SR-test", glusterfs_device_config, shared=True)
191234
yield sr
192235
# teardown
193-
sr.destroy()
236+
try:
237+
sr.destroy()
238+
except Exception as e:
239+
_glusterfs_config.uninstall_glusterfs = False
240+
raise e
194241

195242
@pytest.fixture(scope='module')
196243
def vdi_on_glusterfs_sr(glusterfs_sr):

0 commit comments

Comments
 (0)