IP-based hostname concatenated with a string is not accepted.

Bug #1550083 reported by Karan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
Fix Released
High
Alberto Donato
1.9
Won't Fix
High
Unassigned
2.0
Won't Fix
High
Unassigned

Bug Description

When assigning a hostname like '206-141-40-41-os-compute' to a node using web interface, it is not accepted and a random hostname is used in place of user supplied hostname.

How to reproduce.

Try changing hostname to '206-141-40-41-os-compute' of a node through web interface.

 Output from dpkg -l '*maas*'|cat
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===================================-=====================================-============-===============================================================================
ii maas 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS server all-in-one metapackage
ii maas-cli 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS command line API tool
ii maas-cluster-controller 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS server cluster controller
ii maas-common 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS server common files
ii maas-dhcp 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS DHCP server
ii maas-dns 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS DNS server
ii maas-proxy 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS Caching Proxy
ii maas-region-controller 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS server complete region controller
ii maas-region-controller-min 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS Server minimum region controller
ii python-django-maas 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS server Django web framework
ii python-maas-client 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS python API client
ii python-maas-provisioningserver 1.9.0+bzr4533-0ubuntu1~trusty1 all MAAS server provisioning libraries

I looked into code and found this is happening because IP-based hostnames are replaced by randomly generated hostname.
Replacing
IP_BASED_HOSTNAME_REGEXP = re.compile('\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3}')
with
IP_BASED_HOSTNAME_REGEXP = re.compile('^\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3}$') fixes this

File: maasserver/forms.pyc

class WithMACAddressesMixin:
...
...
def save(self):
        # Generate a hostname for this node if the provided hostname is
        # IP-based (because this means that this name comes from a DNS
        # reverse query to the MAAS DNS) or an empty string.
        generate_hostname = (
            hostname == "" or
            IP_BASED_HOSTNAME_REGEXP.match(stripped_hostname) is not None)
        if generate_hostname:
            node.set_random_hostname()

Related branches

Karan (karan-pugla)
description: updated
Revision history for this message
Andres Rodriguez (andreserl) wrote :

Hi Karan,

How are you trying to change the hostname?

Changed in maas:
status: New → Incomplete
milestone: none → 1.9.1
Revision history for this message
Karan (karan-pugla) wrote :

I am doing it through MAAS dashboard

Revision history for this message
Karan (karan-pugla) wrote :

It works fine with CLI though.

Changed in maas:
milestone: 1.9.1 → 1.9.2
Changed in maas:
milestone: 1.9.2 → 1.9.3
Changed in maas:
milestone: 1.9.3 → 1.9.4
Changed in maas:
milestone: 1.9.4 → 1.9.5
Revision history for this message
LaMont Jones (lamont) wrote :

Any hostname that the user attempts to assign via the form, which starts with (re.match is anchored to start of string) something that matches '\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3}' will be rejected by the form. This was introduced in october 2012. The fix is to change the regex to have the trailing "$".

Changed in maas:
status: Incomplete → Confirmed
no longer affects: maas/2.1
Revision history for this message
LaMont Jones (lamont) wrote :

As a trivial workaround, prepending anything before the IP-based name also avoids the issue.

Changed in maas:
milestone: 2.1.0 → 2.1.1
Changed in maas:
milestone: 2.1.1 → 2.1.2
Changed in maas:
milestone: 2.1.2 → 2.1.3
Changed in maas:
milestone: 2.1.3 → 2.3.x
no longer affects: maas/trunk
Alberto Donato (ack)
Changed in maas:
assignee: nobody → Alberto Donato (ack)
Alberto Donato (ack)
Changed in maas:
status: Triaged → In Progress
Changed in maas:
status: In Progress → Fix Committed
Changed in maas:
milestone: 2.3.x → 2.3.0
Changed in maas:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.