diff --git a/src/Makefile b/src/Makefile index 6f61f28..3a67a9f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,8 +9,6 @@ OBJECTS = $(patsubst %.cpp,$(BIN)/%.o,$(SRC)) LIBRARIES = $(EXE) : $(OBJECTS) - $(ECHO) "objects $(OBJECTS) exe $(EXE) " - $(ECHO) "-Linking $(EXE)-" $(GCC) -o $@ $^ $(LIBRARIES) diff --git a/src/Module.cpp b/src/Module.cpp index 1c36094..b1130db 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -10,27 +10,7 @@ //destructor, could not be inline because pure virtual Module::~Module(){} -//protected methods (unprotected for tests purposes) -int Module::isserviceOnServer() -//this method tests if a certain service is on the current server -//it uses the bash command dig, thanks to a pipe to a separate bash process -{ - FILE *p; - char result [100]; - - p = popen("ls -la","r"); //just to test that popen works - if( p == NULL) - { - cout << "Unable to verify if the service is on the server, bash process opening error." << endl; - return -1; - } - while(fgets(result,100,p)!=NULL){ - //if several lines, copy result somewhere to save it - cout << result << endl; - } - pclose(p); - return 0; -} + diff --git a/src/Module.h b/src/Module.h index 5a1c653..756a25b 100644 --- a/src/Module.h +++ b/src/Module.h @@ -17,7 +17,5 @@ class Module virtual int prepare ()=0; virtual int deploy (Service service)=0; virtual int clean ()=0; - //protected: commented for test purposes - virtual int isserviceOnServer(); }; #endif \ No newline at end of file diff --git a/src/Service.cpp b/src/Service.cpp index 7f3c3fd..520536f 100644 --- a/src/Service.cpp +++ b/src/Service.cpp @@ -20,6 +20,16 @@ list Service::getServers() const return servers; } +//operator == override +bool Service::operator == (const Service & service) const +{ + if (service.getServers()==servers && service.getUserID()==userID && service.getUsername()==username){ + return true; + }else{ + return false; + } +} + //operator << override ostream & operator << (ostream & out, const Service & s) { diff --git a/src/Service.h b/src/Service.h index a5c50a8..fc081af 100644 --- a/src/Service.h +++ b/src/Service.h @@ -19,6 +19,7 @@ class Service { int getUserID () const; string getUsername() const; list getServers() const; + bool operator == (const Service & service) const; friend ostream & operator<<(ostream & out, const Service & s); private: int userID; diff --git a/src/Services.cpp b/src/Services.cpp index 07b2502..03e7309 100644 --- a/src/Services.cpp +++ b/src/Services.cpp @@ -25,6 +25,7 @@ vector Services::getServices()const const Service* Services::findByUsername(string aUsername) const { + //this method may disappear. Serves development purposes for now. for (const Service & service : services){ if (service.getUsername().compare(aUsername)==0){ return &service; @@ -35,6 +36,7 @@ const Service* Services::findByUsername(string aUsername) const const Service * Services::findByID(int aUserID) const { + //this method may disappear. Serves development purposes for now. for (const Service & service : services){ if (service.getUserID()==aUserID){ return &service; @@ -45,6 +47,7 @@ const Service * Services::findByID(int aUserID) const list Services::findByServer(string aServer) const { + //this method may disappear. Serves development purposes for now. list result; for (const Service & service : services){ for (string server : service.getServers()){ @@ -73,6 +76,7 @@ vector Services::readServicesFromCSV (string CSV) const string server; list servers; while(getline(streamServices,line)){ + servers.clear(); if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account continue; } @@ -83,7 +87,7 @@ vector Services::readServicesFromCSV (string CSV) const while(getline(streamLine,server,';')){ //extracting the server(s) servers.push_back(server); } - Service entry = {userID,username,servers}; + Service entry = Service(userID,username,servers); result.push_back(entry); } } diff --git a/src/deployer b/src/deployer index c127462..e44acd3 100755 Binary files a/src/deployer and b/src/deployer differ diff --git a/src/main.cpp b/src/main.cpp index f5c9824..6eb5a74 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,20 +10,39 @@ #include "DockerModule.h" using namespace std; -bool action_deploy=false; -bool action_remove=false; -bool all=false; -//list modules; - void help() { //temporary - cout << "usage: ./deployer action file \n with action=deploy or remove and file=path to a file or all. \n" << endl; + cout << "usage: ./$argv[0] action file \n with action=deploy or remove and file=path to a file or all. \n" << endl; } +int isServiceOnServer() +//this method tests if a certain service is on the current server +//it uses the bash command dig, thanks to a pipe to a separate bash process +{ + FILE *p; + char result [100]; + + p = popen("ls -la","r"); //just to test that popen works + if( p == NULL) + { + cout << "Unable to verify if the service is on the server, bash process opening error." << endl; + return -1; + } + while(fgets(result,100,p)!=NULL){ + //if several lines, copy result somewhere to save + cout << result << endl; + } + pclose(p); + return 0; +} int main(int argc, char *argv[]) { + bool action_deploy=false; + bool action_remove=false; + bool all=false; + //list modules; if (argc != 3){ cout << "Invalid number of arguments. \n" << endl; help(); @@ -39,7 +58,7 @@ int main(int argc, char *argv[]) } DockerModule dmodule; - dmodule.isserviceOnServer(); + isServiceOnServer(); } return 0; } diff --git a/src/services.csv b/src/services.csv index 162ce54..c2deb64 100644 --- a/src/services.csv +++ b/src/services.csv @@ -1,4 +1,4 @@ -1;sftp.jean-cloud.net;raku.jean-cloud.org;pourdefaux +1;sftp.jean-cloud.net;raku.jean-cloud.org #2;benevoles31.karnaval.fr;max.jean-cloud.org 3;builder.rimarima.fr;raku.jean-cloud.org 5;chiloe.eu;shlago.jean-cloud.org diff --git a/test/ServicesTest/Makefile b/test/ServicesTest/Makefile index 7726cec..45e71fd 100644 --- a/test/ServicesTest/Makefile +++ b/test/ServicesTest/Makefile @@ -9,7 +9,7 @@ $(EXE) : $(OBJECTS) $(ECHO) "-Linking $(EXE)-" $(GCC) -o $@ $^ -$(OBJECTS):$(SRC) +./%.o:%.cpp $(ECHO) "-Compilation $<- " $(GCC) $(CCFLAGS) -o $@ $< diff --git a/test/ServicesTest/Services.cpp b/test/ServicesTest/Services.cpp index 07b2502..03e7309 100644 --- a/test/ServicesTest/Services.cpp +++ b/test/ServicesTest/Services.cpp @@ -25,6 +25,7 @@ vector Services::getServices()const const Service* Services::findByUsername(string aUsername) const { + //this method may disappear. Serves development purposes for now. for (const Service & service : services){ if (service.getUsername().compare(aUsername)==0){ return &service; @@ -35,6 +36,7 @@ const Service* Services::findByUsername(string aUsername) const const Service * Services::findByID(int aUserID) const { + //this method may disappear. Serves development purposes for now. for (const Service & service : services){ if (service.getUserID()==aUserID){ return &service; @@ -45,6 +47,7 @@ const Service * Services::findByID(int aUserID) const list Services::findByServer(string aServer) const { + //this method may disappear. Serves development purposes for now. list result; for (const Service & service : services){ for (string server : service.getServers()){ @@ -73,6 +76,7 @@ vector Services::readServicesFromCSV (string CSV) const string server; list servers; while(getline(streamServices,line)){ + servers.clear(); if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account continue; } @@ -83,7 +87,7 @@ vector Services::readServicesFromCSV (string CSV) const while(getline(streamLine,server,';')){ //extracting the server(s) servers.push_back(server); } - Service entry = {userID,username,servers}; + Service entry = Service(userID,username,servers); result.push_back(entry); } } diff --git a/test/ServicesTest/main.cpp b/test/ServicesTest/main.cpp index d12bdf0..14b654b 100644 --- a/test/ServicesTest/main.cpp +++ b/test/ServicesTest/main.cpp @@ -10,18 +10,28 @@ int main() vector expectedResult; list s1={"server1","server1bis"}; list s3={"server3"}; - list s4={""}; - list s5={""}; - list s6={""}; - list s7={""}; + list s4; + list s5; + list s6; + list s7; list s8={"server8","server8bis","server8ter"}; + string emptyUsername; + expectedResult.push_back(Service(1,"username1",s1)); expectedResult.push_back(Service(3,"username3",s3)); expectedResult.push_back(Service(4,"username4",s4)); expectedResult.push_back(Service(5,"username5",s5)); - expectedResult.push_back(Service(6,"",s6)); + expectedResult.push_back(Service(6,emptyUsername,s6)); expectedResult.push_back(Service(7,"username7",s7)); + expectedResult.push_back(Service(8,"username8",s8)); + + + if(expectedResult[4]==result[4]){ + cout << "first good" << endl; + }else{ + cout << "not good" << endl; + } if(expectedResult==result){ cout << "Services test: OK" << endl;