libzypp 17.38.14
TestcaseSetup.cc
Go to the documentation of this file.
1#include "TestcaseSetupImpl.h"
2
3#include <zypp/ZYpp.h>
4#include <zypp/ZYppFactory.h>
5#include <zypp/Resolver.h>
6#include <zypp/ResPool.h>
7#include <zypp/VendorAttr.h>
10
12{
13
14 // ─── Helpers (migrated verbatim from deptestomatic, refactor in second pass) ─
15 namespace {
16
17 struct FindPackage
18 {
19 PoolItem poolItem;
21 bool edition_set;
22 Edition edition;
23 bool arch_set;
24 Arch arch;
25
26 FindPackage( Resolvable::Kind k, const std::string & v,
27 const std::string & r, const std::string & a )
28 : kind( k )
29 , edition_set( !v.empty() )
30 , edition( v, r )
31 , arch_set( !a.empty() )
32 , arch( a )
33 {}
34
35 void _remember( PoolItem p ) { poolItem = p; }
36
37 bool operator()( PoolItem p )
38 {
39 if ( arch_set && arch != p->arch() )
40 return true;
41 if ( !p->arch().compatibleWith( ZConfig::instance().systemArchitecture() ) )
42 return true;
43 if ( edition_set && p->edition().match( edition ) != 0 )
44 return true;
45 if ( !poolItem
46 || poolItem->arch().compare( p->arch() ) < 0
47 || poolItem->edition().compare( p->edition() ) < 0 )
48 _remember( p );
49 return true;
50 }
51 };
52
53 static PoolItem get_poolItem( const std::string & source_alias,
54 const std::string & package_name,
55 const std::string & kind_name = "",
56 const std::string & ver = "",
57 const std::string & rel = "",
58 const std::string & arch = "" )
59 {
60 PoolItem poolItem;
61 ResPool pool = ResPool::instance();
64
65 try {
66 FindPackage info( kind, ver, rel, arch );
67
68 invokeOnEach( pool.byIdentBegin( kind, package_name ),
69 pool.byIdentEnd ( kind, package_name ),
70 resfilter::ByRepository( source_alias ),
71 std::ref( info ) );
72
73 poolItem = info.poolItem;
74 if ( !poolItem ) {
75 // Try all channels — useful for language packages.
76 invokeOnEach( pool.byIdentBegin( kind, package_name ),
77 pool.byIdentEnd ( kind, package_name ),
78 std::ref( info ) );
79 poolItem = info.poolItem;
80 }
81 }
82 catch ( const Exception & e ) {
83 ZYPP_CAUGHT( e );
84 WAR << "Can't find kind[" << kind_name << "]:'" << package_name
85 << "': source '" << source_alias << "' not defined" << std::endl;
86 }
87
88 if ( !poolItem )
89 WAR << "Can't find kind: " << kind << ":'" << package_name
90 << "' in source '" << source_alias << "': no such name/kind" << std::endl;
91
92 return poolItem;
93 }
94
95 void applyLockEntry(const TestcaseSetup::LockEntry &entry, ResPool &pool )
96 {
97 const bool isKeep = ( entry.first == "keep" );
98 const auto & props = entry.second;
99
100 auto getProp = [&]( const std::string & k ) -> std::string {
101 auto it = props.find(k);
102 return it != props.end() ? it->second : std::string();
103 };
104
105 if ( !isKeep ) {
106 std::string source_alias = getProp ("channel");
107 std::string package_name = getProp ("name");
108 if (package_name.empty())
109 package_name = getProp ("package");
110 std::string kind_name = getProp ("kind");
111 std::string version = getProp ("version");
112 if ( version.empty() )
113 version = getProp ("ver");
114 std::string release = getProp ("release");
115 if ( release.empty() )
116 release = getProp ("rel");
117 std::string architecture = getProp ("arch");
118
119 if ( version.empty() )
120 {
121 if ( kind_name.empty() )
122 kind_name = "package";
123 ui::Selectable::Ptr item = ui::Selectable::get( ResKind(kind_name), package_name );
124 if ( item )
125 {
126 // first set to protected, then to taboo so we run through both logic paths
127 // to make sure that if there is a installed object the candidates are also locked
128 item->setStatus( item->hasInstalledObj() ? ui::S_Protected : ui::S_Taboo );
129 item->setStatus( ui::S_Taboo );
130 }
131 else
132 {
133 WAR << "Unknown Selectable " << kind_name << ":" << package_name << std::endl;
134 }
135 }
136 else
137 {
138 PoolItem poolItem;
139 poolItem = get_poolItem (source_alias, package_name, kind_name, version, release, architecture );
140 if (poolItem) {
141 MIL << "Locking " << package_name << " from channel " << source_alias << poolItem << std::endl;
142 poolItem.status().setLock (true, ResStatus::USER);
143 } else {
144 WAR << "Unknown package " << source_alias << "::" << package_name << std::endl;
145 }
146 }
147
148 } else {
149
150 std::string kind_name = getProp ("kind");
151 std::string name = getProp ("name");
152 if (name.empty())
153 name = getProp ("package");
154
155 std::string source_alias = getProp ("channel");
156 if (source_alias.empty())
157 source_alias = "@System";
158
159 if (name.empty())
160 {
161 WAR << "transact need 'name' parameter" << std::endl;
162 return;
163 }
164
165 PoolItem poolItem;
166
167 poolItem = get_poolItem( source_alias, name, kind_name, getProp ("version"), getProp ("release") );
168
169 if (poolItem) {
170 // first: set anything
171 if (source_alias == "@System") {
172 poolItem.status().setToBeUninstalled( ResStatus::USER );
173 }
174 else {
175 poolItem.status().setToBeInstalled( ResStatus::USER );
176 }
177 // second: keep old state
178 poolItem.status().setTransact( false, ResStatus::USER );
179 }
180 else {
181 WAR << "Unknown item " << source_alias << "::" << name << std::endl;
182 }
183 }
184 }
185 }
186
187 // ─────────────────────────────────────────────────────────────────────────────
188
191
194
197
199 { return _pimpl->type; }
200
201 const std::string &RepoData::alias() const
202 { return _pimpl->alias; }
203
205 { return _pimpl->priority; }
206
207 const std::string &RepoData::path() const
208 { return _pimpl->path; }
209
211 { return *_pimpl; }
212
214 { return *_pimpl; }
215
218
221
224
226 { return *_pimpl; }
227
230
231 const std::string &ForceInstall::channel() const
232 { return _pimpl->channel; }
233
234 const std::string &ForceInstall::package() const
235 { return _pimpl->package; }
236
237 const std::string &ForceInstall::kind() const
238 { return _pimpl->kind; }
239
242
245
247 { return _pimpl->architecture; }
248
249 const std::optional<RepoData> &TestcaseSetup::systemRepo() const
250 { return _pimpl->systemRepo; }
251
252 const std::vector<RepoData> &TestcaseSetup::repos() const
253 { return _pimpl->repos; }
254
256 { return _pimpl->resolverFocus; }
257
259 { return _pimpl->globalPath; }
260
262 { return _pimpl->hardwareInfoFile; }
263
265 { return _pimpl->systemCheck; }
266
268 { return _pimpl->modaliasList; }
269
271 { return _pimpl->localesTracker; }
272
273 const std::vector<std::vector<std::string> > &TestcaseSetup::vendorLists() const
274 { return _pimpl->vendorLists; }
275
277 { return _pimpl->autoinstalled; }
278
279 const std::set<std::string> &TestcaseSetup::multiversionSpec() const
280 { return _pimpl->multiversionSpec; }
281
282 const std::vector<ForceInstall> &TestcaseSetup::forceInstallTasks() const
283 { return _pimpl->forceInstallTasks; }
284
285 const std::vector<TestcaseSetup::LockEntry> &TestcaseSetup::locks() const
286 { return _pimpl->locks; }
287
289 { return _pimpl->set_licence; }
290
292 { return _pimpl->show_mediaid; }
293
295 { return _pimpl->ignorealreadyrecommended; }
296
298 { return _pimpl->onlyRequires; }
299
301 { return _pimpl->forceResolve; }
302
304 { return _pimpl->cleandepsOnRemove; }
305
307 { return _pimpl->noUpdateProvide; }
308
310 { return _pimpl->allowDowngrade; }
311
313 { return _pimpl->allowNameChange; }
314
316 { return _pimpl->allowArchChange; }
317
319 { return _pimpl->allowVendorChange; }
320
322 { return _pimpl->dupAllowDowngrade; }
323
325 { return _pimpl->dupAllowNameChange; }
326
328 { return _pimpl->dupAllowArchChange; }
329
331 { return _pimpl->dupAllowVendorChange; }
332
334 {
335 const auto &setup = data();
336 if ( !setup.architecture.empty() )
337 {
338 MIL << "Setting architecture to '" << setup.architecture << "'" << std::endl;
339 ZConfig::instance().setSystemArchitecture( setup.architecture );
340 setenv ("ZYPP_TESTSUITE_FAKE_ARCH", setup.architecture.c_str(), 1);
341 }
342
343 if ( setup.systemRepo ) {
344 if (!loadRepo( manager, *this, *setup.systemRepo ) )
345 {
346 ERR << "Can't setup 'system'" << std::endl;
347 return false;
348 }
349 }
350
351 if ( !setup.hardwareInfoFile.empty() ) {
352 setenv( "ZYPP_MODALIAS_SYSFS", setup.hardwareInfoFile.asString().c_str(), 1 );
353 MIL << "setting HardwareInfo to: " << setup.hardwareInfoFile.asString() << std::endl;
354 }
355
356 for ( const auto &channel : setup.repos ) {
357 if ( !loadRepo( manager, *this, channel ) )
358 {
359 ERR << "Can't setup 'channel'" << std::endl;
360 return false;
361 }
362 }
363
364 if ( !setup.systemCheck.empty() ) {
365 MIL << "setting systemCheck to: " << setup.systemCheck.asString() << std::endl;
366 SystemCheck::instance().setFile( setup.systemCheck );
367 }
368
369 return true;
370 }
371
373 {
374 const auto &repoData = data.data();
375 Pathname pathname = setup._pimpl->globalPath + repoData.path;
376 MIL << "'" << pathname << "'" << std::endl;
377
379
381
382 if ( repoData.type == TrType::Url ) {
383 try {
384 MIL << "Load from Url '" << repoData.path << "'" << std::endl;
385
386 RepoInfo nrepo;
387 nrepo.setAlias ( repoData.alias );
388 nrepo.setName ( repoData.alias );
389 nrepo.setEnabled ( true );
390 nrepo.setAutorefresh( false );
391 nrepo.setPriority ( repoData.priority );
392 nrepo.addBaseUrl ( Url(repoData.path) );
393
394 manager.refreshMetadata( nrepo );
395 manager.buildCache( nrepo );
396 manager.loadFromCache( nrepo );
397 }
398 catch ( Exception & excpt_r ) {
399 ZYPP_CAUGHT (excpt_r);
400 ERR << "Couldn't load packages from Url '" << repoData.path << "'" << std::endl;
401 return false;
402 }
403 }
404 else {
405 try {
406 MIL << "Load from File '" << pathname << "'" << std::endl;
407 zypp::Repository satRepo;
408
409 if ( repoData.alias == "@System" ) {
411 } else {
412 satRepo = zypp::sat::Pool::instance().reposInsert( repoData.alias );
413 }
414
415 RepoInfo nrepo;
416
417 nrepo.setAlias ( repoData.alias );
418 nrepo.setName ( repoData.alias );
419 nrepo.setEnabled ( true );
420 nrepo.setAutorefresh( false );
421 nrepo.setPriority ( repoData.priority );
422 nrepo.addBaseUrl ( pathname.asUrl() );
423
424 satRepo.setInfo (nrepo);
425 if ( repoData.type == TrType::Helix )
426 satRepo.addHelix( pathname );
427 else
428 satRepo.addTesttags( pathname );
429 MIL << "Loaded " << satRepo.solvablesSize() << " resolvables from " << ( repoData.path.empty()?pathname.asString():repoData.path) << "." << std::endl;
430 }
431 catch ( Exception & excpt_r ) {
432 ZYPP_CAUGHT (excpt_r);
433 ERR << "Couldn't load packages from XML file '" << repoData.path << "'" << std::endl;
434 return false;
435 }
436 }
437 return true;
438 }
439
441 {
442 return *_pimpl;
443 }
444
446 {
447 return *_pimpl;
448 }
449
450 bool TestcaseSetup::applySetup( zypp::RepoManager &manager, ApplySetupFlags flags_r ) const
451 {
452 // Repos/arch/hardware are always applied via the existing overload.
453 if ( !applySetup( manager ) )
454 return false;
455
456 if ( flags_r.testFlag( AS_LOCALES ) )
457 {
459 lt.removed().insert( lt.current().begin(), lt.current().end() );
461 lt.added().insert( lt.current().begin(), lt.current().end() );
463 }
464
465 if ( flags_r.testFlag( AS_AUTOINSTALLED ) )
466 {
468 }
469
470 if ( flags_r.testFlag( AS_VENDOR_LISTS ) )
471 {
472 for ( const auto & vlist : vendorLists() )
474 }
475
476 if ( flags_r.testFlag( AS_MODALIAS ) )
477 {
479 }
480
481 if ( flags_r.testFlag( AS_MULTIVERSION ) )
482 {
484 }
485
486 if ( flags_r.testFlag( AS_LOCKS ) )
487 {
489 for ( const auto & entry : locks() )
490 applyLockEntry( entry, pool );
491 }
492
493 if ( flags_r.testFlag( AS_SOLVER_FLAGS ) )
494 {
495 Resolver_Ptr resolver = getZYpp()->resolver();
496 resolver->setFocus ( resolverFocus() );
497 resolver->setIgnoreAlreadyRecommended( ignorealreadyrecommended() );
498 resolver->setOnlyRequires ( onlyRequires() );
499 resolver->setForceResolve ( forceResolve() );
500 resolver->setCleandepsOnRemove ( cleandepsOnRemove() );
501 resolver->setAllowDowngrade ( allowDowngrade() );
502 resolver->setAllowNameChange ( allowNameChange() );
503 resolver->setAllowArchChange ( allowArchChange() );
504 resolver->setAllowVendorChange ( allowVendorChange() );
505 resolver->dupSetAllowDowngrade ( dupAllowDowngrade() );
506 resolver->dupSetAllowNameChange ( dupAllowNameChange() );
507 resolver->dupSetAllowArchChange ( dupAllowArchChange() );
508 resolver->dupSetAllowVendorChange ( dupAllowVendorChange() );
509 }
510
511 return true;
512 }
513}
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
#define MIL
Definition Logger.h:130
#define ERR
Definition Logger.h:132
#define WAR
Definition Logger.h:131
Architecture.
Definition Arch.h:37
Base class for Exception.
Definition Exception.h:153
What is known about a repository.
Definition RepoInfo.h:72
void addBaseUrl(Url url)
Add a base url.
Definition RepoInfo.cc:767
void setPriority(unsigned newval_r)
Set repository priority for solver.
Definition RepoInfo.cc:619
creates and provides information about known sources.
Definition RepoManager.h:60
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy=RefreshIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local raw cache.
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
void loadFromCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Load resolvables into the pool.
void addHelix(const Pathname &file_r)
Load Solvables from a helix-file.
void addTesttags(const Pathname &file_r)
Load Solvables from a libsolv testtags-file.
size_type solvablesSize() const
Number of solvables in Repository.
void setInfo(const RepoInfo &info_r)
Set RepoInfo for this repository.
static const ResKind nokind
Value representing nokind ("").
Definition ResKind.h:38
static const ResKind package
Definition ResKind.h:40
static ResKind fromBuiltin(const std::string &str)
Converts the string representation of a kind to its ResKind value or noKind if the passed string is n...
Definition ResKind.cc:68
Global ResObject pool.
Definition ResPool.h:62
static ResPool instance()
Singleton ctor.
Definition ResPool.cc:38
TraitsType::KindType Kind
Definition Resolvable.h:57
static VendorAttr & noTargetInstance()
Singleton, settings used if no Target is active.
void addVendorList(VendorList &&list_r)
Adding new equivalent vendor strings container.
Definition VendorAttr.h:105
Arch systemArchitecture() const
The system architecture zypp uses.
Definition ZConfig.cc:857
void setSystemArchitecture(const Arch &arch_r)
Override the zypp system architecture.
Definition ZConfig.cc:860
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:794
const std::set< std::string > & multiversionSpec() const
Definition ZConfig.cc:1141
Url asUrl(const std::string &scheme_r) const
Url representation using scheme_r schema .
Definition Pathname.cc:172
const std::string & asString() const
String representation.
Definition Pathname.h:94
RWCOW_pointer< ForceInstallImpl > _pimpl
const std::string & package() const
const std::string & kind() const
const std::string & channel() const
const ForceInstallImpl & data() const
const RepoDataImpl & data() const
TestcaseRepoType type() const
RWCOW_pointer< RepoDataImpl > _pimpl
const std::string & path() const
const std::string & alias() const
const std::vector< RepoData > & repos() const
bool applySetup(zypp::RepoManager &manager) const
const target::Modalias::ModaliasList & modaliasList() const
const std::vector< ForceInstall > & forceInstallTasks() const
const std::optional< RepoData > & systemRepo() const
const std::vector< std::vector< std::string > > & vendorLists() const
const std::set< std::string > & multiversionSpec() const
RWCOW_pointer< TestcaseSetupImpl > _pimpl
const sat::StringQueue & autoinstalled() const
static bool loadRepo(zypp::RepoManager &manager, const TestcaseSetup &setup, const RepoData &data)
const Pathname & systemCheck() const
std::pair< std::string, std::map< std::string, std::string > > LockEntry
lock/keep node data extracted from trial nodes and applied as pool setup.
const Pathname & globalPath() const
const Pathname & hardwareInfoFile() const
const base::SetTracker< LocaleSet > & localesTracker() const
const std::vector< LockEntry > & locks() const
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
void setAlias(const std::string &alias)
set the repository alias
void setName(const std::string &name)
set the repository name
void setEnabled(bool enabled)
enable or disable the repository
void setAutoInstalled(const Queue &autoInstalled_r)
Set ident list of all autoinstalled solvables.
Definition Pool.cc:265
static Pool instance()
Singleton ctor.
Definition Pool.h:55
Repository reposInsert(const std::string &alias_r)
Return a Repository named alias_r.
Definition Pool.cc:143
void setRequestedLocales(const LocaleSet &locales_r)
Set the requested locales.
Definition Pool.cc:236
Repository systemRepo()
Return the system repository, create it if missing.
Definition Pool.cc:178
void initRequestedLocales(const LocaleSet &locales_r)
Start tracking changes based on this locales_r.
Definition Pool.cc:251
std::vector< std::string > ModaliasList
Definition Modalias.h:45
static Modalias & instance()
Singleton access.
Definition Modalias.cc:223
const ModaliasList & modaliasList() const
List of modaliases found on system.
Definition Modalias.cc:232
static Ptr get(const pool::ByIdent &ident_r)
Get the Selctable.
Definition Selectable.cc:29
intrusive_ptr< Selectable > Ptr
Definition Selectable.h:58
unsigned short a
Definition ansi.h:855
@ Edition
Editions with v-r setparator highlighted.
Definition Table.h:160
@ AS_VENDOR_LISTS
VendorAttr vendor-equivalence lists.
@ AS_AUTOINSTALLED
setAutoInstalled
@ AS_SOLVER_FLAGS
Resolver flags, focus, DUP flags.
@ AS_MODALIAS
Modalias list.
@ AS_LOCKS
lock/keep nodes extracted from trial nodes
@ AS_MULTIVERSION
ZConfig multiversion spec.
@ AS_LOCALES
initRequestedLocales + setRequestedLocales
bool empty() const
Whether neither idents nor provides are set.
Queue StringQueue
Queue with String ids.
Definition Queue.h:28
@ S_Taboo
Definition Status.h:38
@ S_Protected
Definition Status.h:37
ResolverFocus
The resolver's general attitude.
ZYpp::Ptr getZYpp()
relates: ZYppFactory Convenience to get the Pointer to the ZYpp instance.
Definition ZYppFactory.h:77
const ResKind ResTraits< Package >::kind(ResKind::package)
int invokeOnEach(TIterator begin_r, TIterator end_r, TFilter filter_r, TFunction fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
Definition Algorithm.h:30
Track added/removed set items based on an initial set.
Definition SetTracker.h:39
const set_type & current() const
Return the current set.
Definition SetTracker.h:140
const set_type & added() const
Return the set of added items.
Definition SetTracker.h:143
const set_type & removed() const
Return the set of removed items.
Definition SetTracker.h:146