Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bashtub Tests Working #4586

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions buildkite/scripts/bash_tub_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -e

build_bacalhau() {
make build
}


bash_test() {
make bash-test
}


main () {
build_bacalhau
bash_test
}

main
15 changes: 8 additions & 7 deletions cmd/util/fatal.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import (
var Fatal = fatalError

func fatalError(cmd *cobra.Command, err error, code int) {
cmd.PrintErrln()
cmd.SetOut(os.Stdout)
cmd.Println()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think setting the writer here is necessary as we are already doing that in cli/root

bacalhau/cmd/cli/root.go

Lines 136 to 137 in 48dc1a7

rootCmd.SetOut(os.Stdout)
rootCmd.SetErr(os.Stderr)


var bErr bacerrors.Error
if errors.As(err, &bErr) {
// Print error message
cmd.PrintErrln(output.RedStr("Error: ") + bErr.Error())
cmd.Println(output.RedStr("Error: ") + bErr.Error())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we switching from stderr to stdout for error messages? It doesn't sound the right thing to do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed reverting it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not reverted yet!


// Print hint if available
if bErr.Hint() != "" {
cmd.PrintErrln(output.GreenStr("Hint: ") + bErr.Hint())
cmd.Println(output.GreenStr("Hint: ") + bErr.Hint())
}

// If debug mode, then print details and stack trace
Expand All @@ -37,14 +38,14 @@ func fatalError(cmd *cobra.Command, err error, code int) {
}
stackTrace := bErr.StackTrace()
if stackTrace != "" {
cmd.PrintErrln()
cmd.PrintErrln(output.YellowStr("Stack Trace:"))
cmd.PrintErrln(stackTrace)
cmd.Println()
cmd.Println(output.YellowStr("Stack Trace:"))
cmd.Println(stackTrace)
}
}

} else {
cmd.PrintErrln(output.RedStr("Error: ") + err.Error())
cmd.Println(output.RedStr("Error: ") + err.Error())
}
os.Exit(code)
}
2 changes: 1 addition & 1 deletion pkg/config/types/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

type Compute struct {
// Enabled indicates whether the compute node is active and available for job execution.
Enabled bool `yaml:"Enabled,omitempty" json:"Enabled,omitempty"`
Enabled bool `yaml:"Enabled" json:"Enabled"`
// Orchestrators specifies a list of orchestrator endpoints that this compute node connects to.
Orchestrators []string `yaml:"Orchestrators,omitempty" json:"Orchestrators,omitempty"`
// Auth specifies the authentication configuration for compute nodes to connect to the orchestrator.
Expand Down
13 changes: 12 additions & 1 deletion test/bin/bacalhau.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ clean_repo() {
create_node() {
TYPE=$1
shift 1
$BACALHAU serve --node-type=$TYPE $@ 1>$BACALHAU_DIR/out.log 2>$BACALHAU_DIR/err.log &

if [[ "$TYPE" == *","* ]]; then
# Split the types and run the command with both
IFS=',' read -ra TYPES <<< "$TYPE"
$BACALHAU serve --"${TYPES[0]}" --"${TYPES[1]}" "$@" 1>$BACALHAU_DIR/out.log 2>$BACALHAU_DIR/err.log &
echo $BACALHAU serve --"${TYPES[0]}" --"${TYPES[1]}" "$@" 1>$BACALHAU_DIR/out.log 2>$BACALHAU_DIR/err.log
else
# Run the command with the single type
$BACALHAU serve --"$TYPE" "$@" 1>$BACALHAU_DIR/out.log 2>$BACALHAU_DIR/err.log &
echo $BACALHAU serve --"$TYPE" "$@" 1>$BACALHAU_DIR/out.log 2>$BACALHAU_DIR/err.log
fi

NODE_PID=$!
RUNNING_NODES+=($NODE_PID)
{
Expand Down
10 changes: 2 additions & 8 deletions test/config_set_persistent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@ source bin/bacalhau.sh

testcase_config_set_is_persistent() {
TEST_VALUE=$RANDOM
subject bacalhau config set --config=./test-persistent.yaml 'NameProvider' $TEST_VALUE
assert_equal 0 $status

subject file ./test-persistent.yaml
touch test-persistent.yaml
subject ${BACALHAU} config set --config=./test-persistent.yaml 'NameProvider' $TEST_VALUE
assert_equal 0 $status

# Verify the contents of the config file
subject cat "./test-persistent.yaml | grep -i NameProvider"
assert_match "${TEST_VALUE}" "$stdout"
rm ./test-persistent.yaml
}




1 change: 0 additions & 1 deletion test/config_with_defaults.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ testcase_config_with__defaults() {

kill $SERVER_PID
}

3 changes: 1 addition & 2 deletions test/config_with_file.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ testcase_config_with_file() {

# These are values set in the config file
assert_match "uuid" $(echo $stdout | jq .NameProvider)
assert_match "bar" $(echo $stdout | jq .Compute.Labels.foo)
assert_match "bar" $(echo $stdout | jq .Labels.foo)

kill $SERVER_PID
}

4 changes: 2 additions & 2 deletions test/config_with_file_override.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ testcase_config_with_override_file() {
assert_match "false" $(echo $stdout | jq .Compute.Enabled)

# These are values set in the base config file that were not overridden
assert_match "bar" $(echo $stdout | jq .Compute.Labels.foo)
assert_match "bar" $(echo $stdout | jq .Labels.foo)


# This value overrides the base config
assert_match "hostname" $(echo $stdout | jq .NameProvider)

# This value is merged between the configs
assert_match "boo" $(echo $stdout | jq .Compute.Labels.buz)
assert_match "boo" $(echo $stdout | jq .Labels.buz)

kill $SERVER_PID
}
6 changes: 3 additions & 3 deletions test/config_with_file_override_and_flag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ testcase_config_with_override_config_file_and_flag() {
assert_match "hostname" $(echo $stdout | jq .NameProvider)

# overritten by the flag
assert_match "null" $(echo $stdout | jq .Compute.Labels.foo)
assert_match "null" $(echo $stdout | jq .Compute.Labels.buz)
assert_match "null" $(echo $stdout | jq .Labels.foo)
assert_match "null" $(echo $stdout | jq .Labels.buz)


# This value is merged between the configs
assert_match "banana" $(echo $stdout | jq .Compute.Labels.apple)
assert_match "banana" $(echo $stdout | jq .Labels.apple)

kill $SERVER_PID
}
7 changes: 3 additions & 4 deletions test/config_with_file_override_and_flag_and_config_flag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source bin/bacalhau.sh

testcase_config_with_override_config_file_with_api_config_flag_and_dedicated_flag() {
start_bacalhau_serve_with_config -c $ROOT/testdata/config/base.yaml -c $ROOT/testdata/config/override.yaml --web-ui=false --config webui.enabled=true
start_bacalhau_serve_with_config -c $ROOT/testdata/config/base.yaml -c $ROOT/testdata/config/override.yaml --config webui.enabled=true

subject curl -s http://localhost:1234/api/v1/agent/config
assert_equal 0 $status > /dev/null
Expand All @@ -15,18 +15,17 @@ testcase_config_with_override_config_file_with_api_config_flag_and_dedicated_fla
assert_match "false" $(echo $stdout | jq .Compute.Enabled)

# These are values set in the base config file that were not overridden
assert_match "bar" $(echo $stdout | jq .Compute.Labels.foo)
assert_match "bar" $(echo $stdout | jq .Labels.foo)


# This value overrides the base config
assert_match "hostname" $(echo $stdout | jq .NameProvider)

# This value is merged between the configs
assert_match "boo" $(echo $stdout | jq .Compute.Labels.buz)
assert_match "boo" $(echo $stdout | jq .Labels.buz)

assert_match "true" $(echo $stdout | jq .WebUI.Enabled)


kill $SERVER_PID
}

6 changes: 3 additions & 3 deletions test/errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
source bin/bacalhau.sh

testcase_ranking_failures_are_printed() {
create_node compute,requester
create_node compute,orchestrator

subject bacalhau job run $ROOT/testdata/jobs/custom-task-type.yaml
assert_match 'does not support flibble' $(echo $stderr)
subject ${BACALHAU} job run $ROOT/testdata/jobs/custom-task-type.yaml
assert_match 'does not support flibble' $(echo $stdout)
}
8 changes: 4 additions & 4 deletions test/get-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ source bin/bacalhau.sh

testcase_can_get_results() {
# Assuming create_node is a function that takes two arguments separated by space, not comma
create_node requester,compute
create_node orchestrator,compute

job_id=$(bacalhau job run --id-only $ROOT/testdata/jobs/docker-output.yaml)
bacalhau job get $job_id > /dev/null 2>&1
job_id=$(${BACALHAU} job run --id-only $ROOT/testdata/jobs/docker-output.yaml)
${BACALHAU} job get $job_id > /dev/null 2>&1
subject cat job-*/output_custom/output.txt
assert_equal 0 $status
assert_match "15" $(echo $stdout)
assert_equal '' $stderr
rm -rf job-${job_id%%-*}
}
}
6 changes: 3 additions & 3 deletions test/hello-world-docker-v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
source bin/bacalhau.sh

testcase_can_run_docker_hello_world() {
# Assuming create_node is a function that takes two arguments separated by comma, not space
# Assuming create_node is a function that takes two arguments separated by comma, not space
create_node requester,compute

subject bacalhau job run --follow $ROOT/testdata/jobs/docker-hello.yaml
subject ${BACALHAU} job run --follow $ROOT/testdata/jobs/docker-hello.yaml
assert_equal 0 $status
assert_match "Hello Bacalhau!" $(echo $stdout)
assert_equal '' $stderr
}
}
14 changes: 5 additions & 9 deletions test/labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ source bin/bacalhau.sh

run_test() {
WORD=$RANDOM
subject bacalhau config set node.labels key=value "random=$WORD"
subject ${BACALHAU} config set labels "key=value,random=$WORD"
create_node $1

# Wait for node to have published information.
subject bacalhau node list --output=json
subject ${BACALHAU} node list --output=json
while ! jq -e 'length > 0' <<< $stdout 1>/dev/null; do
sleep 0.05;
subject bacalhau node list --output=json
subject ${BACALHAU} node list --output=json
done

assert_equal 1 $(jq -rcM length <<< $stdout)
Expand All @@ -22,10 +22,6 @@ run_test() {
assert_equal $WORD $(jq -rcM '.[0].Info.Labels["random"]' <<< $stdout)
}

testcase_receive_labels_about_requester_node() {
run_test requester
}

testcase_receive_labels_about_compute_node() {
run_test requester,compute
testcase_receive_labels_about_node() {
run_test compute,orchestrator
}
6 changes: 3 additions & 3 deletions test/list_nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
source bin/bacalhau.sh

testcase_can_list_nodes_and_count() {
create_node requester,compute
create_node orchestrator,compute

subject bacalhau node list --output json
subject ${BACALHAU} node list --output json
assert_equal 0 $status
assert_match '1' $(echo $stdout | jq length)
assert_equal '' $stderr
}
}
4 changes: 2 additions & 2 deletions test/logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
source bin/bacalhau.sh

testcase_can_follow_job_logs() {
create_node requester,compute
create_node orchestrator,compute

subject bacalhau job run --follow $ROOT/testdata/jobs/wasm.yaml
subject ${BACALHAU} job run --follow $ROOT/testdata/jobs/wasm.yaml
assert_equal 0 $status
assert_match 'Hello, world!' $(echo $stdout | tail -n1)
assert_equal '' $stderr
Expand Down
45 changes: 14 additions & 31 deletions test/node_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,39 @@
source bin/bacalhau.sh

testcase_node_can_connect_without_token() {
subject bacalhau config set node.network.type nats
create_node requester
create_node orchestrator

create_node compute
# If this returns successfully, the node started and authenticated.
}

testcase_preconfigured_token_not_printed() {
subject bacalhau config set node.network.type nats
subject bacalhau config set node.network.authsecret kerfuffle
subject ${BACALHAU} config set orchestrator.auth.token kerfuffle
assert_equal 0 $status

create_node requester
assert_equal 0 $status

# check stdout
subject grep BACALHAU_NODE_NETWORK_ORCHESTRATORS $BACALHAU_DIR/out.log
assert_equal 0 $status
assert_not_match kerfuffle $stdout

# check bacalhau.run
subject grep BACALHAU_NODE_NETWORK_ORCHESTRATORS $BACALHAU_DIR/bacalhau.run
create_node orchestrator
assert_equal 0 $status
assert_not_match kerfuffle $stdout
}

testcase_node_connects_with_preconfigured_token() {
subject bacalhau config set node.network.type nats
subject bacalhau config set node.network.authsecret kerfuffle
subject ${BACALHAU} config set orchestrator.auth.token kerfuffle
assert_match 0 $status
create_node requester
create_node orchestrator

subject bacalhau config set node.network.authsecret kerfuffle
subject bacalhau config set node.network.type nats
subject ${BACALHAU} config set orchestrator.auth.token kerfuffle
create_node compute
# If this returns successfully, the node started and authenticated.
Comment on lines -39 to 28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should pass. We are setting orchestrator.auth.token which secures the orchestrator node, but not setting compute.auth.token. This is making me question if we are actually validating all the tests properly or not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not addressed yet!

}

testcase_node_connects_with_url_embedded_token() {
subject bacalhau config set node.network.type nats
subject bacalhau config set node.network.authsecret kerfuffle
subject ${BACALHAU} config set orchestrator.auth.token kerfuffle
assert_match 0 $status
create_node requester
create_node orchestrator


# remove the token from the config
subject bacalhau config set node.network.authsecret ""
subject bacalhau config set node.network.type nats
subject ${BACALHAU} config set orchestrator.auth.token ""

# add the token to the orchestrator URL
export BACALHAU_NODE_NETWORK_ORCHESTRATORS=$(echo $BACALHAU_NODE_NETWORK_ORCHESTRATORS | sed "s|nats://|nats://kerfuffle@|")
Expand All @@ -60,14 +45,12 @@ testcase_node_connects_with_url_embedded_token() {
}

testcase_node_cannot_connect_with_wrong_token() {
subject bacalhau config set node.network.type nats
subject bacalhau config set node.network.authsecret kerfuffle
subject ${BACALHAU} config set orchestrator.auth.token kerfuffle
assert_match 0 $status
create_node requester
create_node orchestrator

subject bacalhau config set node.network.type nats
subject bacalhau config set node.network.authsecret kerfalafel
subject bacalhau serve --node-type compute
export BACALHAU_DIR=$(mktemp -d)
subject ${BACALHAU} serve --compute 1>$BACALHAU_DIR/out.log 2>$BACALHAU_DIR/err.log
assert_not_equal 0 $status
assert_match "nats: Authorization Violation" $stderr
assert_match "nats: Authorization Violation" $stdout
}
Loading
Loading