Merge "Provide reference implementation for Cyborg"
This commit is contained in:
commit
74dfb65aa8
@ -16,18 +16,65 @@
|
||||
"""
|
||||
Cyborg Generic driver implementation.
|
||||
"""
|
||||
|
||||
from modules import generic
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from cyborg.accelerator import accelerator
|
||||
from cyborg.conductor.rpcapi import ConductorAPI as conductor_api
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class GenericDriver(object):
|
||||
"""Abstract base class representing the generic driver for Cyborg.
|
||||
CONF = cfg.CONF
|
||||
|
||||
This class provides a reference implementation for a Cyborg driver.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.discover = generic.discover()
|
||||
self.list = generic.list()
|
||||
self.update = generic.update
|
||||
self.attach = generic.attach()
|
||||
self.detach = generic.detach()
|
||||
class GenericDriver(generic.GENERICDRIVER):
|
||||
"""Executes commands relating to Shares."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Do initialization."""
|
||||
super(GenericDriver, self).__init__()
|
||||
self.configuration.append_config_values()
|
||||
self._helpers = {}
|
||||
self.backend_name = self.configuration.safe_get(
|
||||
'accelerator_backend_name')
|
||||
|
||||
def do_setup(self, context):
|
||||
"""Any initialization the generic driver does while starting."""
|
||||
super(GenericDriver, self).do_setup(context)
|
||||
self.acc = accelerator.accelerator()
|
||||
|
||||
def create_accelerator(self, context):
|
||||
"""Creates accelerator."""
|
||||
self.acc = conductor_api.accelerator_create(
|
||||
context=context, obj_acc=self.accelerator)
|
||||
LOG.debug("Created a new accelerator with the UUID %s ",
|
||||
self.accelerator.accelerator_id)
|
||||
|
||||
def get_accelerator(self, context):
|
||||
"""Gets accelerator by UUID."""
|
||||
self.acc = conductor_api.accelerator_list_one(
|
||||
context=context, obj_acc=self.accelerator)
|
||||
return self.acc
|
||||
|
||||
def list_accelerators(self, context):
|
||||
"""Lists all accelerators."""
|
||||
self.acc = conductor_api.accelerator_list_all(
|
||||
context=context, obj_acc=self.accelerator)
|
||||
return self.acc
|
||||
|
||||
def update_accelerator(self, context):
|
||||
"""Updates accelerator with a patch update."""
|
||||
|
||||
self.acc = conductor_api.accelerator_update(
|
||||
context=context, obj_acc=self.accelerator)
|
||||
LOG.debug("Updated accelerator %s ",
|
||||
self.accelerator.accelerator_id)
|
||||
|
||||
def delete_accelerator(self, context):
|
||||
"""Deletes a specific accelerator."""
|
||||
LOG.debug("Deleting accelerator %s ", self.accelerator.accelerator_id)
|
||||
conductor_api.accelerator_delete(context=context,
|
||||
obj_acc=self.accelerator)
|
||||
|
@ -24,7 +24,7 @@ from oslo_log import log as logging
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# NOTE (crushil): REQUIRED_PROPERTIES needs to be filled out.
|
||||
REQUIRED_PROPERTIES = {}
|
||||
REQUIRED_PROPERTIES = {'create', 'get', 'list', 'update', 'delete'}
|
||||
COMMON_PROPERTIES = REQUIRED_PROPERTIES
|
||||
|
||||
|
||||
@ -58,14 +58,14 @@ class GENERICDRIVER(base.BaseDriver):
|
||||
"""
|
||||
return COMMON_PROPERTIES
|
||||
|
||||
def attach(self):
|
||||
def attach(self, accelerator, instance):
|
||||
|
||||
def install(self):
|
||||
def install(self, accelerator):
|
||||
pass
|
||||
|
||||
def detach(self):
|
||||
def detach(self, accelerator, instance):
|
||||
|
||||
def uninstall(self):
|
||||
def uninstall(self, accelerator):
|
||||
pass
|
||||
|
||||
def delete(self):
|
||||
@ -77,5 +77,5 @@ class GENERICDRIVER(base.BaseDriver):
|
||||
def list(self):
|
||||
pass
|
||||
|
||||
def update(self):
|
||||
def update(self, accelerator, **kwargs):
|
||||
pass
|
||||
|
@ -74,7 +74,28 @@ class ConductorAPI(object):
|
||||
:param obj_acc: an accelerator object to delete.
|
||||
"""
|
||||
cctxt = self.client.prepare(topic=self.topic, server=CONF.host)
|
||||
cctxt.call(context, 'accelerator_delete', obj_acc=obj_acc)
|
||||
return cctxt.call(context, 'accelerator_delete', obj_acc=obj_acc)
|
||||
|
||||
def accelerator_list_one(self, context, obj_acc):
|
||||
"""Signal to conductor service to list an accelerator.
|
||||
|
||||
:param context: request context.
|
||||
:param obj_acc: an accelerator object to list.
|
||||
:returns: accelerator object.
|
||||
"""
|
||||
cctxt = self.client.prepare(topic=self.topic, server=CONF.host)
|
||||
cctxt.call(context, 'get_one', obj_acc=obj_acc)
|
||||
|
||||
def accelerator_list_all(self, context, obj_acc):
|
||||
"""Signal to conductor service to list all accelerators.
|
||||
|
||||
:param context: request context.
|
||||
:param obj_acc: accelerator objects to list.
|
||||
:returns: accelerator objects.
|
||||
|
||||
"""
|
||||
cctxt = self.client.prepare(topic=self.topic, server=CONF.host)
|
||||
return cctxt.call(context, 'get_all', obj_acc=obj_acc)
|
||||
|
||||
def deployable_create(self, context, obj_dep):
|
||||
"""Signal to conductor service to create a deployable.
|
||||
|
@ -0,0 +1,66 @@
|
||||
# Copyright 2017 Lenovo Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Base classes for Generic Driver tests."""
|
||||
|
||||
import mock
|
||||
|
||||
from cyborg.accelerator.drivers.generic_driver import GenericDriver as generic
|
||||
from cyborg.conductor.rpcapi import ConductorAPI as conductor_api
|
||||
|
||||
FAKE_CONTEXT = mock.MagicMock()
|
||||
|
||||
|
||||
class GenericDriverTest():
|
||||
"""Class for testing of generic driver
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(GenericDriverTest, self).setUp()
|
||||
|
||||
@mock.patch.object(conductor_api, 'accelerator_create')
|
||||
def test_create_accelerator(self, mock_acc_create):
|
||||
mock_acc_create.return_value = self.acc
|
||||
generic.create_accelerator(context=FAKE_CONTEXT)
|
||||
|
||||
mock_acc_create.assert_called()
|
||||
|
||||
@mock.patch.object(conductor_api, 'accelerator_list_one')
|
||||
def test_get_accelerator(self, mock_acc_get):
|
||||
mock_acc_get.return_value = self.acc
|
||||
generic.get_accelerator(context=FAKE_CONTEXT)
|
||||
|
||||
mock_acc_get.assert_called()
|
||||
|
||||
@mock.patch.object(conductor_api, 'accelerator_list_all')
|
||||
def test_list_accelerators(self, mock_acc_list):
|
||||
mock_acc_list.return_value = self.acc
|
||||
generic.list_accelerators(context=FAKE_CONTEXT)
|
||||
|
||||
mock_acc_list.assert_called()
|
||||
|
||||
@mock.patch.object(conductor_api, 'accelerator_update')
|
||||
def test_update_accelerator(self, mock_acc_update):
|
||||
mock_acc_update.return_value = self.acc
|
||||
generic.update_accelerator(context=FAKE_CONTEXT)
|
||||
|
||||
mock_acc_update.assert_called()
|
||||
|
||||
@mock.patch.object(conductor_api, 'accelerator_delete')
|
||||
def test_delete_accelerator(self, mock_acc_delete):
|
||||
mock_acc_delete.return_value = self.acc
|
||||
generic.delete_accelerator(context=FAKE_CONTEXT)
|
||||
|
||||
mock_acc_delete.assert_called()
|
Loading…
x
Reference in New Issue
Block a user