openfaas / faas-swarm

OpenFaaS provider for Docker Swarm
https://github.com/openfaas/faas
MIT License
79 stars 38 forks source link

Update status code for CRUD operations #33

Closed viveksyngh closed 5 years ago

viveksyngh commented 5 years ago

This commit updates the status code from 200 to 202 for create, update or delete APIs.

Fixes: #25

Signed-off-by: Vivek Singh vivekkmr45@yahoo.in

Description

Motivation and Context

Fixes: #25

How Has This Been Tested?

Tested on local swarm cluster.

func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:45 Forwarded [PUT] to /system/functions - [404] - 0.007258 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:45 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:45 Forwarded [POST] to /system/functions - [400] - 0.007525 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:45 Forwarded [PUT] to /system/functions - [404] - 0.003527 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:45 Forwarded [POST] to /system/functions - [400] - 0.005835 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:50 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:55 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:57 Forwarded [PUT] to /system/functions - [404] - 0.006341 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:57 Forwarded [POST] to /system/functions - [202] - 0.006329 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:57 Forwarded [PUT] to /system/functions - [404] - 0.003409 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:24:57 Forwarded [POST] to /system/functions - [202] - 0.004641 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:00 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:05 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:10 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:11 Forwarded [PUT] to /system/functions - [202] - 0.012306 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:11 Forwarded [PUT] to /system/functions - [202] - 0.006914 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:15 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:20 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:25 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:30 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:35 <nil>
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:36 Forwarded [DELETE] to /system/functions - [202] - 0.008955 seconds
func_gateway.1.kvkck8zyiva2@linuxkit-025000000001    | 2018/09/22 09:25:36 Forwarded [DELETE] to /system/functions - [202] - 0.009504 seconds
faas-cli deploy --network=func_functions
Deploying: go-hello-world.

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/go-hello-world

Deploying: python-hello-word.

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/python-hello-word

➜  of-cloud-test-fn git:(master) ✗ faas-cli deploy --network=func_functions
Deploying: go-hello-world.

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/go-hello-world

Deploying: python-hello-word.

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/python-hello-word

➜  of-cloud-test-fn git:(master) ✗ faas-cli remove
Deleting: go-hello-world.
Removing old function.
Deleting: python-hello-word.
Removing old function.

Types of changes

Checklist:

alexellis commented 5 years ago

Can you both confirm that you built and tested the code with the CLI and with the certifier?

https://github.com/openfaas/certifier

Thanks,

Alex

viveksyngh commented 5 years ago
ID                  NAME                MODE                REPLICAS            IMAGE                              PORTS
p6misxu7ccoi        func_alertmanager   replicated          1/1                 prom/alertmanager:v0.15.0
hgxwb82oe6m0        func_faas-swarm     replicated          1/1                 viveksyngh/faas-swarm:latest-dev
r0cz69k05mg7        func_gateway        replicated          1/1                 openfaas/gateway:0.9.2             *:8080->8080/tcp
zqeluv52r4lo        func_nats           replicated          1/1                 nats-streaming:0.6.0
tvalw7og8lmb        func_prometheus     replicated          1/1                 prom/prometheus:v2.3.1             *:9090->9090/tcp
vqq5i6vt5o6k        func_queue-worker   replicated          1/1                 openfaas/queue-worker:0.4.8
make test-swarm
docker service rm stronghash env-test env-test-labels env-test-annotations env-test-verbs test-secret ; docker secret rm secret-api-test-key
Error: No such service: stronghash
Error: No such service: env-test
Error: No such service: env-test-labels
Error: No such service: env-test-annotations
Error: No such service: env-test-verbs
Error: No such service: test-secret
secret-api-test-key
./create-swarm-secret.sh
y7ja308dvlwy3u8mci60a0pui
Swarm secret created
gateway_url=http://127.0.0.1:8080/ time go test -count=1 ./tests -v
=== RUN   Test_Access_Secret
=== RUN   Test_Access_Secret/Empty_QueryString
--- PASS: Test_Access_Secret (16.08s)
    --- PASS: Test_Access_Secret/Empty_QueryString (16.07s)
        verify.go:52: [1/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/test-secret
        verify.go:52: [2/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/test-secret
        verify.go:52: [3/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/test-secret
        verify.go:52: [4/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/test-secret
        verify.go:52: [5/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/test-secret
        verify.go:52: [6/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/test-secret
        verify.go:52: [7/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/test-secret
        verify.go:52: [8/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/test-secret
        verify.go:71: [9/30] Got correct response: 200 - http://127.0.0.1:8080/function/test-secret
=== RUN   Test_Deploy_Stronghash
--- PASS: Test_Deploy_Stronghash (0.01s)
=== RUN   Test_Deploy_PassingCustomEnvVars_AndQueryString
=== RUN   Test_Deploy_PassingCustomEnvVars_AndQueryString/Empty_QueryString
=== RUN   Test_Deploy_PassingCustomEnvVars_AndQueryString/Populated_QueryString
--- PASS: Test_Deploy_PassingCustomEnvVars_AndQueryString (12.07s)
    --- PASS: Test_Deploy_PassingCustomEnvVars_AndQueryString/Empty_QueryString (12.05s)
        verify.go:52: [1/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test
        verify.go:52: [2/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test
        verify.go:52: [3/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test
        verify.go:52: [4/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test
        verify.go:52: [5/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test
        verify.go:52: [6/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test
        verify.go:71: [7/30] Got correct response: 200 - http://127.0.0.1:8080/function/env-test
    --- PASS: Test_Deploy_PassingCustomEnvVars_AndQueryString/Populated_QueryString (0.00s)
        verify.go:71: [1/30] Got correct response: 200 - http://127.0.0.1:8080/function/env-test?testing=1
=== RUN   Test_Deploy_WithLabels
--- PASS: Test_Deploy_WithLabels (12.07s)
    verify.go:52: [1/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-labels
    verify.go:52: [2/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-labels
    verify.go:52: [3/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-labels
    verify.go:52: [4/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-labels
    verify.go:52: [5/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-labels
    verify.go:52: [6/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-labels
    verify.go:71: [7/30] Got correct response: 200 - http://127.0.0.1:8080/function/env-test-labels
=== RUN   Test_Deploy_WithAnnotations
--- PASS: Test_Deploy_WithAnnotations (12.07s)
    verify.go:52: [1/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-annotations
    verify.go:52: [2/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-annotations
    verify.go:52: [3/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-annotations
    verify.go:52: [4/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-annotations
    verify.go:52: [5/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-annotations
    verify.go:52: [6/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-annotations
    verify.go:71: [7/30] Got correct response: 200 - http://127.0.0.1:8080/function/env-test-annotations
=== RUN   Test_InvokeNotFound
--- PASS: Test_InvokeNotFound (0.00s)
    verify.go:71: [1/30] Got correct response: 502 - http://127.0.0.1:8080/function/notfound
=== RUN   Test_Invoke_With_Supported_Verbs
=== RUN   Test_Invoke_With_Supported_Verbs/GET
=== RUN   Test_Invoke_With_Supported_Verbs/POST
=== RUN   Test_Invoke_With_Supported_Verbs/PUT
=== RUN   Test_Invoke_With_Supported_Verbs/PATCH
=== RUN   Test_Invoke_With_Supported_Verbs/DELETE
--- PASS: Test_Invoke_With_Supported_Verbs (12.08s)
    --- PASS: Test_Invoke_With_Supported_Verbs/GET (12.06s)
        verify.go:52: [1/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-verbs
        verify.go:52: [2/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-verbs
        verify.go:52: [3/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-verbs
        verify.go:52: [4/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-verbs
        verify.go:52: [5/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-verbs
        verify.go:52: [6/30] Bad response want: [200], got: 502 - http://127.0.0.1:8080/function/env-test-verbs
        verify.go:71: [7/30] Got correct response: 200 - http://127.0.0.1:8080/function/env-test-verbs
    --- PASS: Test_Invoke_With_Supported_Verbs/POST (0.00s)
        verify.go:71: [1/30] Got correct response: 200 - http://127.0.0.1:8080/function/env-test-verbs
    --- PASS: Test_Invoke_With_Supported_Verbs/PUT (0.00s)
        verify.go:71: [1/30] Got correct response: 200 - http://127.0.0.1:8080/function/env-test-verbs
    --- PASS: Test_Invoke_With_Supported_Verbs/PATCH (0.00s)
        verify.go:71: [1/30] Got correct response: 200 - http://127.0.0.1:8080/function/env-test-verbs
    --- PASS: Test_Invoke_With_Supported_Verbs/DELETE (0.00s)
        verify.go:71: [1/30] Got correct response: 200 - http://127.0.0.1:8080/function/env-test-verbs
PASS
ok      github.com/openfaas/certifier/tests 64.422s
       65.59 real         0.60 user         0.67 sys