LCOV - code coverage report
Current view: top level - vnsw/agent/test-xml - test_xml.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 308 402 76.6 %
Date: 2026-09-07 02:14:47 Functions: 43 58 74.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : #include "base/os.h"
       5             : #include <iostream>
       6             : #include <fstream>
       7             : #include <pugixml/pugixml.hpp>
       8             : #include <boost/filesystem.hpp>
       9             : #include <boost/uuid/uuid.hpp>
      10             : 
      11             : #include <test/test_cmn_util.h>
      12             : #include <pkt/test/test_pkt_util.h>
      13             : #include <pkt/flow_mgmt.h>
      14             : #include <oper/global_vrouter.h>
      15             : #include "test_xml.h"
      16             : #include "test_xml_validate.h"
      17             : #include "test_xml_packet.h"
      18             : 
      19             : using namespace std;
      20             : using namespace pugi;
      21             : using namespace boost::uuids;
      22             : using namespace AgentUtXmlUtils;
      23             : 
      24             : namespace AgentUtXmlUtils {
      25        2295 : bool GetStringAttribute(const xml_node &node, const string &name,
      26             :                         string *value) {
      27        2295 :     xml_attribute attr = node.attribute(name.c_str());
      28        2295 :     if (!attr) {
      29        1098 :         return false;;
      30             :     }
      31             : 
      32        1197 :     *value = attr.as_string();
      33             : 
      34        1197 :     return true;
      35             : }
      36             : 
      37         774 : bool GetUintAttribute(const xml_node &node, const string &name,
      38             :                       uint16_t *value) {
      39         774 :     xml_attribute attr = node.attribute(name.c_str());
      40         774 :     if (!attr) {
      41         361 :         return false;;
      42             :     }
      43             : 
      44         413 :     *value = attr.as_uint();
      45             : 
      46         413 :     return true;
      47             : }
      48             : 
      49           0 : bool GetIntAttribute(const xml_node &node, const string &name, int *value) {
      50           0 :     xml_attribute attr = node.attribute(name.c_str());
      51           0 :     if (!attr) {
      52           0 :         return false;;
      53             :     }
      54             : 
      55           0 :     *value = attr.as_int();
      56             : 
      57           0 :     return true;
      58             : }
      59             : 
      60           0 : bool GetBoolAttribute(const xml_node &node, const string &name,
      61             :                       bool *value) {
      62           0 :     xml_attribute attr = node.attribute(name.c_str());
      63           0 :     if (!attr) {
      64           0 :         return false;;
      65             :     }
      66             : 
      67           0 :     string str = attr.as_string();
      68           0 :     if (str == "true" || str == "yes")
      69           0 :         *value = true;
      70             :     else
      71           0 :         *value = false;
      72           0 :     return true;
      73           0 : }
      74             : 
      75          28 : void NovaIntfAdd(bool op_delete, const uuid &id, const Ip4Address &ip,
      76             :                  const uuid &vm_uuid, const uuid vn_uuid, const string &name,
      77             :                  const string &mac, const string vm_name) {
      78          28 :     if (op_delete) {
      79          15 :         PortUnSubscribe(id);
      80          15 :         cout << "Nova Del Interface Message " << endl;
      81          15 :         return;
      82             :     }
      83             : 
      84          13 :     PortSubscribe(name, id, vm_uuid, vm_name, vn_uuid, MakeUuid(1), ip,
      85          13 :                   Ip6Address::v4_compatible(ip), mac);
      86          13 :     cout << "Nova Add Interface Message " << endl;
      87          13 :     return;
      88             : }
      89             : 
      90         155 : void LinkXmlNode(xml_node *parent, const string &ltype, const string lname,
      91             :                  const string &rtype, const string rname) {
      92         155 :     xml_node n = parent->append_child("link");
      93             : 
      94         155 :     xml_node n1 = n.append_child("node");
      95         155 :     n1.append_attribute("type") = ltype.c_str();
      96             : 
      97         155 :     xml_node n2 = n1.append_child("name");
      98         155 :     n2.append_child(pugi::node_pcdata).set_value(lname.c_str());
      99             : 
     100         155 :     n1 = n.append_child("node");
     101         155 :     n1.append_attribute("type") = rtype.c_str();
     102             : 
     103         155 :     n2 = n1.append_child("name");
     104         155 :     n2.append_child(pugi::node_pcdata).set_value(rname.c_str());
     105             : 
     106         155 :     string mdata = GetMetadata(ltype.c_str(), rtype.c_str());
     107         155 :     xml_node n3 = n.append_child("metadata");
     108         155 :     n3.append_attribute("type") = mdata.c_str();
     109         310 :     return;
     110         155 : }
     111             : 
     112         131 : xml_node AddXmlNodeWithAttr(xml_node *parent, const char *attr) {
     113         131 :     xml_node n = parent->append_child("node");
     114         131 :     n.append_attribute("type") = attr;
     115         131 :     return n;
     116             : }
     117             : 
     118         898 : xml_node AddXmlNodeWithValue(xml_node *parent, const char *name,
     119             :                              const string &value) {
     120         898 :     xml_node n = parent->append_child(name);
     121         898 :     n.append_child(pugi::node_pcdata).set_value(value.c_str());
     122         898 :     return n;
     123             : }
     124             : 
     125          27 : xml_node AddXmlNodeWithIntValue(xml_node *parent, const char *name,
     126             :                                 int val) {
     127          27 :     stringstream s;
     128          27 :     s << val;
     129          27 :     xml_node n = parent->append_child(name);
     130          27 :     n.append_child(pugi::node_pcdata).set_value(s.str().c_str());
     131          27 :     return n;
     132          27 : }
     133             : }
     134             : 
     135             : /////////////////////////////////////////////////////////////////////////////
     136             : //  AgentUtXmlTest routines
     137             : /////////////////////////////////////////////////////////////////////////////
     138           7 : AgentUtXmlTest::AgentUtXmlTest(const std::string &name) : file_name_(name) {
     139           7 : }
     140             : 
     141           7 : AgentUtXmlTest::~AgentUtXmlTest() {
     142             : 
     143           7 :     for (AgentUtXmlTestList::iterator i = test_list_.begin();
     144          14 :          i != test_list_.end(); i++) {
     145           7 :         delete *i;
     146             :     }
     147           7 : }
     148             : 
     149         168 : void AgentUtXmlTest::AddConfigEntry(const std::string &name,
     150             :                                     AgentUtXmlTestConfigCreateFn fn) {
     151         168 :     config_factory_[name] = fn;
     152         168 : }
     153             : 
     154         150 : void AgentUtXmlTest::AddValidateEntry(const std::string &name,
     155             :                                       AgentUtXmlTestValidateCreateFn fn) {
     156         150 :     validate_factory_[name] = fn;
     157         150 : }
     158             : 
     159             : AgentUtXmlTest::AgentUtXmlTestConfigCreateFn
     160         221 : AgentUtXmlTest::GetConfigCreateFn(const std::string &name) {
     161         221 :     AgentUtXmlTestConfigFactory::iterator iter = config_factory_.find(name);
     162         221 :     if (iter == config_factory_.end()) {
     163          71 :         return AgentUtXmlTest::AgentUtXmlTestConfigCreateFn();
     164             :     }
     165             : 
     166         150 :     return iter->second;
     167             : }
     168             : 
     169             : AgentUtXmlTest::AgentUtXmlTestValidateCreateFn
     170          82 : AgentUtXmlTest::GetValidateCreateFn(const std::string &name) {
     171          82 :     AgentUtXmlTestValidateFactory::iterator iter = validate_factory_.find(name);
     172          82 :     if (iter == validate_factory_.end()) {
     173           0 :         assert(0);
     174             :     }
     175         164 :     return iter->second;
     176             : }
     177             : 
     178           7 : bool AgentUtXmlTest::ReadXml() {
     179           7 :     xml_node list = doc_.child("test_suite");
     180           7 :     GetStringAttribute(list, "name", &name_);
     181             : 
     182          14 :     for (xml_node node = list.first_child(); node; node = node.next_sibling()) {
     183           7 :         if (strcmp(node.name(), "test") == 0) {
     184           7 :             xml_attribute attr = node.attribute("name");
     185           7 :             if (!attr) {
     186           0 :                 cout << "Missing attribute \"name\". Skipping" << endl;
     187           0 :                 continue;
     188             :             }
     189             :             AgentUtXmlTestCase *test = new AgentUtXmlTestCase(attr.value(),
     190           7 :                                                               node, this);
     191           7 :             attr = node.attribute("verbose");
     192           7 :             bool verbose = false;
     193           7 :             if (!attr) {
     194           0 :                 verbose = false;
     195             :             } else {
     196           7 :                 if (atoi(attr.value()))
     197           0 :                     verbose = true;
     198             :             }
     199           7 :             test->set_verbose(verbose);
     200           7 :             test_list_.push_back(test);
     201           7 :             test->ReadXml();
     202             :         }
     203             :     }
     204             : 
     205           7 :     return true;
     206             : }
     207             : 
     208           7 : bool AgentUtXmlTest::Load() {
     209           7 :     boost::system::error_code ec;
     210           7 :     boost::filesystem::path file_path(file_name_);
     211           7 :     uintmax_t file_size = boost::filesystem::file_size(file_path, ec);
     212           7 :     if (ec) {
     213           0 :         cout << "Error <" << ec << "> opening file" << file_name_ << endl;
     214           0 :         return false;
     215             :     }
     216             : 
     217           7 :     std::fstream file(file_name_.c_str(), std::ios::binary | std::ios_base::in);
     218           7 :     if (!file) {
     219           0 :         cout << "Error <fstream error> opening file" << file_name_ << endl;
     220           0 :         return false;
     221             :     }
     222             : 
     223           7 :     std::vector<char> data(file_size + 1, 0);
     224           7 :     file.read(data.data(), file_size);
     225           7 :     if (!file || file.gcount() < static_cast<std::streamsize>(file_size)) {
     226           0 :         cout << "Error <fstream::read> reading file" << file_name_ << endl;
     227           0 :         return false;
     228             :     }
     229             : 
     230           7 :     xml_parse_result result = doc_.load_string(data.data());
     231           7 :     if (result) {
     232           7 :         cout << "Loaded data file successfully" << endl;
     233             :     } else {
     234           0 :         cout << "Error in XML string at offset <: " << result.offset
     235           0 :             << "> (error at [..." << (data.data() + result.offset) << "])" << endl;
     236           0 :         return false;
     237             :     }
     238             : 
     239           7 :     return true;
     240           7 : }
     241             : 
     242           7 : void AgentUtXmlTest::ToString(string *str) {
     243           7 :     stringstream s;
     244             : 
     245           7 :     s << "Test Suite : " << name_ << endl;
     246           7 :     *str += s.str();
     247           7 :     for (AgentUtXmlTestList::iterator it = test_list_.begin();
     248          14 :          it != test_list_.end(); it++) {
     249           7 :         (*it)->ToString(str);
     250             :     }
     251          14 :     return;
     252           7 : }
     253             : 
     254           7 : bool AgentUtXmlTest::Run() {
     255           7 :     for (AgentUtXmlTestList::iterator it = test_list_.begin();
     256          14 :          it != test_list_.end(); it++) {
     257           7 :         (*it)->Run();
     258             :     }
     259             : 
     260           7 :     return true;
     261             : }
     262             : 
     263           0 : bool AgentUtXmlTest::Run(std::string test_case) {
     264           0 :     for (AgentUtXmlTestList::iterator it = test_list_.begin();
     265           0 :          it != test_list_.end(); it++) {
     266           0 :         if ((*it)->name().compare(test_case) == 0) {
     267           0 :             (*it)->Run();
     268           0 :             return true;
     269             :         }
     270             :     }
     271             : 
     272           0 :     return false;
     273             : }
     274             : 
     275             : /////////////////////////////////////////////////////////////////////////////
     276             : //  AgentUtXmlTestCase routines
     277             : /////////////////////////////////////////////////////////////////////////////
     278         221 : static bool CheckConfigNode(const string &node_name, const xml_node &node,
     279             :                             uuid *id, string *name) {
     280         221 :     if (strcmp(node.name(), node_name.c_str()) != 0) {
     281           0 :         return false;
     282             :     }
     283             : 
     284         221 :     xml_attribute attr = node.attribute("name");
     285         221 :     if (!attr) {
     286             :         cout << "Attribute \"name\" not found for " << node_name
     287          14 :             << ". Skipping..." << endl;
     288          14 :         return false;
     289             :     }
     290             : 
     291         207 :     *name = attr.as_string();
     292         207 :     if (*name == "") {
     293           0 :         cout << "Invalid \"name\" for " << node_name << " Skipping" << endl;
     294           0 :         return false;
     295             :     }
     296             : 
     297         207 :     if (node_name == "validate")
     298          33 :         return false;
     299             : 
     300         174 :     attr = node.attribute("uuid");
     301         174 :     if (!attr) {
     302             :         cout << "Attribute \"uuid\" not found for " << node_name
     303           0 :             << ". Skipping..." << endl;
     304           0 :         return false;;
     305             :     }
     306             : 
     307         174 :     int x = attr.as_uint();
     308         174 :     if (x == 0) {
     309           0 :         cout << "Invalid \"uuid\" (0) for " << node_name << " Skipping" << endl;
     310           0 :         return false;
     311             :     }
     312             : 
     313         174 :     *id = MakeUuid(x);
     314             : 
     315         174 :     return true;
     316             : }
     317             : 
     318           7 : AgentUtXmlTestCase::AgentUtXmlTestCase(const std::string &name,
     319             :                                        const xml_node &node,
     320           7 :                                        AgentUtXmlTest *test)
     321           7 :     : name_(name), xml_node_(node), test_(test), verbose_(false) {
     322           7 :     cout << "Creating test-case <" << name_ << ">" << endl;
     323           7 : }
     324             : 
     325          14 : AgentUtXmlTestCase::~AgentUtXmlTestCase() {
     326           7 :     for (AgentUtXmlNodeList::iterator i =  node_list_.begin();
     327         228 :          i != node_list_.end(); i++) {
     328         221 :         delete *i;
     329             :     }
     330          14 : }
     331             : 
     332           7 : bool AgentUtXmlTestCase::ReadXml() {
     333         228 :     for (xml_node node = xml_node_.first_child(); node;
     334         221 :          node = node.next_sibling()) {
     335             : 
     336         221 :         string str;
     337         221 :         bool op_delete = false;
     338         588 :         if (GetStringAttribute(node, "delete", &str) == true ||
     339         367 :             GetStringAttribute(node, "del", &str) == true) {
     340          75 :             if (str != "false" && str != "0")
     341          75 :                 op_delete = true;
     342             :         }
     343             : 
     344             :         uuid id;
     345         221 :         string name;
     346         221 :         AgentUtXmlNode *cfg = NULL;
     347             : 
     348             :         AgentUtXmlTest::AgentUtXmlTestConfigCreateFn fn =
     349         442 :             test_->GetConfigCreateFn(node.name());
     350         221 :         if (CheckConfigNode(node.name(), node, &id, &name) == true) {
     351         174 :             if (fn.empty() == false)
     352         150 :                 cfg = fn(node.name(), name, id, node, this);
     353             :         }
     354             : 
     355         221 :         if (strcmp(node.name(), "link") == 0) {
     356          14 :             cfg = new AgentUtXmlLink(node, this);
     357             :         }
     358             : 
     359         221 :         if (strcmp(node.name(), "packet") == 0) {
     360          24 :             if (GetStringAttribute(node, "name", &name) == false) {
     361           0 :                 cout << "Attribute \"name\" not specified for Packet. Skipping"
     362           0 :                     << endl;
     363           0 :                 continue;
     364             :             }
     365          24 :             cfg = new AgentUtXmlPacket(name, node, this);
     366             :         }
     367             : 
     368         221 :         if (strcmp(node.name(), "task") == 0) {
     369           0 :             cfg = new AgentUtXmlTask(node, this);
     370             :         }
     371             : 
     372         221 :         if (strcmp(node.name(), "validate") == 0) {
     373          33 :             if (GetStringAttribute(node, "name", &name) == false) {
     374             :                 cout << "Attribute \"name\" not specified for validate."
     375           0 :                    " Skipping" << endl;
     376           0 :                 continue;
     377             :             }
     378          33 :             cfg = new AgentUtXmlValidate(name, node, this);
     379             :         }
     380             : 
     381         221 :         if (cfg) {
     382         221 :             cfg->set_op_delete(op_delete);
     383             :         } else {
     384           0 :             cout << "Unknown node name <" << node.name() << ">. Ignoring"
     385           0 :                 << endl;
     386             :         }
     387         221 :         if (cfg) {
     388         221 :             bool ret = cfg->ReadXml();
     389         221 :             if (op_delete == false && ret == false) {
     390           0 :                 delete cfg;
     391           0 :                 cfg = NULL;
     392             :             }
     393             :         }
     394             : 
     395         221 :         if (cfg) {
     396         221 :             node_list_.push_back(cfg);
     397             :         }
     398         221 :     }
     399             : 
     400           7 :     return true;
     401             : }
     402             : 
     403           7 : bool AgentUtXmlTestCase::Run() {
     404           7 :     for (AgentUtXmlNodeList::iterator it = node_list_.begin();
     405         228 :          it != node_list_.end(); it++) {
     406         221 :         if ((*it)->gen_xml() == false) {
     407          76 :             (*it)->Run();
     408          76 :             TestClient::WaitForIdle();
     409          76 :             continue;
     410             :         }
     411             : 
     412         145 :         xml_document doc;
     413             : 
     414         145 :         xml_node decl = doc.prepend_child(pugi::node_declaration);
     415         145 :         decl.append_attribute("version") = "1.0";
     416             : 
     417         145 :         xml_node n = doc.append_child("config");
     418         145 :         xml_node n1;
     419         145 :         if ((*it)->op_delete()) {
     420          66 :             n1 = n.append_child("delete");
     421             :         } else {
     422          79 :             n1 = n.append_child("update");
     423             :         }
     424         145 :         (*it)->ToXml(&n1);
     425         145 :         if (verbose_) {
     426           0 :             doc.print(std::cout);
     427             :         }
     428         145 :         Agent *agent = Agent::GetInstance();
     429         145 :         agent->ifmap_parser()->ConfigParse(n, 0);
     430         145 :         TestClient::WaitForIdle();
     431         145 :     }
     432             : 
     433           7 :     return true;
     434             : }
     435             : 
     436           7 : void AgentUtXmlTestCase::ToString(string *str) {
     437           7 :     stringstream s;
     438             : 
     439           7 :     s << "Test Case : " << name_ << endl;
     440           7 :     *str += s.str();
     441           7 :     for (AgentUtXmlNodeList::iterator it = node_list_.begin();
     442         228 :          it != node_list_.end(); it++) {
     443         221 :         (*it)->ToString(str);
     444             :     }
     445          14 :     return;
     446           7 : }
     447             : 
     448             : /////////////////////////////////////////////////////////////////////////////
     449             : //  AgentUtXmlNode routines
     450             : /////////////////////////////////////////////////////////////////////////////
     451         145 : AgentUtXmlNode::AgentUtXmlNode(const string &name, const xml_node &node,
     452         145 :                                AgentUtXmlTestCase *test_case) :
     453         145 :     node_(node), name_(name), op_delete_(false), gen_xml_(true),
     454         145 :     test_case_(test_case) {
     455         145 : }
     456             : 
     457          76 : AgentUtXmlNode::AgentUtXmlNode(const string &name, const xml_node &node,
     458          76 :                                bool gen_xml, AgentUtXmlTestCase *test_case) :
     459          76 :     node_(node), name_(name), op_delete_(false), gen_xml_(gen_xml),
     460          76 :     test_case_(test_case) {
     461          76 : }
     462             : 
     463         221 : AgentUtXmlNode::~AgentUtXmlNode() {
     464         221 : }
     465             : 
     466         188 : bool AgentUtXmlNode::ReadXml() {
     467         188 :     string str;
     468         188 :     op_delete_ = false;
     469         506 :     if (GetStringAttribute(node_, "delete", &str) == true ||
     470         318 :         GetStringAttribute(node_, "del", &str) == true) {
     471          58 :         if (str != "false" && str != "0")
     472          58 :             op_delete_ = true;
     473             :     }
     474             : 
     475         188 :     return true;
     476         188 : }
     477             : 
     478         178 : void AgentUtXmlNode::ToString(string *str) {
     479         178 :     stringstream s;
     480             : 
     481         178 :     if (op_delete_)
     482          66 :         s << "Delete ";
     483             :     else
     484         112 :         s << "Add ";
     485             : 
     486         178 :     s << NodeType() << " : " << name_ << " ";
     487             : 
     488         178 :     *str += s.str();
     489         356 :     return;
     490         178 : }
     491             : 
     492             : /////////////////////////////////////////////////////////////////////////////
     493             : //  AgentUtXmlTask routines
     494             : /////////////////////////////////////////////////////////////////////////////
     495           0 : AgentUtXmlTask::AgentUtXmlTask(const xml_node &node,
     496           0 :                                AgentUtXmlTestCase *test_case) :
     497           0 :     AgentUtXmlNode("task", node, false, test_case) {
     498           0 : }
     499             : 
     500           0 : AgentUtXmlTask::~AgentUtXmlTask() {
     501           0 : }
     502             : 
     503           0 : bool AgentUtXmlTask::ReadXml() {
     504           0 :     GetStringAttribute(node(), "stop", &stop_);
     505           0 :     return true;
     506             : }
     507             : 
     508           0 : bool AgentUtXmlTask::ToXml(xml_node *parent) {
     509           0 :     return true;
     510             : }
     511             : 
     512           0 : void AgentUtXmlTask::ToString(string *str) {
     513           0 :     AgentUtXmlNode::ToString(str);
     514           0 :     stringstream s;
     515             : 
     516           0 :     s << "Stop : " << stop_ << endl;
     517           0 :     *str += s.str();
     518           0 :     return;
     519           0 : }
     520             : 
     521           0 : string AgentUtXmlTask::NodeType() {
     522           0 :     return "Task";
     523             : }
     524             : 
     525           0 : bool AgentUtXmlTask::Run() {
     526           0 :     if (boost::iequals(stop_, "1") || boost::iequals(stop_, "yes")) {
     527           0 :         TestClient::WaitForIdle();
     528           0 :         TaskScheduler::GetInstance()->Stop();
     529             :     } else {
     530           0 :         TaskScheduler::GetInstance()->Start();
     531           0 :         TestClient::WaitForIdle();
     532             :     }
     533           0 :     return true;
     534             : }
     535             : 
     536             : /////////////////////////////////////////////////////////////////////////////
     537             : //  AgentUtXmlLink routines
     538             : /////////////////////////////////////////////////////////////////////////////
     539          14 : AgentUtXmlLink::AgentUtXmlLink(const xml_node &node,
     540          14 :                                AgentUtXmlTestCase *test_case) :
     541          14 :     AgentUtXmlNode("link", node, test_case) {
     542          14 : }
     543             : 
     544          28 : AgentUtXmlLink::~AgentUtXmlLink() {
     545          28 : }
     546             : 
     547          14 : bool AgentUtXmlLink::ReadXml() {
     548          14 :     if (GetStringAttribute(node(), "left", &l_node_) == false) {
     549           0 :         cout << "Left node-type not specified for link. Skipping" << endl;
     550           0 :         return false;
     551             :     }
     552             : 
     553          14 :     if (GetStringAttribute(node(), "left-name", &l_name_) == false) {
     554           0 :         cout << "Right node-name not specified for link. Skipping" << endl;
     555           0 :         return false;
     556             :     }
     557             : 
     558          14 :     if (GetStringAttribute(node(), "right", &r_node_) == false) {
     559           0 :         cout << "Right node-type not specified for link. Skipping" << endl;
     560           0 :         return false;
     561             :     }
     562             : 
     563          14 :     if (GetStringAttribute(node(), "right-name", &r_name_) == false) {
     564           0 :         cout << "Right node-name not specified for link. Skipping" << endl;
     565           0 :         return false;
     566             :     }
     567             : 
     568          14 :     return true;
     569             : }
     570             : 
     571          14 : bool AgentUtXmlLink::ToXml(xml_node *parent) {
     572          14 :     LinkXmlNode(parent, l_node_, l_name_, r_node_, r_name_);
     573          14 :     return true;
     574             : }
     575             : 
     576          14 : void AgentUtXmlLink::ToString(string *str) {
     577          14 :     AgentUtXmlNode::ToString(str);
     578          14 :     stringstream s;
     579             : 
     580          28 :     s << "<" << l_node_ << " : " << l_name_ << "> <" << " right-node "
     581          14 :         << r_node_ << " : " << r_name_ << ">" << endl;
     582             : 
     583          14 :     *str += s.str();
     584          28 :     return;
     585          14 : }
     586             : 
     587          14 : string AgentUtXmlLink::NodeType() {
     588          14 :     return "Link";
     589             : }
     590             : 
     591             : /////////////////////////////////////////////////////////////////////////////
     592             : //  AgentUtXmlConfig routines
     593             : /////////////////////////////////////////////////////////////////////////////
     594         131 : AgentUtXmlConfig::AgentUtXmlConfig(const string &name, const uuid &id,
     595             :                                    const xml_node &node,
     596         131 :                                    AgentUtXmlTestCase *test_case) :
     597         131 :     AgentUtXmlNode(name, node, test_case), id_(id) {
     598         131 : }
     599             : 
     600           0 : AgentUtXmlConfig::AgentUtXmlConfig(const string &name, const uuid &id,
     601             :                                    const xml_node &node, bool gen_xml,
     602           0 :                                    AgentUtXmlTestCase *test_case) :
     603           0 :     AgentUtXmlNode(name, node, gen_xml, test_case), id_(id) {
     604           0 : }
     605             : 
     606         131 : AgentUtXmlConfig::~AgentUtXmlConfig() {
     607         131 : }
     608             : 
     609         131 : bool AgentUtXmlConfig::ReadXml() {
     610         131 :     return AgentUtXmlNode::ReadXml();
     611             : }
     612             : 
     613         131 : void AgentUtXmlConfig::ToString(std::string *str) {
     614         131 :     AgentUtXmlNode::ToString(str);
     615         131 :     stringstream s;
     616         131 :     s << " UUID : " << id_;
     617         131 :     *str += s.str();
     618         131 : }
     619             : 
     620          73 : static void AddPermissions(xml_node *parent) {
     621          73 :     xml_node n = parent->append_child("permissions");
     622             : 
     623          73 :     AddXmlNodeWithValue(&n, "owner", "cloud-admin");
     624          73 :     AddXmlNodeWithValue(&n, "owner-access", "7");
     625          73 :     AddXmlNodeWithValue(&n, "group", "cloud-admin-group");
     626          73 :     AddXmlNodeWithValue(&n, "group-access", "7");
     627          73 :     AddXmlNodeWithValue(&n, "other-access", "7");
     628          73 : }
     629             : 
     630          73 : static void AddUuid(xml_node *parent, const uuid &id) {
     631          73 :     xml_node n = parent->append_child("uuid");
     632             : 
     633          73 :     std::vector<uint8_t> v1(id.size());
     634          73 :     std::vector<uint64_t> v(id.size());
     635          73 :     std::copy(id.begin(), id.end(), v.begin());
     636             : 
     637          73 :     uint64_t ms_val = v[7] + (v[6] << 8) + (v[5] << 16) + (v[4] << 24) +
     638          73 :                    (v[3] << 32) + (v[2] << 40) + (v[1] << 48) + (v[0] << 56);
     639          73 :     uint64_t ls_val = v[15] + (v[14] << 8) + (v[13] << 16) + (v[12] << 24) +
     640          73 :                    (v[11] << 32) + (v[10] << 40) + (v[9] << 48) + (v[8] << 56);
     641          73 :     stringstream s;
     642          73 :     s << ms_val;
     643          73 :     AddXmlNodeWithValue(&n, "uuid-mslong", s.str());
     644             : 
     645          73 :     stringstream s1;
     646          73 :     s1 << ls_val;
     647          73 :     AddXmlNodeWithValue(&n, "uuid-lslong", s1.str());
     648          73 : }
     649             : 
     650         114 : void AgentUtXmlConfig::AddIdPerms(xml_node *parent) {
     651             : 
     652         114 :     if (op_delete())
     653          41 :         return;
     654             : 
     655          73 :     xml_node n = parent->append_child("id-perms");
     656          73 :     AddPermissions(&n);
     657          73 :     AddUuid(&n, id());
     658          73 :     AddXmlNodeWithValue(&n, "enable", "true");
     659             : }

Generated by: LCOV version 1.14