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

Generated by: LCOV version 1.14