Merge "Access the controller's mistral endpoint instead of VIM"

This commit is contained in:
Jenkins 2017-03-22 10:33:04 +00:00 committed by Gerrit Code Review
commit d185a03707
4 changed files with 94 additions and 99 deletions

View File

@ -471,63 +471,42 @@ class OpenStack_Driver(abstract_vim_driver.VimAbstractDriver,
neutronclient_ = NeutronClient(auth_attr)
neutronclient_.flow_classifier_delete(fc_id)
def prepare_and_create_workflow(self, resource, action, vim_auth,
kwargs, auth_token=None):
if not auth_token:
LOG.warning(_("auth token required to create mistral workflows"))
raise EnvironmentError('auth token required for'
def get_mistral_client(self, auth_dict):
if not auth_dict:
LOG.warning(_("auth dict required to instantiate mistral client"))
raise EnvironmentError('auth dict required for'
' mistral workflow driver')
mistral_client = MistralClient(
self.keystone.initialize_client('2', **vim_auth),
auth_token).get_client()
return MistralClient(
keystone.Keystone().initialize_client('2', **auth_dict),
auth_dict['token']).get_client()
def prepare_and_create_workflow(self, resource, action,
kwargs, auth_dict=None):
mistral_client = self.get_mistral_client(auth_dict)
wg = workflow_generator.WorkflowGenerator(resource, action)
wg.task(**kwargs)
definition_yaml = yaml.safe_dump(wg.definition)
workflow = mistral_client.workflows.create(definition_yaml)
return {'id': workflow[0].id, 'input': wg.get_input_dict()}
def execute_workflow(self, workflow, vim_auth, auth_token=None):
if not auth_token:
LOG.warning(_("auth token required to create mistral workflows"))
raise EnvironmentError('auth token required for'
' mistral workflow driver')
mistral_client = MistralClient(
self.keystone.initialize_client('2', **vim_auth),
auth_token).get_client()
return mistral_client.executions.create(
def execute_workflow(self, workflow, auth_dict=None):
return self.get_mistral_client(auth_dict)\
.executions.create(
workflow_identifier=workflow['id'],
workflow_input=workflow['input'],
wf_params={})
def get_execution(self, execution_id, vim_auth, auth_token=None):
if not auth_token:
LOG.warning(_("auth token required to create mistral workflows"))
raise EnvironmentError('auth token required for'
' mistral workflow driver')
mistral_client = MistralClient(
self.keystone.initialize_client('2', **vim_auth),
auth_token).get_client()
return mistral_client.executions.get(execution_id)
def get_execution(self, execution_id, auth_dict=None):
return self.get_mistral_client(auth_dict)\
.executions.get(execution_id)
def delete_execution(self, execution_id, vim_auth, auth_token=None):
if not auth_token:
LOG.warning(_("auth token required to create mistral workflows"))
raise EnvironmentError('auth token required for'
' mistral workflow driver')
mistral_client = MistralClient(
self.keystone.initialize_client('2', **vim_auth),
auth_token).get_client()
return mistral_client.executions.delete(execution_id)
def delete_execution(self, execution_id, auth_dict=None):
return self.get_mistral_client(auth_dict).executions\
.delete(execution_id)
def delete_workflow(self, workflow_id, vim_auth, auth_token=None):
if not auth_token:
LOG.warning(_("auth token required to create mistral workflows"))
raise EnvironmentError('auth token required for'
' mistral workflow driver')
mistral_client = MistralClient(
self.keystone.initialize_client('2', **vim_auth),
auth_token).get_client()
return mistral_client.workflows.delete(workflow_id)
def delete_workflow(self, workflow_id, auth_dict=None):
return self.get_mistral_client(auth_dict)\
.workflows.delete(workflow_id)
class MistralClient(object):
@ -536,6 +515,7 @@ class MistralClient(object):
def __init__(self, keystone, auth_token):
endpoint = keystone.session.get_endpoint(
service_type='workflowv2', region_name=None)
self.client = mistral_client.client(auth_token=auth_token,
mistral_url=endpoint)

View File

@ -101,6 +101,15 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
for created_vim in self._created_vims.values():
self.monitor_vim(created_vim)
def get_auth_dict(self, context):
auth = CONF.keystone_authtoken
return {
'auth_url': auth.auth_url + '/v3',
'token': context.auth_token,
'project_domain_name': auth.project_domain_name or context.domain,
'project_name': context.tenant_name
}
def spawn_n(self, function, *args, **kwargs):
self._pool.spawn_n(function, *args, **kwargs)
@ -577,23 +586,20 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
'prepare_and_create_workflow',
resource='vnf',
action='create',
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token,
auth_dict=self.get_auth_dict(context),
kwargs=kwargs)
try:
mistral_execution = self._vim_drivers.invoke(
driver_type,
'execute_workflow',
workflow=workflow,
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
except Exception as ex:
LOG.error(_('Error while executing workflow: %s'), ex)
self._vim_drivers.invoke(driver_type,
'delete_workflow',
workflow_id=workflow['id'],
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
raise ex
ns_dict = super(NfvoPlugin, self).create_ns(context, ns)
@ -606,8 +612,7 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
driver_type,
'get_execution',
execution_id=execution_id,
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token).state
auth_dict=self.get_auth_dict(context)).state
LOG.debug(_('status: %s'), exec_state)
if exec_state == 'SUCCESS' or exec_state == 'ERROR':
break
@ -622,18 +627,15 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
exec_obj = self._vim_drivers.invoke(driver_type,
'get_execution',
execution_id=execution_id,
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
self._vim_drivers.invoke(driver_type,
'delete_execution',
execution_id=execution_id,
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
self._vim_drivers.invoke(driver_type,
'delete_workflow',
workflow_id=workflow['id'],
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
super(NfvoPlugin, self).create_ns_post(context, ns_id, exec_obj,
vnfd_dict, error_reason)
@ -676,23 +678,20 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
'prepare_and_create_workflow',
resource='vnf',
action='delete',
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token,
auth_dict=self.get_auth_dict(context),
kwargs={'ns': ns})
try:
mistral_execution = self._vim_drivers.invoke(
driver_type,
'execute_workflow',
workflow=workflow,
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
except Exception as ex:
LOG.error(_('Error while executing workflow: %s'), ex)
self._vim_drivers.invoke(driver_type,
'delete_workflow',
workflow_id=workflow['id'],
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
raise ex
super(NfvoPlugin, self).delete_ns(context, ns_id)
@ -706,8 +705,7 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
driver_type,
'get_execution',
execution_id=execution_id,
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token).state
auth_dict=self.get_auth_dict(context)).state
LOG.debug(_('status: %s'), exec_state)
if exec_state == 'SUCCESS' or exec_state == 'ERROR':
break
@ -722,20 +720,16 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
exec_obj = self._vim_drivers.invoke(driver_type,
'get_execution',
execution_id=execution_id,
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
self._vim_drivers.invoke(driver_type,
'delete_execution',
execution_id=execution_id,
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
self._vim_drivers.invoke(driver_type,
'delete_workflow',
workflow_id=workflow['id'],
vim_auth=vim_res['vim_auth'],
auth_token=context.auth_token)
auth_dict=self.get_auth_dict(context))
super(NfvoPlugin, self).delete_ns_post(context, ns_id, exec_obj,
error_reason)
self.spawn_n(_delete_ns_wait, ns['id'], mistral_execution.id)
return ns['id']

View File

@ -599,11 +599,18 @@ class TestNfvoPlugin(db_base.SqlTestCase):
self.assertIsNotNone(result)
self.assertEqual(result['name'], 'dummy_NSD')
@mock.patch.object(nfvo_plugin.NfvoPlugin, 'get_auth_dict')
@mock.patch.object(vim_client.VimClient, 'get_vim')
@mock.patch.object(nfvo_plugin.NfvoPlugin, '_get_by_name')
def test_create_ns(self, mock_get_by_name, mock_get_vim):
def test_create_ns(self, mock_get_by_name, mock_get_vimi, mock_auth_dict):
self._insert_dummy_ns_template()
self._insert_dummy_vim()
mock_auth_dict.return_value = {
'auth_url': 'http://127.0.0.1',
'token': 'DummyToken',
'project_domain_name': 'dummy_domain',
'project_name': 'dummy_project'
}
with patch.object(TackerManager, 'get_service_plugins') as \
mock_plugins:
mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()}
@ -620,12 +627,20 @@ class TestNfvoPlugin(db_base.SqlTestCase):
self.assertIn('status', result)
self.assertIn('tenant_id', result)
@mock.patch.object(nfvo_plugin.NfvoPlugin, 'get_auth_dict')
@mock.patch.object(vim_client.VimClient, 'get_vim')
@mock.patch.object(nfvo_plugin.NfvoPlugin, '_get_by_name')
def test_delete_ns(self, mock_get_by_name, mock_get_vim):
def test_delete_ns(self, mock_get_by_name, mock_get_vim, mock_auth_dict):
self._insert_dummy_vim()
self._insert_dummy_ns_template()
self._insert_dummy_ns()
mock_auth_dict.return_value = {
'auth_url': 'http://127.0.0.1',
'token': 'DummyToken',
'project_domain_name': 'dummy_domain',
'project_name': 'dummy_project'
}
with patch.object(TackerManager, 'get_service_plugins') as \
mock_plugins:
mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()}

View File

@ -53,9 +53,15 @@ class Keystone(object):
def initialize_client(self, version, **kwargs):
if version == 'v2.0':
from keystoneclient.v2_0 import client
if 'token' in kwargs:
auth_plugin = identity.v2.Token(**kwargs)
else:
auth_plugin = identity.v2.Password(**kwargs)
else:
from keystoneclient.v3 import client
if 'token' in kwargs:
auth_plugin = identity.v3.Token(**kwargs)
else:
auth_plugin = identity.v3.Password(**kwargs)
ses = self.get_session(auth_plugin=auth_plugin)
cli = client.Client(session=ses)