]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/kclient.py
2 Mount/unmount a ``kernel`` client.
7 from teuthology
.misc
import deep_merge
8 from teuthology
.exceptions
import CommandFailedError
9 from teuthology
import misc
10 from teuthology
.contextutil
import MaxWhileTries
11 from tasks
.cephfs
.kernel_mount
import KernelMount
13 log
= logging
.getLogger(__name__
)
15 @contextlib.contextmanager
16 def task(ctx
, config
):
18 Mount/unmount a ``kernel`` client.
20 The config is optional and defaults to mounting on all clients. If
21 a config is given, it is expected to be a list of clients to do
22 this operation on. This lets you e.g. set up one client with
23 ``ceph-fuse`` and another with ``kclient``.
25 ``brxnet`` should be a Private IPv4 Address range, default range is
28 Example that mounts all clients::
34 - brxnet: [192.168.0.0/16]
36 Example that uses both ``kclient` and ``ceph-fuse``::
40 - ceph-fuse: [client.0]
45 Pass a dictionary instead of lists to specify per-client config:
54 :param config: Configuration
56 log
.info('Mounting kernel clients...')
59 ids
= misc
.all_roles_of_type(ctx
.cluster
, 'client')
60 client_roles
= [f
'client.{id_}' for id_
in ids
]
61 config
= dict([r
, dict()] for r
in client_roles
)
62 elif isinstance(config
, list):
64 config
= dict([r
, dict()] for r
in client_roles
)
65 elif isinstance(config
, dict):
66 client_roles
= filter(lambda x
: 'client.' in x
, config
.keys())
68 raise ValueError(f
"Invalid config object: {config} ({config.__class__})")
69 log
.info(f
"config is {config}")
71 clients
= list(misc
.get_clients(ctx
=ctx
, roles
=client_roles
))
73 test_dir
= misc
.get_testdir(ctx
)
75 for id_
, remote
in clients
:
76 KernelMount
.cleanup_stale_netnses_and_bridge(remote
)
79 overrides
= ctx
.config
.get('overrides', {}).get('kclient', {})
80 top_overrides
= dict(filter(lambda x
: 'client.' not in x
[0], overrides
.items()))
81 for id_
, remote
in clients
:
82 entity
= f
"client.{id_}"
83 client_config
= config
.get(entity
)
84 if client_config
is None:
87 deep_merge(client_config
, top_overrides
)
88 # mount specific overrides
89 client_config_overrides
= overrides
.get(entity
)
90 deep_merge(client_config
, client_config_overrides
)
91 log
.info(f
"{entity} config is {client_config}")
93 cephfs_name
= client_config
.get("cephfs_name")
94 if config
.get("disabled", False) or not client_config
.get('mounted', True):
97 kernel_mount
= KernelMount(
101 client_remote
=remote
,
102 brxnet
=ctx
.teuthology_config
.get('brxnet', None),
103 client_config
=client_config
,
104 cephfs_name
=cephfs_name
)
106 mounts
[id_
] = kernel_mount
108 if client_config
.get('debug', False):
109 remote
.run(args
=["sudo", "bash", "-c", "echo 'module ceph +p' > /sys/kernel/debug/dynamic_debug/control"])
110 remote
.run(args
=["sudo", "bash", "-c", "echo 'module libceph +p' > /sys/kernel/debug/dynamic_debug/control"])
112 kernel_mount
.mount(mntopts
=client_config
.get('mntopts', []))
115 log
.info('Unmounting kernel clients...')
118 for mount
in mounts
.values():
119 if mount
.is_mounted():
122 except (CommandFailedError
, MaxWhileTries
):
123 log
.warning("Ordinary umount failed, forcing...")
125 mount
.umount_wait(force
=True)
127 for id_
, remote
in clients
:
128 KernelMount
.cleanup_stale_netnses_and_bridge(remote
)
136 umount_all() # ignore forced retval, we are already in error handling
139 forced
= umount_all()
141 # The context managers within the kclient manager worked (i.e.
142 # the test workload passed) but for some reason we couldn't
143 # umount, so turn this into a test failure.
144 raise RuntimeError("Kernel mounts did not umount cleanly")