]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/tgt.py
import 15.2.0 Octopus source
[ceph.git] / ceph / qa / tasks / tgt.py
CommitLineData
7c673cae
FG
1"""
2Task to handle tgt
3
4Assumptions made:
5 The ceph-extras tgt package may need to get installed.
6 The open-iscsi package needs to get installed.
7"""
8import logging
9import contextlib
10
11from teuthology import misc as teuthology
12from teuthology import contextutil
13
14log = logging.getLogger(__name__)
15
16
17@contextlib.contextmanager
18def start_tgt_remotes(ctx, start_tgtd):
19 """
20 This subtask starts up a tgtd on the clients specified
21 """
22 remotes = ctx.cluster.only(teuthology.is_type('client')).remotes
23 tgtd_list = []
9f95a23c 24 for rem, roles in remotes.items():
7c673cae
FG
25 for _id in roles:
26 if _id in start_tgtd:
27 if not rem in tgtd_list:
28 tgtd_list.append(rem)
29 size = ctx.config.get('image_size', 10240)
30 rem.run(
31 args=[
32 'rbd',
33 'create',
34 'iscsi-image',
35 '--size',
36 str(size),
37 ])
38 rem.run(
39 args=[
40 'sudo',
41 'tgtadm',
42 '--lld',
43 'iscsi',
44 '--mode',
45 'target',
46 '--op',
47 'new',
48 '--tid',
49 '1',
50 '--targetname',
51 'rbd',
52 ])
53 rem.run(
54 args=[
55 'sudo',
56 'tgtadm',
57 '--lld',
58 'iscsi',
59 '--mode',
60 'logicalunit',
61 '--op',
62 'new',
63 '--tid',
64 '1',
65 '--lun',
66 '1',
67 '--backing-store',
68 'iscsi-image',
69 '--bstype',
70 'rbd',
71 ])
72 rem.run(
73 args=[
74 'sudo',
75 'tgtadm',
76 '--lld',
77 'iscsi',
78 '--op',
79 'bind',
80 '--mode',
81 'target',
82 '--tid',
83 '1',
84 '-I',
85 'ALL',
86 ])
87 try:
88 yield
89
90 finally:
91 for rem in tgtd_list:
92 rem.run(
93 args=[
94 'sudo',
95 'tgtadm',
96 '--lld',
97 'iscsi',
98 '--mode',
99 'target',
100 '--op',
101 'delete',
102 '--force',
103 '--tid',
104 '1',
105 ])
106 rem.run(
107 args=[
108 'rbd',
109 'snap',
110 'purge',
111 'iscsi-image',
112 ])
113 rem.run(
114 args=[
115 'sudo',
116 'rbd',
117 'rm',
118 'iscsi-image',
119 ])
120
121
122@contextlib.contextmanager
123def task(ctx, config):
124 """
125 Start up tgt.
126
127 To start on on all clients::
128
129 tasks:
130 - ceph:
131 - tgt:
132
133 To start on certain clients::
134
135 tasks:
136 - ceph:
137 - tgt: [client.0, client.3]
138
139 or
140
141 tasks:
142 - ceph:
143 - tgt:
144 client.0:
145 client.3:
146
147 An image blocksize size can also be specified::
148
149 tasks:
150 - ceph:
151 - tgt:
152 image_size = 20480
153
154 The general flow of things here is:
155 1. Find clients on which tgt is supposed to run (start_tgtd)
156 2. Remotely start up tgt daemon
157 On cleanup:
158 3. Stop tgt daemon
159
160 The iscsi administration is handled by the iscsi task.
161 """
162 if config:
163 config = {key : val for key, val in config.items()
164 if key.startswith('client')}
165 # config at this point should only contain keys starting with 'client'
166 start_tgtd = []
167 remotes = ctx.cluster.only(teuthology.is_type('client')).remotes
168 log.info(remotes)
169 if not config:
170 start_tgtd = ['client.{id}'.format(id=id_)
171 for id_ in teuthology.all_roles_of_type(ctx.cluster, 'client')]
172 else:
173 start_tgtd = config
174 log.info(start_tgtd)
175 with contextutil.nested(
176 lambda: start_tgt_remotes(ctx=ctx, start_tgtd=start_tgtd),):
177 yield