9 from teuthology import misc as teuthology
10 from teuthology.orchestra import run
11 from teuthology.orchestra.daemon import DaemonGroup
13 log = logging.getLogger(__name__)
16 def get_sambas(ctx, roles):
18 Scan for roles that are samba. Yield the id of the the samba role
19 (samba.0, samba.1...) and the associated remote site
22 :param roles: roles for this test (extracted from yaml files)
25 assert isinstance(role, basestring)
27 assert role.startswith(PREFIX)
28 id_ = role[len(PREFIX):]
29 (remote,) = ctx.cluster.only(role).remotes.iterkeys()
33 @contextlib.contextmanager
34 def task(ctx, config):
36 Setup samba smbd with ceph vfs module. This task assumes the samba
37 package has already been installed via the install task.
39 The config is optional and defaults to starting samba on all nodes.
40 If a config is given, it is expected to be a list of
41 samba nodes to start smbd servers on.
43 Example that starts smbd on all samba nodes::
49 extra_packages: ['samba']
54 Example that starts smbd on just one of the samba nodes and cifs on the other::
60 An optional backend can be specified, and requires a path which smbd will
61 use as the backend storage location:
64 - [osd.0, osd.1, osd.2, mon.0, mon.1, mon.2, mds.a]
69 - ceph-fuse: [client.0]
72 cephfuse: "{testdir}/mnt.0"
74 This mounts ceph to {testdir}/mnt.0 using fuse, and starts smbd with
75 a UNC of //localhost/cephfuse. Access through that UNC will be on
76 the ceph fuse mount point.
78 If no arguments are specified in the samba
79 role, the default behavior is to enable the ceph UNC //localhost/ceph
80 and use the ceph vfs module as the smbd backend.
83 :param config: Configuration
85 log.info("Setting up smbd with ceph vfs...")
86 assert config is None or isinstance(config, list) or isinstance(config, dict), \
87 "task samba got invalid config"
90 config = dict(('samba.{id}'.format(id=id_), None)
91 for id_ in teuthology.all_roles_of_type(ctx.cluster, 'samba'))
92 elif isinstance(config, list):
93 config = dict((name, None) for name in config)
95 samba_servers = list(get_sambas(ctx=ctx, roles=config.keys()))
97 testdir = teuthology.get_testdir(ctx)
99 if not hasattr(ctx, 'daemons'):
100 ctx.daemons = DaemonGroup()
102 for id_, remote in samba_servers:
104 rolestr = "samba.{id_}".format(id_=id_)
106 confextras = """vfs objects = ceph
107 ceph:config_file = /etc/ceph/ceph.conf"""
112 if config[rolestr] is not None:
113 # verify that there's just one parameter in role
114 if len(config[rolestr]) != 1:
115 log.error("samba config for role samba.{id_} must have only one parameter".format(id_=id_))
116 raise Exception('invalid config')
118 (unc, backendstr) = config[rolestr].items()[0]
119 backend = backendstr.format(testdir=testdir)
121 # on first samba role, set ownership and permissions of ceph root
122 # so that samba tests succeed
123 if config[rolestr] is None and id_ == samba_servers[0][0]:
126 'mkdir', '-p', '/tmp/cmnt', run.Raw('&&'),
127 'sudo', 'ceph-fuse', '/tmp/cmnt', run.Raw('&&'),
128 'sudo', 'chown', 'ubuntu:ubuntu', '/tmp/cmnt/', run.Raw('&&'),
129 'sudo', 'chmod', '1777', '/tmp/cmnt/', run.Raw('&&'),
130 'sudo', 'umount', '/tmp/cmnt/', run.Raw('&&'),
131 'rm', '-rf', '/tmp/cmnt',
137 'sudo', 'chown', 'ubuntu:ubuntu', backend, run.Raw('&&'),
138 'sudo', 'chmod', '1777', backend,
142 teuthology.sudo_write_file(remote, "/usr/local/samba/etc/smb.conf", """
144 workgroup = WORKGROUP
145 netbios name = DOMAIN
152 """.format(extras=confextras, unc=unc, backend=backend))
157 'sudo', '/usr/local/samba/bin/smbpasswd', '-e', 'ubuntu',
159 'printf', run.Raw('"ubuntu\nubuntu\n"'),
161 'sudo', '/usr/local/samba/bin/smbpasswd', '-s', '-a', 'ubuntu'
169 '/usr/local/samba/sbin/smbd',
172 ctx.daemons.add_daemon(remote, 'smbd', id_,
174 logger=log.getChild("smbd.{id_}".format(id_=id_)),
179 # let smbd initialize, probably a better way...
180 seconds_to_sleep = 100
181 log.info('Sleeping for %s seconds...' % seconds_to_sleep)
182 time.sleep(seconds_to_sleep)
183 log.info('Sleeping stopped...')
188 log.info('Stopping smbd processes...')
189 exc_info = (None, None, None)
190 for d in ctx.daemons.iter_daemons_of_role('smbd'):
193 except (run.CommandFailedError,
194 run.CommandCrashedError,
195 run.ConnectionLostError):
196 exc_info = sys.exc_info()
197 log.exception('Saw exception from %s.%s', d.role, d.id_)
198 if exc_info != (None, None, None):
199 raise exc_info[0], exc_info[1], exc_info[2]
201 for id_, remote in samba_servers:
206 '/usr/local/samba/etc/smb.conf',
207 '/usr/local/samba/private/*',
208 '/usr/local/samba/var/run/',
209 '/usr/local/samba/var/locks',
210 '/usr/local/samba/var/lock',
213 # make sure daemons are gone
218 'sudo', 'killall', '-9', 'smbd',
244 log.exception("Saw exception")