test qui fail à cause d'une interprétation d'empty string, à régler
This commit is contained in:
parent
49106e25f2
commit
53b8139135
@ -9,8 +9,6 @@ OBJECTS = $(patsubst %.cpp,$(BIN)/%.o,$(SRC))
|
|||||||
LIBRARIES =
|
LIBRARIES =
|
||||||
|
|
||||||
$(EXE) : $(OBJECTS)
|
$(EXE) : $(OBJECTS)
|
||||||
$(ECHO) "objects $(OBJECTS) exe $(EXE) "
|
|
||||||
|
|
||||||
$(ECHO) "-Linking $(EXE)-"
|
$(ECHO) "-Linking $(EXE)-"
|
||||||
$(GCC) -o $@ $^ $(LIBRARIES)
|
$(GCC) -o $@ $^ $(LIBRARIES)
|
||||||
|
|
||||||
|
@ -10,27 +10,7 @@
|
|||||||
//destructor, could not be inline because pure virtual
|
//destructor, could not be inline because pure virtual
|
||||||
Module::~Module(){}
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,5 @@ class Module
|
|||||||
virtual int prepare ()=0;
|
virtual int prepare ()=0;
|
||||||
virtual int deploy (Service service)=0;
|
virtual int deploy (Service service)=0;
|
||||||
virtual int clean ()=0;
|
virtual int clean ()=0;
|
||||||
//protected: commented for test purposes
|
|
||||||
virtual int isserviceOnServer();
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
@ -20,6 +20,16 @@ list<string> Service::getServers() const
|
|||||||
return servers;
|
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
|
//operator << override
|
||||||
ostream & operator << (ostream & out, const Service & s)
|
ostream & operator << (ostream & out, const Service & s)
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,7 @@ class Service {
|
|||||||
int getUserID () const;
|
int getUserID () const;
|
||||||
string getUsername() const;
|
string getUsername() const;
|
||||||
list<string> getServers() const;
|
list<string> getServers() const;
|
||||||
|
bool operator == (const Service & service) const;
|
||||||
friend ostream & operator<<(ostream & out, const Service & s);
|
friend ostream & operator<<(ostream & out, const Service & s);
|
||||||
private:
|
private:
|
||||||
int userID;
|
int userID;
|
||||||
|
@ -25,6 +25,7 @@ vector<Service> Services::getServices()const
|
|||||||
|
|
||||||
const Service* Services::findByUsername(string aUsername) const
|
const Service* Services::findByUsername(string aUsername) const
|
||||||
{
|
{
|
||||||
|
//this method may disappear. Serves development purposes for now.
|
||||||
for (const Service & service : services){
|
for (const Service & service : services){
|
||||||
if (service.getUsername().compare(aUsername)==0){
|
if (service.getUsername().compare(aUsername)==0){
|
||||||
return &service;
|
return &service;
|
||||||
@ -35,6 +36,7 @@ const Service* Services::findByUsername(string aUsername) const
|
|||||||
|
|
||||||
const Service * Services::findByID(int aUserID) const
|
const Service * Services::findByID(int aUserID) const
|
||||||
{
|
{
|
||||||
|
//this method may disappear. Serves development purposes for now.
|
||||||
for (const Service & service : services){
|
for (const Service & service : services){
|
||||||
if (service.getUserID()==aUserID){
|
if (service.getUserID()==aUserID){
|
||||||
return &service;
|
return &service;
|
||||||
@ -45,6 +47,7 @@ const Service * Services::findByID(int aUserID) const
|
|||||||
|
|
||||||
list<const Service*> Services::findByServer(string aServer) const
|
list<const Service*> Services::findByServer(string aServer) const
|
||||||
{
|
{
|
||||||
|
//this method may disappear. Serves development purposes for now.
|
||||||
list<const Service*> result;
|
list<const Service*> result;
|
||||||
for (const Service & service : services){
|
for (const Service & service : services){
|
||||||
for (string server : service.getServers()){
|
for (string server : service.getServers()){
|
||||||
@ -73,6 +76,7 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
|||||||
string server;
|
string server;
|
||||||
list <string> servers;
|
list <string> servers;
|
||||||
while(getline(streamServices,line)){
|
while(getline(streamServices,line)){
|
||||||
|
servers.clear();
|
||||||
if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account
|
if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -83,7 +87,7 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
|||||||
while(getline(streamLine,server,';')){ //extracting the server(s)
|
while(getline(streamLine,server,';')){ //extracting the server(s)
|
||||||
servers.push_back(server);
|
servers.push_back(server);
|
||||||
}
|
}
|
||||||
Service entry = {userID,username,servers};
|
Service entry = Service(userID,username,servers);
|
||||||
result.push_back(entry);
|
result.push_back(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
src/deployer
BIN
src/deployer
Binary file not shown.
33
src/main.cpp
33
src/main.cpp
@ -10,20 +10,39 @@
|
|||||||
#include "DockerModule.h"
|
#include "DockerModule.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool action_deploy=false;
|
|
||||||
bool action_remove=false;
|
|
||||||
bool all=false;
|
|
||||||
//list<Module> modules;
|
|
||||||
|
|
||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
//temporary
|
//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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
bool action_deploy=false;
|
||||||
|
bool action_remove=false;
|
||||||
|
bool all=false;
|
||||||
|
//list<Module *> modules;
|
||||||
if (argc != 3){
|
if (argc != 3){
|
||||||
cout << "Invalid number of arguments. \n" << endl;
|
cout << "Invalid number of arguments. \n" << endl;
|
||||||
help();
|
help();
|
||||||
@ -39,7 +58,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
DockerModule dmodule;
|
DockerModule dmodule;
|
||||||
dmodule.isserviceOnServer();
|
isServiceOnServer();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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
|
#2;benevoles31.karnaval.fr;max.jean-cloud.org
|
||||||
3;builder.rimarima.fr;raku.jean-cloud.org
|
3;builder.rimarima.fr;raku.jean-cloud.org
|
||||||
5;chiloe.eu;shlago.jean-cloud.org
|
5;chiloe.eu;shlago.jean-cloud.org
|
||||||
|
|
@ -9,7 +9,7 @@ $(EXE) : $(OBJECTS)
|
|||||||
$(ECHO) "-Linking $(EXE)-"
|
$(ECHO) "-Linking $(EXE)-"
|
||||||
$(GCC) -o $@ $^
|
$(GCC) -o $@ $^
|
||||||
|
|
||||||
$(OBJECTS):$(SRC)
|
./%.o:%.cpp
|
||||||
$(ECHO) "-Compilation $<- "
|
$(ECHO) "-Compilation $<- "
|
||||||
$(GCC) $(CCFLAGS) -o $@ $<
|
$(GCC) $(CCFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ vector<Service> Services::getServices()const
|
|||||||
|
|
||||||
const Service* Services::findByUsername(string aUsername) const
|
const Service* Services::findByUsername(string aUsername) const
|
||||||
{
|
{
|
||||||
|
//this method may disappear. Serves development purposes for now.
|
||||||
for (const Service & service : services){
|
for (const Service & service : services){
|
||||||
if (service.getUsername().compare(aUsername)==0){
|
if (service.getUsername().compare(aUsername)==0){
|
||||||
return &service;
|
return &service;
|
||||||
@ -35,6 +36,7 @@ const Service* Services::findByUsername(string aUsername) const
|
|||||||
|
|
||||||
const Service * Services::findByID(int aUserID) const
|
const Service * Services::findByID(int aUserID) const
|
||||||
{
|
{
|
||||||
|
//this method may disappear. Serves development purposes for now.
|
||||||
for (const Service & service : services){
|
for (const Service & service : services){
|
||||||
if (service.getUserID()==aUserID){
|
if (service.getUserID()==aUserID){
|
||||||
return &service;
|
return &service;
|
||||||
@ -45,6 +47,7 @@ const Service * Services::findByID(int aUserID) const
|
|||||||
|
|
||||||
list<const Service*> Services::findByServer(string aServer) const
|
list<const Service*> Services::findByServer(string aServer) const
|
||||||
{
|
{
|
||||||
|
//this method may disappear. Serves development purposes for now.
|
||||||
list<const Service*> result;
|
list<const Service*> result;
|
||||||
for (const Service & service : services){
|
for (const Service & service : services){
|
||||||
for (string server : service.getServers()){
|
for (string server : service.getServers()){
|
||||||
@ -73,6 +76,7 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
|||||||
string server;
|
string server;
|
||||||
list <string> servers;
|
list <string> servers;
|
||||||
while(getline(streamServices,line)){
|
while(getline(streamServices,line)){
|
||||||
|
servers.clear();
|
||||||
if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account
|
if (line.empty() || line[0] == '#') { //not taking comments and empty lines into account
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -83,7 +87,7 @@ vector <Service> Services::readServicesFromCSV (string CSV) const
|
|||||||
while(getline(streamLine,server,';')){ //extracting the server(s)
|
while(getline(streamLine,server,';')){ //extracting the server(s)
|
||||||
servers.push_back(server);
|
servers.push_back(server);
|
||||||
}
|
}
|
||||||
Service entry = {userID,username,servers};
|
Service entry = Service(userID,username,servers);
|
||||||
result.push_back(entry);
|
result.push_back(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,18 +10,28 @@ int main()
|
|||||||
vector <Service> expectedResult;
|
vector <Service> expectedResult;
|
||||||
list <string> s1={"server1","server1bis"};
|
list <string> s1={"server1","server1bis"};
|
||||||
list <string> s3={"server3"};
|
list <string> s3={"server3"};
|
||||||
list <string> s4={""};
|
list <string> s4;
|
||||||
list <string> s5={""};
|
list <string> s5;
|
||||||
list <string> s6={""};
|
list <string> s6;
|
||||||
list <string> s7={""};
|
list <string> s7;
|
||||||
list <string> s8={"server8","server8bis","server8ter"};
|
list <string> s8={"server8","server8bis","server8ter"};
|
||||||
|
|
||||||
|
string emptyUsername;
|
||||||
|
|
||||||
expectedResult.push_back(Service(1,"username1",s1));
|
expectedResult.push_back(Service(1,"username1",s1));
|
||||||
expectedResult.push_back(Service(3,"username3",s3));
|
expectedResult.push_back(Service(3,"username3",s3));
|
||||||
expectedResult.push_back(Service(4,"username4",s4));
|
expectedResult.push_back(Service(4,"username4",s4));
|
||||||
expectedResult.push_back(Service(5,"username5",s5));
|
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(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){
|
if(expectedResult==result){
|
||||||
cout << "Services test: OK" << endl;
|
cout << "Services test: OK" << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user