KeyError: 'metadata' error when creating server with OS API

Bug #724143 reported by Dan Prince
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
High
justinsb

Bug Description

Using the nova revision 727.

I'm not longer able to create a server using the Openstack API. The following API error occurs:

---
(nova.api.openstack): TRACE: result = method(**arg_dict)
(nova.api.openstack): TRACE: File "/usr/lib/pymodules/python2.6/nova/api/openstack/servers.py", line 159, in create
(nova.api.openstack): TRACE: if env['server']['metadata']:
(nova.api.openstack): TRACE: KeyError: 'metadata'
(nova.api.openstack): TRACE:
---

To reproduce you can use the 'openstack-compute' Ruby gem with the following example:

require 'rubygems'
require 'openstack/compute'

USERNAME=ENV['NOVA_USERNAME']
API_KEY=ENV['NOVA_API_KEY']
API_URL=ENV['NOVA_URL']
cs = OpenStack::Compute::Connection.new(:username => USERNAME, :api_key => API_KEY, :api_url => API_URL)

cs.create_server(:name => "Yo", :imageId => 3, :flavorId => 1)

---

I should be able to create a server without metadata.

Related branches

Dan Prince (dan-prince)
Changed in nova:
assignee: nobody → Dan Prince (dan-prince)
Revision history for this message
justinsb (justin-fathomdb) wrote :

This is probably my bug. What's the link to the Ruby gem source code?

Revision history for this message
justinsb (justin-fathomdb) wrote :

Created hotfix: lp:~justin-fathomdb/nova/bug724143

If you could merge and check whether it fixes your issue, that would be much appreciated.

I'm going to write some unit tests that check this bit of the OpenStack API. One step at a time...

Revision history for this message
justinsb (justin-fathomdb) wrote :

Also created unit tests that would have caught this problem, by testing the OpenStack API for servers over HTTP.

Linked branch & proposed for merge: lp:~justin-fathomdb/nova/test-openstack-api-servers

Thierry Carrez (ttx)
Changed in nova:
assignee: Dan Prince (dan-prince) → justinsb (justin-fathomdb)
importance: Undecided → High
status: New → In Progress
Revision history for this message
Dan Prince (dan-prince) wrote :

You should be able to gem install the openstack-compute binding with the following command:

  'gem install openstack-compute'

** You'll need Ruby and Rubygems installed before running this command (those are available as packages).

I tried your hot fix and it allowed me to create a server with no metadata:

  cs.create_server(:name => "Yo", :imageId => 3, :flavorId => 1)

I also tried to create a server with metadata:

  cs.create_server(:name => "Yo", :imageId => 3, :flavorId => 1, :metadata=>{"foo" => "bar"} )

When trying with metadata I get a totally different exception:

(nova.api.openstack): TRACE: File "/usr/lib/python2.6/dist-packages/sqlalchemy/orm/collections.py", line 660, in bulk_replace
(nova.api.openstack): TRACE: constants = idset(existing_adapter or ()).intersection(values or ())
(nova.api.openstack): TRACE: File "/usr/lib/python2.6/dist-packages/sqlalchemy/util.py", line 1104, in intersection
(nova.api.openstack): TRACE: self._working_set(self._member_id_tuples()).intersection(_iter_id(iterable)))
(nova.api.openstack): TRACE: TypeError: unhashable type: 'dict'

---

I'm not sure the metadata code works 'as-is' with cloud servers bindings. Using the Ruby binding above should allow you to reproduce the issue on your end. To be fair *any* of the Rackspace Cloud Servers bindings (Ruby or Python) should allow you to reproduce these issue from an end users prospective.

Adding more unit tests to catch these things would be great too. Let me know if you want me to take a look at anything else.

Revision history for this message
justinsb (justin-fathomdb) wrote :

Thanks Dan - sounds like the hotfix solves your blocking issue. Let's hope we can get that merged into trunk asap.

I'm going to treat the metadata bug as a non-hotfix issue, and go through a slower process of writing tests, reproducing the issue and fixing it, because I presume it's not a blocker for you (given I only added metadata support recently!). Let me know if that's incorrect.

Revision history for this message
justinsb (justin-fathomdb) wrote :

I opened a new bug for the 'can't create metadata issue': bug 724143

Changed in nova:
status: In Progress → Fix Committed
Revision history for this message
justinsb (justin-fathomdb) wrote :

OK ... fairly obviously, that bug number wasn't right. It's actually bug 724623

Thierry Carrez (ttx)
Changed in nova:
milestone: none → 2011.2
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.