[virt-tools-list] [virt-manager PATCH] interface: check ip address format

Cole Robinson crobinso at redhat.com
Sun Mar 30 17:44:20 UTC 2014


On 03/30/2014 11:33 AM, Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
> 
> Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
> ---
>  tests/xmlparse-xml/interface-test-bridge-ip-out.xml |  2 +-
>  tests/xmlparse.py                                   |  2 +-
>  virtinst/interface.py                               | 11 ++++++++++-
>  3 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/xmlparse-xml/interface-test-bridge-ip-out.xml b/tests/xmlparse-xml/interface-test-bridge-ip-out.xml
> index d4cfba0..49e0510 100644
> --- a/tests/xmlparse-xml/interface-test-bridge-ip-out.xml
> +++ b/tests/xmlparse-xml/interface-test-bridge-ip-out.xml
> @@ -15,7 +15,7 @@
>    </protocol>
>    <protocol family="ipv6">
>      <ip address="fe99::215:58ff:fe6e:5" prefix="32"/>
> -    <ip address="foobar" prefix="38"/>
> +    <ip address="2002::" prefix="38"/>
>      <route gateway="1.2.3.4"/>
>    </protocol>
>  </interface>
> diff --git a/tests/xmlparse.py b/tests/xmlparse.py
> index 3e78a5d..75189bc 100644
> --- a/tests/xmlparse.py
> +++ b/tests/xmlparse.py
> @@ -965,7 +965,7 @@ class XMLParseTest(unittest.TestCase):
>          check("autoconf", True, False)
>  
>          check = self._make_checker(iface.protocols[1].ips[1])
> -        check("address", "fe80::215:58ff:fe6e:5", "foobar")
> +        check("address", "fe80::215:58ff:fe6e:5", "2002::")
>          check("prefix", 64, 38)
>  
>          # Remove a child interface, verify it's data remains intact
> diff --git a/virtinst/interface.py b/virtinst/interface.py
> index c1e0c88..4fca76a 100644
> --- a/virtinst/interface.py
> +++ b/virtinst/interface.py
> @@ -23,6 +23,7 @@ Classes for building and installing libvirt interface xml
>  import logging
>  
>  import libvirt
> +import ipaddr
>  
>  from virtinst import util
>  from virtinst.xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
> @@ -32,7 +33,15 @@ class _IPAddress(XMLBuilder):
>      _XML_PROP_ORDER = ["address", "prefix"]
>      _XML_ROOT_NAME = "ip"
>  
> -    address = XMLProperty("./@address")
> +    ######################
> +    # Validation helpers #
> +    ######################
> +
> +    def _validate_ipaddr(self, addr):
> +        ipaddr.IPAddress(addr)
> +        return addr
> +
> +    address = XMLProperty("./@address", validate_cb=_validate_ipaddr)
>      prefix = XMLProperty("./@prefix", is_int=True)
>  
>  
> 

ACK

- Cole




More information about the virt-tools-list mailing list