12 #ifndef ZYPP_MISC_YAMLTESTCASEHELPERS_H 13 #define ZYPP_MISC_YAMLTESTCASEHELPERS_H 18 #include <yaml-cpp/yaml.h> 20 #include <type_traits> 26 MIL <<
"Parsing setup node " << std::endl;
27 for ( YAML::const_iterator it = setup.begin(); it != setup.end(); it++ ) {
29 const std::string &key = it->first.as<std::string>();
30 const auto &data = it->second;
32 MIL <<
"Found key " << key << std::endl;
35 auto readListInlineOrFromFile = [&](
const auto &cb , std::string *err ) ->
bool {
36 if ( data.Type() == YAML::NodeType::Sequence ) {
38 for (
const auto &
node: data ) {
39 if ( !cb(
node, err ) )
return false;
42 MIL <<
"Loaded " << cnt <<
" Elements inline" << std::endl;
44 const std::string &fName = data.as<std::string>();
45 MIL <<
"Trying to load list from file " << fName << std::endl;
47 auto doc = YAML::LoadFile( fName );
48 if ( doc.Type() != YAML::NodeType::Sequence ) {
49 if ( err ) *err =
"Expected the top node to be a sequence in external file for key: ";
54 for (
const auto &
node : doc ) {
55 if ( !cb(
node, err ) )
return false;
58 MIL <<
"Loaded " << cnt <<
" Elements from file" << std::endl;
59 }
catch ( YAML::Exception &e ) {
60 if ( err ) *err = e.what();
63 if ( err ) *err =
zypp::str::Str() <<
"Unknown error when parsing the file for " << key;
70 if ( key ==
"resolverFlags" ) {
71 #define if_SolverFlag( N ) if ( data[#N] ) { target.N = data[#N].as<bool>(); } 73 if_SolverFlag( onlyRequires )
if ( data[
"ignorerecommended"] ) { target.
onlyRequires = data[
"ignorerecommended"].as<
bool>(); }
88 if ( data[
"focus"] ) {
89 target.
resolverFocus = zypp::resolverFocusFromString( data[
"focus"].as<std::string>() );
91 }
else if ( key == (
"system") ) {
96 data[
"file"].as<std::string>()
99 else if ( key == (
"hardwareInfo") ) {
102 else if ( key == (
"modalias") ) {
103 bool success = readListInlineOrFromFile( [&target](
const YAML::Node &dataNode,
auto ){
104 target.
modaliasList.push_back( dataNode.as<std::string>() );
107 if ( !success )
return false;
109 else if ( key == (
"multiversion") ) {
110 bool success = readListInlineOrFromFile( [&target](
const YAML::Node &dataNode,
auto ){
114 if ( !success )
return false;
116 else if (key == (
"channels")) {
117 bool success = readListInlineOrFromFile( [&target](
const YAML::Node &dataNode,
auto ){
118 std::string name = dataNode[
"alias"].as<std::string>();
119 std::string file = dataNode[
"file"].as<std::string>();
120 std::string type = dataNode[
"type"].as<std::string>();
123 if ( dataNode[
"priority"] )
124 prio = dataNode[
"priority"].as<
unsigned>();
134 if ( !success )
return false;
136 else if ( key == (
"sources") )
138 bool success = readListInlineOrFromFile( [&target](
const YAML::Node &dataNode,
auto ){
139 std::string
url = dataNode[
"url"].as<std::string>();
140 std::string alias = dataNode[
"name"].as<std::string>();
149 if ( !success )
return false;
151 else if ( key == (
"force-install") )
153 bool success = readListInlineOrFromFile( [&target](
const YAML::Node &dataNode,
auto ){
155 dataNode[
"channel"].as<std::string>(),
156 dataNode[
"package"].as<std::string>(),
157 dataNode[
"kind"].as<std::string>()
161 if ( !success )
return false;
163 else if ( key == (
"mediaid") )
167 else if ( key == (
"arch") ) {
168 std::string architecture = data.as<std::string>();
169 if ( architecture.empty() ) {
170 if (err) *err =
zypp::str::Str() <<
"Property 'arch' in setup can not be empty." << std::endl;
174 MIL <<
"Setting architecture to '" << architecture <<
"'" << std::endl;
178 else if ( key == (
"locales") )
180 bool success = readListInlineOrFromFile( [&target](
const YAML::Node &dataNode, std::string *err ){
182 std::string fate = dataNode[
"fate"].as<std::string>();
184 if (err) *err =
zypp::str::Str() <<
"Bad or missing name in locale..." << std::endl;
187 else if ( fate ==
"added" ) {
190 else if ( fate ==
"removed" ) {
198 if ( !success )
return false;
200 else if ( key == (
"autoinst") ) {
201 bool success = readListInlineOrFromFile( [&](
const YAML::Node &dataNode,
auto ){
205 if ( !success )
return false;
207 else if ( key == (
"systemCheck") ) {
210 else if ( key == (
"setlicencebit") ) {
214 ERR <<
"Ignoring unrecognized tag '" << key <<
"' in setup" << std::endl;
220 template <
typename T>
221 bool parseJobs (
const YAML::Node &trial, std::vector<T> &target, std::string *err );
223 template <
typename T>
224 bool parseSingleJob (
const YAML::Node &jobNode, std::vector<T> &target, std::string *err ) {
226 constexpr
bool isSubNode = std::is_same_v<T, std::shared_ptr<zypp::misc::testcase::TestcaseTrial::Node>>;
227 if ( jobNode[
"include"] ) {
229 const auto &fName = jobNode[
"include"].as<std::string>();
230 MIL <<
"Including file " << fName << std::endl;
232 auto doc = YAML::LoadFile( fName );
235 MIL <<
"Including file " << fName <<
"was successfull" << std::endl;
236 }
catch ( YAML::Exception &e ) {
237 if ( err ) *err = e.what();
240 if ( err ) *err =
zypp::str::Str() <<
"Unknown error when parsing the file: " << fName;
247 if ( !jobNode[
"job"] ) {
250 const auto &mark = jobNode.Mark();
251 errStr <<
"'job' key missing from trial node.";
252 if ( !mark.is_null() ) {
253 errStr <<
" Line: " << mark.line <<
" Col: " << mark.column <<
" pos: " << mark.pos;
260 for (
const auto &elem : jobNode ) {
261 const std::string &key = elem.first.as<std::string>();
262 const auto &data = elem.second;
263 if ( key ==
"job" ) {
264 n.
name = data.as<std::string>();
265 }
else if ( key ==
"__content") {
266 n.
value = data.as<std::string>();
268 if( data.IsScalar() ) {
269 n.
properties.insert( { key, data.as<std::string>() } );
270 }
if ( data.IsSequence() ) {
276 }
else if ( data.IsMap() ) {
283 ERR <<
"Ignoring field " << key <<
" with unsupported type." << std::endl;
287 if constexpr ( isSubNode ) {
288 target.push_back( std::make_shared<zypp::misc::testcase::TestcaseTrial::Node>( std::move(n) ) );
290 target.push_back( std::move(n) );
295 template <
typename T>
296 bool parseJobs (
const YAML::Node &trial, std::vector<T> &target, std::string *err ) {
297 for (
const auto &jobNode : trial ) {
305 MIL <<
"Parsing trials." << std::endl;
310 #endif // ZYPP_MISC_YAMLTESTCASEHELPERS_H std::vector< Node > nodes
bool parseSingleJob(const YAML::Node &jobNode, std::vector< T > &target, std::string *err)
std::ostream & node(std::ostream &out_r, const std::string &name_r, Node::Attr attr_r)
std::map< std::string, std::string > properties
IdType id() const
Expert backdoor.
std::vector< RepoData > repos
Access to the sat-pools string space.
bool parseSetup(const YAML::Node &setup, zypp::misc::testcase::TestcaseSetup &target, std::string *err)
std::set< std::string > multiversionSpec
bool parseTrial(const YAML::Node &trial, zypp::misc::testcase::TestcaseTrial &target, std::string *err)
std::optional< RepoData > systemRepo
const set_type & removed() const
Return the set of removed items.
void push(value_type val_r)
Push a value to the end off the Queue.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
std::vector< ForceInstall > forceInstallTasks
const set_type & current() const
Return the current set.
bool parseJobs(const YAML::Node &trial, std::vector< T > &target, std::string *err)
ResolverFocus resolverFocus
std::vector< std::shared_ptr< Node > > children
const set_type & added() const
Return the set of added items.
base::SetTracker< LocaleSet > localesTracker
'Language[_Country]' codes.
sat::StringQueue autoinstalled
bool ignorealreadyrecommended
Pathname hardwareInfoFile
target::Modalias::ModaliasList modaliasList