nova boot vm failed

在juno上指定ip启动虚拟机会出错,查询日志,在/var/log/nova/nova-compute.log 里面有如下出错信息(拖动滚动条看最右边的):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
2015-06-09 05:53:41.966 19951 ERROR nova.compute.manager [-] [instance: d9058791-9971-4962-8c18-5fb3188355ab] Instance failed to spawn
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab] Traceback (most recent call last):
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/compute/manager.py", line 2246, in _build_resources
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     yield resources
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/compute/manager.py", line 2116, in _build_and_run_instance
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     block_device_info=block_device_info)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py", line 2616, in spawn
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     admin_pass=admin_password)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py", line 3097, in _create_image
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     instance, network_info, admin_pass, files, suffix)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/virt/libvirt/driver.py", line 2894, in _inject_data
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     network_info, libvirt_virt_type=CONF.libvirt.virt_type)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/virt/netutils.py", line 87, in get_injected_network_template
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     if not (network_info and template):
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/model.py", line 463, in __len__
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return self._sync_wrapper(fn, *args, **kwargs)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/model.py", line 450, in _sync_wrapper
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     self.wait()
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/model.py", line 482, in wait
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     self[:] = self._gt.wait()
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/eventlet/greenthread.py", line 173, in wait
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return self._exit_event.wait()
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/eventlet/event.py", line 125, in wait
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     current.throw(*self._exc)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/eventlet/greenthread.py", line 212, in main
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     result = function(*args, **kwargs)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/compute/manager.py", line 1646, in _allocate_network_async
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     dhcp_options=dhcp_options)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/neutronv2/api.py", line 443, in allocate_for_instance
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     self._delete_ports(neutron, instance, created_port_ids)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/openstack/common/excutils.py", line 82, in __exit__
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     six.reraise(self.type_, self.value, self.tb)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/neutronv2/api.py", line 423, in allocate_for_instance
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     security_group_ids, available_macs, dhcp_opts)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/neutronv2/api.py", line 214, in _create_port
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     port_id = port_client.create_port(port_req_body)['port']['id']
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/neutronv2/__init__.py", line 84, in wrapper
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     ret = obj(*args, **kwargs)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 98, in with_params
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     ret = self.function(instance, *args, **kwargs)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 322, in create_port
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return self.post(self.ports_path, body=body)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/neutronv2/__init__.py", line 84, in wrapper
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     ret = obj(*args, **kwargs)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 1325, in post
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     headers=headers, params=params)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/neutronv2/__init__.py", line 84, in wrapper
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     ret = obj(*args, **kwargs)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 1236, in do_request
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     body = self.serialize(body)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/nova/network/neutronv2/__init__.py", line 84, in wrapper
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     ret = obj(*args, **kwargs)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/v2_0/client.py", line 1266, in serialize
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     self.get_attr_metadata()).serialize(data, self.content_type())
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/common/serializer.py", line 390, in serialize
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return self._get_serialize_handler(content_type).serialize(data)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/common/serializer.py", line 54, in serialize
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return self.dispatch(data, action=action)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/common/serializer.py", line 44, in dispatch
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return action_method(*args, **kwargs)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/common/serializer.py", line 66, in default
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return jsonutils.dumps(data, default=sanitizer)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/openstack/common/jsonutils.py", line 168, in dumps
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return json.dumps(value, default=default, **kwargs)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib64/python2.7/json/__init__.py", line 250, in dumps
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     sort_keys=sort_keys, **kw).encode(obj)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     chunks = self.iterencode(o, _one_shot=True)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return _iterencode(o, 0)
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]   File "/usr/lib/python2.7/site-packages/neutronclient/common/serializer.py", line 65, in sanitizer
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab]     return six.text_type(obj, 'utf8')
2015-06-09 05:53:41.966 19951 TRACE nova.compute.manager [instance: d9058791-9971-4962-8c18-5fb3188355ab] TypeError: coercing to Unicode: need string or buffer, IPAddress found

以关键字 “TypeError: coercing to Unicode: need string or buffer, IPAddress found” ,搜索到此bug网页:https://bugs.launchpad.net/nova/+bug/1408529

文中给出了bug原因:If ip address is provided when running nova boot, nova compute will invoke neutron client to create a port. However, the ip address parameter is an IPAddress object so neutron client will fail to send the request to neutron server. Transform IPAddress object to string to address this issue.

只需要把发送给neutronclient的参数改为str就可以了

bug修复https://git.openstack.org/cgit/openstack/nova/commit/?id=aae858a246e20b1bf55004517b5d9ab28968190a:

编辑/usr/lib/python2.7/site-packages/nova/network/neutronv2/api.py

1
2
3
4
 198   try:
 199       if fixed_ip:
 200           port_req_body['port']['fixed_ips'] = [{'ip_address': fixed_ip}]
 201           port_req_body['port']['network_id'] = network_id

修改200行为:

1
 200            port_req_body['port']['fixed_ips'] = [{'ip_address': str(fixed_ip)}]

重启 nova-compute后成功指定ip启动虚拟机

一个默默无闻的工程师的日常
Built with Hugo
主题 StackJimmy 设计