1 #include "TestcaseSetupImpl.h"
3 namespace zypp::misc::testcase
5 RepoData::RepoData() : _pimpl( new RepoDataImpl )
11 RepoData::RepoData(RepoDataImpl &&data) : _pimpl( new RepoDataImpl( std::move(data)) )
14 TestcaseRepoType RepoData::type() const
15 { return _pimpl->type; }
17 const std::string &RepoData::alias() const
18 { return _pimpl->alias; }
20 uint RepoData::priority() const
21 { return _pimpl->priority; }
23 const std::string &RepoData::path() const
24 { return _pimpl->path; }
26 const RepoDataImpl &RepoData::data() const
29 RepoDataImpl &RepoData::data()
32 ForceInstall::ForceInstall() : _pimpl( new ForceInstallImpl )
35 ForceInstall::~ForceInstall()
38 ForceInstall::ForceInstall(ForceInstallImpl &&data) : _pimpl( new ForceInstallImpl( std::move(data) ))
41 const ForceInstallImpl &ForceInstall::data() const
44 ForceInstallImpl &ForceInstall::data()
47 const std::string &ForceInstall::channel() const
48 { return _pimpl->channel; }
50 const std::string &ForceInstall::package() const
51 { return _pimpl->package; }
53 const std::string &ForceInstall::kind() const
54 { return _pimpl->kind; }
56 TestcaseSetup::TestcaseSetup() : _pimpl( new TestcaseSetupImpl )
59 TestcaseSetup::~TestcaseSetup()
62 Arch TestcaseSetup::architecture() const
63 { return _pimpl->architecture; }
65 const std::optional<RepoData> &TestcaseSetup::systemRepo() const
66 { return _pimpl->systemRepo; }
68 const std::vector<RepoData> &TestcaseSetup::repos() const
69 { return _pimpl->repos; }
71 ResolverFocus TestcaseSetup::resolverFocus() const
72 { return _pimpl->resolverFocus; }
74 const zypp::filesystem::Pathname &TestcaseSetup::globalPath() const
75 { return _pimpl->globalPath; }
77 const zypp::filesystem::Pathname &TestcaseSetup::hardwareInfoFile() const
78 { return _pimpl->hardwareInfoFile; }
80 const zypp::filesystem::Pathname &TestcaseSetup::systemCheck() const
81 { return _pimpl->systemCheck; }
83 const target::Modalias::ModaliasList &TestcaseSetup::modaliasList() const
84 { return _pimpl->modaliasList; }
86 const base::SetTracker<LocaleSet> &TestcaseSetup::localesTracker() const
87 { return _pimpl->localesTracker; }
89 const std::vector<std::vector<std::string> > &TestcaseSetup::vendorLists() const
90 { return _pimpl->vendorLists; }
92 const sat::StringQueue &TestcaseSetup::autoinstalled() const
93 { return _pimpl->autoinstalled; }
95 const std::set<std::string> &TestcaseSetup::multiversionSpec() const
96 { return _pimpl->multiversionSpec; }
98 const std::vector<ForceInstall> &TestcaseSetup::forceInstallTasks() const
99 { return _pimpl->forceInstallTasks; }
101 bool TestcaseSetup::set_licence() const
102 { return _pimpl->set_licence; }
104 bool TestcaseSetup::show_mediaid() const
105 { return _pimpl->show_mediaid; }
107 bool TestcaseSetup::ignorealreadyrecommended() const
108 { return _pimpl->ignorealreadyrecommended; }
110 bool TestcaseSetup::onlyRequires() const
111 { return _pimpl->onlyRequires; }
113 bool TestcaseSetup::forceResolve() const
114 { return _pimpl->forceResolve; }
116 bool TestcaseSetup::cleandepsOnRemove() const
117 { return _pimpl->cleandepsOnRemove; }
119 bool TestcaseSetup::allowDowngrade() const
120 { return _pimpl->allowDowngrade; }
122 bool TestcaseSetup::allowNameChange() const
123 { return _pimpl->allowNameChange; }
125 bool TestcaseSetup::allowArchChange() const
126 { return _pimpl->allowArchChange; }
128 bool TestcaseSetup::allowVendorChange() const
129 { return _pimpl->allowVendorChange; }
131 bool TestcaseSetup::dupAllowDowngrade() const
132 { return _pimpl->dupAllowDowngrade; }
134 bool TestcaseSetup::dupAllowNameChange() const
135 { return _pimpl->dupAllowNameChange; }
137 bool TestcaseSetup::dupAllowArchChange() const
138 { return _pimpl->dupAllowArchChange; }
140 bool TestcaseSetup::dupAllowVendorChange() const
141 { return _pimpl->dupAllowVendorChange; }
143 bool TestcaseSetup::applySetup( zypp::RepoManager &manager ) const
145 const auto &setup = data();
146 if ( !setup.architecture.empty() )
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);
153 if ( setup.systemRepo ) {
154 if (!loadRepo( manager, *this, *setup.systemRepo ) )
156 ERR << "Can't setup 'system'" << std::endl;
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;
166 for ( const auto &channel : setup.repos ) {
167 if ( !loadRepo( manager, *this, channel ) )
169 ERR << "Can't setup 'channel'" << std::endl;
174 if ( !setup.systemCheck.empty() ) {
175 MIL << "setting systemCheck to: " << setup.systemCheck.asString() << std::endl;
176 SystemCheck::instance().setFile( setup.systemCheck );
182 bool TestcaseSetup::loadRepo( zypp::RepoManager &manager, const TestcaseSetup &setup, const RepoData &data )
184 const auto &repoData = data.data();
185 Pathname pathname = setup._pimpl->globalPath + repoData.path;
186 MIL << "'" << pathname << "'" << std::endl;
190 using TrType = zypp::misc::testcase::TestcaseRepoType;
192 if ( repoData.type == TrType::Url ) {
194 MIL << "Load from Url '" << repoData.path << "'" << std::endl;
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) );
204 manager.refreshMetadata( nrepo );
205 manager.buildCache( nrepo );
206 manager.loadFromCache( nrepo );
208 catch ( Exception & excpt_r ) {
209 ZYPP_CAUGHT (excpt_r);
210 ERR << "Couldn't load packages from Url '" << repoData.path << "'" << std::endl;
216 MIL << "Load from File '" << pathname << "'" << std::endl;
217 zypp::Repository satRepo;
219 if ( repoData.alias == "@System" ) {
220 satRepo = zypp::sat::Pool::instance().systemRepo();
222 satRepo = zypp::sat::Pool::instance().reposInsert( repoData.alias );
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() );
234 satRepo.setInfo (nrepo);
235 if ( repoData.type == TrType::Helix )
236 satRepo.addHelix( pathname );
238 satRepo.addTesttags( pathname );
239 MIL << "Loaded " << satRepo.solvablesSize() << " resolvables from " << ( repoData.path.empty()?pathname.asString():repoData.path) << "." << std::endl;
241 catch ( Exception & excpt_r ) {
242 ZYPP_CAUGHT (excpt_r);
243 ERR << "Couldn't load packages from XML file '" << repoData.path << "'" << std::endl;
250 TestcaseSetupImpl &TestcaseSetup::data()
255 const TestcaseSetupImpl &TestcaseSetup::data() const