]>
git.proxmox.com Git - ceph.git/blob - ceph/qa/tasks/samba.py
8 from teuthology
import misc
as teuthology
9 from teuthology
.orchestra
import run
10 from teuthology
.orchestra
.daemon
import DaemonGroup
12 log
= logging
.getLogger(__name__
)
15 def get_sambas(ctx
, roles
):
17 Scan for roles that are samba. Yield the id of the the samba role
18 (samba.0, samba.1...) and the associated remote site
21 :param roles: roles for this test (extracted from yaml files)
24 assert isinstance(role
, str)
26 assert role
.startswith(PREFIX
)
27 id_
= role
[len(PREFIX
):]
28 (remote
,) = ctx
.cluster
.only(role
).remotes
.keys()
32 @contextlib.contextmanager
33 def task(ctx
, config
):
35 Setup samba smbd with ceph vfs module. This task assumes the samba
36 package has already been installed via the install task.
38 The config is optional and defaults to starting samba on all nodes.
39 If a config is given, it is expected to be a list of
40 samba nodes to start smbd servers on.
42 Example that starts smbd on all samba nodes::
48 extra_packages: ['samba']
53 Example that starts smbd on just one of the samba nodes and cifs on the other::
59 An optional backend can be specified, and requires a path which smbd will
60 use as the backend storage location:
63 - [osd.0, osd.1, osd.2, mon.0, mon.1, mon.2, mds.a]
68 - ceph-fuse: [client.0]
71 cephfuse: "{testdir}/mnt.0"
73 This mounts ceph to {testdir}/mnt.0 using fuse, and starts smbd with
74 a UNC of //localhost/cephfuse. Access through that UNC will be on
75 the ceph fuse mount point.
77 If no arguments are specified in the samba
78 role, the default behavior is to enable the ceph UNC //localhost/ceph
79 and use the ceph vfs module as the smbd backend.
82 :param config: Configuration
84 log
.info("Setting up smbd with ceph vfs...")
85 assert config
is None or isinstance(config
, list) or isinstance(config
, dict), \
86 "task samba got invalid config"
89 config
= dict(('samba.{id}'.format(id=id_
), None)
90 for id_
in teuthology
.all_roles_of_type(ctx
.cluster
, 'samba'))
91 elif isinstance(config
, list):
92 config
= dict((name
, None) for name
in config
)
94 samba_servers
= list(get_sambas(ctx
=ctx
, roles
=config
.keys()))
96 testdir
= teuthology
.get_testdir(ctx
)
98 if not hasattr(ctx
, 'daemons'):
99 ctx
.daemons
= DaemonGroup()
101 for id_
, remote
in samba_servers
:
103 rolestr
= "samba.{id_}".format(id_
=id_
)
105 confextras
= """vfs objects = ceph
106 ceph:config_file = /etc/ceph/ceph.conf"""
111 if config
[rolestr
] is not None:
112 # verify that there's just one parameter in role
113 if len(config
[rolestr
]) != 1:
114 log
.error("samba config for role samba.{id_} must have only one parameter".format(id_
=id_
))
115 raise Exception('invalid config')
117 (unc
, backendstr
) = config
[rolestr
].items()[0]
118 backend
= backendstr
.format(testdir
=testdir
)
120 # on first samba role, set ownership and permissions of ceph root
121 # so that samba tests succeed
122 if config
[rolestr
] is None and id_
== samba_servers
[0][0]:
125 'mkdir', '-p', '/tmp/cmnt', run
.Raw('&&'),
126 'sudo', 'ceph-fuse', '/tmp/cmnt', run
.Raw('&&'),
127 'sudo', 'chown', 'ubuntu:ubuntu', '/tmp/cmnt/', run
.Raw('&&'),
128 'sudo', 'chmod', '1777', '/tmp/cmnt/', run
.Raw('&&'),
129 'sudo', 'umount', '/tmp/cmnt/', run
.Raw('&&'),
130 'rm', '-rf', '/tmp/cmnt',
136 'sudo', 'chown', 'ubuntu:ubuntu', backend
, run
.Raw('&&'),
137 'sudo', 'chmod', '1777', backend
,
141 remote
.sudo_write_file("/usr/local/samba/etc/smb.conf", """
143 workgroup = WORKGROUP
144 netbios name = DOMAIN
151 """.format(extras
=confextras
, unc
=unc
, backend
=backend
))
156 'sudo', '/usr/local/samba/bin/smbpasswd', '-e', 'ubuntu',
158 'printf', run
.Raw('"ubuntu\nubuntu\n"'),
160 'sudo', '/usr/local/samba/bin/smbpasswd', '-s', '-a', 'ubuntu'
168 '/usr/local/samba/sbin/smbd',
171 ctx
.daemons
.add_daemon(remote
, 'smbd', id_
,
173 logger
=log
.getChild("smbd.{id_}".format(id_
=id_
)),
178 # let smbd initialize, probably a better way...
179 seconds_to_sleep
= 100
180 log
.info('Sleeping for %s seconds...' % seconds_to_sleep
)
181 time
.sleep(seconds_to_sleep
)
182 log
.info('Sleeping stopped...')
187 log
.info('Stopping smbd processes...')
189 for d
in ctx
.daemons
.iter_daemons_of_role('smbd'):
192 except (run
.CommandFailedError
,
193 run
.CommandCrashedError
,
194 run
.ConnectionLostError
) as e
:
196 log
.exception('Saw exception from %s.%s', d
.role
, d
.id_
)
200 for id_
, remote
in samba_servers
:
205 '/usr/local/samba/etc/smb.conf',
206 '/usr/local/samba/private/*',
207 '/usr/local/samba/var/run/',
208 '/usr/local/samba/var/locks',
209 '/usr/local/samba/var/lock',
212 # make sure daemons are gone
217 'sudo', 'killall', '-9', 'smbd',
243 log
.exception("Saw exception")