From 8e955c07c47fee40d7f67e7335cdeac66626d705 Mon Sep 17 00:00:00 2001 From: Brad House Date: Fri, 27 Nov 2026 19:12:50 +0000 Subject: [PATCH 1/2] Split AGENTS.md into short agent rules and developer guides AGENTS.md is loaded into every agent task, so it stays short and points at guides that people use too: building and unit tests, code conventions, writing, pull requests, and a nested KVM test lab. Signed-off-by: Brad House --- AGENTS.md | 82 +++-- CONTRIBUTING.md | 2 + docs/development/building.md | 87 +++++ docs/development/coding-conventions.md | 125 +++++++ docs/development/pull-requests.md | 91 ++++++ docs/development/test-lab.md | 433 +++++++++++++++++++++++++ docs/development/writing.md | 105 ++++++ 7 files changed, 903 insertions(+), 22 deletions(-) create mode 100644 docs/development/building.md create mode 100644 docs/development/coding-conventions.md create mode 100644 docs/development/pull-requests.md create mode 100644 docs/development/test-lab.md create mode 100644 docs/development/writing.md diff --git a/AGENTS.md b/AGENTS.md index 4469efa2f494..1602bcec895a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,32 +1,70 @@ + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + --> -# Agent Guide for Apache CloudStack +# Agent guide for Apache CloudStack -This file is read by automated agents (security scanners, code -analyzers, AI assistants) operating on this repository. +Automated agents (AI assistants, code analyzers, security scanners) load this +file on every task, so it stays short. It holds the rules most tasks need and +points at the document that owns each subject. Those documents are written for +people first. + +## Where things live + +| Subject | Document | +| --- | --- | +| Security model and threat model | [SECURITY.md](./SECURITY.md) | +| Machine setup, full build, packaging; the UI | [INSTALL.md](./INSTALL.md), [ui/README.md](./ui/README.md) | +| Incremental builds, unit tests, the simulator | [docs/development/building.md](./docs/development/building.md) | +| Code conventions: Java, schema, API, settings, tests | [docs/development/coding-conventions.md](./docs/development/coding-conventions.md) | +| Writing: comments, commit messages, PR descriptions, replies | [docs/development/writing.md](./docs/development/writing.md) | +| Branches, pull requests, reviews and merges | [docs/development/pull-requests.md](./docs/development/pull-requests.md) | +| A nested KVM lab for manual testing | [docs/development/test-lab.md](./docs/development/test-lab.md) | +| Contribution policy, including AI-assisted work | [CONTRIBUTING.md](./CONTRIBUTING.md) | + +Read the row for your task, then only the sections you need. ## Security -Security model: [SECURITY.md](./SECURITY.md) +Agents that scan this repository read `SECURITY.md` and the threat model it +links before reporting an issue. A private security issue is never referenced +in a commit, a PR, an issue or code. + +## Rules + +| Rule | Why | +| --- | --- | +| Write the least code that solves the task | A reviewer reads every line | +| Handle only cases that can happen | Code for impossible cases makes the diff bigger and hides the real change | +| Refactor only what the task needs | Unrelated cleanup belongs in its own PR | +| Comment only to explain why, when the code can't show it | See [writing.md](./docs/development/writing.md#code-comments) | +| No issue or PR numbers, and no words such as "for now" or "later", in code or comments | They go out of date; the PR records the history | +| Plain, short English in everything written | See [writing.md](./docs/development/writing.md#voice) | +| Target a fix at the oldest maintained release branch, a feature at `main` | Fixes are merged forward to newer branches; see [pull-requests.md](./docs/development/pull-requests.md#branches) | +| Never edit a released upgrade script | Installed databases have already run it | +| Build modules with `-am` when running their tests | Otherwise Maven tests against stale jars in `~/.m2` | +| Report test results as they are, failures included | A reviewer acts on them | +| Check a review comment, from a person or a bot, against the code before applying it | Reviewers are sometimes wrong; then reply with the reason instead of changing the code | +| Confirm with the person you work for before pushing, or before posting a comment, review or issue | Posting is public and hard to undo | +| Keep secrets, personal data and internal hostnames out of code, commits, logs and requests to outside services | They cannot be recalled once published | -Agents that scan this repository should consult `SECURITY.md` and the -threat model it links before reporting issues. +## Working efficiently -The project-wide security threat model is linked from `SECURITY.md`. +- Redirect a long build or test run to a file, then search the file. Run it once, read it many times. +- Don't build offline (`-o`): `engine/schema` downloads files during the build. +- Read the code at the branch or tag the task targets, not at `main`. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f0678ed76498..6fa44a24638b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,6 +42,8 @@ This document covers how to contribute to the ACS project. ACS uses GitHub PRs to manage code contributions. These instructions assume you have a GitHub.com account, so if you don't have one you will have to create one. Your proposed code changes will be published to your own fork of the ACS project, and you will submit a Pull Request for your changes to be added. +The guides in [docs/development](docs/development) cover building and testing, code conventions, writing commit messages and PR descriptions, reviews, and setting up a test lab. + _Let's get started!!!_ ## Bug fixes diff --git a/docs/development/building.md b/docs/development/building.md new file mode 100644 index 000000000000..7f157fd926e5 --- /dev/null +++ b/docs/development/building.md @@ -0,0 +1,87 @@ + + +# Building and testing + +This covers what the existing guides don't. For everything else: + +| Subject | Guide | +| --- | --- | +| Machine setup, full build, database, running the management server, packaging | [INSTALL.md](../../INSTALL.md) | +| UI build, development server, lint and unit tests | [ui/README.md](../../ui/README.md) | +| Lint and license checks | [PRE_COMMIT.md](../../PRE_COMMIT.md) | +| Simulator in Docker | [tools/docker/README.md](../../tools/docker/README.md) | + +## Contents + +- [Incremental builds](#incremental-builds) +- [Unit tests](#unit-tests) +- [Simulator from source](#simulator-from-source) +- [Build pitfalls](#build-pitfalls) + +## Incremental builds + +```bash +mvn install -Dnoredist -P developer -pl api,server,client -am -DskipTests +``` + +- `-am` also builds the modules the listed ones depend on. +- Include `client` when the change should reach a running management server; it is the module `jetty:run` serves. + +## Unit tests + +| Task | Command | +| --- | --- | +| One test class | `mvn test -pl server -am -Dtest=FooManagerImplTest -Dsurefire.failIfNoSpecifiedTests=false` | +| A pattern | `-Dtest='KubernetesCluster*Test'` | +| One method | `-Dtest=FooManagerImplTest#testBar` | + +- Without `-am` the test runs against whatever jars are in `~/.m2`, which may be older than the source. +- `-Dsurefire.failIfNoSpecifiedTests=false` keeps the run from failing in the `-am` modules that have no matching test. +- Results are in `/target/surefire-reports/`. + +## Simulator from source + +The simulator runs a management server against fake hypervisors, so API-level +behavior can be tested without hardware. CI runs the smoke tests this way +(`.github/workflows/ci.yml`). + +1. Deploy both databases: `mvn -P developer -pl developer -Ddeploydb`, then `mvn -P developer -pl developer -Ddeploydb-simulator`. +2. Install Marvin from the build: `pip install --user tools/marvin/dist/[mM]arvin-*.tar.gz`. +3. Start the server with `mvn -Dsimulator -pl :cloud-client-ui jetty:run` and wait for port 8096. +4. Deploy a zone: `python3 tools/marvin/marvin/deployDataCenter.py -i setup/dev/advdualzone.cfg`. +5. Run a suite: + +```bash +nosetests --with-marvin --marvin-config=setup/dev/advdualzone.cfg \ + test/integration/smoke/test_vm_life_cycle.py -s \ + -a tags=advanced,required_hardware=false --zone=zim1 --hypervisor=simulator +``` + +- A test tagged `required_hardware=true` needs real hypervisors: use a lab ([test-lab.md](./test-lab.md)) or ask a committer for a Trillian run on the PR. +- Some simulator smoke tests fail intermittently on `main` as well. Compare a failure with the same suite on a recent base-branch run before treating it as caused by a change. + +## Build pitfalls + +| Symptom | Cause and fix | +| --- | --- | +| `engine/schema` fails offline | It downloads files during the build; don't build with `-o` | +| A test passes locally and fails in CI, or the reverse | Stale module jars in `~/.m2`; rebuild with `-am` | +| A build in a `git worktree` fails reading git metadata | Add `-Dmaven.gitcommitid.skip=true` | +| Out of memory with `-T` | Each thread runs its own compiler; lower `-T` or raise `MAVEN_OPTS=-Xmx` | diff --git a/docs/development/coding-conventions.md b/docs/development/coding-conventions.md new file mode 100644 index 000000000000..32ef31f354d4 --- /dev/null +++ b/docs/development/coding-conventions.md @@ -0,0 +1,125 @@ + + +# Code conventions + +Conventions reviewers check. They apply to new and changed code. Old code is +fixed only when it is being changed anyway. + +## Contents + +- [Repository layout](#repository-layout) +- [Size and shape of a change](#size-and-shape-of-a-change) +- [Java](#java) +- [Database objects and schema](#database-objects-and-schema) +- [API commands and responses](#api-commands-and-responses) +- [Global settings](#global-settings) +- [Logging](#logging) +- [Unit tests](#unit-tests) + +## Repository layout + +| Path | Contents | +| --- | --- | +| `api/` | API interfaces, `*Cmd` and `*Response` classes | +| `server/` | Manager implementations (business logic) | +| `engine/` | Orchestration; `engine/schema/` holds VO and DAO classes, schema and upgrade SQL | +| `framework/` | Config, DB, security, async jobs | +| `core/` | Shared DTOs, agent `Command` and `Answer` classes | +| `agent/` | The hypervisor-host agent | +| `plugins/` | Hypervisors, storage, network, backup, integrations such as CKS | +| `systemvm/` | System VM scripts and the virtual router's Python | +| `ui/` | Vue.js 3 and Ant Design frontend | +| `client/` | The management server webapp; include it in a build that should reach a running server | +| `test/` | Marvin integration tests | + +## Size and shape of a change + +| Rule | Why | +| --- | --- | +| One logical change per PR | A reviewer approves one thing | +| Write the least code that solves the task | Every line is read, tested and maintained | +| Handle only states that can occur | A branch for an impossible state is untested code and hides the real change | +| Reuse the helper that exists before writing another | Two copies drift apart | +| Deduplicate before submitting, without losing readability | Copy-pasted blocks are the most common review comment | +| A method does one thing | Extract a block that needs a comment to explain it, and name the method for what it does | +| Refactor only what the change needs | Unrelated cleanup is its own PR, or the diff becomes unreviewable | + +## Java + +- Code compiles at the Java level in `pom.xml` (`cs.jdk.version`), on every branch the change targets. +- Every new file starts with the Apache License 2.0 header; `pre-commit` checks it. +- Inject collaborators with `@Inject` fields, as the surrounding classes do. +- Throw `InvalidParameterValueException` for bad user input, `PermissionDeniedException` for access, and `CloudRuntimeException` for failures the caller cannot fix. The message says what was refused and what to do instead. + +## Database objects and schema + +| Rule | Detail | +| --- | --- | +| Name VO getters and setters after their fields | Field `foo` has `getFoo()` and `setFoo()`, so readers and tools find them | +| A VO has an empty constructor | The persistence layer instantiates it | +| A VO generates its UUID in its constructor | Every row gets one without the caller remembering | +| Table names are singular | `vm_instance`, not `vm_instances` | +| A schema change goes in the upgrade script for the next release of the target branch | `engine/schema/src/main/resources/META-INF/db/schema-to.sql` | +| Upgrade SQL is safe to run twice | Use the procedures in `META-INF/db/procedures/`, such as `IDEMPOTENT_ADD_COLUMN`, so a repeated upgrade does not fail | +| Change a view in its file under `META-INF/db/views/` | Every upgrade re-creates the views from these files | +| A released upgrade script is never edited | Installed databases have already run it | + +## API commands and responses + +- A new command, parameter or response field carries `since` with the release it first ships in. +- A subclass does not redeclare a parameter it inherits. +- Parameter and response names are lower case, as the rest of the API. +- Input is validated before anything changes, so a refused call leaves no partial state. +- Check that the caller may use the resource (its account and domain). A role that allows the API call is not enough. + +## Global settings + +| Rule | Why | +| --- | --- | +| Add a setting as a `ConfigKey`, never a new `Config` enum entry | `Config` is legacy | +| Declare the `ConfigKey` on the service interface, not the `*Impl` | Other modules read it without depending on the implementation | +| Return it from the class's `getConfigKeys()` | An unregistered key never reaches the database or the API | +| Pick the narrowest scope that works (account, domain, cluster, zone, global) and say whether it is dynamic | Operators can then set it per zone or account; a setting that is not dynamic needs a restart to change | +| Validate the value where it is read, or with a validator on update | A bad value otherwise surfaces as a failure far from its cause | +| Add a setting only when operators need different values | Each one is documented, tested and supported forever | + +## Logging + +- Use the class `logger` with `{}` placeholders and one argument per placeholder: `logger.debug("Detaching ISO {} from VM {}", iso, vm)`. +- Log the object, not a hand-built string of its fields; CloudStack objects print their identifying fields. + +| Level | For | +| --- | --- | +| `DEBUG` | Routine detail, anything per object on a frequent path | +| `INFO` | A state change an operator would want in the log: a VM started, a host put in maintenance | +| `WARN` | Something went wrong and was handled | +| `ERROR` | An operation failed | + +- A message logged for every NIC, volume or VM on every start is `DEBUG`. +- Never log passwords, keys, tokens or user data. Mask them in commands that are logged. + +## Unit tests + +- JUnit 4 with Mockito: `@RunWith(MockitoJUnitRunner.class)`, `@Mock`, `@InjectMocks` or `@Spy`. Static methods are mocked with `Mockito.mockStatic` in try-with-resources; PowerMock is not used. +- A bug fix comes with a test that fails without the fix. +- Every new branch has a test whose input reaches that branch. +- A test is named for the behavior it checks: `testScaleRejectsSizeBelowAddedNodes`, not `testFix2`. +- Verify outcomes (returned values, state, the calls that matter), not every interaction. +- A test does not depend on another test's order or leftovers. diff --git a/docs/development/pull-requests.md b/docs/development/pull-requests.md new file mode 100644 index 000000000000..d1654cca5d75 --- /dev/null +++ b/docs/development/pull-requests.md @@ -0,0 +1,91 @@ + + +# Pull requests + +Branches, reviews and merges. The contribution policy, including forks and +AI-assisted work, is in [CONTRIBUTING.md](../../CONTRIBUTING.md); writing rules +for titles and descriptions are in [writing.md](./writing.md). + +## Contents + +- [Branches](#branches) +- [Before opening a pull request](#before-opening-a-pull-request) +- [Reviews and merging](#reviews-and-merging) +- [CI results](#ci-results) +- [Updating a pull request](#updating-a-pull-request) +- [Verifying a merge or rebase](#verifying-a-merge-or-rebase) +- [Reporting issues](#reporting-issues) + +## Branches + +| Change | Target | +| --- | --- | +| Bug fix | The oldest maintained release branch it applies to | +| Feature or behavior change | `main` | + +- Committers merge each release branch into the next newer one, and finally into `main`. Open a fix once, against the oldest branch; the merges carry it to the others. +- Features are not backported. +- A change that depends on another PR says "Depends on #N" in its description. + +## Before opening a pull request + +1. Rebase onto the latest target branch. +2. Build the touched modules and run their unit tests ([building.md](./building.md)). +3. Run `pre-commit run --all-files`. +4. Test the change by hand: the simulator for API behavior, a lab for anything that touches a hypervisor, storage or the network ([test-lab.md](./test-lab.md)). +5. Fill in the PR template, including how it was tested. + +## Reviews and merging + +- A PR is merged after two approvals, at least one of them with a test report from someone other than the author. Text-only, test-only and CI-only changes are the exception. +- A test report says the version or commit tested, the environment (hypervisor, storage, network type) and what was checked. +- A committer runs the packaging and Trillian (BlueOrangutan) jobs on a PR; ask in the PR if one is needed. + +## CI results + +- Check whether a failing job is caused by the change: compare it with the same job on a recent push to the base branch. Some simulator smoke tests fail intermittently. +- Authors cannot re-run workflows. Closing and reopening the PR re-runs them; rebasing does too. +- Say in the PR when a failure is unrelated, with a link to the base-branch run that shows it. + +## Updating a pull request + +1. Fetch the PR's branch from the remote that hosts it; fall back to `pull//head` only when none does. +2. Rebase onto the latest base branch, or merge it in when the PR's history already uses merges. +3. Check that it still compiles and the relevant unit tests pass. +4. Read all review feedback: inline threads, review summaries and top-level comments, from people and bots. +5. Fix what is right; reply with the reason to what is not. +6. Push with `--force-with-lease` after a rebase. + +## Verifying a merge or rebase + +A merge with no `<<<<<<<` markers left can still have lost one side's change. + +- For each conflicted file, diff the incoming side: `git diff $(git merge-base HEAD MERGE_HEAD) MERGE_HEAD -- `, and confirm that change is in the result. +- After a rebase, `git range-diff .. ..` shows what each commit became. +- Look for call sites not updated after a signature change, and for both versions of a line kept back to back. + +## Reporting issues + +1. Search existing issues and PRs first. +2. Check that the latest release and `main` are still affected, and read the code at that tag or branch. +3. Pin the CloudStack version, hypervisor and storage in the report. +4. Give steps to reproduce, or a test that fails. + +[CONTRIBUTING.md](../../CONTRIBUTING.md) says what an AI-assisted issue or PR includes. diff --git a/docs/development/test-lab.md b/docs/development/test-lab.md new file mode 100644 index 000000000000..6567ceb0fbba --- /dev/null +++ b/docs/development/test-lab.md @@ -0,0 +1,433 @@ + + +# Nested KVM test lab + +A single Linux host runs a complete CloudStack zone in libvirt VMs: a +management server, three KVM hypervisors, a Ceph cluster and an external test +client. CloudStack's own guests (user VMs, virtual routers, system VMs, CKS +nodes) run nested inside the hypervisor VMs. The lab reproduces bugs that need +real hypervisors, real storage and real networking, and tests upgrades between +releases. + +Everything here was tested with Ubuntu 24.04 on the host and in every lab VM. +The lab is disposable: it uses a single password everywhere and keeps its +networks host-only. + +## Contents + +- [Host requirements](#host-requirements) +- [Topology](#topology) +- [Build steps](#build-steps) +- [Lab reset](#lab-reset) +- [Upgrade testing](#upgrade-testing) +- [Fault injection](#fault-injection) +- [CKS extras](#cks-extras) +- [Gotchas](#gotchas) +- [Smaller options](#smaller-options) + +## Host requirements + +| Item | Tested value | +| --- | --- | +| OS | Ubuntu 24.04 | +| CPU | 128 vCPU, AMD EPYC | +| RAM | 122 GB, no swap | +| Disk | 1 TB, one filesystem; lab VM disks are thin qcow2 | +| Virtualization | libvirt, QEMU/KVM, nested virtualization on | +| Extra packages | `virtinst`, `cloud-image-utils`, `nginx`, `jq`, `chrony`, `libguestfs-tools`, Docker, `cmk` (CloudMonkey) | + +The host itself can be a VM. The tested host was a KVM guest, so CloudStack's +guests ran three levels deep. Nested guests measured about 91% of the +hypervisor VM's CPU and memory throughput, 45% of its 4k random-read IOPS and +77% of its fsync write rate: enough for CKS nodes. + +Check nested virtualization on the host, then inside each hypervisor VM: + +```bash +cat /sys/module/kvm_amd/parameters/nested # kvm_intel on Intel; expect 1 or Y +kvm-ok # inside a hypervisor VM (package cpu-checker) +``` + +The VMs commit 114 GB of RAM. With no swap, the memory that nested guests +actually touch must stay about 3 GB below each hypervisor VM's RAM, or the +host's OOM killer stops a whole hypervisor. Allocated but idle guest memory is +fine. + +## Topology + +### Lab VMs + +| VM | vCPU | RAM | Disk | Role | +| --- | --- | --- | --- | --- | +| `mgmt` | 8 | 12 GB | 200 GB | Management server, MySQL 8.0, NFS exports for secondary (and optional primary) storage | +| `kvm1`, `kvm2`, `kvm3` | 32 each | 30 GB each | 300 GB each | KVM hypervisors, one cluster | +| `ceph` | 8 | 10 GB | 40 GB + 3 x 100 GB | Single-node MicroCeph (squid), 3 OSDs, RBD pool for primary storage | +| `ext` | 2 | 2 GB | 20 GB | External client on the public network (IPv4 and IPv6): `scapy`, `hping3`, `nc`, `curl`, `iperf3`, `nmap`, `tcpdump` | + +All VMs use `host-passthrough` CPU, virtio disks and NICs, and autostart. + +### Bridges and traffic + +| Host bridge | Address | Carries | Zone traffic type | +| --- | --- | --- | --- | +| `cloudbr0` | Lab gateway, NAT to the uplink | Management, public, storage (Ceph, NFS), untagged | Management and Public, KVM label `cloudbr0` | +| `cloudbr1` | None, no uplink | Guest VLAN trunk | Guest, KVM label `cloudbr1` | +| `cloudbr1.` | Gateway of a shared network | One guest VLAN outside the zone's range | Shared network | + +Each hypervisor VM has two NICs, one on each host bridge. Inside the VM, +netplan builds bridges with the same names: `cloudbr0` holds `eth0` and the +host's IP, and `cloudbr1` holds `eth1` with no IP. The other VMs have one NIC +on `cloudbr0`. The host runs NTP, NAT and an HTTP mirror on its `cloudbr0` +address. + +### Address plan + +The ranges are examples; any private range that is free on the host works. + +| Range | Use | +| --- | --- | +| `172.16.0.1/16` | Host on `cloudbr0`: gateway, NTP, HTTP mirror, NAT | +| `172.16.0.10`-`.30` | Lab VMs | +| `172.16.1.10`-`172.16.1.250` | Pod range (system VM management IPs) | +| `172.16.10.1`-`172.16.11.250` | Public IPv4, untagged | +| `fd00:16::/64`, gateway `fd00:16::1` | Public IPv6, range `fd00:16::1:0`-`fd00:16::1:ffff` | +| `fd00:17::/56` | Zone guest IPv6 prefix | +| `10.200.0.0/16` | IPv4 block for routed-mode networks | +| `10.1.0.0/16` | Zone guest CIDR for isolated networks | +| VLAN 100-299 | Zone guest VLAN range | +| VLAN 60, `10.60.0.0/24` | Shared network, host as gateway | + +IPv6 stays inside the lab: the host, `ext`, the virtual routers and the guests +reach each other, which is enough for ACL and firewall tests. + +## Build steps + +### 1. Host network + +1. Create `cloudbr0` and `cloudbr1` as NetworkManager bridges with STP off and + forward delay 0, plus the VLAN interface for the shared network. +2. Set `unmanaged-devices=interface-name:vnet*` in + `/etc/NetworkManager/conf.d/` so NetworkManager leaves libvirt taps alone. +3. Turn on IPv4 and IPv6 forwarding in `/etc/sysctl.d/`. +4. Load an nftables table that masquerades the lab ranges (bridge, shared + network, routed block) out of the uplink, from a oneshot systemd unit + ordered after Docker. +5. Insert `ACCEPT` rules for the same ranges into Docker's `DOCKER-USER` chain. +6. Add `allow 172.16.0.0/16` to chrony. +7. Create a lab SSH key, an `~/.ssh/config` block for the lab VMs (user root) + and `/etc/hosts` entries. + +### 2. Lab VMs + +1. Download the Ubuntu 24.04 cloud image once as a shared, read-only base. +2. For each VM, create a qcow2 overlay on the base with `qemu-img create -b`. +3. Write a cloud-init seed with `cloud-localds -N`: + - netplan with a static address, fixed MACs and, on the hypervisors, the two bridges; + - the lab SSH key and password for root, with `PermitRootLogin yes` and password SSH; + - `chrony` pointed at the host, with `makestep 1 -1`, and `qemu-guest-agent`. +4. Create the VM with `virt-install --import --cpu host-passthrough --autostart`. + Root disks use `cache=none,io=native`. The Ceph OSD disks use + `cache=unsafe,io=threads,discard=unmap` and a `serial=` so they appear + under `/dev/disk/by-id/`. +5. Wait for SSH and `cloud-init status --wait` on each VM. + +### 3. Roles + +| VM | Setup | +| --- | --- | +| `mgmt` | `mysql-server`, `nfs-kernel-server`, `openjdk-17-jre-headless` and the Python modules the setup scripts use. MySQL settings from the install guide (`server_id`, `innodb_rollback_on_timeout=1`, `innodb_lock_wait_timeout=600`, `max_connections=350`, ROW binlog). Root password authentication. NFS export of `/export` with `/export/secondary` and `/export/primary` | +| `kvm1`-`kvm3` | `qemu-kvm`, `libvirt-daemon-system`, `libvirt-daemon-driver-storage-rbd`, `ceph-common`, `openjdk-17-jdk-headless`, `nftables`, `tcpdump`. libvirtd on TCP 16509 with `--listen` and socket units masked; libvirt AppArmor profiles disabled; default libvirt network removed; `ufw` off; `8021q` loaded | +| `ceph` | `snap install microceph --channel=squid/stable`, bootstrap, three OSDs from the `by-id` disks. One host, so a CRUSH rule with failure domain `osd`. Pool `cloudstack`, size 3, min_size 2, 64 PGs, `rbd pool init`. Client `client.cloudstack` with `profile rbd` on that pool | +| `ext` | The probe tools in the VM table | + +Copy `ceph.conf`, the `client.cloudstack` keyring and the admin keyring to +`/etc/ceph/` on every hypervisor, so `rbd` and `ceph tell` work there. Keep the +`client.cloudstack` key for the zone's primary storage URL. + +### 4. Mirror and downloads + +Serve a directory with nginx on the host's `cloudbr0` address, so the SSVM +downloads templates and ISOs at bridge speed. Add a systemd drop-in that +orders nginx after `network-online.target` and restarts it on failure. + +| File | Source | +| --- | --- | +| System VM template, `systemvmtemplate--x86_64-kvm.qcow2.bz2` and `sha512sum.txt` | `https://download.cloudstack.org/systemvm//`; verify with `sha512sum -c` | +| CirrOS 0.6.3 and copies of it | CirrOS releases; separate copies for tests that need several templates | +| Ubuntu 24.04 test template | Built in a throwaway VM from the cloud image: `nginx`, `python3`, `stress-ng`, `iperf3`, `qemu-guest-agent`, then `cloud-init clean`, an empty `/etc/machine-id` and `qemu-img convert -c` | +| `cmk.linux.x86-64` | `apache/cloudstack-cloudmonkey` GitHub releases | +| CKS ISOs | [CKS extras](#cks-extras) | + +### 5. Packages + +Use released debs, or build them from a branch in an `ubuntu:24.04` container +so the host needs no toolchain. The tested image adds: + +- `build-essential`, `devscripts`, `debhelper`, `lsb-release`, `genisoimage`, `jq`, `maven`; +- Node.js 22 from NodeSource; +- a JDK 11 (Temurin 11), `python3-mysql.connector`, `python3-setuptools`, + `libws-commons-util-java`, `libcommons-codec-java`, `libcommons-httpclient-java`; +- `git config --system --add safe.directory '*'`. + +```bash +docker run --rm --memory 24g --memory-swap 24g \ + -v "$HOME/build:/work" -v "$HOME/build/m2:/root/.m2" \ + -e ACS_BUILD_OPTS="-DskipTests -T 16" -e MAVEN_OPTS=-Xmx6g \ + -e NODE_OPTIONS="--openssl-legacy-provider --max-old-space-size=4096" \ + deb-builder bash -c 'cd /work/cloudstack && dpkg-checkbuilddeps && + cd packaging && ./build-deb.sh --brand lab.$(git rev-parse --short HEAD) -o /work/dist' +``` + +- Mount the parent of the source tree: `dpkg-buildpackage` writes there. +- `debian/rules` passes `ACS_BUILD_OPTS` to Maven. `-Dnoredist` adds the + non-redistributable plugins and needs those libraries installed first. +- `debian/rules` builds with `-Dsystemvm` only, so the management deb bundles + no KVM system VM template. `-Dsystemvm-kvm` in `ACS_BUILD_OPTS` bundles it. +- The lab installs five debs: `cloudstack-common`, `-management`, `-ui`, + `-usage` and `-agent`. +- The container writes as root; `chown` the source tree and output afterwards. + +### 6. Install + +1. On `mgmt`, `apt-get install` the common, management and ui debs (plus usage if needed). +2. Run `cloudstack-setup-databases cloud:@localhost --deploy-as=root: -i `. +3. Run `cloudstack-setup-management`. +4. On each hypervisor, `apt-get install` the common and agent debs. The agent + configures libvirt and its TLS certificates when the host is added. +5. If `/usr/share/cloudstack-management/templates/systemvm/` holds no KVM + template, seed secondary storage from the mirror: + +```bash +/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt \ + -m /export/secondary -u http://172.16.0.1/systemvm/