Skip to content

Commit

Permalink
userdata: add tests for write_files in containers
Browse files Browse the repository at this point in the history
Since we added support for write_files in cloud-init configuration for
containers - here is a test that will check that functionality,
including whether the cloud-init config is reapplied at the containers's
reboot

Signed-off-by: Paul Gaiduk <[email protected]>
  • Loading branch information
europaul committed Nov 6, 2023
1 parent 9a9738f commit 0ffcc67
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion tests/eclient/testdata/userdata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
{{$port := "2223"}}

{{$userdata_file := "/tmp/userdata_file_eden_test"}}
{{define "ssh"}}ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no -i {{EdenConfig "eden.tests"}}/eclient/image/cert/id_rsa root@FWD_IP -p FWD_PORT{{end}}
{{define "eclient_image"}}docker://{{EdenConfig "eden.eclient.image"}}:{{EdenConfig "eden.eclient.tag"}}{{end}}

[!exec:bash] stop
[!exec:sleep] stop
[!exec:chmod] stop
[!exec:ssh] stop

exec -t 10s bash generate_file.sh

Expand All @@ -24,9 +26,28 @@ test eden.app.test -test.v -timewait 20m RUNNING eclient
exec sleep 10

eden pod delete eclient
eden network delete n1

test eden.app.test -test.v -timewait 10m - eclient

exec -t 10s bash generate_userdata.sh
eden pod deploy -n eclient --memory=512MB --networks=n1 {{template "eclient_image"}} -p {{$port}}:22 --metadata={{$userdata_file}}
test eden.app.test -test.v -timewait 20m RUNNING eclient

Check failure on line 34 in tests/eclient/testdata/userdata.txt

View workflow job for this annotation

GitHub Actions / Integration test (tpm=true;ext4)

[stdout] Docker app's state test === RUN TestAppStatus apps: '[eclient]' state: 'RUNNING' secs: 1200 time: 2023-11-06T14:59:12.786792959Z out: appName eclient state changed to UNKNOWN time: 2023-11-06T14:59:20.426970232Z out: appName eclient state changed to INITIAL time: 2023-11-06T14:59:20.426996812Z out: appName eclient state changed to RESOLVING_TAG time: 2023-11-06T14:59:24.429442125Z out: appName eclient state changed to DOWNLOAD_STARTED time: 2023-11-06T14:59:35.437896181Z out: appName eclient state changed to DOWNLOAD_STARTED (0%) time: 2023-11-06T14:59:40.441391995Z out: appName eclient state changed to DOWNLOAD_STARTED (100%) time: 2023-11-06T14:59:47.447947481Z out: appName eclient state changed to DOWNLOAD_STARTED (0%) time: 2023-11-06T15:00:01.46107602Z out: appName eclient state changed to DOWNLOAD_STARTED (2%) time: 2023-11-06T15:00:05.462971311Z out: appName eclient state changed to DOWNLOAD_STARTED (5%) time: 2023-11-06T15:00:07.464565621Z out: appName eclient state changed to DOWNLOAD_STARTED (9%) time: 2023-11-06T15:00:09.467009408Z out: appName eclient state changed to DOWNLOAD_STARTED (12%) time: 2023-11-06T15:00:12.469675101Z out: appName eclient state changed to DOWNLOAD_STARTED (34%) time: 2023-11-06T15:00:15.473014998Z out: appName eclient state changed to DOWNLOAD_STARTED (48%) time: 2023-11-06T15:00:17.474812721Z out: appName eclient state changed to DOWNLOAD_STARTED (64%) time: 2023-11-06T15:00:20.477492911Z out: appName eclient state changed to DOWNLOAD_STARTED (70%) time: 2023-11-06T15:00:21.478846327Z out: appName eclient state changed to DOWNLOAD_STARTED (76%) time: 2023-11-06T15:00:21.478892463Z out: appName eclient state changed to DOWNLOAD_STARTED (80%) time: 2023-11-06T15:00:22.479804456Z out: appName eclient state changed to DOWNLOAD_STARTED (83%) time: 2023-11-06T15:00:23.481095381Z out: appName eclient state changed to DOWNLOAD_STARTED (85%) time: 2023-11-06T15:00:24.481992413Z out: appName eclient state changed to DOWNLOAD_STARTED (90%) time: 2023-11-06T15:00:32.487019219Z out: appName eclient state changed to DOWNLOAD_STARTED (95%) time: 2023-11-06T15:00:34.489210005Z out: appName eclient state changed to DOWNLOAD_STARTED (100%) time: 2023-11-06T15:00:35.489899044Z out: appName eclient state changed to LOADING time: 2023-11-06T15:00:51.503759168Z out: appName eclient state changed to DELIVERED time: 2023-11-06T15:00:55.505701571Z out: appName eclient state changed to CREATING_VOLUME time: 2023-11-06T15:02:24.578661343Z out: appName eclient state changed to INSTALLED time: 2023-11-06T15:02:50.601434461Z out: appName eclient state changed to INSTALLED: [description:"failed to parse environment variable from cloud-init userdata: Variable \"#cloud-config\" not defined properly\nKey value pair should be delimited by \"=\"" timestamp:{seconds:1699282969 nanos:286767739} severity:SEVERITY_ERROR] time: 2023-11-06T15:03:07.613726231Z out: appName eclient state changed to INSTALLED: [description:"failed to parse environment variable from cloud-init userdata: Variable \"#cloud-config\" not defined properly\nKey value pair should be delimited by \"=\"" timestamp:{seconds:1699282986 nanos:670415006} severity:SEVERITY_ERROR] time: 2023-11-06T15:03:30.629570309Z out: appName eclient state changed to INSTALLED: [description:"failed to parse environment variable from cloud-init userdata: Variable \"#cloud-config\" not defined properly\nKey value pair should be delimited by \"=\"" timestamp:{seconds:1699283008 nanos:711739553} severity:SEVERITY_ERROR] time: 2023-11-06T15:03:55.647294774Z out: appName eclient state changed to INSTALLED: [description:"failed to parse environment variable from cloud-init userdata: Variable \"#cloud-config\" not defined properly\nKey value pair should be delimited by \"=\"" timestamp:{seconds:1699283034 nanos:433984161} severity:SEVERITY_ERROR] time: 2023-11-06T15:04:07.656313062Z out: appName eclient state changed to INSTALLED: [description:"failed to parse environment variable from cloud-init userdata: Variable \"#cloud-co

Check failure on line 34 in tests/eclient/testdata/userdata.txt

View workflow job for this annotation

GitHub Actions / Integration test (tpm=false;ext4)

[stdout] Docker app's state test === RUN TestAppStatus apps: '[eclient]' state: 'RUNNING' secs: 1200 time: 2023-11-06T14:52:47.777788908Z out: appName eclient state changed to UNKNOWN time: 2023-11-06T14:52:57.128073668Z out: appName eclient state changed to INITIAL time: 2023-11-06T14:52:58.129224003Z out: appName eclient state changed to RESOLVING_TAG time: 2023-11-06T14:53:00.130810426Z out: appName eclient state changed to DOWNLOAD_STARTED time: 2023-11-06T14:53:11.141111949Z out: appName eclient state changed to DOWNLOAD_STARTED (0%) time: 2023-11-06T14:53:15.144668631Z out: appName eclient state changed to DOWNLOAD_STARTED (100%) time: 2023-11-06T14:53:21.150704698Z out: appName eclient state changed to DOWNLOAD_STARTED (0%) time: 2023-11-06T14:53:29.160485121Z out: appName eclient state changed to DOWNLOAD_STARTED (1%) time: 2023-11-06T14:53:32.162868598Z out: appName eclient state changed to DOWNLOAD_STARTED (3%) time: 2023-11-06T14:53:35.165499311Z out: appName eclient state changed to DOWNLOAD_STARTED (8%) time: 2023-11-06T14:53:39.169630848Z out: appName eclient state changed to DOWNLOAD_STARTED (13%) time: 2023-11-06T14:53:40.170389616Z out: appName eclient state changed to DOWNLOAD_STARTED (16%) time: 2023-11-06T14:53:42.172552353Z out: appName eclient state changed to DOWNLOAD_STARTED (21%) time: 2023-11-06T14:53:44.174783883Z out: appName eclient state changed to DOWNLOAD_STARTED (36%) time: 2023-11-06T14:53:47.178205748Z out: appName eclient state changed to DOWNLOAD_STARTED (44%) time: 2023-11-06T14:53:50.180496609Z out: appName eclient state changed to DOWNLOAD_STARTED (51%) time: 2023-11-06T14:53:51.181601959Z out: appName eclient state changed to DOWNLOAD_STARTED (60%) time: 2023-11-06T14:53:52.182706975Z out: appName eclient state changed to DOWNLOAD_STARTED (69%) time: 2023-11-06T14:53:56.186840734Z out: appName eclient state changed to DOWNLOAD_STARTED (72%) time: 2023-11-06T14:53:57.18746014Z out: appName eclient state changed to DOWNLOAD_STARTED (80%) time: 2023-11-06T14:53:57.187478274Z out: appName eclient state changed to DOWNLOAD_STARTED (84%) time: 2023-11-06T14:53:59.188776867Z out: appName eclient state changed to DOWNLOAD_STARTED (86%) time: 2023-11-06T14:53:59.188798297Z out: appName eclient state changed to DOWNLOAD_STARTED (91%) time: 2023-11-06T14:54:07.196280548Z out: appName eclient state changed to DOWNLOAD_STARTED (96%) time: 2023-11-06T14:54:09.197852377Z out: appName eclient state changed to LOADING time: 2023-11-06T14:54:20.207114128Z out: appName eclient state changed to DELIVERED time: 2023-11-06T14:54:25.212592111Z out: appName eclient state changed to CREATING_VOLUME time: 2023-11-06T14:55:47.295098719Z out: appName eclient state changed to INSTALLED time: 2023-11-06T14:56:17.32270274Z out: appName eclient state changed to INSTALLED: [description:"failed to parse environment variable from cloud-init userdata: Variable \"#cloud-config\" not defined properly\nKey value pair should be delimited by \"=\"" timestamp:{seconds:1699282575 nanos:247575055} severity:SEVERITY_ERROR] time: 2023-11-06T14:56:30.335421011Z out: appName eclient state changed to INSTALLED: [description:"failed to parse environment variable from cloud-init userdata: Variable \"#cloud-config\" not defined properly\nKey value pair should be delimited by \"=\"" timestamp:{seconds:1699282589 nanos:282538116} severity:SEVERITY_ERROR] time: 2023-11-06T14:56:49.353141158Z out: appName eclient state changed to INSTALLED: [description:"failed to parse environment variable from cloud-init userdata: Variable \"#cloud-config\" not defined properly\nKey value pair should be delimited by \"=\"" timestamp:{seconds:1699282609 nanos:23413699} severity:SEVERITY_ERROR] time: 2023-11-06T14:57:03.368104555Z out: appName eclient state changed to INSTALLED: [description:"failed to parse environment variable from cloud-init userdata: Variable \"#cloud-config\" not defined properly\nKey value pair should be delimited by \"=\"" timestamp:{seconds:1699282622 nanos:180454394} severity:SEVER

exec -t 2m bash test_injected_file.sh "before_restart"

exec -t 2m bash change_injected_file.sh "after_restart"

eden pod restart eclient
test eden.app.test -test.v -timewait 20m RUNNING eclient

exec -t 2m bash test_injected_file.sh "after_restart"

eden pod delete eclient

test eden.app.test -test.v -timewait 10m - eclient

eden network delete n1

test eden.network.test -test.v -timewait 10m - n1

-- eden-config.yml --
Expand All @@ -43,3 +64,39 @@ test:
# allocate about 90014 of raw data
printf 'variable=value\n%.0s' {1..6000} >{{$userdata_file}}
printf 'variable=value' >>{{$userdata_file}}

-- generate_userdata.sh --
cat > {{$userdata_file}} <<EOF
#cloud-config
write_files:
- path: /etc/injected_file.txt
owner: root:root
permissions: '0644'
encoding:
content: before_restart
EOF

-- test_injected_file.sh --
EDEN={{EdenConfig "eden.root"}}/{{EdenConfig "eden.bin-dist"}}/{{EdenConfig "eden.eden-bin"}}
TEXT=$1

echo $EDEN sdn fwd eth0 {{$port}} -- {{template "ssh"}} grep -q $TEXT /etc/injected_file.txt

# Retry in case there are connectivity issues
for i in `seq 35`
do
echo Try $i
$EDEN sdn fwd eth0 {{$port}} -- {{template "ssh"}} grep -q $TEXT /etc/injected_file.txt && echo "Success" && break
if [ $? -eq 1 ]; then
echo "$TEXT is not present in /etc/injected_file.txt"
exit 1
fi
sleep 2
done

-- change_injected_file.sh --
EDEN={{EdenConfig "eden.root"}}/{{EdenConfig "eden.bin-dist"}}/{{EdenConfig "eden.eden-bin"}}
TEXT=$1

echo $EDEN sdn fwd eth0 {{$port}} -- {{template "ssh"}} "echo $TEXT > /etc/injected_file.txt"
$EDEN sdn fwd eth0 {{$port}} -- {{template "ssh"}} "echo $TEXT > /etc/injected_file.txt"

0 comments on commit 0ffcc67

Please sign in to comment.