all_mounts = getattr(ctx, 'mounts', {})
mounted_by_me = {}
skipped = {}
+ remotes = set()
brxnet = config.get("brxnet", None)
# Construct any new FuseMount instances
for id_, remote in clients:
+ remotes.add(remote)
client_config = config.get("client.%s" % id_)
if client_config is None:
client_config = {}
ctx.mounts = all_mounts
+ # Umount any pre-existing clients that we have not been asked to mount
+ for client_id in set(all_mounts.keys()) - set(mounted_by_me.keys()) - set(skipped.keys()):
+ mount = all_mounts[client_id]
+ if mount.is_mounted():
+ mount.umount_wait()
+
+ for remote in remotes:
+ FuseMount.cleanup_stale_netnses_and_bridge(remote)
+
# Mount any clients we have been asked to (default to mount all)
log.info('Mounting ceph-fuse clients...')
for info in mounted_by_me.values():
for info in mounted_by_me.values():
info["mount"].wait_until_mounted()
- # Umount any pre-existing clients that we have not been asked to mount
- for client_id in set(all_mounts.keys()) - set(mounted_by_me.keys()) - set(skipped.keys()):
- mount = all_mounts[client_id]
- if mount.is_mounted():
- mount.umount_wait()
-
try:
yield all_mounts
finally:
log = logging.getLogger(__name__)
-
class CephFSMount(object):
def __init__(self, ctx, test_dir, client_id, client_remote, brxnet):
"""
self.background_procs = []
+ # This will cleanup the stale netnses, which are from the
+ # last failed test cases.
+ @staticmethod
+ def cleanup_stale_netnses_and_bridge(remote):
+ p = remote.run(args=['ip', 'netns', 'list'],
+ stdout=StringIO(), timeout=(5*60))
+ p = p.stdout.getvalue().strip()
+
+ # Get the netns name list
+ netns_list = re.findall(r'ceph-ns-[^()\s][-.\w]+[^():\s]', p)
+
+ # Remove the stale netnses
+ for ns in netns_list:
+ ns_name = ns.split()[0]
+ args = ['sudo', 'ip', 'netns', 'delete', '{0}'.format(ns_name)]
+ try:
+ remote.run(args=args, timeout=(5*60), omit_sudo=False)
+ except Exception:
+ pass
+
+ # Remove the stale 'ceph-brx'
+ try:
+ args = ['sudo', 'ip', 'link', 'delete', 'ceph-brx']
+ remote.run(args=args, timeout=(5*60), omit_sudo=False)
+ except Exception:
+ pass
+
def _parse_netns_name(self):
self._netns_name = '-'.join(["ceph-ns",
re.sub(r'/+', "-", self.mountpoint)])
for ns in netns_list:
ns_name = ns.split()[0]
args = ['sudo', 'ip', 'netns', 'exec', '{0}'.format(ns_name), 'ip', 'addr']
- p = self.client_remote.run(args=args, stderr=StringIO(),
- stdout=StringIO(), timeout=(5*60),
- omit_sudo=False)
- q = re.search("{0}".format(ip), p.stdout.getvalue())
- if q is not None:
- found = True
- break
+ try:
+ p = self.client_remote.run(args=args, stderr=StringIO(),
+ stdout=StringIO(), timeout=(5*60),
+ omit_sudo=False)
+ q = re.search("{0}".format(ip), p.stdout.getvalue())
+ if q is not None:
+ found = True
+ break
+ except CommandFailedError:
+ if "No such file or directory" in p.stderr.getvalue():
+ pass
+ if "Invalid argument" in p.stderr.getvalue():
+ pass
if found == False:
break
from tasks.cephfs.fuse_mount import FuseMount
from tasks.cephfs.kernel_mount import KernelMount
from tasks.cephfs.filesystem import Filesystem, MDSCluster, CephCluster
+ from tasks.cephfs.mount import CephFSMount
from tasks.mgr.mgr_test_case import MgrCluster
from teuthology.contextutil import MaxWhileTries
from teuthology.task import interactive
global remote
remote = LocalRemote()
+ CephFSMount.cleanup_stale_netnses_and_bridge(remote)
+
# Tolerate no MDSs or clients running at start
ps_txt = remote.run(args=["ps", "-u"+str(os.getuid())],
stdout=StringIO()).stdout.getvalue().strip()