Wsme ipv4address type can not used for rest api validate

Bug #1455404 reported by Kai Qiang Wu(Kennan)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
WSME
Fix Released
Undecided
Unassigned

Bug Description

Magnum project used wsme and it has code as following
https://github.com/openstack/magnum/blob/master/magnum/api/controllers/v1/baymodel.py

baymodel has following(code snip)

class BayModel(base.APIBase):
    """API representation of a baymodel.
    This class enforces type checking and value constraints, and converts
    between the internal object model and the API representation of a baymodel.
    """

    _coe = None

    def _get_coe(self):
        return self._coe

    def _set_coe(self, value):
        if value and self._coe != value:
            self._coe = value
        elif value == wtypes.Unset:
            self._coe = wtypes.Unset

    uuid = types.uuid
    """Unique UUID for this baymodel"""

    name = wtypes.StringType(min_length=1, max_length=255)
    """The name of the bay model"""

    coe = wsme.wsproperty(wtypes.text, _get_coe, _set_coe, mandatory=True)
    """The Container Orchestration Engine for this bay model"""

    image_id = wsme.wsattr(wtypes.StringType(min_length=1, max_length=255),
                           mandatory=True)
    """The image name or UUID to use as a base image for this baymodel"""

    flavor_id = wtypes.StringType(min_length=1, max_length=255)
    """The flavor of this bay model"""

    master_flavor_id = wtypes.StringType(min_length=1, max_length=255)
    """The flavor of the master node for this bay model"""

    dns_nameserver = wtypes.IPv4AddressType()
    """The DNS nameserver address"""

....

Here the dns_nameserver if set with wtypes.IPv4AddressType() , can not deal with string '8.8.1.1',

as wsme .IPv4AddressType() has logic as: (https://github.com/stackforge/wsme/blob/master/wsme/types.py)

class IPv4AddressType(UserType):
    """
    A simple IPv4 type.
    """
    basetype = six.string_types
    name = "ipv4address"

    @staticmethod
    def validate(value):
        try:
            ipaddress.IPv4Address(value)
        except ipaddress.AddressValueError:
            error = 'Value should be IPv4 format'
            raise ValueError(error)
        else:
            return value

The ipaddress it import logic is:
try:
    import ipaddress
except ImportError:
    import ipaddr as ipaddress

The first ipaddress module can not accept unocide, like u'8.8.1.1', only import ipaddr as ipaddress can accept both string and unicode.

So it can cause issue, if it only have ipaddress module, so rest api pass string '8.8.1.1' would failed for ipaddress validate.

Our jenkins failure job can be found here:

http://logs.openstack.org/89/182589/4/check/gate-magnum-python27/5841b0f/console.html

2015-05-14 06:58:55.425 | FAIL: magnum.tests.unit.api.controllers.v1.test_baymodel.TestPost.test_create_baymodel_doesnt_contain_id
2015-05-14 06:58:55.425 | tags: worker-4
2015-05-14 06:58:55.425 | ----------------------------------------------------------------------
2015-05-14 06:58:55.425 | Empty attachments:
2015-05-14 06:58:55.426 | stderr
2015-05-14 06:58:55.426 |
2015-05-14 06:58:55.426 | stdout: {{{POST: /v1/baymodels {'external_network_id': 'd1f02cfb-d27f-4068-9332-84d907cb0e2e', 'image_id': 'my-image', 'name': 'baymodel1', 'project_id': 'fake_project', 'dns_nameserver': '8.8.1.1', 'flavor_id': 'm1.small', 'ssh_authorized_key': 'ssh-rsa AAAAB3NzaC1ycEAAAADAv0XRqg3tm+jlsOKGO81lPDH+KaSJQ7wvmjUqszP/H6NC/m+qiGp/sTisDYucqbeuM7nmJi+8Hb55y1xWoOZIKMa71G5/4EOQxuQ/sgW965OOO2HqX8vjlQUnTK0HijrbSTLxp/9kazWWFrfsdB8RtZBN digambar@magnum', 'cluster_distro': 'fedora-atomic', 'uuid': 'e74c40e0-d825-11e2-a28f-0800200c9a66', 'coe': 'swarm', 'docker_volume_size': 20, 'fixed_network': 'private', 'apiserver_port': 8080, 'keypair_id': 'keypair1', 'master_flavor_id': 'm1.small', 'user_id': 'fake_user'}}}}
2015-05-14 06:58:55.427 |
2015-05-14 06:58:55.427 | Traceback (most recent call last):
2015-05-14 06:58:55.427 | File "/home/jenkins/workspace/gate-magnum-python27/.tox/py27/local/lib/python2.7/site-packages/mock.py", line 1201, in patched
2015-05-14 06:58:55.428 | return func(*args, **keywargs)
2015-05-14 06:58:55.428 | File "magnum/tests/unit/api/controllers/v1/test_baymodel.py", line 368, in test_create_baymodel_doesnt_contain_id
2015-05-14 06:58:55.428 | response = self.post_json('/baymodels', cdict)
2015-05-14 06:58:55.429 | File "magnum/tests/unit/api/base.py", line 143, in post_json
2015-05-14 06:58:55.429 | status=status, method="post")
2015-05-14 06:58:55.429 | File "magnum/tests/unit/api/base.py", line 104, in _request_json
2015-05-14 06:58:55.429 | expect_errors=expect_errors
2015-05-14 06:58:55.430 | File "/home/jenkins/workspace/gate-magnum-python27/.tox/py27/local/lib/python2.7/site-packages/webtest/utils.py", line 37, in wrapper
2015-05-14 06:58:55.430 | return self._gen_request(method, url, **kw)
2015-05-14 06:58:55.430 | File "/home/jenkins/workspace/gate-magnum-python27/.tox/py27/local/lib/python2.7/site-packages/webtest/app.py", line 735, in _gen_request
2015-05-14 06:58:55.431 | expect_errors=expect_errors)
2015-05-14 06:58:55.436 | File "/home/jenkins/workspace/gate-magnum-python27/.tox/py27/local/lib/python2.7/site-packages/webtest/app.py", line 631, in do_request
2015-05-14 06:58:55.436 | self._check_status(status, res)
2015-05-14 06:58:55.436 | File "/home/jenkins/workspace/gate-magnum-python27/.tox/py27/local/lib/python2.7/site-packages/webtest/app.py", line 663, in _check_status
2015-05-14 06:58:55.436 | res)
2015-05-14 06:58:55.437 | webtest.app.AppError: Bad response: 400 Bad Request (not 200 OK or 3xx redirect for http://localhost/v1/baymodels)
2015-05-14 06:58:55.437 | '{"error_message": "{\\"faultcode\\": \\"Client\\", \\"debuginfo\\": null, \\"faultstring\\": \\"Invalid input for field/attribute dns_nameserver. Value: \'8.8.1.1\'. Value should be IPv4 format\\"}"}'
2015-05-14 06:58:55.438 | ======================================================================
2015-05-14 06:58:55.438 | FAIL: magnum.tests.unit.api.controllers.v1.test_baymodel.TestPost.test_create_baymodel_with_docker_volume_size
2015-05-14 06:58:55.438 | tags: worker-0
2015-05-14 06:58:55.438 | ----------------------------------------------------------------------

Revision history for this message
Stéphane Bisinger (kjir) wrote :

There is a patch that is being worked on to substitute ipaddr with netaddr, I think it should fix this issue: https://review.openstack.org/#/c/183449/

We should add unitests to check for this case...

Revision history for this message
Kai Qiang Wu(Kennan) (wkqwu) wrote :

Good to know that, thanks

Changed in wsme:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to wsme (master)

Reviewed: https://review.openstack.org/183449
Committed: https://git.openstack.org/cgit/stackforge/wsme/commit/?id=002473c0eaff5bde539e6f6980c387d3817f7063
Submitter: Jenkins
Branch: master

commit 002473c0eaff5bde539e6f6980c387d3817f7063
Author: Lan Qi song <email address hidden>
Date: Fri May 15 17:32:39 2015 +0800

    Move ipaddr to netaddr

    Ipaddr module was never introduced by openstack and never used by
    other openstack components. We should move to more reliable module
    netaddr to validate ip format.

    Change-Id: I38d0c6f4ea2147ce071ab62a7c9d546436aec185
    Closes-Bug: #1455404

Changed in wsme:
status: In Progress → Fix Committed
Changed in wsme:
milestone: none → 0.8.0
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.