Merge "Access the controller's mistral endpoint instead of VIM"
This commit is contained in:
commit
d185a03707
@ -471,63 +471,42 @@ class OpenStack_Driver(abstract_vim_driver.VimAbstractDriver,
|
|||||||
neutronclient_ = NeutronClient(auth_attr)
|
neutronclient_ = NeutronClient(auth_attr)
|
||||||
neutronclient_.flow_classifier_delete(fc_id)
|
neutronclient_.flow_classifier_delete(fc_id)
|
||||||
|
|
||||||
def prepare_and_create_workflow(self, resource, action, vim_auth,
|
def get_mistral_client(self, auth_dict):
|
||||||
kwargs, auth_token=None):
|
if not auth_dict:
|
||||||
if not auth_token:
|
LOG.warning(_("auth dict required to instantiate mistral client"))
|
||||||
LOG.warning(_("auth token required to create mistral workflows"))
|
raise EnvironmentError('auth dict required for'
|
||||||
raise EnvironmentError('auth token required for'
|
|
||||||
' mistral workflow driver')
|
' mistral workflow driver')
|
||||||
mistral_client = MistralClient(
|
return MistralClient(
|
||||||
self.keystone.initialize_client('2', **vim_auth),
|
keystone.Keystone().initialize_client('2', **auth_dict),
|
||||||
auth_token).get_client()
|
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 = workflow_generator.WorkflowGenerator(resource, action)
|
||||||
wg.task(**kwargs)
|
wg.task(**kwargs)
|
||||||
definition_yaml = yaml.safe_dump(wg.definition)
|
definition_yaml = yaml.safe_dump(wg.definition)
|
||||||
workflow = mistral_client.workflows.create(definition_yaml)
|
workflow = mistral_client.workflows.create(definition_yaml)
|
||||||
return {'id': workflow[0].id, 'input': wg.get_input_dict()}
|
return {'id': workflow[0].id, 'input': wg.get_input_dict()}
|
||||||
|
|
||||||
def execute_workflow(self, workflow, vim_auth, auth_token=None):
|
def execute_workflow(self, workflow, auth_dict=None):
|
||||||
if not auth_token:
|
return self.get_mistral_client(auth_dict)\
|
||||||
LOG.warning(_("auth token required to create mistral workflows"))
|
.executions.create(
|
||||||
raise EnvironmentError('auth token required for'
|
workflow_identifier=workflow['id'],
|
||||||
' mistral workflow driver')
|
workflow_input=workflow['input'],
|
||||||
mistral_client = MistralClient(
|
wf_params={})
|
||||||
self.keystone.initialize_client('2', **vim_auth),
|
|
||||||
auth_token).get_client()
|
|
||||||
return mistral_client.executions.create(
|
|
||||||
workflow_identifier=workflow['id'],
|
|
||||||
workflow_input=workflow['input'],
|
|
||||||
wf_params={})
|
|
||||||
|
|
||||||
def get_execution(self, execution_id, vim_auth, auth_token=None):
|
def get_execution(self, execution_id, auth_dict=None):
|
||||||
if not auth_token:
|
return self.get_mistral_client(auth_dict)\
|
||||||
LOG.warning(_("auth token required to create mistral workflows"))
|
.executions.get(execution_id)
|
||||||
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 delete_execution(self, execution_id, vim_auth, auth_token=None):
|
def delete_execution(self, execution_id, auth_dict=None):
|
||||||
if not auth_token:
|
return self.get_mistral_client(auth_dict).executions\
|
||||||
LOG.warning(_("auth token required to create mistral workflows"))
|
.delete(execution_id)
|
||||||
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_workflow(self, workflow_id, vim_auth, auth_token=None):
|
def delete_workflow(self, workflow_id, auth_dict=None):
|
||||||
if not auth_token:
|
return self.get_mistral_client(auth_dict)\
|
||||||
LOG.warning(_("auth token required to create mistral workflows"))
|
.workflows.delete(workflow_id)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
class MistralClient(object):
|
class MistralClient(object):
|
||||||
@ -536,8 +515,9 @@ class MistralClient(object):
|
|||||||
def __init__(self, keystone, auth_token):
|
def __init__(self, keystone, auth_token):
|
||||||
endpoint = keystone.session.get_endpoint(
|
endpoint = keystone.session.get_endpoint(
|
||||||
service_type='workflowv2', region_name=None)
|
service_type='workflowv2', region_name=None)
|
||||||
|
|
||||||
self.client = mistral_client.client(auth_token=auth_token,
|
self.client = mistral_client.client(auth_token=auth_token,
|
||||||
mistral_url=endpoint)
|
mistral_url=endpoint)
|
||||||
|
|
||||||
def get_client(self):
|
def get_client(self):
|
||||||
return self.client
|
return self.client
|
||||||
|
@ -101,6 +101,15 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
|
|||||||
for created_vim in self._created_vims.values():
|
for created_vim in self._created_vims.values():
|
||||||
self.monitor_vim(created_vim)
|
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):
|
def spawn_n(self, function, *args, **kwargs):
|
||||||
self._pool.spawn_n(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',
|
'prepare_and_create_workflow',
|
||||||
resource='vnf',
|
resource='vnf',
|
||||||
action='create',
|
action='create',
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context),
|
||||||
auth_token=context.auth_token,
|
|
||||||
kwargs=kwargs)
|
kwargs=kwargs)
|
||||||
try:
|
try:
|
||||||
mistral_execution = self._vim_drivers.invoke(
|
mistral_execution = self._vim_drivers.invoke(
|
||||||
driver_type,
|
driver_type,
|
||||||
'execute_workflow',
|
'execute_workflow',
|
||||||
workflow=workflow,
|
workflow=workflow,
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error(_('Error while executing workflow: %s'), ex)
|
LOG.error(_('Error while executing workflow: %s'), ex)
|
||||||
self._vim_drivers.invoke(driver_type,
|
self._vim_drivers.invoke(driver_type,
|
||||||
'delete_workflow',
|
'delete_workflow',
|
||||||
workflow_id=workflow['id'],
|
workflow_id=workflow['id'],
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
raise ex
|
raise ex
|
||||||
ns_dict = super(NfvoPlugin, self).create_ns(context, ns)
|
ns_dict = super(NfvoPlugin, self).create_ns(context, ns)
|
||||||
|
|
||||||
@ -606,8 +612,7 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
|
|||||||
driver_type,
|
driver_type,
|
||||||
'get_execution',
|
'get_execution',
|
||||||
execution_id=execution_id,
|
execution_id=execution_id,
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context)).state
|
||||||
auth_token=context.auth_token).state
|
|
||||||
LOG.debug(_('status: %s'), exec_state)
|
LOG.debug(_('status: %s'), exec_state)
|
||||||
if exec_state == 'SUCCESS' or exec_state == 'ERROR':
|
if exec_state == 'SUCCESS' or exec_state == 'ERROR':
|
||||||
break
|
break
|
||||||
@ -620,20 +625,17 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
|
|||||||
wait=MISTRAL_RETRIES * MISTRAL_RETRY_WAIT,
|
wait=MISTRAL_RETRIES * MISTRAL_RETRY_WAIT,
|
||||||
mistral=execution_id)
|
mistral=execution_id)
|
||||||
exec_obj = self._vim_drivers.invoke(driver_type,
|
exec_obj = self._vim_drivers.invoke(driver_type,
|
||||||
'get_execution',
|
'get_execution',
|
||||||
execution_id=execution_id,
|
execution_id=execution_id,
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
self._vim_drivers.invoke(driver_type,
|
self._vim_drivers.invoke(driver_type,
|
||||||
'delete_execution',
|
'delete_execution',
|
||||||
execution_id=execution_id,
|
execution_id=execution_id,
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
self._vim_drivers.invoke(driver_type,
|
self._vim_drivers.invoke(driver_type,
|
||||||
'delete_workflow',
|
'delete_workflow',
|
||||||
workflow_id=workflow['id'],
|
workflow_id=workflow['id'],
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
super(NfvoPlugin, self).create_ns_post(context, ns_id, exec_obj,
|
super(NfvoPlugin, self).create_ns_post(context, ns_id, exec_obj,
|
||||||
vnfd_dict, error_reason)
|
vnfd_dict, error_reason)
|
||||||
|
|
||||||
@ -673,26 +675,23 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
|
|||||||
vim_res = self.vim_client.get_vim(context, ns['vim_id'])
|
vim_res = self.vim_client.get_vim(context, ns['vim_id'])
|
||||||
driver_type = vim_res['vim_type']
|
driver_type = vim_res['vim_type']
|
||||||
workflow = self._vim_drivers.invoke(driver_type,
|
workflow = self._vim_drivers.invoke(driver_type,
|
||||||
'prepare_and_create_workflow',
|
'prepare_and_create_workflow',
|
||||||
resource='vnf',
|
resource='vnf',
|
||||||
action='delete',
|
action='delete',
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context),
|
||||||
auth_token=context.auth_token,
|
kwargs={'ns': ns})
|
||||||
kwargs={'ns': ns})
|
|
||||||
try:
|
try:
|
||||||
mistral_execution = self._vim_drivers.invoke(
|
mistral_execution = self._vim_drivers.invoke(
|
||||||
driver_type,
|
driver_type,
|
||||||
'execute_workflow',
|
'execute_workflow',
|
||||||
workflow=workflow,
|
workflow=workflow,
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error(_('Error while executing workflow: %s'), ex)
|
LOG.error(_('Error while executing workflow: %s'), ex)
|
||||||
self._vim_drivers.invoke(driver_type,
|
self._vim_drivers.invoke(driver_type,
|
||||||
'delete_workflow',
|
'delete_workflow',
|
||||||
workflow_id=workflow['id'],
|
workflow_id=workflow['id'],
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
|
|
||||||
raise ex
|
raise ex
|
||||||
super(NfvoPlugin, self).delete_ns(context, ns_id)
|
super(NfvoPlugin, self).delete_ns(context, ns_id)
|
||||||
@ -706,8 +705,7 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
|
|||||||
driver_type,
|
driver_type,
|
||||||
'get_execution',
|
'get_execution',
|
||||||
execution_id=execution_id,
|
execution_id=execution_id,
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context)).state
|
||||||
auth_token=context.auth_token).state
|
|
||||||
LOG.debug(_('status: %s'), exec_state)
|
LOG.debug(_('status: %s'), exec_state)
|
||||||
if exec_state == 'SUCCESS' or exec_state == 'ERROR':
|
if exec_state == 'SUCCESS' or exec_state == 'ERROR':
|
||||||
break
|
break
|
||||||
@ -720,22 +718,18 @@ class NfvoPlugin(nfvo_db.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
|
|||||||
wait=MISTRAL_RETRIES * MISTRAL_RETRY_WAIT,
|
wait=MISTRAL_RETRIES * MISTRAL_RETRY_WAIT,
|
||||||
mistral=execution_id)
|
mistral=execution_id)
|
||||||
exec_obj = self._vim_drivers.invoke(driver_type,
|
exec_obj = self._vim_drivers.invoke(driver_type,
|
||||||
'get_execution',
|
'get_execution',
|
||||||
execution_id=execution_id,
|
execution_id=execution_id,
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
self._vim_drivers.invoke(driver_type,
|
self._vim_drivers.invoke(driver_type,
|
||||||
'delete_execution',
|
'delete_execution',
|
||||||
execution_id=execution_id,
|
execution_id=execution_id,
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
self._vim_drivers.invoke(driver_type,
|
self._vim_drivers.invoke(driver_type,
|
||||||
'delete_workflow',
|
'delete_workflow',
|
||||||
workflow_id=workflow['id'],
|
workflow_id=workflow['id'],
|
||||||
vim_auth=vim_res['vim_auth'],
|
auth_dict=self.get_auth_dict(context))
|
||||||
auth_token=context.auth_token)
|
|
||||||
super(NfvoPlugin, self).delete_ns_post(context, ns_id, exec_obj,
|
super(NfvoPlugin, self).delete_ns_post(context, ns_id, exec_obj,
|
||||||
error_reason)
|
error_reason)
|
||||||
|
|
||||||
self.spawn_n(_delete_ns_wait, ns['id'], mistral_execution.id)
|
self.spawn_n(_delete_ns_wait, ns['id'], mistral_execution.id)
|
||||||
return ns['id']
|
return ns['id']
|
||||||
|
@ -599,11 +599,18 @@ class TestNfvoPlugin(db_base.SqlTestCase):
|
|||||||
self.assertIsNotNone(result)
|
self.assertIsNotNone(result)
|
||||||
self.assertEqual(result['name'], 'dummy_NSD')
|
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(vim_client.VimClient, 'get_vim')
|
||||||
@mock.patch.object(nfvo_plugin.NfvoPlugin, '_get_by_name')
|
@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_ns_template()
|
||||||
self._insert_dummy_vim()
|
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 \
|
with patch.object(TackerManager, 'get_service_plugins') as \
|
||||||
mock_plugins:
|
mock_plugins:
|
||||||
mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()}
|
mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()}
|
||||||
@ -620,12 +627,20 @@ class TestNfvoPlugin(db_base.SqlTestCase):
|
|||||||
self.assertIn('status', result)
|
self.assertIn('status', result)
|
||||||
self.assertIn('tenant_id', 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(vim_client.VimClient, 'get_vim')
|
||||||
@mock.patch.object(nfvo_plugin.NfvoPlugin, '_get_by_name')
|
@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_vim()
|
||||||
self._insert_dummy_ns_template()
|
self._insert_dummy_ns_template()
|
||||||
self._insert_dummy_ns()
|
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 \
|
with patch.object(TackerManager, 'get_service_plugins') as \
|
||||||
mock_plugins:
|
mock_plugins:
|
||||||
mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()}
|
mock_plugins.return_value = {'VNFM': FakeVNFMPlugin()}
|
||||||
|
@ -53,10 +53,16 @@ class Keystone(object):
|
|||||||
def initialize_client(self, version, **kwargs):
|
def initialize_client(self, version, **kwargs):
|
||||||
if version == 'v2.0':
|
if version == 'v2.0':
|
||||||
from keystoneclient.v2_0 import client
|
from keystoneclient.v2_0 import client
|
||||||
auth_plugin = identity.v2.Password(**kwargs)
|
if 'token' in kwargs:
|
||||||
|
auth_plugin = identity.v2.Token(**kwargs)
|
||||||
|
else:
|
||||||
|
auth_plugin = identity.v2.Password(**kwargs)
|
||||||
else:
|
else:
|
||||||
from keystoneclient.v3 import client
|
from keystoneclient.v3 import client
|
||||||
auth_plugin = identity.v3.Password(**kwargs)
|
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)
|
ses = self.get_session(auth_plugin=auth_plugin)
|
||||||
cli = client.Client(session=ses)
|
cli = client.Client(session=ses)
|
||||||
return cli
|
return cli
|
||||||
|
Loading…
x
Reference in New Issue
Block a user