libzypp 17.37.10

TestcaseSetup.cc
Go to the documentation of this file.
1#include "TestcaseSetupImpl.h"
2
3 namespace zypp::misc::testcase
4{
5 RepoData::RepoData() : _pimpl( new RepoDataImpl )
6 {}
7
8 RepoData::~RepoData()
9 { }
10
11 RepoData::RepoData(RepoDataImpl &&data) : _pimpl( new RepoDataImpl( std::move(data)) )
12 { }
13
14 TestcaseRepoType RepoData::type() const
15 { return _pimpl->type; }
16
17 const std::string &RepoData::alias() const
18 { return _pimpl->alias; }
19
20 uint RepoData::priority() const
21 { return _pimpl->priority; }
22
23 const std::string &RepoData::path() const
24 { return _pimpl->path; }
25
26 const RepoDataImpl &RepoData::data() const
27 { return *_pimpl; }
28
29 RepoDataImpl &RepoData::data()
30 { return *_pimpl; }
31
32 ForceInstall::ForceInstall() : _pimpl( new ForceInstallImpl )
33 { }
34
35 ForceInstall::~ForceInstall()
36 { }
37
38 ForceInstall::ForceInstall(ForceInstallImpl &&data) : _pimpl( new ForceInstallImpl( std::move(data) ))
39 { }
40
41 const ForceInstallImpl &ForceInstall::data() const
42 { return *_pimpl; }
43
44 ForceInstallImpl &ForceInstall::data()
45 { return *_pimpl; }
46
47 const std::string &ForceInstall::channel() const
48 { return _pimpl->channel; }
49
50 const std::string &ForceInstall::package() const
51 { return _pimpl->package; }
52
53 const std::string &ForceInstall::kind() const
54 { return _pimpl->kind; }
55
56 TestcaseSetup::TestcaseSetup() : _pimpl( new TestcaseSetupImpl )
57 { }
58
59 TestcaseSetup::~TestcaseSetup()
60 { }
61
62 Arch TestcaseSetup::architecture() const
63 { return _pimpl->architecture; }
64
65 const std::optional<RepoData> &TestcaseSetup::systemRepo() const
66 { return _pimpl->systemRepo; }
67
68 const std::vector<RepoData> &TestcaseSetup::repos() const
69 { return _pimpl->repos; }
70
71 ResolverFocus TestcaseSetup::resolverFocus() const
72 { return _pimpl->resolverFocus; }
73
74 const zypp::filesystem::Pathname &TestcaseSetup::globalPath() const
75 { return _pimpl->globalPath; }
76
77 const zypp::filesystem::Pathname &TestcaseSetup::hardwareInfoFile() const
78 { return _pimpl->hardwareInfoFile; }
79
80 const zypp::filesystem::Pathname &TestcaseSetup::systemCheck() const
81 { return _pimpl->systemCheck; }
82
83 const target::Modalias::ModaliasList &TestcaseSetup::modaliasList() const
84 { return _pimpl->modaliasList; }
85
86 const base::SetTracker<LocaleSet> &TestcaseSetup::localesTracker() const
87 { return _pimpl->localesTracker; }
88
89 const std::vector<std::vector<std::string> > &TestcaseSetup::vendorLists() const
90 { return _pimpl->vendorLists; }
91
92 const sat::StringQueue &TestcaseSetup::autoinstalled() const
93 { return _pimpl->autoinstalled; }
94
95 const std::set<std::string> &TestcaseSetup::multiversionSpec() const
96 { return _pimpl->multiversionSpec; }
97
98 const std::vector<ForceInstall> &TestcaseSetup::forceInstallTasks() const
99 { return _pimpl->forceInstallTasks; }
100
101 bool TestcaseSetup::set_licence() const
102 { return _pimpl->set_licence; }
103
104 bool TestcaseSetup::show_mediaid() const
105 { return _pimpl->show_mediaid; }
106
107 bool TestcaseSetup::ignorealreadyrecommended() const
108 { return _pimpl->ignorealreadyrecommended; }
109
110 bool TestcaseSetup::onlyRequires() const
111 { return _pimpl->onlyRequires; }
112
113 bool TestcaseSetup::forceResolve() const
114 { return _pimpl->forceResolve; }
115
116 bool TestcaseSetup::cleandepsOnRemove() const
117 { return _pimpl->cleandepsOnRemove; }
118
119 bool TestcaseSetup::allowDowngrade() const
120 { return _pimpl->allowDowngrade; }
121
122 bool TestcaseSetup::allowNameChange() const
123 { return _pimpl->allowNameChange; }
124
125 bool TestcaseSetup::allowArchChange() const
126 { return _pimpl->allowArchChange; }
127
128 bool TestcaseSetup::allowVendorChange() const
129 { return _pimpl->allowVendorChange; }
130
131 bool TestcaseSetup::dupAllowDowngrade() const
132 { return _pimpl->dupAllowDowngrade; }
133
134 bool TestcaseSetup::dupAllowNameChange() const
135 { return _pimpl->dupAllowNameChange; }
136
137 bool TestcaseSetup::dupAllowArchChange() const
138 { return _pimpl->dupAllowArchChange; }
139
140 bool TestcaseSetup::dupAllowVendorChange() const
141 { return _pimpl->dupAllowVendorChange; }
142
143 bool TestcaseSetup::applySetup( zypp::RepoManager &manager ) const
144 {
145 const auto &setup = data();
146 if ( !setup.architecture.empty() )
147 {
148 MIL << "Setting architecture to '" << setup.architecture << "'" << std::endl;
149 ZConfig::instance().setSystemArchitecture( setup.architecture );
150 setenv ("ZYPP_TESTSUITE_FAKE_ARCH", setup.architecture.c_str(), 1);
151 }
152
153 if ( setup.systemRepo ) {
154 if (!loadRepo( manager, *this, *setup.systemRepo ) )
155 {
156 ERR << "Can't setup 'system'" << std::endl;
157 return false;
158 }
159 }
160
161 if ( !setup.hardwareInfoFile.empty() ) {
162 setenv( "ZYPP_MODALIAS_SYSFS", setup.hardwareInfoFile.asString().c_str(), 1 );
163 MIL << "setting HardwareInfo to: " << setup.hardwareInfoFile.asString() << std::endl;
164 }
165
166 for ( const auto &channel : setup.repos ) {
167 if ( !loadRepo( manager, *this, channel ) )
168 {
169 ERR << "Can't setup 'channel'" << std::endl;
170 return false;
171 }
172 }
173
174 if ( !setup.systemCheck.empty() ) {
175 MIL << "setting systemCheck to: " << setup.systemCheck.asString() << std::endl;
176 SystemCheck::instance().setFile( setup.systemCheck );
177 }
178
179 return true;
180 }
181
182 bool TestcaseSetup::loadRepo( zypp::RepoManager &manager, const TestcaseSetup &setup, const RepoData &data )
183 {
184 const auto &repoData = data.data();
185 Pathname pathname = setup._pimpl->globalPath + repoData.path;
186 MIL << "'" << pathname << "'" << std::endl;
187
188 Repository repo;
189
190 using TrType = zypp::misc::testcase::TestcaseRepoType;
191
192 if ( repoData.type == TrType::Url ) {
193 try {
194 MIL << "Load from Url '" << repoData.path << "'" << std::endl;
195
196 RepoInfo nrepo;
197 nrepo.setAlias ( repoData.alias );
198 nrepo.setName ( repoData.alias );
199 nrepo.setEnabled ( true );
200 nrepo.setAutorefresh( false );
201 nrepo.setPriority ( repoData.priority );
202 nrepo.addBaseUrl ( Url(repoData.path) );
203
204 manager.refreshMetadata( nrepo );
205 manager.buildCache( nrepo );
206 manager.loadFromCache( nrepo );
207 }
208 catch ( Exception & excpt_r ) {
209 ZYPP_CAUGHT (excpt_r);
210 ERR << "Couldn't load packages from Url '" << repoData.path << "'" << std::endl;
211 return false;
212 }
213 }
214 else {
215 try {
216 MIL << "Load from File '" << pathname << "'" << std::endl;
217 zypp::Repository satRepo;
218
219 if ( repoData.alias == "@System" ) {
220 satRepo = zypp::sat::Pool::instance().systemRepo();
221 } else {
222 satRepo = zypp::sat::Pool::instance().reposInsert( repoData.alias );
223 }
224
225 RepoInfo nrepo;
226
227 nrepo.setAlias ( repoData.alias );
228 nrepo.setName ( repoData.alias );
229 nrepo.setEnabled ( true );
230 nrepo.setAutorefresh( false );
231 nrepo.setPriority ( repoData.priority );
232 nrepo.addBaseUrl ( pathname.asUrl() );
233
234 satRepo.setInfo (nrepo);
235 if ( repoData.type == TrType::Helix )
236 satRepo.addHelix( pathname );
237 else
238 satRepo.addTesttags( pathname );
239 MIL << "Loaded " << satRepo.solvablesSize() << " resolvables from " << ( repoData.path.empty()?pathname.asString():repoData.path) << "." << std::endl;
240 }
241 catch ( Exception & excpt_r ) {
242 ZYPP_CAUGHT (excpt_r);
243 ERR << "Couldn't load packages from XML file '" << repoData.path << "'" << std::endl;
244 return false;
245 }
246 }
247 return true;
248 }
249
250 TestcaseSetupImpl &TestcaseSetup::data()
251 {
252 return *_pimpl;
253 }
254
255 const TestcaseSetupImpl &TestcaseSetup::data() const
256 {
257 return *_pimpl;
258 }
259
260}
TestcaseSetupImpl.h
zypp::Arch
Architecture.
Definition Arch.h:37
zypp::Exception
Base class for Exception.
Definition Exception.h:153
zypp::RepoInfo
What is known about a repository.
Definition RepoInfo.h:72
zypp::RepoInfo::addBaseUrl
void addBaseUrl(Url url)
Add a base url.
Definition RepoInfo.cc:666
zypp::RepoInfo::setPriority
void setPriority(unsigned newval_r)
Set repository priority for solver.
Definition RepoInfo.cc:518
zypp::RepoManager
creates and provides information about known sources.
Definition RepoManager.h:59
zypp::RepoManager::refreshMetadata
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy=RefreshIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local raw cache.
Definition RepoManager.cc:140
zypp::RepoManager::buildCache
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
Definition RepoManager.cc:156
zypp::RepoManager::loadFromCache
void loadFromCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Load resolvables into the pool.
Definition RepoManager.cc:169
zypp::Repository
Definition Repository.h:40
zypp::Repository::addHelix
void addHelix(const Pathname &file_r)
Load Solvables from a helix-file.
Definition Repository.cc:340
zypp::Repository::addTesttags
void addTesttags(const Pathname &file_r)
Load Solvables from a libsolv testtags-file.
Definition Repository.cc:362
zypp::Repository::solvablesSize
size_type solvablesSize() const
Number of solvables in Repository.
Definition Repository.cc:226
zypp::Repository::setInfo
void setInfo(const RepoInfo &info_r)
Set RepoInfo for this repository.
Definition Repository.cc:280
zypp::ZConfig::setSystemArchitecture
void setSystemArchitecture(const Arch &arch_r)
Override the zypp system architecture.
Definition ZConfig.cc:1007
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:940
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::filesystem::Pathname::asUrl
Url asUrl(const std::string &scheme_r) const
Url representation using scheme_r schema .
Definition Pathname.cc:172
zypp::filesystem::Pathname::asString
const std::string & asString() const
String representation.
Definition Pathname.h:93
zypp::misc::testcase::ForceInstall::_pimpl
RWCOW_pointer< ForceInstallImpl > _pimpl
Definition TestcaseSetup.h:75
zypp::misc::testcase::ForceInstall::package
const std::string & package() const
Definition TestcaseSetup.cc:50
zypp::misc::testcase::ForceInstall::kind
const std::string & kind() const
Definition TestcaseSetup.cc:53
zypp::misc::testcase::ForceInstall::~ForceInstall
~ForceInstall()
Definition TestcaseSetup.cc:35
zypp::misc::testcase::ForceInstall::ForceInstall
ForceInstall()
Definition TestcaseSetup.cc:32
zypp::misc::testcase::ForceInstall::channel
const std::string & channel() const
Definition TestcaseSetup.cc:47
zypp::misc::testcase::ForceInstall::data
const ForceInstallImpl & data() const
Definition TestcaseSetup.cc:41
zypp::misc::testcase::RepoData
Definition TestcaseSetup.h:47
zypp::misc::testcase::RepoData::data
const RepoDataImpl & data() const
Definition TestcaseSetup.cc:26
zypp::misc::testcase::RepoData::~RepoData
~RepoData()
Definition TestcaseSetup.cc:8
zypp::misc::testcase::RepoData::type
TestcaseRepoType type() const
Definition TestcaseSetup.cc:14
zypp::misc::testcase::RepoData::priority
uint priority() const
Definition TestcaseSetup.cc:20
zypp::misc::testcase::RepoData::RepoData
RepoData()
Definition TestcaseSetup.cc:5
zypp::misc::testcase::RepoData::_pimpl
RWCOW_pointer< RepoDataImpl > _pimpl
Definition TestcaseSetup.h:60
zypp::misc::testcase::RepoData::path
const std::string & path() const
Definition TestcaseSetup.cc:23
zypp::misc::testcase::RepoData::alias
const std::string & alias() const
Definition TestcaseSetup.cc:17
zypp::misc::testcase::TestcaseSetup::architecture
Arch architecture() const
Definition TestcaseSetup.cc:62
zypp::misc::testcase::TestcaseSetup::repos
const std::vector< RepoData > & repos() const
Definition TestcaseSetup.cc:68
zypp::misc::testcase::TestcaseSetup::applySetup
bool applySetup(zypp::RepoManager &manager) const
Definition TestcaseSetup.cc:143
zypp::misc::testcase::TestcaseSetup::resolverFocus
ResolverFocus resolverFocus() const
Definition TestcaseSetup.cc:71
zypp::misc::testcase::TestcaseSetup::onlyRequires
bool onlyRequires() const
Definition TestcaseSetup.cc:110
zypp::misc::testcase::TestcaseSetup::modaliasList
const target::Modalias::ModaliasList & modaliasList() const
Definition TestcaseSetup.cc:83
zypp::misc::testcase::TestcaseSetup::forceInstallTasks
const std::vector< ForceInstall > & forceInstallTasks() const
Definition TestcaseSetup.cc:98
zypp::misc::testcase::TestcaseSetup::systemRepo
const std::optional< RepoData > & systemRepo() const
Definition TestcaseSetup.cc:65
zypp::misc::testcase::TestcaseSetup::vendorLists
const std::vector< std::vector< std::string > > & vendorLists() const
Definition TestcaseSetup.cc:89
zypp::misc::testcase::TestcaseSetup::multiversionSpec
const std::set< std::string > & multiversionSpec() const
Definition TestcaseSetup.cc:95
zypp::misc::testcase::TestcaseSetup::dupAllowVendorChange
bool dupAllowVendorChange() const
Definition TestcaseSetup.cc:140
zypp::misc::testcase::TestcaseSetup::_pimpl
RWCOW_pointer< TestcaseSetupImpl > _pimpl
Definition TestcaseSetup.h:130
zypp::misc::testcase::TestcaseSetup::allowNameChange
bool allowNameChange() const
Definition TestcaseSetup.cc:122
zypp::misc::testcase::TestcaseSetup::autoinstalled
const sat::StringQueue & autoinstalled() const
Definition TestcaseSetup.cc:92
zypp::misc::testcase::TestcaseSetup::allowDowngrade
bool allowDowngrade() const
Definition TestcaseSetup.cc:119
zypp::misc::testcase::TestcaseSetup::loadRepo
static bool loadRepo(zypp::RepoManager &manager, const TestcaseSetup &setup, const RepoData &data)
Definition TestcaseSetup.cc:182
zypp::misc::testcase::TestcaseSetup::systemCheck
const Pathname & systemCheck() const
Definition TestcaseSetup.cc:80
zypp::misc::testcase::TestcaseSetup::data
TestcaseSetupImpl & data()
Definition TestcaseSetup.cc:250
zypp::misc::testcase::TestcaseSetup::set_licence
bool set_licence() const
Definition TestcaseSetup.cc:101
zypp::misc::testcase::TestcaseSetup::dupAllowNameChange
bool dupAllowNameChange() const
Definition TestcaseSetup.cc:134
zypp::misc::testcase::TestcaseSetup::allowArchChange
bool allowArchChange() const
Definition TestcaseSetup.cc:125
zypp::misc::testcase::TestcaseSetup::cleandepsOnRemove
bool cleandepsOnRemove() const
Definition TestcaseSetup.cc:116
zypp::misc::testcase::TestcaseSetup::show_mediaid
bool show_mediaid() const
Definition TestcaseSetup.cc:104
zypp::misc::testcase::TestcaseSetup::~TestcaseSetup
~TestcaseSetup()
Definition TestcaseSetup.cc:59
zypp::misc::testcase::TestcaseSetup::forceResolve
bool forceResolve() const
Definition TestcaseSetup.cc:113
zypp::misc::testcase::TestcaseSetup::globalPath
const Pathname & globalPath() const
Definition TestcaseSetup.cc:74
zypp::misc::testcase::TestcaseSetup::hardwareInfoFile
const Pathname & hardwareInfoFile() const
Definition TestcaseSetup.cc:77
zypp::misc::testcase::TestcaseSetup::ignorealreadyrecommended
bool ignorealreadyrecommended() const
Definition TestcaseSetup.cc:107
zypp::misc::testcase::TestcaseSetup::allowVendorChange
bool allowVendorChange() const
Definition TestcaseSetup.cc:128
zypp::misc::testcase::TestcaseSetup::TestcaseSetup
TestcaseSetup()
Definition TestcaseSetup.cc:56
zypp::misc::testcase::TestcaseSetup::localesTracker
const base::SetTracker< LocaleSet > & localesTracker() const
Definition TestcaseSetup.cc:86
zypp::misc::testcase::TestcaseSetup::dupAllowArchChange
bool dupAllowArchChange() const
Definition TestcaseSetup.cc:137
zypp::misc::testcase::TestcaseSetup::dupAllowDowngrade
bool dupAllowDowngrade() const
Definition TestcaseSetup.cc:131
zypp::repo::RepoInfoBase::setAutorefresh
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition RepoInfoBase.cc:86
zypp::repo::RepoInfoBase::setAlias
void setAlias(const std::string &alias)
set the repository alias
Definition RepoInfoBase.cc:89
zypp::repo::RepoInfoBase::setName
void setName(const std::string &name)
set the repository name
Definition RepoInfoBase.cc:92
zypp::repo::RepoInfoBase::setEnabled
void setEnabled(bool enabled)
enable or disable the repository
Definition RepoInfoBase.cc:83
zypp::sat::Pool::instance
static Pool instance()
Singleton ctor.
Definition Pool.h:55
zypp::sat::Pool::reposInsert
Repository reposInsert(const std::string &alias_r)
Return a Repository named alias_r.
Definition Pool.cc:143
zypp::sat::Pool::systemRepo
Repository systemRepo()
Return the system repository, create it if missing.
Definition Pool.cc:178
zypp::target::Modalias::ModaliasList
std::vector< std::string > ModaliasList
Definition Modalias.h:45
std
Definition Arch.h:364
zypp::misc::testcase
Definition LoadTestcase.cc:18
zypp::misc::testcase::TestcaseRepoType
TestcaseRepoType
Definition TestcaseSetup.h:37
zypp::misc::testcase::TestcaseRepoType::Url
@ Url
Definition TestcaseSetup.h:40
zypp::repo
Definition DeltaCandidates.cc:30
zypp::sat::StringQueue
Queue StringQueue
Queue with String ids.
Definition Queue.h:28
zypp::ResolverFocus
ResolverFocus
The resolver's general attitude.
Definition ResolverFocus.h:24
zypp::base::SetTracker
Track added/removed set items based on an initial set.
Definition SetTracker.h:38
zypp::misc::testcase::ForceInstallImpl
Definition TestcaseSetupImpl.h:34
zypp::misc::testcase::RepoDataImpl
Definition TestcaseSetupImpl.h:25
zypp::misc::testcase::TestcaseSetupImpl
Definition TestcaseSetupImpl.h:43
ZYPP_CAUGHT
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
MIL
#define MIL
Definition Logger.h:100
ERR
#define ERR
Definition Logger.h:102