diff --git a/.drone.yml b/.drone.yml index a0b0e23..d32685d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,6 +6,7 @@ steps: - name: build image: kmaster.ti.unibw-hamburg.de:30808/debianbullseye commands: + - git submodule update --init --recursive --jobs=4 - mkdir -p build && cd build - CC=clang-11 CXX=clang++-11 cmake -DCMAKE_BUILD_TYPE=DEBUG .. - make -j diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c9a5f2b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# Set the default behavior for all files. +* text=auto eol=lf + +# Normalized and converts to native line endings on checkout. +*.c text +*.cc text +*.cxx +*.cpp text +*.h text +*.hxx text +*.hpp text diff --git a/.gitignore b/.gitignore index 87a0ee3..7450a7d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ compile_commands.json .cache .vscode config/pods +.github +.clang* +.cmake-format* +.pre-commit* +.editorconfig diff --git a/include/kubecontrol/KubePod.hpp b/include/kubecontrol/KubePod.hpp index f0c28fb..aa886e9 100644 --- a/include/kubecontrol/KubePod.hpp +++ b/include/kubecontrol/KubePod.hpp @@ -1,6 +1,6 @@ #pragma once -#include "kubecontrol/KubernetesAPI.hpp" +#include #include "nlohmann/json_fwd.hpp" #include "yaml-cpp/node/node.h" #include @@ -17,17 +17,14 @@ #include #include -#include -#include - -namespace kubecontrol +namespace kubecontrol { enum PullPolicy: uint32_t - { + { ALWAYS, IFNOTPRESENT, NEVER @@ -43,10 +40,10 @@ namespace kubecontrol case PullPolicy::NEVER: return "Never"; default: return "Always"; } - } + } + - struct PodChild { std::string UUID; @@ -55,7 +52,6 @@ namespace kubecontrol std::string Status; }; - struct PodInfos { std::string UUID; @@ -68,108 +64,109 @@ namespace kubecontrol + class KubePod { - public: - KubePod(std::string Owner, std::string Uuid, std::string ContainerImage,std::string Namespace = "simulator") ; - KubePod(std::string Owner, std::string Uuid, std::string Component, std::string ContainerImage,std::string Namespace = "simulator"); + public: + KubePod(std::string &Owner, std::string &Uuid, std::string &ContainerImage,std::string Namespace = "simulator") ; + KubePod(std::string &Owner, std::string &Uuid, std::string &Component, std::string &ContainerImage,std::string Namespace = "simulator"); /** * @brief returns the uuid of the pod - * - * @return std::string + * + * @return std::string */ std::string getUUID(); /** * @brief Get the Owner of the pods - * - * @return std::string + * + * @return std::string */ std::string getOwner(); /** * @brief Get the Ip of the pod - * - * @return std::string + * + * @return std::string */ std::string getIp(); /** - * @brief Get the Status - * - * @return std::string + * @brief Get the Status + * + * @return std::string */ std::string getStatus(); /** * @brief Set the Environment Vars for pod - * - * @param key - * @param val + * + * @param key + * @param val */ void setEnvironmentVar(std::string key, std::string val); /** - * @brief Get the Environment Vars - * - * @return std::map + * @brief Get the Environment Vars + * + * @return std::map */ std::map GetEnvironmentVars(); /** * @brief Get the Environment Var for a specific key - * + * * @param key std::string - * @return std::string + * @return std::string */ std::string GetEnvironmentVar(std::string key); /** - * @brief Set CMD args - * - * @param args + * @brief Set CMD args + * + * @param args */ - void setArgs(std::string args); + void setArgs(std::string &args); /** - * @brief Get the Args - * - * @return std::vector + * @brief Get the Args + * + * @return std::vector */ std::vector GetArgs(); - - /** - * @brief Set the Command for a pod - * - * @param command - */ - void setCommand(std::string command); /** - * @brief Get the Command - * - * @return std::string + * @brief Set the Command for a pod + * + * @param command + */ + void setCommand(std::string &command); + + /** + * @brief Get the Command + * + * @return std::string */ std::string getCommand(); /** * @brief Set the Component var for the pod - * - * @param component + * + * @param component */ - void setComponent(std::string component); + void setComponent(std::string &component); /** * @brief Get the Component var - * - * @return std::string + * + * @return std::string */ std::string getComponent(); /** * @brief add a Container to a pod - * + * * @param name std::string * @param image std::string * @param envs std::map @@ -178,17 +175,17 @@ namespace kubecontrol void addContainer(std::string name,std::string image, std::shared_ptr> envs = nullptr, PullPolicy pullPolicy = ALWAYS); /** - * @brief sets the name of the pod - * @param string - term to be displayed + * @brief sets the name of the pod + * @param string - term to be displayed */ - void setName(std::string name); + void setName(std::string &name); /** * @brief return the name of the pod * @return std::string */ std::string getName(); - + int start(KubernetesAPI APIInterface,bool WaitTillRunning = true); int stop(KubernetesAPI APIInterface); @@ -204,7 +201,7 @@ namespace kubecontrol std::vector getPodsChilds(KubernetesAPI APIInterface); - + private: static const int MaxWaitTimeInSeconds; @@ -222,11 +219,11 @@ namespace kubecontrol std::string Ip_; std::string Status_; - std::string PartOf_; + std::string PartOf_; std::vector ChildPods; std::string PodCommand_; - + YAML::Node YAMLNode_; std::map EnvirmonentVars_; @@ -236,12 +233,12 @@ namespace kubecontrol /** * @brief extracts the asked inforamtion from the kubernetes response - * - * + * + * */ int extractInformationFromResopnse(std::string response); - + }; -} \ No newline at end of file +} diff --git a/include/kubecontrol/KubernetesAPI.hpp b/include/kubecontrol/KubernetesAPI.hpp index d9783c1..5046290 100644 --- a/include/kubecontrol/KubernetesAPI.hpp +++ b/include/kubecontrol/KubernetesAPI.hpp @@ -6,11 +6,11 @@ namespace kubecontrol { -class KubernetesAPI +class KubernetesAPI { - public: + public: KubernetesAPI(); - KubernetesAPI(YAML::Node config); + explicit KubernetesAPI(YAML::Node config); KubernetesAPI(std::string APIAddress, std::string Token); @@ -32,4 +32,4 @@ class KubernetesAPI }; -} \ No newline at end of file +} diff --git a/include/kubecontrol/PodController.hpp b/include/kubecontrol/PodController.hpp index 6a96da4..83ba3d0 100644 --- a/include/kubecontrol/PodController.hpp +++ b/include/kubecontrol/PodController.hpp @@ -13,8 +13,8 @@ namespace kubecontrol class PodController { - public: - PodController(std::string pathToKubectlConfig); + public: + explicit PodController(std::string pathToKubectlConfig); std::string getServerAddress(); @@ -38,8 +38,8 @@ namespace kubecontrol PodInfos extractInfosFromKubePod(KubePod *pod); - + mutable std::mutex mx_; - + }; } // namespace ku diff --git a/include/kubecontrol/kubecontrol.hpp b/include/kubecontrol/kubecontrol.hpp index e7a0251..54d9a85 100644 --- a/include/kubecontrol/kubecontrol.hpp +++ b/include/kubecontrol/kubecontrol.hpp @@ -6,20 +6,20 @@ namespace kubecontrol { class kubecontrol { - + public: - kubecontrol(std::string pathToKubectlConfig); + explicit kubecontrol(std::string &pathToKubectlConfig); void getPods(); void startPod(); void deletePod(std::string uid); std::string createYAML(); - private: - std::string BearerToken_; - std::string ServerAddress_; - std::string NameSpace_; + private: + std::string BearerToken_; + std::string ServerAddress_; + std::string NameSpace_; }; -} \ No newline at end of file +} diff --git a/src/kubecontrol/KubePod.cpp b/src/kubecontrol/KubePod.cpp index 608259a..93775a8 100644 --- a/src/kubecontrol/KubePod.cpp +++ b/src/kubecontrol/KubePod.cpp @@ -1,5 +1,6 @@ + +#include #include "curlpp/Options.hpp" -#include "kubecontrol/PodController.hpp" #include "kubecontrol/Utils.hpp" #include "nlohmann/json_fwd.hpp" #include "yaml-cpp/binary.h" @@ -19,27 +20,30 @@ -namespace kubecontrol +namespace kubecontrol { - - KubePod::KubePod(std::string Owner, std::string Uuid, std::string ContainerImage,std::string Namespace) + + + + + KubePod::KubePod(std::string &Owner, std::string &Uuid, std::string &ContainerImage,std::string Namespace) :Owner_(Utils::to_lower(Owner)), Uuid_(Utils::to_lower(Uuid)), - Namespace_(Namespace), - EnvirmonentVars_() + ContainerRegistry_("kmaster.ti.unibw-hamburg.de:30808"), + Namespace_(Namespace) { - ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808"; + EnvirmonentVars_ = std::map(); - + this->PathToYaml_ = "config/pods/" + this->Uuid_ + ".yaml"; - if( std::filesystem::directory_entry("config").exists() != true) + if( !std::filesystem::directory_entry("config").exists()) { std::filesystem::create_directory("config"); } std::filesystem::directory_entry entry("config/pods"); - if(entry.exists() != true) + if(!entry.exists()) { std::filesystem::create_directory("config/pods"); } @@ -48,25 +52,25 @@ namespace kubecontrol } - KubePod::KubePod(std::string Owner, std::string Uuid, std::string Component, std::string ContainerImage,std::string Namespace): + KubePod::KubePod(std::string &Owner, std::string &Uuid, std::string &Component, std::string &ContainerImage,std::string Namespace): Owner_(Utils::to_lower(Owner)), Uuid_(Utils::to_lower(Uuid)), Component_(Utils::to_lower(Component)), - Namespace_(Namespace), - EnvirmonentVars_() + ContainerRegistry_("kmaster.ti.unibw-hamburg.de:30808"), + Namespace_(Namespace) { - ContainerRegistry_ = "kmaster.ti.unibw-hamburg.de:30808"; + EnvirmonentVars_ = std::map(); - + this->PathToYaml_ = "config/pods/" + this->Uuid_ + ".yaml"; - if( std::filesystem::directory_entry("config").exists() != true) + if( !std::filesystem::directory_entry("config").exists()) { std::filesystem::create_directory("config"); } std::filesystem::directory_entry entry("config/pods"); - if(entry.exists() != true) + if(!entry.exists()) { std::filesystem::create_directory("config/pods"); } @@ -80,25 +84,25 @@ namespace kubecontrol void KubePod::addContainer(std::string name,std::string image, std::shared_ptr> envs, PullPolicy pullPolicy ) { YAML::Node container; - transform(image.begin(), image.end(), image.begin(), ::tolower); - transform(name.begin(), name.end(), name.begin(), ::tolower); + transform(image.begin(), image.end(), image.begin(), ::tolower); + transform(name.begin(), name.end(), name.begin(), ::tolower); container["name"] = name+"-container"; container["image"] = this->ContainerRegistry_ + "/" + image; container["imagePullPolicy"] = toString(pullPolicy); - if (envs != nullptr) + if (envs != nullptr) { - int i = 0; + int lauf = 0; for(auto [key,value] : *envs) { - container["env"][i]["name"] = key; - container["env"][i]["value"] = value; - i++; + container["env"][lauf]["name"] = key; + container["env"][lauf]["value"] = value; + lauf++; } - - } - + + } + ContainerImages_.push_back(container); } @@ -138,12 +142,12 @@ namespace kubecontrol { if(EnvirmonentVars_.contains(key)) { return EnvirmonentVars_[key]; - } else { - return nullptr; } + return ""; + } - void KubePod::setArgs(std::string args) + void KubePod::setArgs(std::string &args) { Args_.emplace_back(Utils::to_lower(args)); } @@ -153,7 +157,7 @@ namespace kubecontrol return Args_; } - void KubePod::setCommand(std::string command) + void KubePod::setCommand(std::string &command) { PodCommand_ = Utils::to_lower(command); } @@ -163,7 +167,7 @@ namespace kubecontrol return PodCommand_; } - void KubePod::setComponent(std::string component) + void KubePod::setComponent(std::string &component) { this->Component_ = Utils::to_lower(component); } @@ -173,7 +177,7 @@ namespace kubecontrol return this->Component_; } - void KubePod::setName(std::string name) + void KubePod::setName(std::string &name) { this->Name_ = name; } @@ -200,9 +204,9 @@ namespace kubecontrol // if (!std::empty(this->Component_)) node["metadata"]["labels"]["app.kubernetes.io/component"] = this->Component_; node["metadata"]["labels"]["app.kubernetes.io/component"] = this->Component_; - - - for (int i = 0; i< this->ContainerImages_.size(); i++) + + + for (int i = 0; i< this->ContainerImages_.size(); i++) { node["spec"]["containers"][i] = this->ContainerImages_[i]; // node["spec"]["containers"][i]["name"] = this->Uuid_+"-container"; @@ -212,36 +216,36 @@ namespace kubecontrol // node["spec"]["containers"][i]["ports"][0]["protocol"] = "UDP"; - } - - + } + + int i = 0; - for (auto item :EnvirmonentVars_) { + for (const auto& item :EnvirmonentVars_) { node["spec"]["containers"][0]["env"][i]["name"] = item.first; node["spec"]["containers"][0]["env"][i]["value"] = item.second; i++; } - - if (Args_.size() > 0) + + if (!Args_.empty()) { node["spec"]["containers"][0]["args"].SetStyle(YAML::EmitterStyle::Flow); - for (auto item : Args_) { + for (const auto& item : Args_) { node["spec"]["containers"][0]["args"].push_back(item); } } - if (!PodCommand_.empty()) + if (!PodCommand_.empty()) { - + node["spec"]["containers"][0]["command"].SetStyle(YAML::EmitterStyle::Flow); node["spec"]["containers"][0]["command"].push_back(PodCommand_); } node["spec"]["terminationGracePeriodSeconds"] = 5; - + node["spec"]["restartPolicy"] = "Never"; YAMLNode_ = node; @@ -250,19 +254,19 @@ namespace kubecontrol fout << node; fout.close(); - + return this->PathToYaml_; } - + int KubePod::start(KubernetesAPI APIInterface,bool WaitTillRunning) { std::string request = "/api/v1/namespaces/simulator/pods/"; this->createYAML(); - + std::stringstream stream; stream << YAMLNode_; std::string response = APIInterface.performRequest(request,"POST",stream.str()); @@ -271,10 +275,10 @@ namespace kubecontrol auto timeoutTime = std::chrono::system_clock::now() + std::chrono::seconds(10); - if (WaitTillRunning == true ) { + if (WaitTillRunning ) { while ((this->Status_ != "Running" && this->Status_ != "Succeeded") || std::chrono::system_clock::now() >= timeoutTime) { // LOG_S(INFO)<<"wainting till running " << this->Status_; - + std::this_thread::sleep_for(std::chrono::milliseconds(100)); this->updateInfoForThisPod(APIInterface); @@ -288,15 +292,15 @@ namespace kubecontrol return 0; } - + int KubePod::stop(KubernetesAPI APIInterface) { std::string request = "/api/v1/namespaces/simulator/pods/"+Uuid_; std::string result = APIInterface.performRequest(request,"DELETE"); - LOG_S(INFO)<<"stopping: " <getPodsChilds(APIInterface); - if (uuids.size() == 0) + if (uuids.empty()) { return 1; } - for(auto i: uuids) + for(const auto& uuid: uuids) { - std::string request = "/api/v1/namespaces/simulator/pods/"+i.UUID; + std::string request = "/api/v1/namespaces/simulator/pods/"+uuid.UUID; std::string result = APIInterface.performRequest(request,"DELETE"); } return 0; - + } @@ -326,15 +330,15 @@ namespace kubecontrol { std::string request = "/api/v1/namespaces/simulator/pods/"+Uuid_+"/status"; std::string result = APIInterface.performRequest(request,"GET"); - if (result == "") + if (result.empty()) { return 1; } - - if (extractInformationFromResopnse(result)!= 0) + + if (extractInformationFromResopnse(result)!= 0) { return 1; - } + } return 0; } @@ -344,12 +348,12 @@ namespace kubecontrol std::string request = "/api/v1/namespaces/simulator/pods?labelSelector=app.kubernetes.io/part-of="+Uuid_; std::string result = APIInterface.performRequest(request,"GET"); - if (result == "") + if (result.empty()) { - return std::vector(); + return {}; } - extractInformationFromResopnse(result); + extractInformationFromResopnse(result); return this->ChildPods; } @@ -357,7 +361,7 @@ namespace kubecontrol int KubePod::extractInformationFromResopnse(std::string response) { - if (response == "") + if (response.empty()) { return 1 ; } @@ -366,16 +370,16 @@ namespace kubecontrol try { j = nlohmann::json::parse(response); if(j.contains("kind") && j["kind"] == "Pod") - { + { if( j["status"].contains("podIP")) this->Ip_ = j["status"]["podIP"].get(); this->Status_ = j["status"]["phase"].get(); this->PartOf_ = j["metadata"]["labels"]["app.kubernetes.io/part-of"]; - - }else if(j.contains("items") && j["items"].is_array()) - { - for (auto i : j["items"]) + }else if(j.contains("items") && j["items"].is_array()) + { + + for (auto i : j["items"]) { // LOG_S(INFO)<name(); @@ -398,17 +402,16 @@ namespace kubecontrol } return 0; - + } - + } - diff --git a/src/kubecontrol/kubecontrol.cpp b/src/kubecontrol/kubecontrol.cpp index 00c32b0..4ea108d 100644 --- a/src/kubecontrol/kubecontrol.cpp +++ b/src/kubecontrol/kubecontrol.cpp @@ -1,4 +1,4 @@ -#include "nlohmann/json_fwd.hpp" +#include #include "yaml-cpp/binary.h" #include "yaml-cpp/emitter.h" #include "yaml-cpp/emitterdef.h" @@ -22,7 +22,6 @@ #include -#include #include @@ -31,11 +30,11 @@ namespace kubecontrol { - - kubecontrol::kubecontrol(std::string pathToKubectlConfig) + + kubecontrol::kubecontrol(std::string &pathToKubectlConfig) { YAML::Node config = YAML::LoadFile(pathToKubectlConfig); - + BearerToken_ = config["users"][0]["user"]["token"].as(); ServerAddress_ = config["clusters"][0]["cluster"]["server"].as(); @@ -53,16 +52,16 @@ namespace kubecontrol curlpp::Cleanup cleaner; curlpp::Easy request; - + std::stringstream result; request.setOpt(cURLpp::Options::WriteStream(&result)); - request.setOpt(new curlpp::options::HttpHeader(headers)); + request.setOpt(curlpp::options::HttpHeader(headers)); - request.setOpt(new curlpp::options::Url(curlURL)); - request.setOpt(new curlpp::options::SslEngineDefault()); - request.setOpt(new curlpp::options::CaPath("config/ca.crt")); - request.setOpt(new curlpp::options::SslVerifyPeer(false)); + request.setOpt( curlpp::options::Url(curlURL)); + request.setOpt( curlpp::options::SslEngineDefault()); + request.setOpt( curlpp::options::CaPath("config/ca.crt")); + request.setOpt( curlpp::options::SslVerifyPeer(false)); // request.setOpt(new curlpp::options::Verbose(true)); @@ -71,8 +70,8 @@ namespace kubecontrol request.perform(); auto response = result.str(); - - + + auto j = nlohmann::json::parse(response); LOG_S(INFO)< headers; headers.push_back(AuthString); - headers.push_back("Content-Type: application/yaml"); + headers.emplace_back("Content-Type: application/yaml"); curlpp::Cleanup cleaner; curlpp::Easy request; - // WriterMemoryClass mWriterChunk; + // WriterMemoryClass mWriterChunk; // curlpp::types::WriteFunctionFunctor functor = std::bind(&WriterMemoryClass::WriteMemoryCallback, &mWriterChunk, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); // curlpp::options::WriteFunction *test = new curlpp::options::WriteFunction(functor); // request.setOpt(test); std::stringstream result; request.setOpt(cURLpp::Options::WriteStream(&result)); - request.setOpt(new curlpp::options::HttpHeader(headers)); + request.setOpt( curlpp::options::HttpHeader(headers)); - request.setOpt(new curlpp::options::Url(curlURL)); + request.setOpt( curlpp::options::Url(curlURL)); - request.setOpt(new curlpp::options::SslEngineDefault()); - request.setOpt(new curlpp::options::CaPath("config/ca.crt")); - request.setOpt(new curlpp::options::SslVerifyPeer(false)); + request.setOpt( curlpp::options::SslEngineDefault()); + request.setOpt( curlpp::options::CaPath("config/ca.crt")); + request.setOpt( curlpp::options::SslVerifyPeer(false)); - request.setOpt(new curlpp::options::Post(true)); + request.setOpt( curlpp::options::Post(true)); auto yaml = createYAML(); // YAML::Node node = YAML::LoadFile("config/pods_deployment.yaml"); - // YAML::Binary node = YAML::LoadFile("config/pods_deployment.yaml"); + // YAML::Binary node = YAML::LoadFile("config/pods_deployment.yaml"); // LOG_S(INFO)<< node["spec"]["containers"][0]["imagePullPolicy"]; // YAML::Binary binary = node.as(); @@ -133,14 +132,14 @@ namespace kubecontrol // read data as a block: is.read (buffer,length); - + std::istringstream myStream((std::string( buffer ))); int size = myStream.str().size(); is.close(); - request.setOpt(new curlpp::options::PostFields(buffer)); + request.setOpt( curlpp::options::PostFields(buffer)); // request.setOpt(new curlpp::options::Verbose(true)); @@ -167,21 +166,21 @@ namespace kubecontrol std::stringstream result; request.setOpt(cURLpp::Options::WriteStream(&result)); - - request.setOpt(new curlpp::options::HttpHeader(headers)); - request.setOpt(new curlpp::options::Url(curlURL)); + request.setOpt( curlpp::options::HttpHeader(headers)); + + request.setOpt( curlpp::options::Url(curlURL)); - request.setOpt(new curlpp::options::SslEngineDefault()); - request.setOpt(new curlpp::options::CaPath("config/ca.crt")); - request.setOpt(new curlpp::options::SslVerifyPeer(false)); - + request.setOpt( curlpp::options::SslEngineDefault()); + request.setOpt( curlpp::options::CaPath("config/ca.crt")); + request.setOpt( curlpp::options::SslVerifyPeer(false)); + // request.setOpt(new curlpp::options::Post(true)); // request.setOpt(new curlpp::options::PostFields("DELETE")); - request.setOpt(new curlpp::options::CustomRequest("DELETE")); + request.setOpt( curlpp::options::CustomRequest("DELETE")); // request.setOpt(new curlpp::options::Verbose(true)); @@ -195,7 +194,7 @@ namespace kubecontrol std::string kubecontrol::createYAML() { - + YAML::Node node; node["apiVersion"] = "v1"; node["kind"] = "Pod"; @@ -205,7 +204,7 @@ namespace kubecontrol node["spec"]["containers"][0]["name"] = "debug-debian-container"; node["spec"]["containers"][0]["image"] = "kmaster.ti.unibw-hamburg.de:30808/debugdebianhenry:0.1.3"; - + // node["spec"]["containers"][0]["imagePullPolicy"] = "\"Always\""; node["spec"]["containers"][0]["env"][0]["name"] = "OWN_SHIP_SERVER"; @@ -226,15 +225,15 @@ namespace kubecontrol std::ofstream fout("config/pods_deployment.yaml"); - std::stringstream ss; - ss <>(); +auto envmaps2 = std::make_shared>(); envmaps2->emplace("CONFIG", vars1.dump()); ShipPod2.addContainer("CMS", "systemprototype:latest",envmaps2); @@ -86,7 +92,7 @@ LOG_S(INFO)<<"started multi container pod"; { WHEN("constructing Track Object with data") { - + THEN("check if Track attributes are correct") { std::this_thread::sleep_for(std::chrono::milliseconds(5000)); @@ -96,11 +102,11 @@ std::this_thread::sleep_for(std::chrono::milliseconds(5000)); REQUIRE(ShipPod1.getComponent() == "ship"); REQUIRE(ShipPod1.getOwner() == "controller"); REQUIRE(ShipPod1.getStatus() == "Running"); - REQUIRE(ShipPod1.getIp() != ""); + REQUIRE(!ShipPod1.getIp().empty()); REQUIRE(ShipPod1.getPodsChilds(api).size() == 2); // REQUIRE(info1 != ""); - + ShipPod1.stop(api); @@ -111,4 +117,4 @@ std::this_thread::sleep_for(std::chrono::milliseconds(5000)); } //THEN } // WHEN } // GIVEN -} //SCENARIO \ No newline at end of file +} //SCENARIO diff --git a/tests/test_kubecontrol.cpp b/tests/test_kubecontrol.cpp index f411bf6..98882ce 100644 --- a/tests/test_kubecontrol.cpp +++ b/tests/test_kubecontrol.cpp @@ -14,23 +14,24 @@ SCENARIO("Testing the SimCore Sensor") { -kubecontrol::kubecontrol kc("../docs/config"); - + std::string file= "../docs/config"; +kubecontrol::kubecontrol kubecontroler(file); + GIVEN("different Attributes for a Track in different forms") { - kc.createYAML(); - kc.startPod(); + kubecontroler.createYAML(); + kubecontroler.startPod(); // kc.getPods(); // kc.deletePod("debug-debian"); - kc.getPods(); - + kubecontroler.getPods(); + WHEN("constructing Track Object with data") { - + THEN("check if Track attributes are correct") { REQUIRE(true == true); - + @@ -38,4 +39,4 @@ kubecontrol::kubecontrol kc("../docs/config"); } //THEN } // WHEN } // GIVEN -} //SCENARIO \ No newline at end of file +} //SCENARIO diff --git a/tests/test_massivPodHandling.cpp b/tests/test_massivPodHandling.cpp index 621805b..1c0bf61 100644 --- a/tests/test_massivPodHandling.cpp +++ b/tests/test_massivPodHandling.cpp @@ -3,6 +3,8 @@ #include "kubecontrol/KubePod.hpp" #include "nlohmann/json_fwd.hpp" +#include + #include #include #include @@ -19,7 +21,10 @@ const int podGrid = 2; void startShip(kubecontrol::PodController* podc,std::string uuid,std::string Name, std::string lat, std::string lon) { - kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator"); +std::string owner = "controller"; +std::string type = "ship"; +std::string image = "ship:latest"; + kubecontrol::KubePod ShipPod1(owner,uuid,type,image,"simulator"); nlohmann::json vars; vars["ENTITY_ID"] = uuid; @@ -37,29 +42,30 @@ void startShip(kubecontrol::PodController* podc,std::string uuid,std::string Nam vars["ENTITY_SENSORS"].push_back("radar:latest"); ShipPod1.setEnvironmentVar("CONFIG", vars.dump()); - + podc->startPod(ShipPod1); } void createScenario(kubecontrol::PodController* podc,std::vector *uuidList) { - // GeographicLib::Geodesic geod(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); + // GeographicLib::Geodesic geod(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); double lat = 54, lon = 1; int counter = 0; double distance = 10000; int rasterSize = podGrid; - for (int i = 0; i < rasterSize; i++ ) + for (int i = 0; i < rasterSize; i++ ) { double lonTmp = lon; - for (int a = 0; a < rasterSize; a++) + for (int a = 0; a < rasterSize; a++) { - + std::string name = "test"; name += std::to_string(counter); - double lat2, lon2; - // geod.Direct(lat, lonTmp, 90, distance, lat2, lon2); + double lat2 = 0; + double lon2 = 0; + // geod.Direct(lat, lonTmp, 90, distance, lat2, lon2); lat2= lat+10; // SimCore::Identifier id; // ids->push_back(id.getUUID()); @@ -79,7 +85,7 @@ void createScenario(kubecontrol::PodController* podc,std::vector *u } double lat2, lon2; - // geod.Direct(lat, lon, 0, distance, lat2, lon2); + // geod.Direct(lat, lon, 0, distance, lat2, lon2); lat = lat + 10; @@ -92,7 +98,7 @@ void createScenario(kubecontrol::PodController* podc,std::vector *u SCENARIO("Testing the SimCore Sensor") { - + // kubecontrol::PodController podc("docs/config"); auto podc = new kubecontrol::PodController("docs/config"); std::vector uuidList; @@ -121,7 +127,7 @@ std::this_thread::sleep_for(std::chrono::milliseconds(4000)); { WHEN("constructing Track Object with data") { - + THEN("check if Track attributes are correct") { auto info = podc->getInfoForPod(uuidList[random_index]); @@ -133,7 +139,7 @@ std::this_thread::sleep_for(std::chrono::milliseconds(4000)); // REQUIRE(info1 != ""); podc->stopAllPods(); - + @@ -141,4 +147,4 @@ std::this_thread::sleep_for(std::chrono::milliseconds(4000)); } //THEN } // WHEN } // GIVEN -} //SCENARIO \ No newline at end of file +} //SCENARIO diff --git a/tests/test_podcontroller.cpp b/tests/test_podcontroller.cpp index 6961082..dcc8536 100644 --- a/tests/test_podcontroller.cpp +++ b/tests/test_podcontroller.cpp @@ -3,6 +3,7 @@ #include "kubecontrol/KubePod.hpp" #include "nlohmann/json_fwd.hpp" +#include #include #define CATCH_CONFIG_MAIN #include @@ -14,12 +15,15 @@ SCENARIO("Testing the SimCore Sensor") { - + kubecontrol::PodController podc("docs/config"); std::string name = "test1"; std::string uuid = name; - kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest","simulator"); +std::string owner = "controller"; +std::string type = "ship"; +std::string image = "ship:latest"; + kubecontrol::KubePod ShipPod1(owner,uuid,type,image,"simulator"); nlohmann::json vars; vars["ENTITY_ID"] = uuid; @@ -63,9 +67,9 @@ ShipPod1.updateInfoForThisPod(podc.getKubernetesAPI()); // LOG_S(INFO)<