Skip to content

Commit

Permalink
BUG: AgentURL not used correctly, robust error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
segator committed Jun 17, 2021
1 parent 28a091a commit b8b70e2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion client/src/go/toscactl/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var (
}

if err=toscaProvider.RunTestSuite(*testSuiteConfig,cmd.Context());err!=nil{
log.Errorf("Error when executing Test:%s error: %v", testSuiteName,err)
log.Errorf("Error when executing TestSuite:%s, error: %v", testSuiteName,err)
os.Exit(2)
}
}
Expand Down
14 changes: 7 additions & 7 deletions client/src/go/toscactl/tosca/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ func (t *Provider) DeleteWorkspace(workspaceSessionID string ,ctx context.Contex
}

func (t *Provider) CreateProject(createProjectRequest ProjectCreateRequest,ctx context.Context) (*Workspace,error) {
provisionerURL,err:=t.getOrchestratorURL(APIworkspace)
return t.createProject(createProjectRequest, t.config.OrchestratorURL,ctx)
}

func (t *Provider) createProject(createProjectRequest ProjectCreateRequest,hostURL string,ctx context.Context) (*Workspace,error) {
provisionerURL,err:=getAPIURL(hostURL,APIworkspace)
if err!=nil{
return nil,err
}
return t.createProject(createProjectRequest, provisionerURL,ctx)
}

func (t *Provider) createProject(createProjectRequest ProjectCreateRequest,provisionerURL string,ctx context.Context) (*Workspace,error) {
if err:=checkProjectRequest(createProjectRequest);err!=nil{
return nil,err
}
Expand Down Expand Up @@ -98,9 +98,9 @@ func (t *Provider) createProject(createProjectRequest ProjectCreateRequest,provi
if err != nil {
return nil, err
}
if response.StatusCode == http.StatusInternalServerError {
if response.StatusCode != http.StatusOK {
bodyString := string(bodyBytes)
return nil, fmt.Errorf("unknown Error when creating project: %s", bodyString)
return nil, fmt.Errorf("unknown Error %d (%s) when creating project: %s", response.StatusCode,response.Status,bodyString)
}

projectCreateResponse := &ProjectCreateResponse{}
Expand Down
10 changes: 9 additions & 1 deletion client/src/go/toscactl/tosca/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ func NewProvider(config *entity.ApplicationConfig) (*Provider, error) {
}

func (t *Provider) getOrchestratorURL(URLpath string) (string,error){
u, err := url.Parse(t.config.OrchestratorURL)
return getAPIURL(t.config.OrchestratorURL,URLpath)
}

func (t *Provider) getAgentURL(config *TestExecutorConfiguration,URLpath string) (string,error){
return getAPIURL(config.hostname,URLpath)
}

func getAPIURL(HostURL string,URLpath string) (string,error){
u, err := url.Parse(HostURL)
if err!=nil{
return "",err
}
Expand Down
19 changes: 8 additions & 11 deletions client/src/go/toscactl/tosca/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,8 @@ func (t *Provider) waitUntilCompletion(ctx context.Context, executorSuiteConfig
return context.Canceled
case <-time.After(15 * time.Second):
status, err := t.checkStatus(executorSuiteConfig, ctx)
if err != nil {
log.Errorf("%v", err)
} else {
log.Infof("Execution %s is in %s state", executorSuiteConfig.executionID, status)
}
log.Infof("Execution %s is in %s state", executorSuiteConfig.executionID, status)

switch status {
case executionCompleted:
return nil
Expand All @@ -253,7 +250,7 @@ func (t *Provider) triggerExecution(testExecutorConfig *TestExecutorConfiguratio
if err!=nil{
return err
}
executionURL,err:=t.getOrchestratorURL(APIExecution)
executionURL,err:=t.getAgentURL(testExecutorConfig,APIExecution)
if err!=nil{
return err
}
Expand Down Expand Up @@ -301,7 +298,7 @@ func (t *Provider) getReports(testExecutorConfig *TestExecutorConfiguration,ctx
return t.getToscaFiles(testExecutorConfig,APIExecutionReportList,APIExecutionReport,testExecutorConfig.reportsPath,ctx)
}
func (t *Provider) getXUnit(testExecutorConfig *TestExecutorConfiguration,ctx context.Context) error {
xunitURL,err:=t.getOrchestratorURL(fmt.Sprintf(APIExecutionXUnit,testExecutorConfig.executionID))
xunitURL,err:=t.getAgentURL(testExecutorConfig,fmt.Sprintf(APIExecutionXUnit,testExecutorConfig.executionID))
if err!=nil{
return err
}
Expand All @@ -311,7 +308,7 @@ func (t *Provider) getXUnit(testExecutorConfig *TestExecutorConfiguration,ctx co
return nil
}
func (t *Provider) getToscaFiles(testExecutorConfig *TestExecutorConfiguration,urlBase string,urldownload string,outputPath string,ctx context.Context) error {
reportListURL,err:=t.getOrchestratorURL(fmt.Sprintf(urlBase,testExecutorConfig.executionID))
reportListURL,err:=t.getAgentURL(testExecutorConfig,fmt.Sprintf(urlBase,testExecutorConfig.executionID))
if err!=nil{
return err
}
Expand All @@ -337,7 +334,7 @@ func (t *Provider) getToscaFiles(testExecutorConfig *TestExecutorConfiguration,u
log.Infof("%d files found",len(executionResponse.Files))
for _,file := range executionResponse.Files {
log.Infof("Downloading %s",file.Path)
downloadURL,err:=t.getOrchestratorURL(fmt.Sprintf(urldownload,testExecutorConfig.executionID,file.Id))
downloadURL,err:=t.getAgentURL(testExecutorConfig,fmt.Sprintf(urldownload,testExecutorConfig.executionID,file.Id))
if err!=nil{
return err
}
Expand Down Expand Up @@ -375,7 +372,7 @@ func (t *Provider) prepareWorkspace(testSuiteConfig TestSuiteConfiguration,ctx c
}

func (t *Provider) checkStatus(config *TestExecutorConfiguration,ctx context.Context) (ExecutionStatus,error) {
executionStatusURL,err:=t.getOrchestratorURL(fmt.Sprintf(APIExecutionStatus,config.executionID))
executionStatusURL,err:=t.getAgentURL(config,fmt.Sprintf(APIExecutionStatus,config.executionID))
if err!=nil{
return "",err
}
Expand Down Expand Up @@ -406,7 +403,7 @@ func (t *Provider) checkStatus(config *TestExecutorConfiguration,ctx context.Con
return "",err
}
if executionResponse.Error !=""{
return "",fmt.Errorf(executionResponse.Error)
return executionFailed,fmt.Errorf(executionResponse.Error)
}

return executionResponse.Status,nil
Expand Down

0 comments on commit b8b70e2

Please sign in to comment.