From 7bc951237bbdb80566ed0e67bf85acbdff67ebdc Mon Sep 17 00:00:00 2001 From: Chris Baker Date: Thu, 20 Jun 2019 20:52:40 +0000 Subject: [PATCH 1/3] alloc lifecycle: 404 when attempting to stop non-existent allocation --- CHANGELOG.md | 1 + command/agent/alloc_endpoint.go | 11 +++++++++-- command/agent/alloc_endpoint_test.go | 13 ++++++------- nomad/alloc_endpoint.go | 4 ++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2214b1488ea..338643196c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ IMPROVEMENTS: BUG FIXES: * core: Improved job spec parsing error messages for variable interpolation failures [[GH-5844](https://github.com/hashicorp/nomad/issues/5844)] + * core: Handle error case when attempting to stop a non-existent allocation [[GH-5865](https://github.com/hashicorp/nomad/issues/5865)] * client: Fixed regression that prevented registering multiple services with the same name but different ports in Consul correctly [[GH-5829](https://github.com/hashicorp/nomad/issues/5829)] * driver: Fixed an issue preventing external driver plugins from launching executor process [[GH-5726](https://github.com/hashicorp/nomad/issues/5726)] * driver/docker: Fixed a bug mounting relative paths on Windows [[GH-5811](https://github.com/hashicorp/nomad/issues/5811)] diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index a5a7fef24d8..9c78c87496e 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -119,8 +119,15 @@ func (s *HTTPServer) allocStop(allocID string, resp http.ResponseWriter, req *ht s.parseWriteRequest(req, &sr.WriteRequest) var out structs.AllocStopResponse - err := s.agent.RPC("Alloc.Stop", &sr, &out) - return &out, err + rpcErr := s.agent.RPC("Alloc.Stop", &sr, &out) + + if rpcErr != nil { + if structs.IsErrUnknownAllocation(rpcErr) { + rpcErr = CodedError(404, allocNotFoundErr) + } + } + + return &out, rpcErr } func (s *HTTPServer) ClientAllocRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { diff --git a/command/agent/alloc_endpoint_test.go b/command/agent/alloc_endpoint_test.go index ed497a6716d..85de625f9a1 100644 --- a/command/agent/alloc_endpoint_test.go +++ b/command/agent/alloc_endpoint_test.go @@ -424,17 +424,16 @@ func TestHTTP_AllocStop(t *testing.T) { // Test that we 404 when the allocid is invalid { // Make the HTTP request - req, err := http.NewRequest("POST", "/v1/allocation/"+alloc.ID+"/stop", nil) + req, err := http.NewRequest("POST", "/v1/allocation/"+uuid.Generate()+"/stop", nil) require.NoError(err) respW := httptest.NewRecorder() // Make the request - obj, err := s.Server.AllocSpecificRequest(respW, req) - require.NoError(err) - - a := obj.(*structs.AllocStopResponse) - require.NotEmpty(a.EvalID, "missing eval") - require.NotEmpty(a.Index, "missing index") + _, err = s.Server.AllocSpecificRequest(respW, req) + require.NotNil(err) + if !strings.Contains(err.Error(), allocNotFoundErr) { + t.Fatalf("err: %v", err) + } } }) } diff --git a/nomad/alloc_endpoint.go b/nomad/alloc_endpoint.go index 491541b32c1..995ce874aa2 100644 --- a/nomad/alloc_endpoint.go +++ b/nomad/alloc_endpoint.go @@ -231,6 +231,10 @@ func (a *Alloc) Stop(args *structs.AllocStopRequest, reply *structs.AllocStopRes return err } + if alloc == nil { + return fmt.Errorf(structs.ErrUnknownAllocationPrefix) + } + eval := &structs.Evaluation{ ID: uuid.Generate(), Namespace: alloc.Namespace, From e6814c08afe92af1e3e09ae9653fd3130d5d893a Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Fri, 21 Jun 2019 14:12:28 -0500 Subject: [PATCH 2/3] Add ember-qunit-nice-errors (#5869) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This shows the entire assertion that’s failing. This is especially useful in combination with page objects. For an assertion like this: assert.equal(PageLayout.flashMessages.length, 1) The failure displayed normally is just “failed” with the expected of 1 and the result of undefined. With this addon, the expected and result remain the same, but “failed” is replaced with the text of the assertion. The typical way to address this is to supply the optional final argument to the assertion function that customises the failure message. That still works with this addon, but most of the time it becomes unnecessary. --- ui/package.json | 1 + ui/yarn.lock | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ui/package.json b/ui/package.json index b7cc42fc054..9f7e9ee36e5 100644 --- a/ui/package.json +++ b/ui/package.json @@ -75,6 +75,7 @@ "ember-moment": "^7.8.1", "ember-native-dom-helpers": "^0.5.4", "ember-power-select": "^2.2.3", + "ember-qunit-nice-errors": "^1.2.0", "ember-resolver": "^5.0.1", "ember-responsive": "^3.0.0", "ember-sinon": "^2.2.0", diff --git a/ui/yarn.lock b/ui/yarn.lock index ba69e1755b7..8d682c2b483 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -1323,6 +1323,11 @@ assign-symbols@^1.0.0: resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367" integrity sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c= +ast-types@0.10.2: + version "0.10.2" + resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.10.2.tgz#aef76a04fde54634976fc94defaad1a67e2eadb0" + integrity sha512-ufWX953VU1eIuWqxS0nRDMYlGyFH+yxln5CsmIHlpzEt3fdYqUnRtsFt0XAsQot8OaVCwFqxT1RiwvtzYjeYeg== + ast-types@0.9.6: version "0.9.6" resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.6.tgz#102c9e9e9005d3e7e3829bf0c4fa24ee862ee9b9" @@ -1415,7 +1420,7 @@ babel-code-frame@^6.26.0: esutils "^2.0.2" js-tokens "^3.0.2" -babel-core@^6.24.1, babel-core@^6.26.0, babel-core@^6.26.3: +babel-core@^6.10.4, babel-core@^6.24.1, babel-core@^6.26.0, babel-core@^6.26.3: version "6.26.3" resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.26.3.tgz#b2e2f09e342d0f0c88e2f02e067794125e75c207" integrity sha512-6jyFLuDmeidKmUEb3NM+/yawG0M2bDZ9Z1qbZP59cyHLz8kYGKYwpJP0UwUKKUiTRNvxfLesJnTedqczP7cTDA== @@ -4767,6 +4772,16 @@ ember-power-select@^2.2.3: ember-text-measurer "^0.5.0" ember-truth-helpers "^2.1.0" +ember-qunit-nice-errors@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/ember-qunit-nice-errors/-/ember-qunit-nice-errors-1.2.0.tgz#8db4468fbe761f42bec9adcddfd21efa31237267" + integrity sha512-DNvqrS6vSMf7VImW7RjlTbiUnYvyxNNeVMNBVyys7g8hgg/IqbWeXQjKUzeSp/dUbzVi9Fr/8cuLHH7S38DSOA== + dependencies: + babel-core "^6.10.4" + broccoli-persistent-filter "^1.4.3" + ember-cli-babel "^6.6.0" + recast "^0.13.0" + ember-qunit@^3.5.0: version "3.5.3" resolved "https://registry.yarnpkg.com/ember-qunit/-/ember-qunit-3.5.3.tgz#bfd0bff8298c78c77e870cca43fe0826e78a0d09" @@ -5096,7 +5111,7 @@ espree@^5.0.1: acorn-jsx "^5.0.0" eslint-visitor-keys "^1.0.0" -esprima@^4.0.0: +esprima@^4.0.0, esprima@~4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== @@ -9116,6 +9131,16 @@ recast@^0.11.3: private "~0.1.5" source-map "~0.5.0" +recast@^0.13.0: + version "0.13.2" + resolved "https://registry.yarnpkg.com/recast/-/recast-0.13.2.tgz#919e7e856d5154f13284142ed1797753c6756137" + integrity sha512-Xqo0mKljGUWGUhnkdbODk7oJGFrMcpgKQ9cCyZ4y+G9VfoTKdum8nHbf/SxIdKx5aBSZ29VpVy20bTyt7jyC8w== + dependencies: + ast-types "0.10.2" + esprima "~4.0.0" + private "~0.1.5" + source-map "~0.6.1" + redent@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/redent/-/redent-1.0.0.tgz#cf916ab1fd5f1f16dfb20822dd6ec7f730c2afde" From 96662bae97346efee71cd1d55cd707115562ab6c Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sun, 23 Jun 2019 10:31:40 -0700 Subject: [PATCH 3/3] Update website example config --- website/source/docs/configuration/index.html.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/website/source/docs/configuration/index.html.md b/website/source/docs/configuration/index.html.md index 12fdaac9859..f4596a3d8f2 100644 --- a/website/source/docs/configuration/index.html.md +++ b/website/source/docs/configuration/index.html.md @@ -59,8 +59,11 @@ server { client { enabled = true network_speed = 10 - options { - "driver.raw_exec.enable" = "1" +} + +plugin "raw_exec" { + config { + enabled = true } }