[ARVADOS] updated: 2233f33d0f274e7226a4754e40c09738dfc72ca8

Git user git at public.curoverse.com
Wed Jul 27 12:01:30 EDT 2016


Summary of changes:
 .../crunch-dispatch-slurm/crunch-dispatch-slurm.go | 14 +++----
 .../crunch-dispatch-slurm_test.go                  | 48 ++++++++++------------
 2 files changed, 27 insertions(+), 35 deletions(-)

       via  2233f33d0f274e7226a4754e40c09738dfc72ca8 (commit)
      from  c78765cfbf09eea3d475f115750aecf143d313fb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 2233f33d0f274e7226a4754e40c09738dfc72ca8
Author: radhika <radhika at curoverse.com>
Date:   Wed Jul 27 11:57:59 2016 -0400

    9581: doMain calling readConfig and other test updates.

diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
index a6a1e0a..740df55 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
@@ -60,7 +60,7 @@ func doMain() error {
 	// Parse args; omit the first arg which is the command name
 	flags.Parse(os.Args[1:])
 
-	err := readConfig(config.SbatchArguments, *configPath)
+	err := readConfig(&config, *configPath)
 	if err != nil {
 		log.Printf("Error reading configuration: %v", err)
 		return err
@@ -73,13 +73,13 @@ func doMain() error {
 	}
 	arv.Retries = 25
 
-	squeueUpdater.StartMonitor(*config.PollPeriod * time.Second)
+	squeueUpdater.StartMonitor(*config.PollPeriod)
 	defer squeueUpdater.Done()
 
 	dispatcher := dispatch.Dispatcher{
 		Arv:            arv,
 		RunContainer:   run,
-		PollInterval:   *config.PollPeriod * time.Second,
+		PollInterval:   *config.PollPeriod,
 		DoneProcessing: make(chan struct{})}
 
 	err = dispatcher.RunDispatcher()
@@ -96,9 +96,7 @@ func sbatchFunc(container arvados.Container) *exec.Cmd {
 
 	var sbatchArgs []string
 	sbatchArgs = append(sbatchArgs, "--share")
-	for i := range config.SbatchArguments {
-		sbatchArgs = append(sbatchArgs, config.SbatchArguments[i])
-	}
+	sbatchArgs = append(sbatchArgs, config.SbatchArguments...)
 	sbatchArgs = append(sbatchArgs, fmt.Sprintf("--job-name=%s", container.UUID))
 	sbatchArgs = append(sbatchArgs, fmt.Sprintf("--mem-per-cpu=%d", int(memPerCPU)))
 	sbatchArgs = append(sbatchArgs, fmt.Sprintf("--cpus-per-task=%d", container.RuntimeConstraints.VCPUs))
@@ -297,8 +295,8 @@ func run(dispatcher *dispatch.Dispatcher,
 }
 
 func readConfig(dst interface{}, path string) error {
-	if buf, err := ioutil.ReadFile(path); err != nil && strings.Contains(err.Error(), "no such file") {
-		if path == defaultConfigPath || path == "" {
+	if buf, err := ioutil.ReadFile(path); err != nil && os.IsNotExist(err) {
+		if path == defaultConfigPath {
 			log.Printf("Config not specified. Continue with default configuration.")
 		} else {
 			return fmt.Errorf("Config file not found %q: %v", path, err)
diff --git a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
index 5528cb7..2da1f70 100644
--- a/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
+++ b/services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
@@ -180,7 +180,7 @@ func (s *TestSuite) integrationTest(c *C,
 	return container
 }
 
-func (s *MockArvadosServerSuite) Test_APIErrorGettingContainers(c *C) {
+func (s *MockArvadosServerSuite) TestAPIErrorGettingContainers(c *C) {
 	apiStubResponses := make(map[string]arvadostest.StubResponse)
 	apiStubResponses["/arvados/v1/api_client_authorizations/current"] = arvadostest.StubResponse{200, `{"uuid":"` + arvadostest.Dispatch1AuthUUID + `"}`}
 	apiStubResponses["/arvados/v1/containers"] = arvadostest.StubResponse{500, string(`{}`)}
@@ -238,46 +238,42 @@ func testWithServerStub(c *C, apiStubResponses map[string]arvadostest.StubRespon
 	c.Check(buf.String(), Matches, `(?ms).*`+expected+`.*`)
 }
 
-func (s *MockArvadosServerSuite) Test_EmptyConfigFile(c *C) {
+func (s *MockArvadosServerSuite) TestNoSuchConfigFile(c *C) {
 	var config Config
-
-	err := readConfig(&config.SbatchArguments, "")
-	c.Assert(err, IsNil)
+	err := readConfig(&config, "/nosuchdir89j7879/8hjwr7ojgyy7")
+	c.Assert(err, NotNil)
 }
 
-func (s *MockArvadosServerSuite) Test_NoSuchConfigFile(c *C) {
+func (s *MockArvadosServerSuite) TestBadSbatchArgsConfig(c *C) {
 	var config Config
 
-	badpath, err := arvadostest.CreateBadPath()
-	if err != nil {
-		c.Fatalf(err.Error())
-	}
-	defer func() {
-		err = arvadostest.DestroyBadPath(badpath)
-		if err != nil {
-			c.Fatalf(err.Error())
-		}
-	}()
+	tmpfile, err := ioutil.TempFile(os.TempDir(), "config")
+	c.Check(err, IsNil)
+	defer os.Remove(tmpfile.Name())
+
+	_, err = tmpfile.Write([]byte(`{"SbatchArguments": "oops this is not a string array"}`))
+	c.Check(err, IsNil)
 
-	err = readConfig(&config.SbatchArguments, badpath)
+	err = readConfig(&config, tmpfile.Name())
 	c.Assert(err, NotNil)
 }
 
-func (s *MockArvadosServerSuite) Test_BadConfig(c *C) {
+func (s *MockArvadosServerSuite) TestNoSuchArgInConfigIgnored(c *C) {
 	var config Config
 
 	tmpfile, err := ioutil.TempFile(os.TempDir(), "config")
 	c.Check(err, IsNil)
 	defer os.Remove(tmpfile.Name())
 
-	_, err = tmpfile.Write([]byte("fileContent"))
+	_, err = tmpfile.Write([]byte(`{"NoSuchArg": "Nobody loves me, not one tiny hunk."}`))
 	c.Check(err, IsNil)
 
-	err = readConfig(&config.SbatchArguments, tmpfile.Name())
-	c.Assert(err, NotNil)
+	err = readConfig(&config, tmpfile.Name())
+	c.Assert(err, IsNil)
+	c.Check(0, Equals, len(config.SbatchArguments))
 }
 
-func (s *MockArvadosServerSuite) Test_ReadConfig(c *C) {
+func (s *MockArvadosServerSuite) TestReadConfig(c *C) {
 	var config Config
 
 	tmpfile, err := ioutil.TempFile(os.TempDir(), "config")
@@ -285,14 +281,12 @@ func (s *MockArvadosServerSuite) Test_ReadConfig(c *C) {
 	defer os.Remove(tmpfile.Name())
 
 	args := []string{"--arg1=v1", "--arg2", "--arg3=v3"}
-	argsS := `["--arg1=v1",  "--arg2", "--arg3=v3"]`
+	argsS := `{"SbatchArguments": ["--arg1=v1",  "--arg2", "--arg3=v3"]}`
 	_, err = tmpfile.Write([]byte(argsS))
 	c.Check(err, IsNil)
 
-	err = readConfig(&config.SbatchArguments, tmpfile.Name())
+	err = readConfig(&config, tmpfile.Name())
 	c.Assert(err, IsNil)
 	c.Check(3, Equals, len(config.SbatchArguments))
-	for i := range args {
-		c.Check(args[i], Equals, config.SbatchArguments[i])
-	}
+	c.Check(args, DeepEquals, config.SbatchArguments)
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list