|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: Simulator CI |
| 19 | + |
| 20 | +on: |
| 21 | + pull_request: |
| 22 | + |
| 23 | +concurrency: |
| 24 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} |
| 25 | + cancel-in-progress: true |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: read |
| 29 | + |
| 30 | +jobs: |
| 31 | + simulator-latest-ci: |
| 32 | + runs-on: ubuntu-24.04 |
| 33 | + timeout-minutes: 60 |
| 34 | + |
| 35 | + env: |
| 36 | + GO111MODULE: on |
| 37 | + CMK_BIN: bin/cmk |
| 38 | + CLOUDSTACK_SIM_API: http://127.0.0.1:8096/client/api |
| 39 | + CLOUDSTACK_UI_API: http://127.0.0.1:8080/client/api |
| 40 | + MAVEN_OPTS: -Xmx4096m -XX:MaxMetaspaceSize=800m -Djava.security.egd=file:/dev/urandom --add-opens=java.base/java.lang=ALL-UNNAMED --add-exports=java.base/sun.security.x509=ALL-UNNAMED --add-opens=java.base/jdk.internal.reflect=ALL-UNNAMED |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Check out CloudMonkey |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Set up Go |
| 47 | + uses: actions/setup-go@v5 |
| 48 | + with: |
| 49 | + go-version: '1.22' |
| 50 | + |
| 51 | + - name: Build cmk |
| 52 | + run: | |
| 53 | + make run |
| 54 | +
|
| 55 | + - name: Fetch latest CloudStack release tag |
| 56 | + id: csrel |
| 57 | + run: | |
| 58 | + TAG=$(curl -s https://api.github.com/repos/apache/cloudstack/releases/latest | jq -r .tag_name) |
| 59 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 60 | + echo "Latest CloudStack tag: $TAG" |
| 61 | +
|
| 62 | + - name: Clone CloudStack at latest release |
| 63 | + run: | |
| 64 | + git clone --depth=1 --branch "${{ steps.csrel.outputs.tag }}" https://github.com/apache/cloudstack.git |
| 65 | +
|
| 66 | + - name: Set up JDK 11 + Maven cache |
| 67 | + uses: actions/setup-java@v4 |
| 68 | + with: |
| 69 | + java-version: '11' |
| 70 | + distribution: 'temurin' |
| 71 | + cache: maven |
| 72 | + cache-dependency-path: cloudstack/pom.xml |
| 73 | + |
| 74 | + - name: Set up Python 3.10 |
| 75 | + uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: '3.10' |
| 78 | + |
| 79 | + - name: Install OS deps |
| 80 | + run: | |
| 81 | + sudo apt-get update |
| 82 | + sudo apt-get install -y \ |
| 83 | + mysql-server uuid-runtime genisoimage netcat-openbsd ipmitool \ |
| 84 | + build-essential libgcrypt20 libgpg-error-dev libgpg-error0 \ |
| 85 | + libopenipmi0 libssl-dev jq curl |
| 86 | +
|
| 87 | + - name: Install Python deps |
| 88 | + run: | |
| 89 | + python3 -m pip install --upgrade pip |
| 90 | + python3 -m pip install --user urllib3 lxml paramiko nose texttable ipmisim pyopenssl pycryptodome mock flask netaddr pylint pycodestyle six astroid mysql-connector-python |
| 91 | +
|
| 92 | + - name: Setup MySQL Server |
| 93 | + run: | |
| 94 | + # https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2004-Readme.md#mysql |
| 95 | + sudo systemctl start mysql |
| 96 | + sudo mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''; FLUSH PRIVILEGES;" |
| 97 | + sudo systemctl restart mysql |
| 98 | + sudo mysql -uroot -e "SELECT VERSION();" |
| 99 | +
|
| 100 | + - name: Build CloudStack (simulator) |
| 101 | + working-directory: cloudstack |
| 102 | + run: | |
| 103 | + mvn -B -P developer,systemvm -Dsimulator clean install -DskipTests=true -T$(nproc) |
| 104 | +
|
| 105 | + - name: Deploy simulator DB + marvin |
| 106 | + working-directory: cloudstack |
| 107 | + run: | |
| 108 | + mvn -q -Pdeveloper -pl developer -Ddeploydb |
| 109 | + mvn -q -Pdeveloper -pl developer -Ddeploydb-simulator |
| 110 | + python3 -m pip install --user --upgrade tools/marvin/dist/Marvin-*.tar.gz |
| 111 | +
|
| 112 | + - name: Start CloudStack mgmt (Jetty) in background |
| 113 | + id: start_ms |
| 114 | + working-directory: cloudstack |
| 115 | + run: | |
| 116 | + set -euo pipefail |
| 117 | + LOG=/tmp/jetty-log.txt |
| 118 | + mvn -Dsimulator -Dorg.eclipse.jetty.annotations.maxWait=120 -pl :cloud-client-ui jetty:run > "$LOG" 2>&1 & |
| 119 | + JETTY_PID=$! |
| 120 | + echo "$JETTY_PID" > /tmp/jetty.pid |
| 121 | + echo "Waiting for simulator API @ 8096…" |
| 122 | + for i in $(seq 1 60); do |
| 123 | + if nc -z 127.0.0.1 8096; then |
| 124 | + echo "Simulator API is up." |
| 125 | + break |
| 126 | + fi |
| 127 | + sleep 5 |
| 128 | + tail -n 50 "$LOG" || true |
| 129 | + if ! kill -0 "$JETTY_PID" 2>/dev/null; then |
| 130 | + echo "Jetty exited early. Last 200 lines:" |
| 131 | + tail -n 200 "$LOG" || true |
| 132 | + exit 1 |
| 133 | + fi |
| 134 | + done |
| 135 | +
|
| 136 | + - name: Deploy Advanced Zone via Marvin |
| 137 | + working-directory: cloudstack |
| 138 | + run: | |
| 139 | + python3 tools/marvin/marvin/deployDataCenter.py -i setup/dev/advdualzone.cfg |
| 140 | +
|
| 141 | + - name: Configure cmk profile |
| 142 | + run: | |
| 143 | + "${CMK_BIN}" set profile simulator |
| 144 | + "${CMK_BIN}" set url "${CLOUDSTACK_UI_API}" |
| 145 | + "${CMK_BIN}" set output json |
| 146 | +
|
| 147 | + - name: API discovery parity (curl vs cmk) |
| 148 | + run: | |
| 149 | + CURL_COUNT=$(curl -s "${CLOUDSTACK_SIM_API}?command=listApis&response=json" | jq '.listapisresponse.count') |
| 150 | + echo "curl count: $CURL_COUNT" |
| 151 | + CMK_COUNT=$("${CMK_BIN}" listApis | jq '.count') |
| 152 | + echo "cmk count: $CMK_COUNT" |
| 153 | + test -n "$CURL_COUNT" -a -n "$CMK_COUNT" |
| 154 | + [ "$CMK_COUNT" -ge 1 ] |
| 155 | +
|
| 156 | + - name: List API |
| 157 | + run: | |
| 158 | + "${CMK_BIN}" set output table |
| 159 | + OUT=$("${CMK_BIN}" listZones) |
| 160 | + echo "$OUT" |
| 161 | + if [ -z "$OUT" ]; then |
| 162 | + echo "No output from listZones. Failing." |
| 163 | + exit 1 |
| 164 | + fi |
| 165 | + "${CMK_BIN}" set output json |
| 166 | + OUT=$("${CMK_BIN}" listZones) |
| 167 | + echo "$OUT" |
| 168 | + if [ -z "$OUT" ]; then |
| 169 | + echo "No output from listZones. Failing." |
| 170 | + exit 1 |
| 171 | + fi |
| 172 | + ZONE_ID=$(echo "$OUT" | jq -r '.zone[0].id') |
| 173 | + echo "ZONE_ID=$ZONE_ID" >> $GITHUB_ENV |
| 174 | + test -n "$ZONE_ID" |
| 175 | +
|
| 176 | + - name: List API with filter |
| 177 | + run: | |
| 178 | + "${CMK_BIN}" set output json |
| 179 | + OUT=$("${CMK_BIN}" listZones filter=id,name) |
| 180 | + echo "$OUT" | jq -e ' |
| 181 | + .zone and (.zone|length>=1) |
| 182 | + and (all(.zone[]; has("id") and has("name") and ((. | keys - ["id","name"])|length==0))) |
| 183 | + ' |
| 184 | +
|
| 185 | + - name: List API with exclude |
| 186 | + run: | |
| 187 | + "${CMK_BIN}" set output json |
| 188 | + OUT=$("${CMK_BIN}" listZones exclude=id,name) |
| 189 | + echo "$OUT" | jq -e ' |
| 190 | + .zone and (.zone|length>=1) |
| 191 | + and (all(.zone[]; (has("id") or has("name"))|not)) |
| 192 | + ' |
| 193 | +
|
| 194 | + - name: "Create API" |
| 195 | + run: | |
| 196 | + "${CMK_BIN}" set output json |
| 197 | + OUT=$("${CMK_BIN}" createUser account=admin [email protected] firstname=Test lastname=User password=password username=test || true) |
| 198 | + echo "$OUT" |
| 199 | + if [ -n "$OUT" ]; then |
| 200 | + echo "$OUT" | jq -e ' |
| 201 | + (.user // {}) as $p |
| 202 | + | ($p|type=="object") |
| 203 | + and ($p|has("id") and has("email")) |
| 204 | + and ((($p|keys) - ["id","email"])|length>0) |
| 205 | + ' |
| 206 | + else |
| 207 | + echo "No output. Failing strict check." |
| 208 | + exit 1 |
| 209 | + fi |
| 210 | +
|
| 211 | + - name: Create API with filter |
| 212 | + run: | |
| 213 | + "${CMK_BIN}" set output json |
| 214 | + OUT=$("${CMK_BIN}" createUser account=admin [email protected] firstname=Test lastname=User password=password username=test-filter filter=id,email || true) |
| 215 | + echo "$OUT" |
| 216 | + if [ -n "$OUT" ]; then |
| 217 | + echo "$OUT" | jq -e ' |
| 218 | + (.user // {}) as $p |
| 219 | + | ($p|type=="object") |
| 220 | + and ($p|has("id") and has("email")) |
| 221 | + and ((($p|keys) - ["id","email"])|length==0) |
| 222 | + ' |
| 223 | + else |
| 224 | + echo "No output. Failing strict check." |
| 225 | + exit 1 |
| 226 | + fi |
| 227 | +
|
| 228 | + - name: Create API with exclude |
| 229 | + run: | |
| 230 | + "${CMK_BIN}" set output json |
| 231 | + OUT=$("${CMK_BIN}" createUser account=admin [email protected] firstname=Test lastname=User password=password username=test-exclude exclude=id,email || true) |
| 232 | + echo "$OUT" |
| 233 | + if [ -n "$OUT" ]; then |
| 234 | + echo "$OUT" | jq -e ' |
| 235 | + (.user // {}) as $p |
| 236 | + | ($p|type=="object") |
| 237 | + and ((($p|has("id")) or ($p|has("email")))|not) |
| 238 | + ' |
| 239 | + else |
| 240 | + echo "No output. Failing strict check." |
| 241 | + exit 1 |
| 242 | + fi |
| 243 | +
|
| 244 | + - name: Get template and service offering IDs for Async API test |
| 245 | + run: | |
| 246 | + TID=$("${CMK_BIN}" listTemplates listall=true templatefilter=executable | jq -r '.template[0].id') |
| 247 | + SOID=$("${CMK_BIN}" listServiceOfferings | jq -r '.serviceoffering[0].id') |
| 248 | + echo "TEMPLATE_ID=$TID" >> $GITHUB_ENV |
| 249 | + echo "SERVICE_OFFERING_ID=$SOID" >> $GITHUB_ENV |
| 250 | + test -n "$TID" -a -n "$SOID" |
| 251 | +
|
| 252 | + - name: Async API |
| 253 | + run: | |
| 254 | + "${CMK_BIN}" set output json |
| 255 | + OUT=$("${CMK_BIN}" deployVirtualMachine zoneid=${ZONE_ID} templateid=${TEMPLATE_ID} serviceofferingid=${SERVICE_OFFERING_ID} || true) |
| 256 | + if [ -n "$OUT" ]; then |
| 257 | + echo "$OUT" | jq -e ' |
| 258 | + (.virtualmachine // {}) as $p |
| 259 | + | ($p|type=="object") |
| 260 | + and ($p|has("id") and has("name")) |
| 261 | + and ((($p|keys) - ["id","name"])|length>0) |
| 262 | + ' |
| 263 | + else |
| 264 | + echo "No output. Failing strict check." |
| 265 | + exit 1 |
| 266 | + fi |
| 267 | +
|
| 268 | + - name: Async API with filter |
| 269 | + run: | |
| 270 | + "${CMK_BIN}" set output json |
| 271 | + OUT=$("${CMK_BIN}" deployVirtualMachine zoneid=${ZONE_ID} templateid=${TEMPLATE_ID} serviceofferingid=${SERVICE_OFFERING_ID} filter=id,name || true) |
| 272 | + if [ -n "$OUT" ]; then |
| 273 | + echo "$OUT" | jq -e ' |
| 274 | + (.virtualmachine // {}) as $p |
| 275 | + | ($p|type=="object") |
| 276 | + and ($p|has("id") and has("name")) |
| 277 | + and ((($p|keys) - ["id","name"])|length==0) |
| 278 | + ' |
| 279 | + else |
| 280 | + echo "No output. Failing strict check." |
| 281 | + exit 1 |
| 282 | + fi |
| 283 | +
|
| 284 | + - name: Async API with exclude |
| 285 | + run: | |
| 286 | + "${CMK_BIN}" set output json |
| 287 | + OUT=$("${CMK_BIN}" deployVirtualMachine zoneid=${ZONE_ID} templateid=${TEMPLATE_ID} serviceofferingid=${SERVICE_OFFERING_ID} exclude=id,name || true) |
| 288 | + echo "$OUT" |
| 289 | + if [ -n "$OUT" ]; then |
| 290 | + echo "$OUT" | jq -e ' |
| 291 | + (.virtualmachine // {}) as $p |
| 292 | + | ($p|type=="object") |
| 293 | + and ((($p|has("id")) or ($p|has("name")))|not) |
| 294 | + ' |
| 295 | + else |
| 296 | + echo "No output. Failing strict check." |
| 297 | + exit 1 |
| 298 | + fi |
| 299 | +
|
| 300 | + - name: Change profile (user) and compare API surface |
| 301 | + run: | |
| 302 | + ADMIN_COUNT=$("${CMK_BIN}" listApis | jq '.count') |
| 303 | + "${CMK_BIN}" createAccount username=user password=p@ssw0rd accounttype=0 domainid=1 firstname=Test lastname=User [email protected] || true |
| 304 | + "${CMK_BIN}" set profile user |
| 305 | + "${CMK_BIN}" set url "${CLOUDSTACK_UI_API}" |
| 306 | + "${CMK_BIN}" set username user |
| 307 | + "${CMK_BIN}" set password p@ssw0rd |
| 308 | + USER_COUNT=$("${CMK_BIN}" listApis | jq '.count // 0') |
| 309 | + echo "admin=${ADMIN_COUNT} user=${USER_COUNT}" |
| 310 | + test $USER_COUNT -le $ADMIN_COUNT |
| 311 | +
|
| 312 | + - name: Stop simulator MS |
| 313 | + if: ${{ always() && steps.start_ms.outcome == 'success' }} |
| 314 | + working-directory: cloudstack |
| 315 | + run: | |
| 316 | + echo -e "Stopping Simulator, integration tests run completed\n" |
| 317 | + mvn -Dsimulator -pl client jetty:stop 2>&1 |
| 318 | +
|
0 commit comments