1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 from spacewalk.common.rhnLog import log_debug
22 from spacewalk.server import rhnSQL, rhnCapability
23 from spacewalk.server.rhnLib import InvalidAction
24
25
26 __rhnexport__ = ['update',
27 'remove',
28 'refresh_list',
29 'runTransaction',
30 'verify']
31
32 _query_action_verify_packages = rhnSQL.Statement("""
33 select distinct
34 pn.name as name,
35 pe.version as version,
36 pe.release as release,
37 pe.epoch as epoch,
38 pa.label as arch
39 from rhnActionPackage ap
40 left join rhnPackageArch pa
41 on ap.package_arch_id = pa.id,
42 rhnPackageName pn,
43 rhnPackageEVR pe
44 where ap.action_id = :actionid
45 and ap.evr_id = pe.id
46 and ap.name_id = pn.id
47 """)
48
49
50 -def verify(serverId, actionId, dry_run=0):
71
72
74 log_debug(3, serverId, actionId, dry_run)
75
76 client_caps = rhnCapability.get_client_capabilities()
77 log_debug(3, "Client Capabilities", client_caps)
78 multiarch = 0
79 if client_caps and 'packages.update' in client_caps:
80 cap_info = client_caps['packages.update']
81 if cap_info['version'] > 1:
82 multiarch = 1
83 if not packagesIn:
84 raise InvalidAction("Packages scheduled in action %s for server %s could not be found." %
85 (actionId, serverId))
86
87 packages = []
88 for package in packagesIn:
89
90 if package['epoch'] is None:
91 package['epoch'] = ""
92 pkg_arch = ''
93 if multiarch:
94 pkg_arch = package['arch'] or ''
95
96 packages.append([package['name'],
97 package['version'] or '',
98 package['release'] or '',
99 package['epoch'],
100 pkg_arch])
101
102 log_debug(4, packages)
103 return packages
104
105
106 -def remove(serverId, actionId, dry_run=0):
111
112
113 -def update(serverId, actionId, dry_run=0):
118
119
121 """ Call the equivalent of up2date -p.
122
123 I.e. update the list of a client's installed packages known by
124 Red Hat's DB.
125 """
126 log_debug(3)
127 return None
128
129
131 log_debug(3, server_id, action_id, dry_run)
132
133
134 h = rhnSQL.prepare("""
135 select package_delta_id
136 from rhnActionPackageDelta
137 where action_id = :action_id
138 """)
139 h.execute(action_id=action_id)
140 row = h.fetchone_dict()
141 if row is None:
142 raise InvalidAction("invalid packages.runTransaction action %s for server %s" %
143 (action_id, server_id))
144
145 package_delta_id = row['package_delta_id']
146
147
148 h = rhnSQL.prepare("""
149 select tro.label as operation, pn.name, pe.version, pe.release, pe.epoch,
150 pa.label as package_arch
151 from rhnPackageDeltaElement pde,
152 rhnTransactionPackage rp
153 left join rhnPackageArch pa
154 on rp.package_arch_id = pa.id,
155 rhnTransactionOperation tro, rhnPackageName pn, rhnPackageEVR pe
156 where pde.package_delta_id = :package_delta_id
157 and pde.transaction_package_id = rp.id
158 and rp.operation = tro.id
159 and rp.name_id = pn.id
160 and rp.evr_id = pe.id
161 order by tro.label, pn.name
162 """)
163 h.execute(package_delta_id=package_delta_id)
164
165 result = []
166 while 1:
167 row = h.fetchone_dict()
168 if not row:
169 break
170
171 operation = row['operation']
172
173
174 if operation == 'insert':
175 operation = 'i'
176 elif operation == 'delete':
177 operation = 'e'
178 elif operation == 'upgrade':
179 operation = 'u'
180 else:
181
182 continue
183
184
185 epoch = row['epoch']
186 if epoch is None:
187 epoch = ''
188
189 name, version, release = row['name'], row['version'], row['release']
190
191 package_arch = row['package_arch'] or ""
192
193 result.append([
194 [name, version, release, epoch, package_arch],
195 operation
196 ])
197 return {'packages': result}
198
199
200 _packageStatement_update = """
201 select distinct
202 pn.name as name,
203 pe.epoch as epoch,
204 pe.version as version,
205 pe.release as release,
206 pa.label as arch
207 from rhnActionPackage ap
208 left join rhnPackageArch pa
209 on ap.package_arch_id = pa.id,
210 rhnPackage p,
211 rhnPackageName pn,
212 rhnPackageEVR pe,
213 rhnServerChannel sc,
214 rhnChannelPackage cp
215 where ap.action_id = :actionid
216 and ap.evr_id is not null
217 and ap.evr_id = p.evr_id
218 and ap.evr_id = pe.id
219 and ap.name_id = p.name_id
220 and (ap.package_arch_id = p.package_arch_id or ap.package_arch_id is null)
221 and ap.name_id = pn.id
222 and p.id = cp.package_id
223 and cp.channel_id = sc.channel_id
224 and sc.server_id = :serverid
225 union
226 select distinct
227 pn.name as name,
228 null as version,
229 null as release,
230 null as epoch,
231 pa.label as arch
232 from rhnActionPackage ap
233 left join rhnPackageArch pa
234 on ap.package_arch_id = pa.id,
235 rhnPackage p,
236 rhnPackageName pn,
237 rhnServerChannel sc,
238 rhnChannelPackage cp
239 where ap.action_id = :actionid
240 and ap.evr_id is null
241 and ap.name_id = p.name_id
242 and p.name_id = pn.id
243 and (ap.package_arch_id = p.package_arch_id or ap.package_arch_id is null)
244 and p.id = cp.package_id
245 and cp.channel_id = sc.channel_id
246 and sc.server_id = :serverid"""
247
248 _packageStatement_remove = """
249 select distinct
250 pn.name as name,
251 pe.epoch as epoch,
252 pe.version as version,
253 pe.release as release,
254 pa.label as arch
255 from rhnActionPackage ap
256 left join rhnPackageArch pa
257 on ap.package_arch_id = pa.id,
258 rhnPackageName pn,
259 rhnPackageEVR pe,
260 rhnServerPackage sp
261 where ap.action_id = :actionid
262 and ap.evr_id is not null
263 and ap.evr_id = pe.id
264 and ap.name_id = pn.id
265 and sp.server_id = :serverid
266 and sp.name_id = ap.name_id
267 and sp.evr_id = ap.evr_id
268 and (sp.package_arch_id = ap.package_arch_id or sp.package_arch_id is null)
269 union
270 select distinct
271 pn.name as name,
272 null as version,
273 null as release,
274 null as epoch,
275 pa.label as arch
276 from rhnActionPackage ap
277 left join rhnPackageArch pa
278 on ap.package_arch_id = pa.id,
279 rhnPackageName pn,
280 rhnServerPackage sp
281 where ap.action_id = :actionid
282 and ap.evr_id is null
283 and sp.server_id = :serverid
284 and (sp.package_arch_id = ap.package_arch_id or sp.package_arch_id is null)"""
285