names: Allow adding multiple static domain names

- Change the mechanism for storing domain names in /etc/hosts. Don't write
hostname to /etc/hosts. Don't prepend hostname to domain name. This means that
when hostname changes, set_domain_name need not be called.

- This means that domain names such as example.fbx.one were not resolvable using
/etc/hosts but these will now resolve to 127.0.1.1. This is a minor concern to
becoming a breaking change.

- Don't use socket.getfqdn() for finding the domain name of the machine. Instead
read from /etc/hosts. There does not seem to a glibc/python API for querying
domain names from /etc/hosts with all variations it allows. Forward resolution
properly works no matter the library.

- Drop a pre-Python 3 conversion from unicode to ascii string for hostname. This
is no longer relevant.

- Domain name form is now domain add form. Passing domain name is mandatory.
Domain delete form and view have been introduced.

- Use augeas to edit hosts file. Add privileged methods to add/delete/get
domains. Add method to migration from old format to new. Support reading old
format too in get_domains.

Tests:

- Without hostname written in /etc/hosts, 'resolvectl query <hostname>' and
'ping <hostname>' work.

- With old /etc/hosts format apply patches and restart service. It will be
converted to new format.

- Adding a domain adds a new line to /etc/hosts file. The domain is shown in
domains list in Names app. Applications get reconfigured with the new domain
name.

- Deleting a domain adds a new line to /etc/hosts file. The domain is shown in
domains list in Names app. Applications get reconfigured with the new domain
name.

- Restarting app triggers domain added signal for all domains and all the
domains are shown in the Names app.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2025-02-16 10:44:50 -05:00
1 parent 889453daff
commit 863d170219
10 files changed
+223 -100

No files matched your search

+29 -5
View File
@@ -592,16 +592,40 @@ def running_inside_container():
#############################
# System -> Names utilities #
#############################
def set_hostname(browser, hostname):
def set_hostname(browser, hostname: str):
"""Configure the system hostname."""
visit(browser, '/plinth/sys/names/hostname/')
browser.find_by_id('id_hostname-hostname').fill(hostname)
submit(browser, form_class='form-hostname')
def set_domain_name(browser, domain_name):
visit(browser, '/plinth/sys/names/domains/')
browser.find_by_id('id_domain-name-domain_name').fill(domain_name)
submit(browser, form_class='form-domain-name')
def domain_add(browser, domain_name: str):
"""Add a domain to list of domains."""
if domain_name in domain_list(browser):
return
visit(browser, '/plinth/sys/names/')
click_link_by_href(browser, '/plinth/sys/names/domains/')
browser.find_by_id('id_domain-add-domain_name').fill(domain_name)
submit(browser, form_class='form-domain-add')
def domain_remove(browser, domain_name: str):
"""Remove a domain from list of domains."""
if domain_name not in domain_list(browser):
return
visit(browser, '/plinth/sys/names/')
click_link_by_href(browser,
f'/plinth/sys/names/domains/{domain_name}/delete/')
submit(browser, form_class='form-delete')
def domain_list(browser) -> list[str]:
"""Return a list of domains configured."""
visit(browser, '/plinth/sys/names/')
elements = browser.find_by_css('td.names-domain-column')
return [element.text for element in elements]
##############################