Merge lp:~jtv/maas/bug-1300059 into lp:~maas-committers/maas/trunk
Proposed by
Jeroen T. Vermeulen
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jeroen T. Vermeulen | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 2225 | ||||
Proposed branch: | lp:~jtv/maas/bug-1300059 | ||||
Merge into: | lp:~maas-committers/maas/trunk | ||||
Diff against target: |
253 lines (+161/-8) 3 files modified
src/maasserver/models/node.py (+42/-2) src/maasserver/models/tests/test_node.py (+117/-2) src/maasserver/tests/test_api_node.py (+2/-4) |
||||
To merge this branch: | bzr merge lp:~jtv/maas/bug-1300059 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raphaël Badin (community) | Approve | ||
Review via email: mp+214032@code.launchpad.net |
Commit message
Validate hostnames.
Description of the change
Until now, hostnames entered for nodes were left completely unvalidated. They could contain anything, valid or not. This branch provides a validator.
The validator does not support unicode, because MAAS doesn't. If you want internationalized domain names, you'll need to encode them yourself and enter the resulting Punycode into MAAS. We could at some point support unicode input, but I believe the changes would probably have to be more extensive than just a change in validator.
Jeroen
To post a comment you must log in.
Looks good. As discussed on IRC, it means people with existing nodes with invalid labels will need to rename their nodes before they can do any modifications to them but:
a) the problem will be quite easy to identify (the validation error will be pretty clear)
b) I don't expect many people will have to face this problem
[0]
> If the hostname is not valid according to RFCs 952 and 1123.
I know a hostname is a hostname (as in "A Big Mac is a Big Mac") but I think this is worth repeating in a place that makes it to the documentation, i.e. in ":ivar hostname: This `Node`'s hostname." in src/maasserver/ models/ node.py: Node
[1]
41 + if len(label) > 63: ("Label is too long: '%s'." % label)
42 + raise ValidationError
The error would be more informative if it mentioned the limit.
[2]
40 + raise ValidationError ("Hostname contains empty label.") ("Label is too long: '%s'." % label)
41 + if len(label) > 63:
42 + raise ValidationError
Do you think it's obvious to people what a "label", in this context, means? I must admit it was not obvious to me before I read your comments. Maybe "part"?
[3]
44 + raise ValidationError(
45 + "Label cannot start or end with hyphen: '%s'." % label)
You can use %r here, this saves you from having to include the single quotes around the string.
[4]
59 + hostname = CharField( [validate_ hostname] )
60 + max_length=255, default='', blank=True, unique=True,
61 + validators=
Once more, maybe mention the RFCs in the help_text.