Skip to content

Commit

Permalink
Move ceph eviction code from manila to manila-ganesha
Browse files Browse the repository at this point in the history
This is so that manila *only* tests without ceph will not try to
clean-up non-existant ceph units.
  • Loading branch information
ajkavanagh committed Jul 18, 2024
1 parent 363ff1d commit af56e9e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 84 deletions.
84 changes: 0 additions & 84 deletions zaza/openstack/charm_tests/manila/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

"""Encapsulate Manila testing."""

import json
import logging
import tenacity

Expand Down Expand Up @@ -353,82 +352,6 @@ def _restart_share_instance(self):
"""
return False

def _make_ceph_healthy(self, model_name=None):
"""Force ceph into a healthy status."""
# wait for 30 seconds for self to get healthy
healthy, ceph_status = self._wait_for_ceph_fs_healthy(
repeat=6, interval=5, model_name=None)
if healthy:
return
logging.info("Ceph is not healthy: %s", ceph_status)
# evict any clients.
self._evict_ceph_mds_clients(model_name)
self._restart_share_instance()
healthy, ceph_status = self._wait_for_ceph_fs_healthy(
repeat=10, interval=15, model_name=None)

def _wait_for_ceph_fs_healthy(
self, repeat=30, interval=20, model_name=None):
"""Wait until the ceph health is healthy."""
logging.info("Waiting for ceph to be healthy - up to 10 minutes")
try:
for attempt in tenacity.Retrying(
wait=tenacity.wait_fixed(interval),
stop=tenacity.stop_after_attempt(repeat),
reraise=True,
):
logging.info("... checking Ceph")
with attempt:
healthy, ceph_status = self._check_ceph_fs_health(
model_name)
if not healthy:
raise RuntimeError("Ceph was unhealthy: {}"
.format(ceph_status))
except RuntimeError:
# we are only retrying for the retries, not to raise an exception.
pass
if healthy:
logging.info("...Ceph is healthy")
else:
logging.info("...Ceph is not healthy %s", ceph_status)
return healthy, ceph_status

@staticmethod
def _check_ceph_fs_health(model_name=None):
"""Check to see if the ceph fs system is healthy."""
cmd_result = zaza.model.run_on_leader(
"ceph-mon",
"sudo ceph status --format=json",
model_name=model_name)
status = json.loads(cmd_result['Stdout'])
ceph_status = status['health']['status']
return (ceph_status == "HEALTH_OK"), ceph_status

@staticmethod
def _evict_ceph_mds_clients(model_name=None):
"""Evict and ceph mds clients present.
Essentially work around a manila-ganesha deployment bug:
https://bugs.launchpad.net/charm-manila-ganesha/+bug/2073498
"""
# NOTE:evicting a client adds them to the mds blocklist; this shouldn't
# matter for the ephemeral nature of the test.
# get the list of clients.
cmd_results = zaza.model.run_on_leader(
"ceph-mon", "sudo ceph tell mds.0 client ls",
model_name=model_name)
result = json.loads(cmd_results['Stdout'])
client_ids = [client['id'] for client in result]
logging.info("Evicting clients %s", ", ".join(
str(c) for c in client_ids))
# now evict the clients.
for client in client_ids:
logging.info("Evicting client %s", client)
zaza.model.run_on_leader(
"ceph-mon",
"sudo ceph tell mds.0 client evict id={}".format(client),
model_name=model_name)

def test_manila_share(self):
"""Test that a Manila share can be accessed on two instances.
Expand All @@ -452,13 +375,6 @@ def test_manila_share(self):
fip_1 = neutron_tests.floating_ips_from_instance(instance_1)[0]
fip_2 = neutron_tests.floating_ips_from_instance(instance_2)[0]

# force a restart to clear out any clients that may be hanging around
# due to restarts on manila-ganesha during deployment; this also forces
# an HA manila into a stable state.
self._restart_share_instance()
# Clean out any old clients causes by restarting manila-ganesha shares
# and ganesha.nfsd daemons.
self._make_ceph_healthy()
# Create a share
share = self.manila_client.shares.create(
share_type=self.share_type_name,
Expand Down
92 changes: 92 additions & 0 deletions zaza/openstack/charm_tests/manila_ganesha/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

"""Encapsulate Manila Ganesha testing."""

import json
import logging
import tenacity

Expand Down Expand Up @@ -219,3 +220,94 @@ def test_905_nrpe_custom_service_checks(self):
]

self._run_nrpe_check_command(commands)

def _make_ceph_healthy(self, model_name=None):
"""Force ceph into a healthy status."""
# wait for 30 seconds for self to get healthy
healthy, ceph_status = self._wait_for_ceph_fs_healthy(
repeat=6, interval=5, model_name=None)
if healthy:
return
logging.info("Ceph is not healthy: %s", ceph_status)
# evict any clients.
self._evict_ceph_mds_clients(model_name)
self._restart_share_instance()
healthy, ceph_status = self._wait_for_ceph_fs_healthy(
repeat=10, interval=15, model_name=None)

def _wait_for_ceph_fs_healthy(
self, repeat=30, interval=20, model_name=None):
"""Wait until the ceph health is healthy."""
logging.info("Waiting for ceph to be healthy ...")
try:
for attempt in tenacity.Retrying(
wait=tenacity.wait_fixed(interval),
stop=tenacity.stop_after_attempt(repeat),
reraise=True,
):
logging.info("... checking Ceph")
with attempt:
healthy, ceph_status = self._check_ceph_fs_health(
model_name)
if not healthy:
raise RuntimeError("Ceph was unhealthy: {}"
.format(ceph_status))
except RuntimeError:
# we are only retrying for the retries, not to raise an exception.
pass
if healthy:
logging.info("...Ceph is healthy")
else:
logging.info("...Ceph is not healthy %s", ceph_status)
return healthy, ceph_status

@staticmethod
def _check_ceph_fs_health(model_name=None):
"""Check to see if the ceph fs system is healthy."""
cmd_result = zaza.model.run_on_leader(
"ceph-mon",
"sudo ceph status --format=json",
model_name=model_name)
status = json.loads(cmd_result['Stdout'])
ceph_status = status['health']['status']
return (ceph_status == "HEALTH_OK"), ceph_status

@staticmethod
def _evict_ceph_mds_clients(model_name=None):
"""Evict and ceph mds clients present.
Essentially work around a manila-ganesha deployment bug:
https://bugs.launchpad.net/charm-manila-ganesha/+bug/2073498
"""
# NOTE:evicting a client adds them to the mds blocklist; this shouldn't
# matter for the ephemeral nature of the test.
# get the list of clients.
cmd_results = zaza.model.run_on_leader(
"ceph-mon", "sudo ceph tell mds.0 client ls",
model_name=model_name)
result = json.loads(cmd_results['Stdout'])
client_ids = [client['id'] for client in result]
logging.info("Evicting clients %s", ", ".join(
str(c) for c in client_ids))
# now evict the clients.
for client in client_ids:
logging.info("Evicting client %s", client)
zaza.model.run_on_leader(
"ceph-mon",
"sudo ceph tell mds.0 client evict id={}".format(client),
model_name=model_name)

def test_manila_share(self):
"""Test that a manila-ganesha share can be accessed on two instances.
This overrides the base manila test by prefixing a make ceph healthy
stage.
"""
# force a restart to clear out any clients that may be hanging around
# due to restarts on manila-ganesha during deployment; this also forces
# an HA manila into a stable state.
self._restart_share_instance()
# Clean out any old clients causes by restarting manila-ganesha shares
# and ganesha.nfsd daemons.
self._make_ceph_healthy()
super().test_manila_share()

0 comments on commit af56e9e

Please sign in to comment.