Show known hypervisors and the Hetzner placeholder for virtual machines

This commit is contained in:
2026-11-18 22:39:29 +01:00
parent 08177d8843
commit bcd3bd86ad
13 changed files with 530 additions and 11 deletions
+78
View File
@@ -292,3 +292,81 @@ test('moves an existing pairing through the WebUI and waits for target inventory
await expect(page.getByRole('link', { name: 'Neue Kopplung öffnen' })).toHaveAttribute('href',
'#geraete/' + target.tenant_id + '/new-asset/new-agent');
});
test('shows real VM hosts and the Hetzner placeholder without adding a device', async ({ page }) => {
const tenant = '11111111-1111-4111-8111-111111111111';
const path = '/api/v1/tenants/' + tenant;
const customer = { tenant_id: tenant, name: 'Testkunde' };
const base = { ...customer, customer_name: customer.name,
lifecycle: 'current', status: 'online', recent_jobs: [], volumes: [] };
const vm = { ...base, hostname: 'Test-VM', asset_id: 'vm-asset', agent_id: 'vm-agent', device_type: 'virtual' };
const pve = { ...base, hostname: 'pve-01', asset_id: 'pve-asset', agent_id: 'pve-agent',
device_type: 'hypervisor', os: 'Proxmox VE' };
const placeholder = { kind: 'placeholder', provider: 'hetzner', hostname: 'Hetzner Cloud' };
let assigned = false;
const guest = () => ({ ...vm, assigned_hypervisor_asset_id: assigned ? pve.asset_id : null,
hypervisor: assigned ? { kind: 'device', hostname: pve.hostname, asset_id: pve.asset_id, agent_id: pve.agent_id } : placeholder });
const listing = (items: unknown[]) => ({ items, next_cursor: null, truncated: false,
completeness: 'complete', as_of: new Date().toISOString() });
await page.route(origin + '/auth/config', r => r.fulfill({ json: {
local_login_enabled: true, oidc_configured: false, oidc_login_url: null, dev_login_enabled: false
} }));
await page.route(origin + '/auth/session', r => r.fulfill({ json: {
principal: 'inventory-owner', tenant_id: tenant, csrf_token: 'host-assignment-fixture',
testsimulation: false, permissions: ['inventory:read', 'devices:revoke']
} }));
await page.route(origin + '/api/v1/**', r => {
const req = r.request(), url = new URL(req.url());
if (url.pathname === '/api/v1/tenants') return r.fulfill({ json: listing([customer]) });
if (url.pathname === '/api/v1/devices' || url.pathname === path + '/devices') {
return r.fulfill({ json: listing([guest(), pve]) });
}
if (url.pathname === path + '/devices/' + vm.asset_id) return r.fulfill({ json: guest() });
if (url.pathname === path + '/devices/' + pve.asset_id) return r.fulfill({ json: pve });
if (url.pathname === path + '/hypervisors') {
expect(req.headers()['x-rmm-tenant']).toBe(tenant);
return r.fulfill({ json: { items: [pve], truncated: false } });
}
if (url.pathname === path + '/devices/' + vm.asset_id + '/hypervisor') {
expect(req.method()).toBe('POST');
expect(req.headers()['x-csrf-token']).toBe('host-assignment-fixture');
expect(url.searchParams.get('agent_id')).toBe(vm.agent_id);
const target = req.postDataJSON().hypervisor_asset_id;
expect(target).toBe(assigned ? null : pve.asset_id);
assigned = target === pve.asset_id;
return r.fulfill({ json: { asset_id: vm.asset_id, hypervisor_asset_id: target } });
}
return r.fulfill({ status: 404, json: { code: 'NOT_FOUND' } });
});
await page.goto(origin + '/#geraete');
const vmRow = page.getByRole('row').filter({ has: page.getByRole('button', { name: vm.hostname }) });
await expect(vmRow).toContainText('Hetzner Cloud');
await expect(vmRow).toContainText('Platzhalter');
await expect(page.getByRole('button', { name: 'Hetzner Cloud' })).toHaveCount(0);
await expect(page.locator('.fleet-table tbody tr')).toHaveCount(2);
await page.getByRole('button', { name: vm.hostname }).click();
await page.getByText('Gerät verwalten', { exact: true }).click();
await page.getByText('Hypervisor zuordnen', { exact: true }).click();
const hostInput = page.getByRole('combobox', { name: 'Hypervisor auswählen' });
await hostInput.selectOption(pve.asset_id);
await page.getByRole('button', { name: 'Zuordnung speichern' }).click();
await expect(page.getByText('Hypervisor zugeordnet.', { exact: true })).toBeVisible();
await page.getByRole('button', { name: 'Zur Geräteliste' }).click();
await page.setViewportSize({ width: 390, height: 844 });
const hostLink = vmRow.getByRole('link', { name: pve.hostname });
await expect(hostLink).toBeVisible();
await expect(vmRow).not.toContainText('Hetzner Cloud');
await hostLink.click();
await expect(page.getByRole('heading', { name: pve.hostname })).toBeVisible();
await page.getByRole('button', { name: 'Zur Geräteliste' }).click();
await page.getByRole('button', { name: vm.hostname }).click();
await page.getByText('Gerät verwalten', { exact: true }).click();
await page.getByText('Hypervisor zuordnen', { exact: true }).click();
await hostInput.selectOption('');
await page.getByRole('button', { name: 'Zuordnung speichern' }).click();
await expect(page.getByText('Hostzuordnung entfernt.', { exact: true })).toBeVisible();
await page.getByRole('button', { name: 'Zur Geräteliste' }).click();
await expect(vmRow).toContainText('Hetzner Cloud');
});