Flavor attribute 'swap' returns unicode'' instead of int 0

Bug #1815476 reported by Jelle Leempoels
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Invalid
Medium
Brin Zhang

Bug Description

Description
===========
When a flavor is created in Horizon with 'Swap Disk (MB)' -> 0.
Nova python API returns unicode'' on flavor.swap attribute.

When swap disk is changed to 10.
API returns -> int 10 instead of unicode.

Steps to reproduce
==================
- In horizon create a new flavor with swap disk 0
- connect to the nova python API.

fl = nova.flavors.find(name="your flavor")
print fl.swap
print(type(fl.swap))

output:

<type 'unicode'>

Expected result
===============
int 0

Actual result
=============
unicode ''

Environment
===========

ubuntu@juju-5dc387-0-lxd-6:~$ nova-manage --version
15.1.5

ubuntu@juju-5dc387-0-lxd-6:~$ dpkg -l | grep nova
ii nova-api-os-compute 2:15.1.5-0ubuntu1~cloud0 all OpenStack Compute - OpenStack Compute API frontend
ii nova-common 2:15.1.5-0ubuntu1~cloud0 all OpenStack Compute - common files
ii nova-conductor 2:15.1.5-0ubuntu1~cloud0 all OpenStack Compute - conductor service
ii nova-consoleauth 2:15.1.5-0ubuntu1~cloud0 all OpenStack Compute - Console Authenticator
ii nova-novncproxy 2:15.1.5-0ubuntu1~cloud0 all OpenStack Compute - NoVNC proxy
ii nova-placement-api 2:15.1.5-0ubuntu1~cloud0 all OpenStack Compute - placement API frontend
ii nova-scheduler 2:15.1.5-0ubuntu1~cloud0 all OpenStack Compute - virtual machine scheduler
ii python-nova 2:15.1.5-0ubuntu1~cloud0 all OpenStack Compute Python libraries

xx@xx-dev:~/Documents$ openstack --version
openstack 3.14.2

Tags: api
summary: - Flavor attribute returns unicode'' when 0
+ Flavor attribute 'swap' returns unicode'' when 0 instead of int
summary: - Flavor attribute 'swap' returns unicode'' when 0 instead of int
+ Flavor attribute 'swap' returns unicode'' instead of int 0
tags: added: api
Revision history for this message
Matt Riedemann (mriedem) wrote :

Hmm, it looks like the API does allow passing a string for the flavor swap size:

https://github.com/openstack/nova/blob/5c18dc108ee12dcc2a3eaf2aa2d7e2be339ff261/nova/api/validation/parameter_types.py#L453

That's unfortunate. However, it should get stored in the database as an integer:

https://github.com/openstack/nova/blob/5c18dc108ee12dcc2a3eaf2aa2d7e2be339ff261/nova/objects/flavor.py#L214

https://github.com/openstack/nova/blob/5c18dc108ee12dcc2a3eaf2aa2d7e2be339ff261/nova/db/sqlalchemy/api_models.py#L193

So I'm not sure why it's coming back as a string.

As for this code:

fl = nova.flavors.find(name="your flavor")

What are you using? python-novaclient?

If you do a curl GET /flavors/{flavor_id} on the flavor what do you get back for the swap entry?

Revision history for this message
Jelle Leempoels (jelle.leempoels1) wrote :

Hi Matt,

for the pyhton part I'm using python-novaclient.

import novaclient.client as nova_client
d = dict()
d['auth_url'] = ""
d['username'] = ""
d['password'] = ""
d['project_name'] = ""
d['version'] = "2"
d['project_domain_name'] = ""
d['user_domain_name'] = ""
nova = nova_client.Client(**d)
fl = nova.flavors.find(name="debug-flavor")
print fl.swap
print type(fl.swap)

When I make the GET call to request this flavor, Nova returns :

HTTP GET: http://x.x.x.x:8774/v2/flavors/77b2377f-740f-4171-906b-5cd68259892c

{
 u 'flavor': {
  u 'name': u 'debug-flavor',
  u 'links': [{
   u 'href': u 'http://x.x.13.x:8774/v2/flavors/77b2377f-740f-4171-906b-5cd68259892c',
   u 'rel': u 'self'
  }, {
   u 'href': u 'http://x.x.x.x:8774/flavors/77b2377f-740f-4171-906b-5cd68259892c',
   u 'rel': u 'bookmark'
  }],
  u 'ram': 2048,
  u 'OS-FLV-DISABLED:disabled': False,
  u 'vcpus': 2,
  u 'swap': u '',
  u 'os-flavor-access:is_public': True,
  u 'rxtx_factor': 1.0,
  u 'OS-FLV-EXT-DATA:ephemeral': 0,
  u 'disk': 20,
  u 'id': u '77b2377f-740f-4171-906b-5cd68259892c'
 }
}

Here swap is also returned as u''.

Revision history for this message
Brin Zhang (zhangbailin) wrote :

Flavor's checksum uses the check rule of volume_size [1], As Matt said, that's unfortunate. Personally think that the transfer type of swap can be restricted to 'integer'.

[1]https://github.com/openstack/nova/blob/5c18dc108ee12dcc2a3eaf2aa2d7e2be339ff261/nova/api/openstack/compute/schemas/flavor_manage.py#L38
https://github.com/openstack/nova/blob/5c18dc108ee12dcc2a3eaf2aa2d7e2be339ff261/nova/api/validation/parameter_types.py#L480

Changed in nova:
assignee: nobody → Brin Zhang (zhangbailin)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/639012

Changed in nova:
status: New → In Progress
Changed in nova:
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on nova (master)

Change abandoned by Brin Zhang (<email address hidden>) on branch: master
Review: https://review.opendev.org/639012

Revision history for this message
Balazs Gibizer (balazs-gibizer) wrote :
Changed in nova:
status: In Progress → Invalid
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.