libzypp: zypp/misc/TestcaseSetup.cc Source File

libzypp 17.38.14

TestcaseSetup.cc
Go to the documentation of this file.
1#include "TestcaseSetupImpl.h"
2
3namespace 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::noUpdateProvide() const
120 { return _pimpl->noUpdateProvide; }
121
122 bool TestcaseSetup::allowDowngrade() const
123 { return _pimpl->allowDowngrade; }
124
125 bool TestcaseSetup::allowNameChange() const
126 { return _pimpl->allowNameChange; }
127
128 bool TestcaseSetup::allowArchChange() const
129 { return _pimpl->allowArchChange; }
130
131 bool TestcaseSetup::allowVendorChange() const
132 { return _pimpl->allowVendorChange; }
133
134 bool TestcaseSetup::dupAllowDowngrade() const
135 { return _pimpl->dupAllowDowngrade; }
136
137 bool TestcaseSetup::dupAllowNameChange() const
138 { return _pimpl->dupAllowNameChange; }
139
140 bool TestcaseSetup::dupAllowArchChange() const
141 { return _pimpl->dupAllowArchChange; }
142
143 bool TestcaseSetup::dupAllowVendorChange() const
144 { return _pimpl->dupAllowVendorChange; }
145
146 bool TestcaseSetup::applySetup( zypp::RepoManager &manager ) const
147 {
148 const auto &setup = data();
149 if ( !setup.architecture.empty() )
150 {
151 MIL << "Setting architecture to '" << setup.architecture << "'" << std::endl;
152 ZConfig::instance().setSystemArchitecture( setup.architecture );
153 setenv ("ZYPP_TESTSUITE_FAKE_ARCH", setup.architecture.c_str(), 1);
154 }
155
156 if ( setup.systemRepo ) {
157 if (!loadRepo( manager, *this, *setup.systemRepo ) )
158 {
159 ERR << "Can't setup 'system'" << std::endl;
160 return false;
161 }
162 }
163
164 if ( !setup.hardwareInfoFile.empty() ) {
165 setenv( "ZYPP_MODALIAS_SYSFS", setup.hardwareInfoFile.asString().c_str(), 1 );
166 MIL << "setting HardwareInfo to: " << setup.hardwareInfoFile.asString() << std::endl;
167 }
168
169 for ( const auto &channel : setup.repos ) {
170 if ( !loadRepo( manager, *this, channel ) )
171 {
172 ERR << "Can't setup 'channel'" << std::endl;
173 return false;
174 }
175 }
176
177 if ( !setup.systemCheck.empty() ) {
178 MIL << "setting systemCheck to: " << setup.systemCheck.asString() << std::endl;
179 SystemCheck::instance().setFile( setup.systemCheck );
180 }
181
182 return true;
183 }
184
185 bool TestcaseSetup::loadRepo( zypp::RepoManager &manager, const TestcaseSetup &setup, const RepoData &data )
186 {
187 const auto &repoData = data.data();
188 Pathname pathname = setup._pimpl->globalPath + repoData.path;
189 MIL << "'" << pathname << "'" << std::endl;
190
191 Repository repo;
192
193 using TrType = zypp::misc::testcase::TestcaseRepoType;
194
195 if ( repoData.type == TrType::Url ) {
196 try {
197 MIL << "Load from Url '" << repoData.path << "'" << std::endl;
198
199 RepoInfo nrepo;
200 nrepo.setAlias ( repoData.alias );
201 nrepo.setName ( repoData.alias );
202 nrepo.setEnabled ( true );
203 nrepo.setAutorefresh( false );
204 nrepo.setPriority ( repoData.priority );
205 nrepo.addBaseUrl ( Url(repoData.path) );
206
207 manager.refreshMetadata( nrepo );
208 manager.buildCache( nrepo );
209 manager.loadFromCache( nrepo );
210 }
211 catch ( Exception & excpt_r ) {
212 ZYPP_CAUGHT (excpt_r);
213 ERR << "Couldn't load packages from Url '" << repoData.path << "'" << std::endl;
214 return false;
215 }
216 }
217 else {
218 try {
219 MIL << "Load from File '" << pathname << "'" << std::endl;
220 zypp::Repository satRepo;
221
222 if ( repoData.alias == "@System" ) {
223 satRepo = zypp::sat::Pool::instance().systemRepo();
224 } else {
225 satRepo = zypp::sat::Pool::instance().reposInsert( repoData.alias );
226 }
227
228 RepoInfo nrepo;
229
230 nrepo.setAlias ( repoData.alias );
231 nrepo.setName ( repoData.alias );
232 nrepo.setEnabled ( true );
233 nrepo.setAutorefresh( false );
234 nrepo.setPriority ( repoData.priority );
235 nrepo.addBaseUrl ( pathname.asUrl() );
236
237 satRepo.setInfo (nrepo);
238 if ( repoData.type == TrType::Helix )
239 satRepo.addHelix( pathname );
240 else
241 satRepo.addTesttags( pathname );
242 MIL << "Loaded " << satRepo.solvablesSize() << " resolvables from " << ( repoData.path.empty()?pathname.asString():repoData.path) << "." << std::endl;
243 }
244 catch ( Exception & excpt_r ) {
245 ZYPP_CAUGHT (excpt_r);
246 ERR << "Couldn't load packages from XML file '" << repoData.path << "'" << std::endl;
247 return false;
248 }
249 }
250 return true;
251 }
252
253 TestcaseSetupImpl &TestcaseSetup::data()
254 {
255 return *_pimpl;
256 }
257
258 const TestcaseSetupImpl &TestcaseSetup::data() const
259 {
260 return *_pimpl;
261 }
262
263}
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:103
ERR
#define ERR
Definition Logger.h:105
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:767
zypp::RepoInfo::setPriority
void setPriority(unsigned newval_r)
Set repository priority for solver.
Definition RepoInfo.cc:619
zypp::RepoManager
creates and provides information about known sources.
Definition RepoManager.h:60
zypp::RepoManager::refreshMetadata
void refreshMetadata(const RepoInfo &info, RawMetadataRefreshPolicy policy=RefreshIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local raw cache.
Definition RepoManager.cc:142
zypp::RepoManager::buildCache
void buildCache(const RepoInfo &info, CacheBuildPolicy policy=BuildIfNeeded, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Refresh local cache.
Definition RepoManager.cc:158
zypp::RepoManager::loadFromCache
void loadFromCache(const RepoInfo &info, const ProgressData::ReceiverFnc &progressrcv=ProgressData::ReceiverFnc())
Load resolvables into the pool.
Definition RepoManager.cc:171
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:364
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::Url::Url
Url()
Definition Url.cc:306
zypp::ZConfig::setSystemArchitecture
void setSystemArchitecture(const Arch &arch_r)
Override the zypp system architecture.
Definition ZConfig.cc:860
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:794
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
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:94
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:146
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::noUpdateProvide
bool noUpdateProvide() const
Definition TestcaseSetup.cc:119
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:143
zypp::misc::testcase::TestcaseSetup::_pimpl
RWCOW_pointer< TestcaseSetupImpl > _pimpl
Definition TestcaseSetup.h:131
zypp::misc::testcase::TestcaseSetup::allowNameChange
bool allowNameChange() const
Definition TestcaseSetup.cc:125
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:122
zypp::misc::testcase::TestcaseSetup::loadRepo
static bool loadRepo(zypp::RepoManager &manager, const TestcaseSetup &setup, const RepoData &data)
Definition TestcaseSetup.cc:185
zypp::misc::testcase::TestcaseSetup::systemCheck
const Pathname & systemCheck() const
Definition TestcaseSetup.cc:80
zypp::misc::testcase::TestcaseSetup::data
TestcaseSetupImpl & data()
Definition TestcaseSetup.cc:253
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:137
zypp::misc::testcase::TestcaseSetup::allowArchChange
bool allowArchChange() const
Definition TestcaseSetup.cc:128
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:131
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:140
zypp::misc::testcase::TestcaseSetup::dupAllowDowngrade
bool dupAllowDowngrade() const
Definition TestcaseSetup.cc:134
zypp::repo::RepoInfoBase::setAutorefresh
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition RepoInfoBase.cc:92
zypp::repo::RepoInfoBase::setAlias
void setAlias(const std::string &alias)
set the repository alias
Definition RepoInfoBase.cc:95
zypp::repo::RepoInfoBase::setName
void setName(const std::string &name)
set the repository name
Definition RepoInfoBase.cc:98
zypp::repo::RepoInfoBase::setEnabled
void setEnabled(bool enabled)
enable or disable the repository
Definition RepoInfoBase.cc:89
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 ansi.h:855
zypp::misc::testcase
Definition LoadTestcase.cc:18
zypp::misc::testcase::TestcaseRepoType
TestcaseRepoType
Definition TestcaseSetup.h:37
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:39
zypp::misc::testcase::ForceInstallImpl
Definition TestcaseSetupImpl.h:34
zypp::misc::testcase::RepoDataImpl
Definition TestcaseSetupImpl.h:25
zypp::misc::testcase::TestcaseSetupImpl
Definition TestcaseSetupImpl.h:43