Move technical manifest exports out of panel workflows
Coulobre Panel CI / Checks (Python 3.12) (pull_request) Successful in 2m0s
Coulobre Panel CI / Checks (Python 3.14) (pull_request) Successful in 2m12s

This commit is contained in:
parkel committed 2026-12-04 13:17:28 +01:00
1 parent 7b486c491b
commit b58d683f21
14 files changed
+265 -73

No files matched your search

+4 -4
View File
@@ -1421,7 +1421,7 @@ confirm its domain using **Retire website**. The web node archives its data
and disables its Apache and PHP configuration. Retiring a failed provisioning request also frees its place in the plan. and disables its Apache and PHP configuration. Retiring a failed provisioning request also frees its place in the plan.
Its domain remains reserved until released with the account's names. Its domain remains reserved until released with the account's names.
Operators can download the website's version 2 manifest. Use the existing Export the website's version 2 manifest with `export_manifest website`. Use the existing
[website SFTP setup](development.md#install-sftp-keys-on-a-web-node) on the web node [website SFTP setup](development.md#install-sftp-keys-on-a-web-node) on the web node
with that manifest to authorize a key for the site's own user. The web with that manifest to authorize a key for the site's own user. The web
node suspends new SFTP logins for a suspended independent website when node suspends new SFTP logins for a suspended independent website when
@@ -1936,9 +1936,9 @@ managed database and restore it to an empty database with the same identity.
## Back up an account's website and databases ## Back up an account's website and databases
Download an account backup manifest from the panel. Use it to create one ZIP Export an account backup manifest from the CLI. Use it to create one ZIP
on a single server or bundle native archives from separate nodes. The CLI can on a single server or bundle native archives from separate nodes. The CLI can
also include mailbox archives when the downloaded manifest lists mailboxes. also include mailbox archives when the manifest lists mailboxes.
[Account backup and recovery](development.md#back-up-a-hosting-account) [Account backup and recovery](development.md#back-up-a-hosting-account)
### Start local account backups from the panel ### Start local account backups from the panel
@@ -2787,7 +2787,7 @@ reported failure. Operators need permission to view hosting accounts and
mailbox requests and the **Can add mailbox provisioning** permission. mailbox requests and the **Can add mailbox provisioning** permission.
The initial password is kept in the root-only credentials file on the mail node. The initial password is kept in the root-only credentials file on the mail node.
To locate that file, download the manifest and use the node's `apply` command. To locate that file, export the mailbox manifest and use the node's `apply` command.
Reapplying the manifest preserves the password and prints the file path. Reapplying the manifest preserves the password and prints the file path.
[Show mailbox connection details in the panel](#show-local-database-and-mailbox-connection-details) [Show mailbox connection details in the panel](#show-local-database-and-mailbox-connection-details)
+50 -25
View File
@@ -146,14 +146,35 @@ ID, operation, resource, and time. SSH key changes record fingerprints of
the keys added or removed. Queued changes still report their execution the keys added or removed. Queued changes still report their execution
status in the hosting account. status in the hosting account.
## Export manifests from the command line
Routine provisioning and backups in the panel do not require a separate
manifest. For manual node operations or local testing, export the matching
resource using the panel's Django management environment.
```sh
panel_manage export_manifest database 1 > coulobre-database-1.json
panel_manage export_manifest dns-zone 1 > coulobre-zone.json
panel_manage export_manifest mailbox 1 > coulobre-mailbox-1.json
panel_manage export_manifest website 1 > coulobre-website-1.json
panel_manage export_manifest apache-preview 1 > coulobre-web-plan-1.json
panel_manage export_manifest account-backup 1 --include-mail > account.json
```
Replace `1` with the ID of the matching database, DNS zone, mailbox,
independent website, Apache preview, or hosting account. Use the
[`panel_manage` helper](deployment.md#prepare-the-panel) on an installed
server, or `python manage.py` in a development checkout. The command only
exports metadata and does not apply changes or create a backup.
## Request a MariaDB database ## Request a MariaDB database
Open a hosting account and select **Request database**. Choose a short suffix Open a hosting account and select **Request database**. Choose a short suffix
such as `wordpress`. The panel derives the full database name from the account such as `wordpress`. The panel derives the full database name from the account
ID and suffix, so two accounts can each request a database named `wordpress`. ID and suffix, so two accounts can each request a database named `wordpress`.
The account page shows the requested databases. Operators can download a The account page shows the requested databases. The CLI manifest contains the
versioned deployment manifest containing the account ID and suffix. Managers account ID and suffix. Managers
can view the requested database names on their own assigned accounts. The can view the requested database names on their own assigned accounts. The
manifest describes the database to provision on a MariaDB node. manifest describes the database to provision on a MariaDB node.
@@ -168,7 +189,7 @@ coulobre-database-node inspect coulobre-database-1.json
Use a local MariaDB server with Unix socket authentication for Use a local MariaDB server with Unix socket authentication for
`root@localhost`. Install Coulobre with the `mariadb` extra in a root-owned `root@localhost`. Install Coulobre with the `mariadb` extra in a root-owned
virtual environment and apply the downloaded manifest on that server. virtual environment and apply the exported manifest on that server.
```sh ```sh
sudo /opt/coulobre/bin/coulobre-database-node apply coulobre-database-1.json sudo /opt/coulobre/bin/coulobre-database-node apply coulobre-database-1.json
@@ -286,11 +307,11 @@ Use `@` for the zone domain in either field. Use fully qualified names
for other records. The panel increments the SOA serial when the zone data for other records. The panel increments the SOA serial when the zone data
changes. Changing the account's primary domain preserves its existing DNS zones. changes. Changing the account's primary domain preserves its existing DNS zones.
Select **Download manifest** in the DNS table and copy the file to the Export the zone using the CLI and copy the file to the hosting server or a
hosting server or a separate DNS node. Managers can see the configured separate DNS node. Managers can see the configured domains and serials for
domains and serials for their assigned accounts. Operators with the their assigned accounts. Operators with the appropriate permissions can add
appropriate permissions can add and edit zones and download manifests. and edit zones in the panel.
The panel exports version 2 for zones containing MX or TXT records and Coulobre exports version 2 for zones containing MX or TXT records and
version 1 for other zones. version 1 for other zones.
A manifest can also be written directly for local testing. Save the A manifest can also be written directly for local testing. Save the
@@ -391,7 +412,7 @@ sudo /opt/coulobre/bin/coulobre-dns-node apply coulobre-zone.json
Coulobre validates the zone with `named-checkzone` and installs it under Coulobre validates the zone with `named-checkzone` and installs it under
`/etc/bind/coulobre/`. BIND9 persists the primary zone registration through `/etc/bind/coulobre/`. BIND9 persists the primary zone registration through
`rndc addzone`. To publish an edit, download the updated manifest and apply `rndc addzone`. To publish an edit manually, export the updated manifest and apply
it again. Coulobre checks the SOA serial, reloads the individual zone, and it again. Coulobre checks the SOA serial, reloads the individual zone, and
waits for BIND9 to report the requested serial. Reapply the same manifest to waits for BIND9 to report the requested serial. Reapply the same manifest to
resume after an interrupted reload. See the [BIND9 command reference](https://bind9.readthedocs.io/en/v9.18.39/manpages.html#rndc) and [RFC 1982](https://www.rfc-editor.org/rfc/rfc1982.html). resume after an interrupted reload. See the [BIND9 command reference](https://bind9.readthedocs.io/en/v9.18.39/manpages.html#rndc) and [RFC 1982](https://www.rfc-editor.org/rfc/rfc1982.html).
@@ -425,8 +446,8 @@ the `@`, such as `support`. The panel uses the account's primary domain,
lowercases the local part, and converts the domain to its ASCII DNS form. lowercases the local part, and converts the domain to its ASCII DNS form.
Existing mailbox requests keep their addresses when the primary domain changes. Existing mailbox requests keep their addresses when the primary domain changes.
The **Mailbox requests** table shows the email addresses. Operators can The **Mailbox requests** table shows the email addresses. The CLI export
download a versioned manifest that contains the domain and local part. contains the domain and local part.
Managers can see mailbox requests on their assigned accounts. Managers can see mailbox requests on their assigned accounts.
Version 2 adds `quota_mib` for mailboxes with a storage limit. Version 1 Version 2 adds `quota_mib` for mailboxes with a storage limit. Version 1
manifests continue to apply with no Coulobre storage limit. manifests continue to apply with no Coulobre storage limit.
@@ -571,7 +592,7 @@ mailbox already provisioned through the panel, saving queues an update on
the local mail node. Use **Retry provisioning** to retry a failed update the local mail node. Use **Retry provisioning** to retry a failed update
before setting another limit. before setting another limit.
For a mailbox provisioned manually, download its updated manifest and run For a mailbox provisioned manually, export its updated manifest and run
the following command on the mail node. the following command on the mail node.
```sh ```sh
@@ -609,7 +630,7 @@ running the check without root privileges.
### Back up and restore a mailbox ### Back up and restore a mailbox
Download the mailbox manifest from the panel and run the backup on the node Export the mailbox manifest and run the backup on the node
that hosts the mailbox. Use a new archive name in a root-controlled directory. that hosts the mailbox. Use a new archive name in a root-controlled directory.
```sh ```sh
@@ -734,8 +755,8 @@ python manage.py import_directadmin user.admin.customer.tar.zst
The import checks domain ownership again and creates the new hosting account, The import checks domain ownership again and creates the new hosting account,
supported database requests and selected domain's mailbox requests in one supported database requests and selected domain's mailbox requests in one
transaction. The JSON report includes the new account ID and the MariaDB transaction. The JSON report includes the new account ID and the MariaDB
names derived from the database requests. Use the account page to download names derived from the database requests. Use the CLI to export deployment
deployment manifests for the nodes. The `manual_review` list records the manifests for the nodes. The `manual_review` list records the
website, DNS, mail and SQL data to review before completing the separate website, DNS, mail and SQL data to review before completing the separate
restore steps below. restore steps below.
@@ -890,8 +911,8 @@ are eligible for delivery again.
## Render configuration on a web node ## Render configuration on a web node
Open a completed preview for the account's current domain and select **Download Export a completed preview for the account's current domain with
deployment manifest**. The versioned JSON file contains the account ID and `export_manifest apache-preview`. The versioned JSON file contains the account ID and
primary domain. The web node command validates those values and derives the primary domain. The web node command validates those values and derives the
system user, document root, and PHP-FPM socket from the account ID. system user, document root, and PHP-FPM socket from the account ID.
@@ -1188,11 +1209,10 @@ backup. The website can be recovered while its web services are stopped.
## Back up a hosting account ## Back up a hosting account
Open the account as an operator and select **Download backup manifest**. The Export the backup manifest with `export_manifest account-backup`. It lists the
manifest lists the primary website and all database requests for the account. website and database resources for the account. Pass `--include-mail` to also
Select **Download backup manifest with mail** to also include mailbox requests include mailbox requests from every mail domain assigned to the account.
from every mail domain assigned to the account. This option requires permission Provision all listed resources before running the
to view mailbox requests. Provision all listed resources before running the
backup. The ZIP contains the native website archive, a compressed SQL dump for backup. The ZIP contains the native website archive, a compressed SQL dump for
each listed database, and the requested mailbox archives. Back up DNS and panel each listed database, and the requested mailbox archives. Back up DNS and panel
settings separately. settings separately.
@@ -1272,13 +1292,18 @@ continue to unpack with the same filenames.
## Run an isolated PHP test site ## Run an isolated PHP test site
Open a completed preview for the account's current domain and select **Download Export a completed preview for the account's current domain to a new tar file.
test bundle**. The archive contains the exact Apache preview, a matching PHP-FPM
```sh
python manage.py export_manifest apache-preview 1 --smoke-bundle coulobre-web-plan-1.tar
```
The archive contains the exact Apache preview, a matching PHP-FPM
pool, site metadata, and a small PHP test page. It is intended for the isolated pool, site metadata, and a small PHP test page. It is intended for the isolated
Ubuntu check below. Ubuntu check below.
Run the test with Docker from the repository root. Set the bundle path to the Run the test with Docker from the repository root. Set the bundle path to the
downloaded tar archive. exported tar archive.
```sh ```sh
docker build -t coulobre-web-smoke tests/web-node docker build -t coulobre-web-smoke tests/web-node
+3
View File
@@ -32,6 +32,9 @@ only use shared components available in its supported Core versions.
time-stamped events and snapshots. Label historical details explicitly time-stamped events and snapshots. Label historical details explicitly
and keep live actions on the current resource or in a dedicated workflow. and keep live actions on the current resource or in a dedicated workflow.
Keep history scoped to the viewer’s role, especially internal config. Keep history scoped to the viewer’s role, especially internal config.
- Keep low-level provisioning manifests and developer test bundles out of
routine panel actions. Document their CLI export instead. Keep meaningful
user downloads, such as backup archives, in the relevant workflow.
- Use `.surface` for sections, `.section-heading` for ordinary section - Use `.surface` for sections, `.section-heading` for ordinary section
headers, and `.table-scroll` around tables. Keep horizontal overflow in headers, and `.table-scroll` around tables. Keep horizontal overflow in
the table wrapper and give empty or pending states an explicit label. the table wrapper and give empty or pending states an explicit label.
@@ -0,0 +1,83 @@
import json
from pathlib import Path
from django.core.management.base import BaseCommand, CommandError
from ...account_backups import account_backup_manifest
from ...models import (
HostingAccount,
HostingDatabase,
HostingDnsZone,
HostingMailbox,
IndependentWebsite,
WebProvisioningPlan,
)
from ...web_node import build_web_smoke_bundle, serialize_deployment_manifest
RESOURCE_MODELS = {
"account-backup": HostingAccount,
"database": HostingDatabase,
"dns-zone": HostingDnsZone,
"mailbox": HostingMailbox,
"website": IndependentWebsite,
"apache-preview": WebProvisioningPlan,
}
class Command(BaseCommand):
help = "Export a Coulobre provisioning or backup manifest as JSON."
def add_arguments(self, parser):
parser.add_argument("resource", choices=RESOURCE_MODELS)
parser.add_argument("id", type=int)
parser.add_argument("--include-mail", action="store_true")
parser.add_argument("--smoke-bundle", type=Path, metavar="TAR")
def handle(self, *args, **options):
resource = options["resource"]
record_id = options["id"]
include_mail = options["include_mail"]
bundle = options["smoke_bundle"]
if include_mail and resource != "account-backup":
raise CommandError("--include-mail requires account-backup.")
if bundle and resource != "apache-preview":
raise CommandError("--smoke-bundle requires apache-preview.")
if not 0 < record_id < 2**63:
raise CommandError("Enter a positive 64-bit resource ID.")
model = RESOURCE_MODELS[resource]
try:
record = model.objects.get(pk=record_id)
except model.DoesNotExist as error:
raise CommandError(
f"No {resource} with ID {record_id}."
) from error
if resource == "apache-preview":
if not record.can_export:
raise CommandError(
"Select a completed preview for the current domain."
)
if bundle:
self.write_bundle(record, bundle)
return
return serialize_deployment_manifest(record)
if resource == "account-backup":
if record.retired_at:
raise CommandError("Select an active hosting account.")
manifest = account_backup_manifest(
record, include_mailboxes=include_mail
)
else:
manifest = record.spec.manifest()
return json.dumps(manifest, indent=2)
def write_bundle(self, plan, path):
data = build_web_smoke_bundle(plan)
try:
with path.open("xb") as output:
output.write(data)
except OSError as error:
raise CommandError(
f"Could not write the bundle: {error}"
) from error
@@ -18,7 +18,7 @@
{% if is_tenant or perms.hosting.view_hostingdnszone %}<a href="#domains-dns">Domains and DNS</a>{% endif %} {% if is_tenant or perms.hosting.view_hostingdnszone %}<a href="#domains-dns">Domains and DNS</a>{% endif %}
{% if is_tenant or perms.hosting.view_hostingmailbox %}<a href="#email">Email</a>{% endif %} {% if is_tenant or perms.hosting.view_hostingmailbox %}<a href="#email">Email</a>{% endif %}
{% if is_tenant or perms.hosting.view_hostingdatabase %}<a href="#databases">Databases</a>{% endif %} {% if is_tenant or perms.hosting.view_hostingdatabase %}<a href="#databases">Databases</a>{% endif %}
{% if show_account_backups or export_backup_manifest %}<a href="#backups">Backups</a>{% endif %} {% if show_account_backups %}<a href="#backups">Backups</a>{% endif %}
{% if can_change_hosting_services or service_change or can_retire_account or is_operator and perms.hosting.change_hostingaccount %}<a href="#account-management">Account management</a>{% endif %} {% if can_change_hosting_services or service_change or can_retire_account or is_operator and perms.hosting.change_hostingaccount %}<a href="#account-management">Account management</a>{% endif %}
<a href="#history">History</a> <a href="#history">History</a>
</nav> </nav>
@@ -174,9 +174,6 @@
<button class="button secondary compact" type="submit">Open phpMyAdmin</button> <button class="button secondary compact" type="submit">Open phpMyAdmin</button>
</form> </form>
{% endif %} {% endif %}
{% if is_operator %}
<a class="button secondary compact" href="{% url 'panel:database_manifest' database.pk %}" aria-label="Download manifest for {{ database }}">Download manifest</a>
{% endif %}
</div> </div>
{% if is_operator and manage_database_provisioning and database.provisioning.problem %} {% if is_operator and manage_database_provisioning and database.provisioning.problem %}
<p class="heading-meta">{{ database.provisioning.problem }}</p> <p class="heading-meta">{{ database.provisioning.problem }}</p>
@@ -224,7 +221,6 @@
{% if is_operator %} {% if is_operator %}
<td> <td>
<div class="form-actions"> <div class="form-actions">
<a class="button secondary compact" href="{% url 'panel:dns_zone_manifest' zone.pk %}" aria-label="Download DNS manifest for {{ zone.domain }}">Download manifest</a>
{% if show_dns_replication %} {% if show_dns_replication %}
<a class="button secondary compact" href="{% url 'panel:dns_replication' zone.pk %}">Check replication</a> <a class="button secondary compact" href="{% url 'panel:dns_replication' zone.pk %}">Check replication</a>
{% endif %} {% endif %}
@@ -366,9 +362,6 @@
{% if show_mailbox_credentials %} {% if show_mailbox_credentials %}
<a class="button secondary compact" href="{% url 'panel:mailbox_credentials' mailbox.pk %}" aria-label="Connection details for {{ mailbox }}">Connection details</a> <a class="button secondary compact" href="{% url 'panel:mailbox_credentials' mailbox.pk %}" aria-label="Connection details for {{ mailbox }}">Connection details</a>
{% endif %} {% endif %}
{% if is_operator %}
<a class="button secondary compact" href="{% url 'panel:mailbox_manifest' mailbox.pk %}" aria-label="Download mailbox manifest for {{ mailbox }}">Download manifest</a>
{% endif %}
{% endif %} {% endif %}
{% include "hosting/mailbox_management_links.html" %} {% include "hosting/mailbox_management_links.html" %}
</div> </div>
@@ -402,19 +395,9 @@
{% endif %} {% endif %}
</section> </section>
{% endif %} {% endif %}
{% if show_account_backups or export_backup_manifest %} {% if show_account_backups %}
<section class="account-content" id="backups" data-account-section tabindex="-1" aria-label="Backups"> <section class="account-content" id="backups" data-account-section tabindex="-1" aria-label="Backups">
{% if export_backup_manifest %} {% include "hosting/account_backups.html" %}
<div class="form-actions account-actions">
{% if export_backup_manifest %}
<a class="button secondary" href="{% url 'panel:account_backup_manifest' account.pk %}">Download backup manifest</a>
{% endif %}
{% if export_mail_backup_manifest %}
<a class="button secondary" href="{% url 'panel:account_backup_manifest' account.pk %}?include_mail=1">Download backup manifest with mail</a>
{% endif %}
</div>
{% endif %}
{% if show_account_backups %}{% include "hosting/account_backups.html" %}{% endif %}
</section> </section>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
@@ -33,9 +33,6 @@
{% if action.value == 'settings' %}<a class="button secondary compact" href="{% url 'panel:independent_php_settings' account.pk website.pk %}">{{ action.label }}</a> {% if action.value == 'settings' %}<a class="button secondary compact" href="{% url 'panel:independent_php_settings' account.pk website.pk %}">{{ action.label }}</a>
{% else %}<a class="button {% if action.value == 'retire' %}danger{% else %}secondary{% endif %} compact" href="{% url 'panel:independent_website_operation' account.pk website.pk action.value %}">{{ action.label }}</a>{% endif %} {% else %}<a class="button {% if action.value == 'retire' %}danger{% else %}secondary{% endif %} compact" href="{% url 'panel:independent_website_operation' account.pk website.pk action.value %}">{{ action.label }}</a>{% endif %}
{% endfor %} {% endfor %}
{% if is_operator and perms.hosting.view_hostingaccount %}
<a class="button secondary compact" href="{% url 'panel:independent_website_manifest' account.pk website.pk %}">Download manifest</a>
{% endif %}
</div></td> </div></td>
</tr> </tr>
{% endfor %} {% endfor %}
@@ -44,12 +44,8 @@
<h2 id="configuration-heading">{% if plan_mode == "current" %}Primary HTTP virtual host{% else %}Virtual host configuration{% endif %}</h2> <h2 id="configuration-heading">{% if plan_mode == "current" %}Primary HTTP virtual host{% else %}Virtual host configuration{% endif %}</h2>
{% if plan_mode == "current" %}<p class="heading-meta">Coulobre’s recorded configuration. HTTPS and alias configuration are managed separately.</p>{% endif %} {% if plan_mode == "current" %}<p class="heading-meta">Coulobre’s recorded configuration. HTTPS and alias configuration are managed separately.</p>{% endif %}
</div> </div>
{% if plan_mode != "history" and not is_reseller and plan.can_export %} {% if may_manage_https %}
<div class="form-actions"> <a class="button secondary" href="{% url 'panel:website_https' plan.account_id %}">Manage HTTPS</a>
{% if may_manage_https %}<a class="button secondary" href="{% url 'panel:website_https' plan.account_id %}">Manage HTTPS</a>{% endif %}
<a class="button secondary" href="{% url 'panel:download_deployment_manifest' plan.pk %}">Download deployment manifest</a>
<a class="button secondary" href="{% url 'panel:download_smoke_bundle' plan.pk %}">Download test bundle</a>
</div>
{% endif %} {% endif %}
</header> </header>
<pre class="configuration"><code>{{ plan.apache_config }}</code></pre> <pre class="configuration"><code>{{ plan.apache_config }}</code></pre>
+2 -2
View File
@@ -83,7 +83,7 @@ class AccountBackupManifestTests(TestCase):
(self.cms.spec, self.shop.spec), (self.cms.spec, self.shop.spec),
), ),
) )
self.assertContains( self.assertNotContains(
self.client.get(self.account.get_absolute_url()), self.url self.client.get(self.account.get_absolute_url()), self.url
) )
@@ -141,7 +141,7 @@ class AccountBackupManifestTests(TestCase):
AccountBackup.from_manifest(response.json()).mailboxes, AccountBackup.from_manifest(response.json()).mailboxes,
(old_mailbox.spec, current_mailbox.spec), (old_mailbox.spec, current_mailbox.spec),
) )
self.assertContains( self.assertNotContains(
self.client.get(self.account.get_absolute_url()), self.client.get(self.account.get_absolute_url()),
"Download backup manifest with mail", "Download backup manifest with mail",
) )
@@ -121,7 +121,7 @@ class DatabaseProvisioningTests(TestCase):
def test_disabled_provisioning_preserves_existing_manifest_download(self): def test_disabled_provisioning_preserves_existing_manifest_download(self):
detail = self.client.get(self.detail) detail = self.client.get(self.detail)
self.assertNotContains(detail, "Provision database") self.assertNotContains(detail, "Provision database")
self.assertContains(detail, "Download manifest") self.assertNotContains(detail, "Download manifest")
self.assertEqual(self.client.post(self.url).status_code, 404) self.assertEqual(self.client.post(self.url).status_code, 404)
def test_operator_can_retry_a_failed_request(self): def test_operator_can_retry_a_failed_request(self):
+1 -1
View File
@@ -391,7 +391,7 @@ class DnsZonePanelTests(TestCase):
zone = self.create_zone() zone = self.create_zone()
self.client.force_login(self.reader) self.client.force_login(self.reader)
account = self.client.get(self.account.get_absolute_url()) account = self.client.get(self.account.get_absolute_url())
self.assertContains(account, "Download DNS manifest") self.assertNotContains(account, "Download DNS manifest")
self.assertNotContains(account, "Edit DNS zone") self.assertNotContains(account, "Edit DNS zone")
self.assertContains( self.assertContains(
self.client.get( self.client.get(
@@ -0,0 +1,102 @@
import json
import tarfile
from io import StringIO
from pathlib import Path
from tempfile import TemporaryDirectory
from django.core.management import CommandError, call_command
from django.test import TestCase
from .models import (
HostingAccount,
HostingDatabase,
HostingDnsZone,
HostingMailbox,
HostingMailDomain,
IndependentWebsite,
WebProvisioningPlan,
WebsiteDomain,
)
from .tasks import render_web_plan
class ExportManifestTests(TestCase):
@classmethod
def setUpTestData(cls):
cls.account = HostingAccount.objects.create(
name="Example", primary_domain="example.net"
)
cls.database = HostingDatabase.objects.create(
account=cls.account, suffix="cms"
)
domain = HostingMailDomain.objects.create(
account=cls.account, domain=cls.account.primary_domain
)
cls.mailbox = HostingMailbox.objects.create(
mail_domain=domain, local_part="contact"
)
cls.zone = HostingDnsZone.objects.create(
account=cls.account,
domain=cls.account.primary_domain,
responsible_name="hostmaster.example.net",
nameservers=["ns1.provider.example", "ns2.provider.example"],
)
cls.website = IndependentWebsite.objects.create(
reservation=WebsiteDomain.objects.create(
account=cls.account, domain="blog.example.net"
)
)
cls.preview = WebProvisioningPlan.for_account(cls.account)
cls.preview.save()
def export(self, resource, pk, *args):
result = StringIO()
call_command(
"export_manifest", resource, str(pk), *args, stdout=result
)
return json.loads(result.getvalue())
def test_provisioning_exports_match_their_manifest_format(self):
for resource, model in (
("database", self.database),
("dns-zone", self.zone),
("mailbox", self.mailbox),
("website", self.website),
):
with self.subTest(resource=resource):
self.assertEqual(
self.export(resource, model.pk), model.spec.manifest()
)
def test_backup_manifest_can_include_requested_mailboxes(self):
self.assertNotIn(
"mailboxes", self.export("account-backup", self.account.pk)
)
self.assertEqual(
self.export("account-backup", self.account.pk, "--include-mail")[
"mailboxes"
],
[self.mailbox.spec.manifest()],
)
def test_preview_must_be_ready_and_bundle_cannot_replace_a_file(self):
with self.assertRaisesMessage(CommandError, "completed preview"):
self.export("apache-preview", self.preview.pk)
render_web_plan.run(self.preview.pk)
self.assertEqual(
self.export("apache-preview", self.preview.pk)["domain"],
"example.net",
)
with TemporaryDirectory() as directory:
path = Path(directory, "test.tar")
args = (
"apache-preview",
str(self.preview.pk),
"--smoke-bundle",
str(path),
)
call_command("export_manifest", *args)
with tarfile.open(path) as archive:
self.assertIn("apache.conf", archive.getnames())
with self.assertRaisesMessage(CommandError, "Could not write"):
call_command("export_manifest", *args)
+12 -3
View File
@@ -82,6 +82,7 @@ class MailboxImportTests(TestCase):
email = reverse("panel:domain_workspace", args=[account.pk, "email"]) email = reverse("panel:domain_workspace", args=[account.pk, "email"])
for path in (email, account.get_absolute_url()): for path in (email, account.get_absolute_url()):
response = self.client.get(path, secure=True) response = self.client.get(path, secure=True)
self.assertNotContains(response, "View import result")
for name, label, variant in ( for name, label, variant in (
("mailbox_import", "Import mail", "secondary"), ("mailbox_import", "Import mail", "secondary"),
( (
@@ -126,11 +127,19 @@ class MailboxImportTests(TestCase):
job.finished_at = timezone.now() job.finished_at = timezone.now()
job.problem = "Check your source password." job.problem = "Check your source password."
job.save(update_fields=["finished_at", "problem"]) job.save(update_fields=["finished_at", "problem"])
self.assertContains(self.client.get(email), "Import needs attention") for path in (email, account.get_absolute_url()):
response = self.client.get(path)
self.assertContains(response, "Import needs attention")
self.assertContains(response, ">Review import</a>")
self.assertNotContains(response, "View import result")
job.problem = "" job.problem = ""
job.save(update_fields=["problem"]) job.save(update_fields=["problem"])
self.assertContains(self.client.get(email), "Import complete") for path in (email, account.get_absolute_url()):
self.assertNotContains(self.client.get(email), "Import in progress") response = self.client.get(path)
self.assertContains(response, "Import complete")
self.assertContains(response, ">View import result</a>", count=1)
self.assertContains(response, ">Import mail</a>", count=1)
self.assertNotContains(response, "Import in progress")
def test_only_the_owner_and_authorized_operator_can_start_import(self): def test_only_the_owner_and_authorized_operator_can_start_import(self):
self.sign_in(self.stranger) self.sign_in(self.stranger)
+2 -2
View File
@@ -39,7 +39,7 @@ class WebSmokeBundleTests(TestCase):
render_web_plan.run(self.plan.pk) render_web_plan.run(self.plan.pk)
detail = self.client.get(reverse("panel:plan", args=[self.plan.pk])) detail = self.client.get(reverse("panel:plan", args=[self.plan.pk]))
self.assertContains(detail, "Download test bundle") self.assertNotContains(detail, "Download test bundle")
response = self.client.get(self.download) response = self.client.get(self.download)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "application/x-tar") self.assertEqual(response["Content-Type"], "application/x-tar")
@@ -96,7 +96,7 @@ class WebSmokeBundleTests(TestCase):
render_web_plan.run(self.plan.pk) render_web_plan.run(self.plan.pk)
detail = self.client.get(reverse("panel:plan", args=[self.plan.pk])) detail = self.client.get(reverse("panel:plan", args=[self.plan.pk]))
self.assertContains(detail, "Download deployment manifest") self.assertNotContains(detail, "Download deployment manifest")
response = self.client.get(self.manifest) response = self.client.get(self.manifest)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertIn(".json", response["Content-Disposition"]) self.assertIn(".json", response["Content-Disposition"])
-6
View File
@@ -824,12 +824,6 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
context["can_enable_alias_https"] = panel_feature_allowed( context["can_enable_alias_https"] = panel_feature_allowed(
"LOCAL_WEB_HTTPS" "LOCAL_WEB_HTTPS"
) and user.has_perms(ENABLE_WEB_HTTPS) ) and user.has_perms(ENABLE_WEB_HTTPS)
context["export_backup_manifest"] = not tenant and user.has_perms(
EXPORT_BACKUP_MANIFEST
)
context["export_mail_backup_manifest"] = context[
"export_backup_manifest"
] and user.has_perm(VIEW_MAILBOXES)
if ( if (
settings.LOCAL_ACCOUNT_BACKUPS settings.LOCAL_ACCOUNT_BACKUPS
and not tenant and not tenant