summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Mazuruk <a.mazuruk@samsung.com>2018-11-23 16:32:43 +0100
committerAlexander Mazuruk <a.mazuruk@samsung.com>2018-12-11 17:59:40 +0100
commit2004de3499eb1904ab51c83c85c7d14178a8531a (patch)
tree7c5eabae4b77d6341bb9b612db287501093feebe
parent7268cf53587a7fe5269ec01c037c9666e419c15b (diff)
downloadweles-2004de3499eb1904ab51c83c85c7d14178a8531a.tar.gz
weles-2004de3499eb1904ab51c83c85c7d14178a8531a.tar.bz2
weles-2004de3499eb1904ab51c83c85c7d14178a8531a.zip
Fix linter errors
Few errors introduced while CI was off, few due to updated checkers. All fixed in this commit. Command line help message was adjusted. Additionally unified "// nolint:linter" comments - one space between text and "//", rest made as short as possible (no spaces) Verification: $ gometalinter --deadline=60s --config .gometalinter.json ./... Change-Id: Ibc18c019385bfb7207b4375d19cb5812bbbf987a Signed-off-by: Alexander Mazuruk <a.mazuruk@samsung.com>
-rw-r--r--artifactmanager.go3
-rw-r--r--artifacts/artifacts.go5
-rw-r--r--artifacts/database/database_test.go3
-rw-r--r--cmd/weles-server/main.go15
-rw-r--r--controller/boruterimpl.go7
-rw-r--r--controller/controller.go6
-rw-r--r--controller/dryaderimpl.go6
-rw-r--r--controller/jobscontroller.go2
-rw-r--r--controller/jobscontrollerimpl.go3
-rw-r--r--manager/dryad/reverse_sshfs.go6
-rw-r--r--manager/dryad/session_provider.go11
-rw-r--r--manager/dryad_job_runner_fota.go4
-rw-r--r--server/artifact_lister_handler_test.go4
-rw-r--r--server/job_lister_handler.go30
-rw-r--r--server/version_handler.go4
-rw-r--r--server/version_handler_test.go3
16 files changed, 69 insertions, 43 deletions
diff --git a/artifactmanager.go b/artifactmanager.go
index 357e066..b130386 100644
--- a/artifactmanager.go
+++ b/artifactmanager.go
@@ -23,7 +23,8 @@ package weles
// It is responsible for downloading job artifacts to ArtifactDB.
type ArtifactManager interface {
// List filters ArtifactDB and returns list of all matching artifacts.
- ListArtifact(filter ArtifactFilter, sorter ArtifactSorter, paginator ArtifactPagination) ([]ArtifactInfo, ListInfo, error) // nolint: lll
+ ListArtifact(filter ArtifactFilter, sorter ArtifactSorter, paginator ArtifactPagination,
+ ) ([]ArtifactInfo, ListInfo, error)
// Push inserts artifact to ArtifactDB and returns its path.
PushArtifact(artifact ArtifactDescription, ch chan ArtifactStatusChange) (ArtifactPath, error)
diff --git a/artifacts/artifacts.go b/artifacts/artifacts.go
index b07a130..5003898 100644
--- a/artifacts/artifacts.go
+++ b/artifacts/artifacts.go
@@ -184,6 +184,9 @@ func (s *Storage) getNewPath(ad weles.ArtifactDescription) (weles.ArtifactPath,
func (s *Storage) listenToChanges() {
for change := range s.notifier {
// Error handled in SetStatus function.
- _ = s.db.SetStatus(change) //nolint: gas, gosec
+ err := s.db.SetStatus(change)
+ if err != nil {
+ log.Println("Failed to set status of artifact.")
+ }
}
}
diff --git a/artifacts/database/database_test.go b/artifacts/database/database_test.go
index 3e45072..d1e848c 100644
--- a/artifacts/database/database_test.go
+++ b/artifacts/database/database_test.go
@@ -414,7 +414,8 @@ var _ = Describe("ArtifactDB", func() {
func(paginator weles.ArtifactPagination,
expectedResponseLength, expectedRemainingRecords int) {
- result, list, err := silverHoneybadger.Filter(emptyFilter, defaultSorter, paginator)
+ result, list, err := silverHoneybadger.Filter(
+ emptyFilter, defaultSorter, paginator)
Expect(err).ToNot(HaveOccurred())
Expect(len(result)).To(BeEquivalentTo(expectedResponseLength))
diff --git a/cmd/weles-server/main.go b/cmd/weles-server/main.go
index afc5343..1d0177b 100644
--- a/cmd/weles-server/main.go
+++ b/cmd/weles-server/main.go
@@ -91,17 +91,10 @@ func main() {
//TODO: input validation
flag.Usage = func() {
- fmt.Fprint(os.Stderr, "Usage:\n")
- fmt.Fprint(os.Stderr, " weles-server [OPTIONS]\n\n")
-
- title := "Weles"
- fmt.Fprint(os.Stderr, title+"\n\n")
- desc := "This is a Weles server. " +
- "You can find out more about Weles at [http://tbd.tbd](http://tbd.tbd)."
- if desc != "" {
- fmt.Fprintf(os.Stderr, desc+"\n\n")
- }
- fmt.Fprintln(os.Stderr, flag.CommandLine.FlagUsages())
+ _, _ = fmt.Fprint(os.Stderr,
+ `Usage: `+os.Args[0]+` [OPTIONS]
+Weles is a lightweight testing framework for Boruta, inspired by LAVA.
+You can find out more at weles.rtfd.io`+"\n\n"+flag.CommandLine.FlagUsages())
}
// parse the CLI flags
flag.Parse()
diff --git a/controller/boruterimpl.go b/controller/boruterimpl.go
index 902c58e..e9a059a 100644
--- a/controller/boruterimpl.go
+++ b/controller/boruterimpl.go
@@ -22,6 +22,7 @@ package controller
import (
"fmt"
+ "log"
"sync"
"time"
@@ -300,5 +301,9 @@ func (h *BoruterImpl) Release(j weles.JobID) {
if err != nil {
return
}
- _ = h.boruta.CloseRequest(r)
+ err = h.boruta.CloseRequest(r)
+ if err != nil {
+ log.Printf("While processing %d Job, failed to close %d request in Boruta: %s",
+ j, r, err.Error())
+ }
}
diff --git a/controller/controller.go b/controller/controller.go
index 1e83aac..50b3035 100644
--- a/controller/controller.go
+++ b/controller/controller.go
@@ -165,13 +165,15 @@ func (c *Controller) loop() {
// fail sets Job in FAILED state and if needed stops Job's execution on Dryad
// and releases Dryad to Boruta.
func (c *Controller) fail(j weles.JobID, msg string) {
- _ = c.jobs.SetStatusAndInfo(j, weles.JobStatusFAILED, msg)
+ // errors logged in the SetStatusAndInfo.
+ _ = c.jobs.SetStatusAndInfo(j, weles.JobStatusFAILED, msg) // nolint:gosec
c.dryader.CancelJob(j)
c.boruter.Release(j)
}
// succeed sets Job in COMPLETED state.
func (c *Controller) succeed(j weles.JobID) {
- _ = c.jobs.SetStatusAndInfo(j, weles.JobStatusCOMPLETED, "")
+ // errors logged in the SetStatusAndInfo.
+ _ = c.jobs.SetStatusAndInfo(j, weles.JobStatusCOMPLETED, "") // nolint:gosec
c.boruter.Release(j)
}
diff --git a/controller/dryaderimpl.go b/controller/dryaderimpl.go
index d4fd6d6..ff305cd 100644
--- a/controller/dryaderimpl.go
+++ b/controller/dryaderimpl.go
@@ -21,6 +21,7 @@ package controller
import (
"fmt"
+ "log"
"sync"
"github.com/SamsungSLAV/weles"
@@ -170,5 +171,8 @@ func (h *DryaderImpl) CancelJob(j weles.JobID) {
}
h.remove(j)
- _ = h.djm.Cancel(j)
+ err := h.djm.Cancel(j)
+ if err != nil {
+ log.Printf("Failed to cancel %d Job execution in DryadJobManager.", j)
+ }
}
diff --git a/controller/jobscontroller.go b/controller/jobscontroller.go
index 2066670..76e3b49 100644
--- a/controller/jobscontroller.go
+++ b/controller/jobscontroller.go
@@ -56,5 +56,5 @@ type JobsController interface {
// - JobPagination containing element after/before which a page should be returned. It also
// contains information about direction of pagination and the size of the returned page which
// must always be set.
- List(filter weles.JobFilter, sorter weles.JobSorter, paginator weles.JobPagination) ([]weles.JobInfo, weles.ListInfo, error) // nolint: lll
+ List(filter weles.JobFilter, sorter weles.JobSorter, paginator weles.JobPagination) ([]weles.JobInfo, weles.ListInfo, error) // nolint:lll
}
diff --git a/controller/jobscontrollerimpl.go b/controller/jobscontrollerimpl.go
index 78f4cdd..dfbdff7 100644
--- a/controller/jobscontrollerimpl.go
+++ b/controller/jobscontrollerimpl.go
@@ -396,7 +396,8 @@ func prepareFilterRegexp(arr []string) (*regexp.Regexp, error) {
var str strings.Builder
str.Grow(size)
for _, s := range arr {
- _, _ = str.WriteString("|(" + s + ")")
+ // WriteString never returns error (as of go 1.11.2) thus err is ignored.
+ _, _ = str.WriteString("|(" + s + ")") // nolint:gosec
}
return regexp.Compile(str.String()[1:])
diff --git a/manager/dryad/reverse_sshfs.go b/manager/dryad/reverse_sshfs.go
index e539aad..1a53732 100644
--- a/manager/dryad/reverse_sshfs.go
+++ b/manager/dryad/reverse_sshfs.go
@@ -66,8 +66,10 @@ func (sshfs *reverseSSHFS) open(session *ssh.Session) (err error) {
// ^log on stderr
ctx, cancel := context.WithCancel(sshfs.ctx)
- // gas/gosec returns error here about subprocess launching with variable. This is intended.
- sftp := exec.CommandContext(ctx, "/usr/lib/openssh/sftp-server", "-e", "-l", "INFO") //nolint: gas, gosec,lll
+ // gosec returns error here about subprocess launching with variable. This is intended.
+ // nolint:gosec
+ sftp := exec.CommandContext(ctx, "/usr/lib/openssh/sftp-server", "-e", "-l", "INFO")
+
session.Stdin, err = sftp.StdoutPipe()
if err != nil {
cancel()
diff --git a/manager/dryad/session_provider.go b/manager/dryad/session_provider.go
index 35d9865..7d4bcb8 100644
--- a/manager/dryad/session_provider.go
+++ b/manager/dryad/session_provider.go
@@ -50,15 +50,20 @@ type sessionProvider struct {
}
func prepareSSHConfig(userName string, key rsa.PrivateKey) *ssh.ClientConfig {
- signer, _ := ssh.NewSignerFromKey(&key)
+ signer, err := ssh.NewSignerFromKey(&key)
+ if err != nil {
+ log.Println("Failed to create signer from received ssh key.")
+ // TODO: If there is a problem with parsing ssh key, job should fail.
+ }
return &ssh.ClientConfig{
User: userName,
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
- HostKeyCallback: ssh.InsecureIgnoreHostKey(),
- Timeout: 30 * time.Second, // TODO: Use value from config when such appears.
+ // TODO: Below will accept any host key. This should change in the future.
+ HostKeyCallback: ssh.InsecureIgnoreHostKey(), // nolint:gosec
+ Timeout: 30 * time.Second, // TODO: Use value from config.
}
}
diff --git a/manager/dryad_job_runner_fota.go b/manager/dryad_job_runner_fota.go
index 1b78560..5b7ea89 100644
--- a/manager/dryad_job_runner_fota.go
+++ b/manager/dryad_job_runner_fota.go
@@ -36,6 +36,10 @@ type fotaCmd struct {
URLs []string
}
+// newFotaCmd creates new fotaCmd instance.
+// Currently it always receives same params thus nolint directive.
+// Those params should be based on job submission file.
+// nolint:unparam
func newFotaCmd(sdcard, mapping string, urls []string) *fotaCmd {
return &fotaCmd{
sdcard: sdcard,
diff --git a/server/artifact_lister_handler_test.go b/server/artifact_lister_handler_test.go
index 3103a42..c24ecb4 100644
--- a/server/artifact_lister_handler_test.go
+++ b/server/artifact_lister_handler_test.go
@@ -111,8 +111,8 @@ var _ = Describe("Listing artifacts with server initialized", func() {
// helper functions
createRequest := func(reqBody io.Reader, query, contentH, acceptH string) (req *http.Request) {
- req, err := http.NewRequest(http.MethodPost, testserver.URL+basePath+listArtifactsPath+query,
- reqBody)
+ req, err := http.NewRequest(
+ http.MethodPost, testserver.URL+basePath+listArtifactsPath+query, reqBody)
Expect(err).ToNot(HaveOccurred())
req.Header.Set("Content-Type", contentH)
req.Header.Set("Accept", acceptH)
diff --git a/server/job_lister_handler.go b/server/job_lister_handler.go
index 88bacdf..e1c7c58 100644
--- a/server/job_lister_handler.go
+++ b/server/job_lister_handler.go
@@ -18,6 +18,7 @@ import (
"time"
"github.com/go-openapi/runtime/middleware"
+ "github.com/go-openapi/strfmt"
"github.com/SamsungSLAV/weles"
"github.com/SamsungSLAV/weles/server/operations/jobs"
@@ -126,26 +127,25 @@ func responder200(listInfo weles.ListInfo, paginator weles.JobPagination,
return
}
+// normalizeDate is a helper function - adjusts 0 value to "0001-01-01T00:00:00.000Z" instead of
+// Unix 0 "1970-01-01T00:00:00.000Z". This is required by controller.
+func normalizeDate(i strfmt.DateTime) strfmt.DateTime {
+ if time.Time(i).Unix() != 0 {
+ return i
+ }
+ return strfmt.DateTime{}
+}
+
// setJobFilter adjusts filter's 0 values to be consistent and acceptable by controller.
-// This is:
-// for strfmt.DateTime elements normalizing 0 time as (0001-01-01T00:00:00.000Z) instead of
-// Unix 0- 1970-01-01T00:00:00.000Z
// Controller treats slices with 0 len as empty, slices with lenght of 1 and empty value should not
// be passed to controller.
func setJobFilter(i *weles.JobFilter) (o weles.JobFilter) {
if i != nil {
- if time.Time(i.CreatedBefore).Unix() != 0 {
- o.CreatedBefore = i.CreatedBefore
- }
- if time.Time(i.CreatedAfter).Unix() != 0 {
- o.CreatedAfter = i.CreatedAfter
- }
- if time.Time(i.UpdatedBefore).Unix() != 0 {
- o.UpdatedBefore = i.UpdatedBefore
- }
- if time.Time(i.UpdatedAfter).Unix() != 0 {
- o.UpdatedAfter = i.UpdatedAfter
- }
+ o.CreatedBefore = normalizeDate(i.CreatedBefore)
+ o.CreatedAfter = normalizeDate(i.CreatedAfter)
+ o.UpdatedBefore = normalizeDate(i.UpdatedBefore)
+ o.UpdatedAfter = normalizeDate(i.UpdatedAfter)
+
if len(i.JobID) > 0 {
if !(len(i.JobID) == 1 && i.JobID[0] == 0) {
o.JobID = i.JobID
diff --git a/server/version_handler.go b/server/version_handler.go
index 67b6427..322fa65 100644
--- a/server/version_handler.go
+++ b/server/version_handler.go
@@ -22,6 +22,10 @@ import (
)
// Version is Weles version information API endpoint handler.
+//
+// Due to go-swagger server generation, and how the API endpoint was designed, parameter to this
+// function will never be used.
+// nolint:unparam
func (a *APIDefaults) Version(params general.VersionParams) middleware.Responder {
var v = &weles.Version{
Server: weles.SrvVersion,
diff --git a/server/version_handler_test.go b/server/version_handler_test.go
index d0e02f5..f241d9b 100644
--- a/server/version_handler_test.go
+++ b/server/version_handler_test.go
@@ -63,7 +63,8 @@ var _ = Describe("VersionHandler", func() {
Expect(resp.StatusCode).To(Equal(200))
Expect(resp.Header).To(HaveKeyWithValue("Weles-Api-Version", []string{v1on010.API}))
Expect(resp.Header).To(HaveKeyWithValue("Weles-Api-State", []string{v1on010.State}))
- Expect(resp.Header).To(HaveKeyWithValue("Weles-Server-Version", []string{v1on010.Server}))
+ Expect(resp.Header).To(HaveKeyWithValue("Weles-Server-Version",
+ []string{v1on010.Server}))
respBody, err := ioutil.ReadAll(resp.Body)
Expect(err).ToNot(HaveOccurred())