Debian Codegraph @

launcher/image/test/scripts/test_launcher_workload_cloudlogging.sh

raw
1 #!/bin/bash
2 set -euo pipefail
3 source util/read_cloud_logging.sh
4
5 # Allow VM some time to boot and write to cloud logging.
6 sleep 120
7
8 # This test requires the workload to run and print
9 # corresponding messages to cloud logging.
10 CLOUD_LOGGING_OUTPUT=$(read_cloud_logging $1)
11 print_logs=false
12
13 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'Workload running'
14 then
15 echo "- workload running verified"
16 else
17 echo "FAILED: workload not running"
18 echo 'TEST FAILED.' > /workspace/status.txt
19 print_logs=true
20 fi
21
22 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'Workload args: \[/main newCmd\]'
23 then
24 echo "- arguments verified"
25 else
26 echo "FAILED: arguments not verified"
27 echo 'TEST FAILED.' > /workspace/status.txt
28 print_logs=true
29 fi
30
31 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'env_bar=val_bar'
32 then
33 echo "- env_bar env var verified"
34 else
35 echo "FAILED: env_bar env not verified"
36 echo 'TEST FAILED.' > /workspace/status.txt
37 print_logs=true
38 fi
39
40 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'ALLOWED_OVERRIDE=overridden'
41 then
42 echo "- ALLOWED_OVERRIDE env var verified"
43 else
44 echo "FAILED: ALLOWED_OVERRIDE env not verified"
45 echo 'TEST FAILED.' > /workspace/status.txt
46 print_logs=true
47 fi
48
49 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'aud: \[https://sts.googleapis.com\]'
50 then
51 echo "- token aud verified"
52 else
53 echo "FAILED: token aud not verified"
54 echo 'TEST FAILED.' > /workspace/status.txt
55 print_logs=true
56 fi
57
58 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'iss: fake-issuer-for-testing'
59 then
60 echo "- token iss verified"
61 else
62 echo "FAILED: token iss not verified"
63 echo 'TEST FAILED.' > /workspace/status.txt
64 print_logs=true
65 fi
66
67 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'secboot: true'
68 then
69 echo "- token secboot verified"
70 else
71 echo "FAILED: token secboot not verified"
72 echo 'TEST FAILED.' > /workspace/status.txt
73 print_logs=true
74 fi
75
76 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'oemid: fake-oem-id'
77 then
78 echo "- token oemid verified"
79 else
80 echo "FAILED: token oemid not verified"
81 echo 'TEST FAILED.' > /workspace/status.txt
82 print_logs=true
83 fi
84
85 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'hwmodel: fake-hw-model'
86 then
87 echo "- token hwmodel verified"
88 else
89 echo "FAILED: token hwmodel not verified"
90 echo 'TEST FAILED.' > /workspace/status.txt
91 print_logs=true
92 fi
93
94 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'swname: fake-sw-name'
95 then
96 echo "- token swname verified"
97 else
98 echo "FAILED: token swname not verified"
99 echo 'TEST FAILED.' > /workspace/status.txt
100 print_logs=true
101 fi
102
103 if echo $CLOUD_LOGGING_OUTPUT | grep -q 'Token looks okay'
104 then
105 echo "- OIDC token accessible"
106 else
107 echo "FAILED: OIDC token not accessible"
108 echo 'TEST FAILED.' > /workspace/status.txt
109 print_logs=true
110 fi
111
112 if $print_logs; then
113 echo $CLOUD_LOGGING_OUTPUT
114 fi