Resume VNF Monitoring after server restart
Change-Id: I42b276e4c2e488ff72adbe80b11f5c30cd1a3076 Closes-Bug: 1502657
This commit is contained in:
parent
814c9509e6
commit
04f1613183
|
@ -145,7 +145,9 @@ class TestVNFMPlugin(db_base.SqlTestCase):
|
|||
plugin=mock.ANY,
|
||||
context=mock.ANY,
|
||||
device=mock.ANY)
|
||||
self._pool.spawn_n.assert_called_once_with(mock.ANY)
|
||||
|
||||
calls = [mock.call(mock.ANY), mock.call(mock.ANY)]
|
||||
self._pool.spawn_n.assert_has_calls(calls)
|
||||
|
||||
def test_delete_vnf(self):
|
||||
self._insert_dummy_device_template()
|
||||
|
@ -157,8 +159,8 @@ class TestVNFMPlugin(db_base.SqlTestCase):
|
|||
context=mock.ANY,
|
||||
device_id=mock.ANY)
|
||||
self._vnf_monitor.delete_hosting_vnf.assert_called_with(mock.ANY)
|
||||
self._pool.spawn_n.assert_called_once_with(mock.ANY, mock.ANY,
|
||||
mock.ANY)
|
||||
calls = [mock.call(mock.ANY)]
|
||||
self._pool.spawn_n.assert_has_calls(calls)
|
||||
|
||||
def test_update_vnf(self):
|
||||
self._insert_dummy_device_template()
|
||||
|
@ -172,5 +174,5 @@ class TestVNFMPlugin(db_base.SqlTestCase):
|
|||
self.assertIn('status', result)
|
||||
self.assertIn('attributes', result)
|
||||
self.assertIn('mgmt_url', result)
|
||||
self._pool.spawn_n.assert_called_once_with(mock.ANY, mock.ANY,
|
||||
mock.ANY)
|
||||
calls = [mock.call(mock.ANY), mock.call(mock.ANY, mock.ANY, mock.ANY)]
|
||||
self._pool.spawn_n.assert_has_calls(calls)
|
||||
|
|
|
@ -19,13 +19,16 @@
|
|||
# under the License.
|
||||
|
||||
import copy
|
||||
import inspect
|
||||
|
||||
import eventlet
|
||||
import inspect
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from tacker.api.v1 import attributes
|
||||
from tacker.common import clients
|
||||
from tacker.common import driver_manager
|
||||
from tacker import context as t_context
|
||||
from tacker.db.vm import proxy_db # noqa
|
||||
from tacker.db.vm import vm_db
|
||||
from tacker.extensions import vnfm
|
||||
|
@ -120,10 +123,37 @@ class VNFMPlugin(vm_db.VNFMPluginDb, VNFMMgmtMixin):
|
|||
'tacker.tacker.device.drivers',
|
||||
cfg.CONF.tacker.infra_driver)
|
||||
self._vnf_monitor = monitor.VNFMonitor(self.boot_wait)
|
||||
self.spawn_n(self._restart_monitoring)
|
||||
|
||||
def spawn_n(self, function, *args, **kwargs):
|
||||
self._pool.spawn_n(function, *args, **kwargs)
|
||||
|
||||
# Restart monitoring for any VNFs that are already running
|
||||
def _restart_monitoring(self):
|
||||
# Wait for config to load
|
||||
time.sleep(2)
|
||||
authtoken = cfg.CONF.keystone_authtoken
|
||||
|
||||
kc = clients.OpenstackClients().keystone_client()
|
||||
token = kc.service_catalog.get_token()
|
||||
|
||||
context = t_context.get_admin_context()
|
||||
context.tenant_name = authtoken.project_name
|
||||
context.user_name = authtoken.username
|
||||
context.auth_token = token['id']
|
||||
context.tenant_id = token['tenant_id']
|
||||
context.user_id = token['user_id']
|
||||
|
||||
with context.session.begin(subtransactions=True):
|
||||
query = context.session.query(vm_db.Device).filter(
|
||||
vm_db.Device.status == constants.ACTIVE).all()
|
||||
|
||||
for device in query:
|
||||
device_dict = self._make_device_dict(device)
|
||||
if device_dict['attributes'].get('monitoring_policy'):
|
||||
LOG.debug('Restart monitoring for %s', device['id'])
|
||||
self.add_device_to_monitor(device_dict)
|
||||
|
||||
###########################################################################
|
||||
# hosting device template
|
||||
|
||||
|
|
Loading…
Reference in New Issue