前段時間,實現這么一個功能,界面上提供修改虛機IP地址的操作,后臺neutron用port update方法,neutron client的port update接口和其他資源的update方法不太一樣,參數沒指定正確,會導致一個port上出現兩個fixed ip.
接下來就是考慮floating ip的問題:
如果虛機綁定了浮動ip,修改虛機的fixed ip,在l3 namespace里還是會保存原來的iptables規則,因此,在port update之前要判斷floating ip的存在關系,需要解綁和綁定的操作.
修改完成后,測試,發現api請求的時間居然快30s,port update會給每個計算節點發送cast的rpc消息,而在消息隊列那邊,同事改了代碼,在cast消息中sleep了1s左右,因此到ml2 plugin的port update方法完成,耗費了很長的時間.
切回到內部環境測試后,使用neutron來看port的狀態,確實已經更新,但是前端并沒有及時的顯示,也就是說nova那邊并沒有及時的獲取這種狀態,當時以為和rpc的sleep有關,就沒仔細想這個問題.
后來老大問了這個問題,并且給出了nova的ExternalEventAPI.
ExternalEventAPI,我也趕緊看了下neutron這邊的代碼,在neutron的NeutronDbPluginV2類中,使用SQLAlchemy的事件監聽來監聽Port數據庫的變化,然后給nova發送notifier,代碼如下:
- class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
- CommonDbMixin):
- """V2 Neutron plugin interface implementation using SQLAlchemy models.
- Whenever a non-read call happens the plugin will call an event handler
- class method (e.g., network_created()). The result is that this class
- can be sub-classed by other classes that add custom behaviors on certain
- events.
- """
- def __init__(self):
- db.configure_db()
- if cfg.CONF.notify_nova_on_port_status_changes:
- # NOTE(arosen) These event listners are here to hook into when //Vevb.com
- # port status changes and notify nova about their change.
- self.nova_notifier = nova.Notifier()
- event.listen(models_v2.Port, 'after_insert',
- self.nova_notifier.send_port_status)
- event.listen(models_v2.Port, 'after_update',
- self.nova_notifier.send_port_status)
- event.listen(models_v2.Port.status, 'set',
- self.nova_notifier.record_port_status_changed)
可見自己對代碼還沒有很熟悉,而且只關注自己這塊,不注意和其他組件的交互,接著和nova這邊的同事一起調試,在neutron server的日志中有報錯,代碼如下:
- 2014-11-28 10:48:21.137 17163 DEBUG neutron.notifiers.nova [req-6b23770b-4f0d-4e85-ba21-1c47f191e136 None] Sending events: [{'status': 'completed', 'tag': u'ddc6cb03-1963-4f7e-bf07-e55acbada573', 'name': 'network-vif-plugged', 'server_uuid': u'fcb2531c-878c-4934-ac7b-9f792071756d'}] send_events /usr/lib/python2.6/site-packages/neutron/notifiers/nova.py:218
- 2014-11-28 10:48:21.138 17163 INFO requests.packages.urllib3.connectionpool [-] Resetting dropped connection: 10.100.100.10
- 2014-11-28 10:48:21.168 17163 DEBUG requests.packages.urllib3.connectionpool [-] "POST /v2/6d381a3f7609474d9cb9b5421cf89943/os-server-external-events HTTP/1.1" 403 131 _make_request /usr/lib/python2.6/site-packages/requests/packages/urllib3/connectionpool.py:362
- 2014-11-28 10:48:21.169 17163 ERROR neutron.notifiers.nova [req-6b23770b-4f0d-4e85-ba21-1c47f191e136 None] Failed to notify nova on events: [{'status': 'completed', 'tag': u'ddc6cb03-1963-4f7e-bf07-e55acbada573', 'name': 'network-vif-plugged', 'server_uuid': u'fcb2531c-878c-4934-ac7b-9f792071756d'}]
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova Traceback (most recent call last):
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova File "/usr/lib/python2.6/site-packages/neutron/notifiers/nova.py", line 221, in send_events
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova batched_events)
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova File "/usr/lib/python2.6/site-packages/novaclient/v1_1/contrib/server_external_events.py", line 39, in create
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova return_raw=True)
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova File "/usr/lib/python2.6/site-packages/novaclient/base.py", line 152, in _create
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova _resp, body = self.api.client.post(url, body=body)
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 286, in post
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova return self._cs_request(url, 'POST', **kwargs)
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 260, in _cs_request
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova **kwargs)
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 242, in _time_request
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova resp, body = self.request(url, method, **kwargs)
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 236, in request
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova raise exceptions.from_response(resp, body, url, method)
- 2014-11-28 10:48:21.169 17163 TRACE neutron.notifiers.nova Forbidden: Policy doesn't allow compute_extension:os-server-external-events:create to be performed. (HTTP 403) (Request-ID: req-054895f0-fda1-4628-b288-d39d292db381)
接下來同事調試,nova那邊使用keystone v3的接口,在nova的policy文件中,對應os-server-external-events:create需要admin的api操作:
- “compute_extension:os-server-external-events:create”: “rule:admin_api”,
- “compute_extension:v3:os-server-external-events:create”: “rule:admin_api”,
對于admin的context,需要admin的角色和cloud_admin的角色.
context_is_admin”:“role:admin and role:cloud_admin”,
因此需要給neutron加入cloud_admin的角色,keystone v3這塊的變化,需要去看看.
新聞熱點
疑難解答