Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #63 from joyent/chris/59-update-validation-endpoints
Browse files Browse the repository at this point in the history
Update Validation Endpoints
  • Loading branch information
perigrin authored Oct 2, 2020
2 parents d576612 + a517898 commit c8b6943
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 57 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ clean: ## Remove build products from bin/ and release/
.PHONY: tools
tools: ## Download and install all dev/code tools
@echo "==> Installing dev tools"
go get -u github.com/golang/dep/cmd/dep
go get -u honnef.co/go/tools/cmd/staticcheck

vendor: ## Install dependencies
dep ensure -v -vendor-only
go mod vendor

.PHONY: deps
deps: ## Update dependencies to latest version
dep ensure -v
go mod verify

.PHONY: test
test: ## Ensure that code matches best practices
staticcheck ./...
go test
go vet
TZ=UTC go test

.PHONY: help
help: ## Display this help message
Expand Down
9 changes: 6 additions & 3 deletions devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (d DetailedDevice) String() string {
RackRole RackRole
HardwareProduct HardwareProduct
Enclosures map[int]map[int]Disk
Validations ValidationStatesWithResults
Validations ValidationStateWithResults
}{d, rackRole, hp, enclosures, validations}

t, err := NewTemplate().Parse(deviceTemplate)
Expand Down Expand Up @@ -492,9 +492,12 @@ func (ds *Devices) FindByTag(key, value string) DeviceList {
/***/

// id is a string because the API accepts both a UUID and a serial number
func (ds *Devices) ValidationState(id string) (v ValidationStatesWithResults) {
func (ds *Devices) ValidationState(id string) (v ValidationStateWithResults) {
uri := fmt.Sprintf("/device/%s/validation_state", url.PathEscape(id))
res := ds.Do(ds.Sling().New().Get(uri))
res := ds.DoBadly(ds.Sling().New().Get(uri))
if res.StatusCode() == 404 {
return v
}
if ok := res.Parse(&v); !ok {
panic(res)
}
Expand Down
12 changes: 7 additions & 5 deletions devices_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestDeviceAPIIntegration(t *testing.T) {
})

t.Run("fetch device validation state", func(t *testing.T) {
defer errorHandler()

s := API.Devices().ValidationState(testDevice.ID.String())
t.Logf("got %v", s)
Expand All @@ -82,12 +83,13 @@ func TestDeviceAPIIntegration(t *testing.T) {

// GetInterface
t.Run("fetch device interface", func(t *testing.T) {
return // TODO: sort out device report submission

defer errorHandler()
// TODO: sort out device report submission
/*
defer errorHandler()
s := API.Devices().GetIPMI(testDevice.ID.String())
t.Logf("got %v", s)
s := API.Devices().GetIPMI(testDevice.ID.String())
t.Logf("got %v", s)
*/
})

t.Run("remove device", func(t *testing.T) {
Expand Down
20 changes: 8 additions & 12 deletions fixtures/conch-v3/device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1390,18 +1390,16 @@ interactions:
url: http://10.51.54.42:5000/device/dd559c03-8901-4250-9946-0cdcf00d953c/validation_state
method: GET
response:
body: '[]'
body: '{"error":"Entity Not Found"}'
headers:
Cache-Control:
- no-cache
Content-Length:
- "2"
- "28"
Content-Type:
- application/json
Date:
- Sun, 26 Jan 2020 19:04:26 GMT
Location:
- /device/dd559c03-8901-4250-9946-0cdcf00d953c
Request-Id:
- Nue0rc9wjDHk
Server:
Expand All @@ -1410,8 +1408,8 @@ interactions:
- v3.0.0-b4-0-gb99fbfff
X-Request-Id:
- Nue0rc9wjDHk
status: 200 OK
code: 200
status: 404 NOT FOUND
code: 404
duration: ""
- request:
body: ""
Expand All @@ -1422,18 +1420,16 @@ interactions:
url: http://10.51.54.42:5000/device/dd559c03-8901-4250-9946-0cdcf00d953c/validation_state
method: GET
response:
body: '[]'
body: '{"error":"Entity Not Found"}'
headers:
Cache-Control:
- no-cache
Content-Length:
- "2"
- "28"
Content-Type:
- application/json
Date:
- Sun, 26 Jan 2020 19:04:26 GMT
Location:
- /device/dd559c03-8901-4250-9946-0cdcf00d953c
Request-Id:
- ixZVfEKuJrJL
Server:
Expand All @@ -1442,8 +1438,8 @@ interactions:
- v3.0.0-b4-0-gb99fbfff
X-Request-Id:
- ixZVfEKuJrJL
status: 200 OK
code: 200
status: 404 NOT FOUND
code: 404
duration: ""
- request:
body: ""
Expand Down
17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/joyent/kosh

go 1.15

require (
github.com/bxcodec/faker v2.0.1+incompatible
github.com/davecgh/go-spew v1.1.1
github.com/dghubble/sling v1.3.0
github.com/dnaeon/go-vcr v1.0.1
github.com/gofrs/uuid v3.2.0+incompatible
github.com/jawher/mow.cli v1.1.0
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/olekukonko/tablewriter v0.0.1
github.com/qri-io/jsonschema v0.1.1
github.com/stretchr/testify v1.4.0
gopkg.in/yaml.v2 v2.2.4 // indirect
)
38 changes: 38 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40Nwln+M/+faA=
github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dghubble/sling v1.3.0 h1:pZHjCJq4zJvc6qVQ5wN1jo5oNZlNE0+8T/h0XeXBUKU=
github.com/dghubble/sling v1.3.0/go.mod h1:XXShWaBWKzNLhu2OxikSNFrlsvowtz4kyRuXUG7oQKY=
github.com/dnaeon/go-vcr v1.0.1 h1:r8L/HqC0Hje5AXMu1ooW8oyQyOFv4GxqpL0nRP7SLLY=
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/jawher/mow.cli v1.1.0 h1:NdtHXRc0CwZQ507wMvQ/IS+Q3W3x2fycn973/b8Zuk8=
github.com/jawher/mow.cli v1.1.0/go.mod h1:aNaQlc7ozF3vw6IJ2dHjp2ZFiA4ozMIYY6PyuRJwlUg=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88=
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/qri-io/jsonpointer v0.1.0 h1:OcTtTmorodUCRc2CZhj/ZwOET8zVj6uo0ArEmzoThZI=
github.com/qri-io/jsonpointer v0.1.0/go.mod h1:DnJPaYgiKu56EuDp8TU5wFLdZIcAnb/uH9v37ZaMV64=
github.com/qri-io/jsonschema v0.1.1 h1:t//Doa/gvMqJ0bDhG7PGIKfaWGGxRVaffp+bcvBGGEk=
github.com/qri-io/jsonschema v0.1.1/go.mod h1:QpzJ6gBQ0GYgGmh7mDQ1YsvvhSgE4rYj0k8t5MBOmUY=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
18 changes: 9 additions & 9 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

package main

const validationStatesWithResultsTemplate = `{{ range . }}
- ID: {{ .ID }}
Created: {{ TimeStr .Created }}
Completed: {{ TimeStr .Completed }}
Status: {{ .Status }}
Validation Plan: {{ .ValidationPlan.Name }}{{ if len .Results }}
Results:
const validationStateWithResultsTemplate = `
ID: {{ .ID }}
Created: {{ TimeStr .Created }}
Completed: {{ TimeStr .Completed }}
Status: {{ .Status }}
Validation Plan: {{ .ValidationPlan.Name }}{{ if len .Results }}
Results:
{{ .Results }}
{{ end }}{{ end }}
{{ end }}
`

const deviceTemplate = `
Expand Down
30 changes: 6 additions & 24 deletions validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,40 +226,22 @@ type ValidationStateWithResults struct {
Results ValidationResults `json:"results"`
}

type ValidationStatesWithResults []ValidationStateWithResults

func (v ValidationStatesWithResults) Len() int {
return len(v)
}

func (v ValidationStatesWithResults) Swap(i, j int) {
v[i], v[j] = v[j], v[i]
}

func (v ValidationStatesWithResults) Less(i, j int) bool {
return v[i].Created.Before(v[j].Created)
}

func (vs ValidationStatesWithResults) String() string {
sort.Sort(vs)
func (v ValidationStateWithResults) String() string {
if API.JsonOnly {
return API.AsJSON(vs)
return API.AsJSON(v)
}

type extendedVsR struct {
ValidationStateWithResults
ValidationPlan ValidationPlan `json:"-"`
}

out := make([]extendedVsR, 0)
for _, v := range vs {
out = append(out, extendedVsR{
v,
API.Validations().GetPlan(v.ValidationPlanID),
})
out := extendedVsR{
v,
API.Validations().GetPlan(v.ValidationPlanID),
}

t, err := NewTemplate().Parse(validationStatesWithResultsTemplate)
t, err := NewTemplate().Parse(validationStateWithResultsTemplate)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit c8b6943

Please sign in to comment.