Specify AWS Functions as list
to conform with the yaml standard of list definition.
This commit is contained in:

committed by
Sebastian Serth

parent
d80761a973
commit
0f8a1fa25a
@ -48,8 +48,11 @@ aws:
|
||||
enabled: false
|
||||
# The endpoint of the WebSocket API
|
||||
endpoint: wss://abcdef1234.execute-api.eu-central-1.amazonaws.com/production
|
||||
# Currently, only static AWS environments are supported. You can list them here separated by spaces.
|
||||
functions: "java11Exec go118Exec"
|
||||
# Currently, only static AWS environments are supported.
|
||||
# For setting this via environment variables you have to use a string separated by spaces, like: POSEIDON_AWS_FUNCTIONS="java11Exec go118Exec".
|
||||
functions:
|
||||
- java11Exec
|
||||
- go118Exec
|
||||
|
||||
# Configuration of the logger
|
||||
logger:
|
||||
|
@ -47,7 +47,7 @@ var (
|
||||
AWS: AWS{
|
||||
Enabled: false,
|
||||
Endpoint: "",
|
||||
Functions: "",
|
||||
Functions: []string{},
|
||||
},
|
||||
Logger: logger{
|
||||
Level: "INFO",
|
||||
@ -105,7 +105,7 @@ func (n *Nomad) URL() *url.URL {
|
||||
type AWS struct {
|
||||
Enabled bool
|
||||
Endpoint string
|
||||
Functions string
|
||||
Functions []string
|
||||
}
|
||||
|
||||
// TLS configures TLS on a connection.
|
||||
@ -235,6 +235,12 @@ func loadValue(prefix string, value reflect.Value, logEntry *logrus.Entry) {
|
||||
return
|
||||
}
|
||||
value.SetBool(boolean)
|
||||
case reflect.Slice:
|
||||
if len(content) > 0 && content[0] == '"' && content[len(content)-1] == '"' {
|
||||
content = content[1 : len(content)-1] // remove wrapping quotes
|
||||
}
|
||||
parts := strings.Fields(content)
|
||||
value.Set(reflect.AppendSlice(value, reflect.ValueOf(parts)))
|
||||
default:
|
||||
// ignore this field
|
||||
logEntry.WithField("type", value.Type().Name()).
|
||||
|
@ -16,6 +16,7 @@ var (
|
||||
getServerPort = func(c *configuration) interface{} { return c.Server.Port }
|
||||
getNomadToken = func(c *configuration) interface{} { return c.Nomad.Token }
|
||||
getNomadTLSActive = func(c *configuration) interface{} { return c.Nomad.TLS.Active }
|
||||
getAWSFunctions = func(c *configuration) interface{} { return c.AWS.Functions }
|
||||
)
|
||||
|
||||
func newTestConfiguration() *configuration {
|
||||
@ -91,6 +92,7 @@ func TestReadEnvironmentVariables(t *testing.T) {
|
||||
{"NOMAD_TOKEN", "ACCESS", "ACCESS", getNomadToken},
|
||||
{"NOMAD_TLS_ACTIVE", "true", true, getNomadTLSActive},
|
||||
{"NOMAD_TLS_ACTIVE", "hello", false, getNomadTLSActive},
|
||||
{"AWS_FUNCTIONS", "java11Exec go118Exec", []string{"java11Exec", "go118Exec"}, getAWSFunctions},
|
||||
}
|
||||
prefix := "POSEIDON_TEST"
|
||||
for _, testCase := range environmentTests {
|
||||
@ -136,6 +138,8 @@ func TestReadYamlConfigFile(t *testing.T) {
|
||||
{[]byte("nomad:\n tls:\n active: true\n"), true, getNomadTLSActive},
|
||||
{[]byte(""), false, getNomadTLSActive},
|
||||
{[]byte("nomad:\n token:\n"), "SECRET", getNomadToken},
|
||||
{[]byte("aws:\n functions:\n - java11Exec\n - go118Exec\n"),
|
||||
[]string{"java11Exec", "go118Exec"}, getAWSFunctions},
|
||||
}
|
||||
for _, testCase := range yamlTests {
|
||||
config := newTestConfiguration()
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"github.com/openHPI/poseidon/internal/config"
|
||||
"github.com/openHPI/poseidon/internal/runner"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// AWSEnvironmentManager contains no functionality at the moment.
|
||||
@ -60,7 +59,7 @@ func (a *AWSEnvironmentManager) CreateOrUpdate(
|
||||
}
|
||||
|
||||
func isAWSEnvironment(request dto.ExecutionEnvironmentRequest) bool {
|
||||
for _, function := range strings.Fields(config.Config.AWS.Functions) {
|
||||
for _, function := range config.Config.AWS.Functions {
|
||||
if request.Image == function {
|
||||
return true
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ func TestAWSEnvironmentManager_CreateOrUpdate(t *testing.T) {
|
||||
uniqueImage := "java11Exec"
|
||||
|
||||
t.Run("can create default Java environment", func(t *testing.T) {
|
||||
config.Config.AWS.Functions = uniqueImage
|
||||
config.Config.AWS.Functions = []string{uniqueImage}
|
||||
_, err := m.CreateOrUpdate(tests.AnotherEnvironmentIDAsInteger, dto.ExecutionEnvironmentRequest{Image: uniqueImage})
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@ -65,7 +64,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func initAWS() {
|
||||
for i, function := range strings.Fields(config.Config.AWS.Functions) {
|
||||
for i, function := range config.Config.AWS.Functions {
|
||||
id := dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger + i + 1)
|
||||
path := helpers.BuildURL(api.BasePath, api.EnvironmentsPath, id.ToString())
|
||||
request := dto.ExecutionEnvironmentRequest{Image: function}
|
||||
|
@ -323,7 +323,7 @@ func createEnvironment(t *testing.T, environmentID string, aws bool) {
|
||||
ExposedPorts: nil,
|
||||
}
|
||||
if aws {
|
||||
functions := strings.Fields(config.Config.AWS.Functions)
|
||||
functions := config.Config.AWS.Functions
|
||||
require.NotZero(t, len(functions))
|
||||
request.Image = functions[0]
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user