provisioning/docs/book/user/test-environment-guide.html

597 lines
26 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html lang="en" class="ayu sidebar-visible" dir="ltr">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>Test Environment Guide - Provisioning Platform Documentation</title>
<!-- Custom HTML head -->
<meta name="description" content="Complete documentation for the Provisioning Platform - Infrastructure automation with Nushell, KCL, and Rust">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="../favicon.svg">
<link rel="shortcut icon" href="../favicon.png">
<link rel="stylesheet" href="../css/variables.css">
<link rel="stylesheet" href="../css/general.css">
<link rel="stylesheet" href="../css/chrome.css">
<link rel="stylesheet" href="../css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="../fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" id="highlight-css" href="../highlight.css">
<link rel="stylesheet" id="tomorrow-night-css" href="../tomorrow-night.css">
<link rel="stylesheet" id="ayu-highlight-css" href="../ayu-highlight.css">
<!-- Custom theme stylesheets -->
<!-- Provide site root and default themes to javascript -->
<script>
const path_to_root = "../";
const default_light_theme = "ayu";
const default_dark_theme = "navy";
</script>
<!-- Start loading toc.js asap -->
<script src="../toc.js"></script>
</head>
<body>
<div id="mdbook-help-container">
<div id="mdbook-help-popup">
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
<div>
<p>Press <kbd></kbd> or <kbd></kbd> to navigate between chapters</p>
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
<p>Press <kbd>?</kbd> to show this help</p>
<p>Press <kbd>Esc</kbd> to hide this help</p>
</div>
</div>
</div>
<div id="body-container">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
let theme = localStorage.getItem('mdbook-theme');
let sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script>
const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme;
let theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
const html = document.documentElement;
html.classList.remove('ayu')
html.classList.add(theme);
html.classList.add("js");
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<!-- Hide / unhide sidebar before it is displayed -->
<script>
let sidebar = null;
const sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<!-- populated by js -->
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="../toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li>
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">Provisioning Platform Documentation</h1>
<div class="right-buttons">
<a href="../print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
<a href="https://github.com/provisioning/provisioning-platform" title="Git repository" aria-label="Git repository">
<i id="git-repository-button" class="fa fa-github"></i>
</a>
<a href="https://github.com/provisioning/provisioning-platform/edit/main/provisioning/docs/src/user/test-environment-guide.md" title="Suggest an edit" aria-label="Suggest an edit">
<i id="git-edit-button" class="fa fa-edit"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<h1 id="test-environment-guide"><a class="header" href="#test-environment-guide">Test Environment Guide</a></h1>
<p><strong>Version</strong>: 1.0.0
<strong>Date</strong>: 2025-10-06
<strong>Status</strong>: Production Ready</p>
<hr />
<h2 id="overview"><a class="header" href="#overview">Overview</a></h2>
<p>The Test Environment Service provides automated containerized testing for taskservs, servers, and multi-node clusters. Built into the orchestrator, it eliminates manual Docker management and provides realistic test scenarios.</p>
<h2 id="architecture"><a class="header" href="#architecture">Architecture</a></h2>
<pre><code>┌─────────────────────────────────────────────────┐
│ Orchestrator (port 8080) │
│ ┌──────────────────────────────────────────┐ │
│ │ Test Orchestrator │ │
│ │ • Container Manager (Docker API) │ │
│ │ • Network Isolation │ │
│ │ • Multi-node Topologies │ │
│ │ • Test Execution │ │
│ └──────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
┌────────────────────────┐
│ Docker Containers │
│ • Isolated Networks │
│ • Resource Limits │
│ • Volume Mounts │
└────────────────────────┘
</code></pre>
<h2 id="test-environment-types"><a class="header" href="#test-environment-types">Test Environment Types</a></h2>
<h3 id="1-single-taskserv-test"><a class="header" href="#1-single-taskserv-test">1. Single Taskserv Test</a></h3>
<p>Test individual taskserv in isolated container.</p>
<pre><code class="language-bash"># Basic test
provisioning test env single kubernetes
# With resource limits
provisioning test env single redis --cpu 2000 --memory 4096
# Auto-start and cleanup
provisioning test quick postgres
</code></pre>
<h3 id="2-server-simulation"><a class="header" href="#2-server-simulation">2. Server Simulation</a></h3>
<p>Simulate complete server with multiple taskservs.</p>
<pre><code class="language-bash"># Server with taskservs
provisioning test env server web-01 [containerd kubernetes cilium]
# With infrastructure context
provisioning test env server db-01 [postgres redis] --infra prod-stack
</code></pre>
<h3 id="3-cluster-topology"><a class="header" href="#3-cluster-topology">3. Cluster Topology</a></h3>
<p>Multi-node cluster simulation from templates.</p>
<pre><code class="language-bash"># 3-node Kubernetes cluster
provisioning test topology load kubernetes_3node | test env cluster kubernetes --auto-start
# etcd cluster
provisioning test topology load etcd_cluster | test env cluster etcd
</code></pre>
<h2 id="quick-start"><a class="header" href="#quick-start">Quick Start</a></h2>
<h3 id="prerequisites"><a class="header" href="#prerequisites">Prerequisites</a></h3>
<ol>
<li>
<p><strong>Docker running:</strong></p>
<pre><code class="language-bash">docker ps # Should work without errors
</code></pre>
</li>
<li>
<p><strong>Orchestrator running:</strong></p>
<pre><code class="language-bash">cd provisioning/platform/orchestrator
./scripts/start-orchestrator.nu --background
</code></pre>
</li>
</ol>
<h3 id="basic-workflow"><a class="header" href="#basic-workflow">Basic Workflow</a></h3>
<pre><code class="language-bash"># 1. Quick test (fastest)
provisioning test quick kubernetes
# 2. Or step-by-step
# Create environment
provisioning test env single kubernetes --auto-start
# List environments
provisioning test env list
# Check status
provisioning test env status &lt;env-id&gt;
# View logs
provisioning test env logs &lt;env-id&gt;
# Cleanup
provisioning test env cleanup &lt;env-id&gt;
</code></pre>
<h2 id="topology-templates"><a class="header" href="#topology-templates">Topology Templates</a></h2>
<h3 id="available-templates"><a class="header" href="#available-templates">Available Templates</a></h3>
<pre><code class="language-bash"># List templates
provisioning test topology list
</code></pre>
<div class="table-wrapper"><table><thead><tr><th>Template</th><th>Description</th><th>Nodes</th></tr></thead><tbody>
<tr><td><code>kubernetes_3node</code></td><td>K8s HA cluster</td><td>1 CP + 2 workers</td></tr>
<tr><td><code>kubernetes_single</code></td><td>All-in-one K8s</td><td>1 node</td></tr>
<tr><td><code>etcd_cluster</code></td><td>etcd cluster</td><td>3 members</td></tr>
<tr><td><code>containerd_test</code></td><td>Standalone containerd</td><td>1 node</td></tr>
<tr><td><code>postgres_redis</code></td><td>Database stack</td><td>2 nodes</td></tr>
</tbody></table>
</div>
<h3 id="using-templates"><a class="header" href="#using-templates">Using Templates</a></h3>
<pre><code class="language-bash"># Load and use template
provisioning test topology load kubernetes_3node | test env cluster kubernetes
# View template
provisioning test topology load etcd_cluster
</code></pre>
<h3 id="custom-topology"><a class="header" href="#custom-topology">Custom Topology</a></h3>
<p>Create <code>my-topology.toml</code>:</p>
<pre><code class="language-toml">[my_cluster]
name = "My Custom Cluster"
cluster_type = "custom"
[[my_cluster.nodes]]
name = "node-01"
role = "primary"
taskservs = ["postgres", "redis"]
[my_cluster.nodes.resources]
cpu_millicores = 2000
memory_mb = 4096
[[my_cluster.nodes]]
name = "node-02"
role = "replica"
taskservs = ["postgres"]
[my_cluster.nodes.resources]
cpu_millicores = 1000
memory_mb = 2048
[my_cluster.network]
subnet = "172.30.0.0/16"
</code></pre>
<h2 id="commands-reference"><a class="header" href="#commands-reference">Commands Reference</a></h2>
<h3 id="environment-management"><a class="header" href="#environment-management">Environment Management</a></h3>
<pre><code class="language-bash"># Create from config
provisioning test env create &lt;config&gt;
# Single taskserv
provisioning test env single &lt;taskserv&gt; [--cpu N] [--memory MB]
# Server simulation
provisioning test env server &lt;name&gt; &lt;taskservs&gt; [--infra NAME]
# Cluster topology
provisioning test env cluster &lt;type&gt; &lt;topology&gt;
# List environments
provisioning test env list
# Get details
provisioning test env get &lt;env-id&gt;
# Show status
provisioning test env status &lt;env-id&gt;
</code></pre>
<h3 id="test-execution"><a class="header" href="#test-execution">Test Execution</a></h3>
<pre><code class="language-bash"># Run tests
provisioning test env run &lt;env-id&gt; [--tests [test1, test2]]
# View logs
provisioning test env logs &lt;env-id&gt;
# Cleanup
provisioning test env cleanup &lt;env-id&gt;
</code></pre>
<h3 id="quick-test"><a class="header" href="#quick-test">Quick Test</a></h3>
<pre><code class="language-bash"># One-command test (create, run, cleanup)
provisioning test quick &lt;taskserv&gt; [--infra NAME]
</code></pre>
<h2 id="rest-api"><a class="header" href="#rest-api">REST API</a></h2>
<h3 id="create-environment"><a class="header" href="#create-environment">Create Environment</a></h3>
<pre><code class="language-bash">curl -X POST http://localhost:9090/test/environments/create \
-H "Content-Type: application/json" \
-d '{
"config": {
"type": "single_taskserv",
"taskserv": "kubernetes",
"base_image": "ubuntu:22.04",
"environment": {},
"resources": {
"cpu_millicores": 2000,
"memory_mb": 4096
}
},
"infra": "my-project",
"auto_start": true,
"auto_cleanup": false
}'
</code></pre>
<h3 id="list-environments"><a class="header" href="#list-environments">List Environments</a></h3>
<pre><code class="language-bash">curl http://localhost:9090/test/environments
</code></pre>
<h3 id="run-tests"><a class="header" href="#run-tests">Run Tests</a></h3>
<pre><code class="language-bash">curl -X POST http://localhost:9090/test/environments/{id}/run \
-H "Content-Type: application/json" \
-d '{
"tests": [],
"timeout_seconds": 300
}'
</code></pre>
<h3 id="cleanup"><a class="header" href="#cleanup">Cleanup</a></h3>
<pre><code class="language-bash">curl -X DELETE http://localhost:9090/test/environments/{id}
</code></pre>
<h2 id="use-cases"><a class="header" href="#use-cases">Use Cases</a></h2>
<h3 id="1-taskserv-development"><a class="header" href="#1-taskserv-development">1. Taskserv Development</a></h3>
<p>Test taskserv before deployment:</p>
<pre><code class="language-bash"># Test new taskserv version
provisioning test env single my-taskserv --auto-start
# Check logs
provisioning test env logs &lt;env-id&gt;
</code></pre>
<h3 id="2-multi-taskserv-integration"><a class="header" href="#2-multi-taskserv-integration">2. Multi-Taskserv Integration</a></h3>
<p>Test taskserv combinations:</p>
<pre><code class="language-bash"># Test kubernetes + cilium + containerd
provisioning test env server k8s-test [kubernetes cilium containerd] --auto-start
</code></pre>
<h3 id="3-cluster-validation"><a class="header" href="#3-cluster-validation">3. Cluster Validation</a></h3>
<p>Test cluster configurations:</p>
<pre><code class="language-bash"># Test 3-node etcd cluster
provisioning test topology load etcd_cluster | test env cluster etcd --auto-start
</code></pre>
<h3 id="4-cicd-integration"><a class="header" href="#4-cicd-integration">4. CI/CD Integration</a></h3>
<pre><code class="language-yaml"># .gitlab-ci.yml
test-taskserv:
stage: test
script:
- provisioning test quick kubernetes
- provisioning test quick redis
- provisioning test quick postgres
</code></pre>
<h2 id="advanced-features"><a class="header" href="#advanced-features">Advanced Features</a></h2>
<h3 id="resource-limits"><a class="header" href="#resource-limits">Resource Limits</a></h3>
<pre><code class="language-bash"># Custom CPU and memory
provisioning test env single postgres \
--cpu 4000 \
--memory 8192
</code></pre>
<h3 id="network-isolation"><a class="header" href="#network-isolation">Network Isolation</a></h3>
<p>Each environment gets isolated network:</p>
<ul>
<li>Subnet: 172.20.0.0/16 (default)</li>
<li>DNS enabled</li>
<li>Container-to-container communication</li>
</ul>
<h3 id="auto-cleanup"><a class="header" href="#auto-cleanup">Auto-Cleanup</a></h3>
<pre><code class="language-bash"># Auto-cleanup after tests
provisioning test env single redis --auto-start --auto-cleanup
</code></pre>
<h3 id="multiple-environments"><a class="header" href="#multiple-environments">Multiple Environments</a></h3>
<p>Run tests in parallel:</p>
<pre><code class="language-bash"># Create multiple environments
provisioning test env single kubernetes --auto-start &amp;
provisioning test env single postgres --auto-start &amp;
provisioning test env single redis --auto-start &amp;
wait
# List all
provisioning test env list
</code></pre>
<h2 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h2>
<h3 id="docker-not-running"><a class="header" href="#docker-not-running">Docker not running</a></h3>
<pre><code>Error: Failed to connect to Docker
</code></pre>
<p><strong>Solution:</strong></p>
<pre><code class="language-bash"># Check Docker
docker ps
# Start Docker daemon
sudo systemctl start docker # Linux
open -a Docker # macOS
</code></pre>
<h3 id="orchestrator-not-running"><a class="header" href="#orchestrator-not-running">Orchestrator not running</a></h3>
<pre><code>Error: Connection refused (port 8080)
</code></pre>
<p><strong>Solution:</strong></p>
<pre><code class="language-bash">cd provisioning/platform/orchestrator
./scripts/start-orchestrator.nu --background
</code></pre>
<h3 id="environment-creation-fails"><a class="header" href="#environment-creation-fails">Environment creation fails</a></h3>
<p>Check logs:</p>
<pre><code class="language-bash">provisioning test env logs &lt;env-id&gt;
</code></pre>
<p>Check Docker:</p>
<pre><code class="language-bash">docker ps -a
docker logs &lt;container-id&gt;
</code></pre>
<h3 id="out-of-resources"><a class="header" href="#out-of-resources">Out of resources</a></h3>
<pre><code>Error: Cannot allocate memory
</code></pre>
<p><strong>Solution:</strong></p>
<pre><code class="language-bash"># Cleanup old environments
provisioning test env list | each {|env| provisioning test env cleanup $env.id }
# Or cleanup Docker
docker system prune -af
</code></pre>
<h2 id="best-practices"><a class="header" href="#best-practices">Best Practices</a></h2>
<h3 id="1-use-templates"><a class="header" href="#1-use-templates">1. Use Templates</a></h3>
<p>Reuse topology templates instead of recreating:</p>
<pre><code class="language-bash">provisioning test topology load kubernetes_3node | test env cluster kubernetes
</code></pre>
<h3 id="2-auto-cleanup"><a class="header" href="#2-auto-cleanup">2. Auto-Cleanup</a></h3>
<p>Always use auto-cleanup in CI/CD:</p>
<pre><code class="language-bash">provisioning test quick &lt;taskserv&gt; # Includes auto-cleanup
</code></pre>
<h3 id="3-resource-planning"><a class="header" href="#3-resource-planning">3. Resource Planning</a></h3>
<p>Adjust resources based on needs:</p>
<ul>
<li>Development: 1-2 cores, 2GB RAM</li>
<li>Integration: 2-4 cores, 4-8GB RAM</li>
<li>Production-like: 4+ cores, 8+ GB RAM</li>
</ul>
<h3 id="4-parallel-testing"><a class="header" href="#4-parallel-testing">4. Parallel Testing</a></h3>
<p>Run independent tests in parallel:</p>
<pre><code class="language-bash">for taskserv in [kubernetes postgres redis] {
provisioning test quick $taskserv &amp;
}
wait
</code></pre>
<h2 id="configuration"><a class="header" href="#configuration">Configuration</a></h2>
<h3 id="default-settings"><a class="header" href="#default-settings">Default Settings</a></h3>
<ul>
<li>Base image: <code>ubuntu:22.04</code></li>
<li>CPU: 1000 millicores (1 core)</li>
<li>Memory: 2048 MB (2GB)</li>
<li>Network: 172.20.0.0/16</li>
</ul>
<h3 id="custom-config"><a class="header" href="#custom-config">Custom Config</a></h3>
<pre><code class="language-bash"># Override defaults
provisioning test env single postgres \
--base-image debian:12 \
--cpu 2000 \
--memory 4096
</code></pre>
<hr />
<h2 id="related-documentation"><a class="header" href="#related-documentation">Related Documentation</a></h2>
<ul>
<li><a href="../api/test-environment-api.html">Test Environment API</a></li>
<li><a href="../architecture/test-topologies.html">Topology Templates</a></li>
<li><a href="./orchestrator-guide.html">Orchestrator Guide</a></li>
<li><a href="./taskserv-development.html">Taskserv Development</a></li>
</ul>
<hr />
<h2 id="version-history"><a class="header" href="#version-history">Version History</a></h2>
<div class="table-wrapper"><table><thead><tr><th>Version</th><th>Date</th><th>Changes</th></tr></thead><tbody>
<tr><td>1.0.0</td><td>2025-10-06</td><td>Initial test environment service</td></tr>
</tbody></table>
</div>
<hr />
<p><strong>Maintained By</strong>: Infrastructure Team</p>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<a rel="prev" href="../user/SERVICE_MANAGEMENT_QUICKREF.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../user/test-environment-usage.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
<a rel="prev" href="../user/SERVICE_MANAGEMENT_QUICKREF.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../user/test-environment-usage.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
</nav>
</div>
<!-- Livereload script (if served using the cli tool) -->
<script>
const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
const socket = new WebSocket(wsAddress);
socket.onmessage = function (event) {
if (event.data === "reload") {
socket.close();
location.reload();
}
};
window.onbeforeunload = function() {
socket.close();
}
</script>
<script>
window.playground_copyable = true;
</script>
<script src="../elasticlunr.min.js"></script>
<script src="../mark.min.js"></script>
<script src="../searcher.js"></script>
<script src="../clipboard.min.js"></script>
<script src="../highlight.js"></script>
<script src="../book.js"></script>
<!-- Custom JS scripts -->
</div>
</body>
</html>