Introduce Flow DeployDriver
Partially implements blueprint: pluggable-do-actions Change-Id: I1bb6a5e904741a8689d08e1939a3e098864a5d03
This commit is contained in:
parent
ff2a4fdd26
commit
f24eaf5712
0
bareon/actions/__init__.py
Normal file
0
bareon/actions/__init__.py
Normal file
41
bareon/actions/base.py
Normal file
41
bareon/actions/base.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# Copyright 2016 Mirantis, Inc.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import abc
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
|
class BaseAction(object):
|
||||||
|
"""BaseAction
|
||||||
|
|
||||||
|
|
||||||
|
Validates data and executes the action
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, driver):
|
||||||
|
self.driver = driver
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def validate(self):
|
||||||
|
"""Validate
|
||||||
|
|
||||||
|
Validates that data/objects of data driver satisfied all necessary
|
||||||
|
requirements
|
||||||
|
"""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def execute(self):
|
||||||
|
"""Executes the action"""
|
@ -28,6 +28,9 @@ class BaseDataDriver(object):
|
|||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = copy.deepcopy(data)
|
self.data = copy.deepcopy(data)
|
||||||
|
self.flow = []
|
||||||
|
if self.data and self.data.get('flow'):
|
||||||
|
self.flow = self.data.get('flow', [])
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
|
37
bareon/drivers/deploy/flow.py
Normal file
37
bareon/drivers/deploy/flow.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2016 Mirantis, Inc.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from bareon.drivers.deploy import base
|
||||||
|
from bareon.drivers.deploy import mixins
|
||||||
|
from bareon.openstack.common import log as logging
|
||||||
|
|
||||||
|
import stevedore.named
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class Flow(base.SimpleDeployDriver, mixins.MountableMixin):
|
||||||
|
|
||||||
|
def __init__(self, data_driver):
|
||||||
|
super(Flow, self).__init__(data_driver)
|
||||||
|
self.ext_mgr = stevedore.named.NamedExtensionManager(
|
||||||
|
'bareon.do_actions', names=self.driver.flow,
|
||||||
|
invoke_on_load=True, invoke_args=(self.driver, ),
|
||||||
|
name_order=True)
|
||||||
|
|
||||||
|
def execute_flow(self):
|
||||||
|
for action in self.ext_mgr:
|
||||||
|
action.validate()
|
||||||
|
action.execute()
|
53
bareon/tests/test_flow_driver.py
Normal file
53
bareon/tests/test_flow_driver.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# Copyright 2016 Mirantis, Inc.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import six
|
||||||
|
import unittest2
|
||||||
|
|
||||||
|
from bareon.actions import base as base_action
|
||||||
|
from bareon.drivers.deploy import flow
|
||||||
|
|
||||||
|
import stevedore
|
||||||
|
|
||||||
|
if six.PY2:
|
||||||
|
import mock
|
||||||
|
elif six.PY3:
|
||||||
|
import unittest.mock as mock
|
||||||
|
|
||||||
|
|
||||||
|
class TestFlowDriver(unittest2.TestCase):
|
||||||
|
|
||||||
|
@mock.patch.object(flow.Flow, '__init__',
|
||||||
|
return_value=None)
|
||||||
|
def test_execute_flow(self, mock_init):
|
||||||
|
fake_ext = mock.Mock(spec=base_action.BaseAction)
|
||||||
|
fake_ext.name = 'foo'
|
||||||
|
self.drv = flow.Flow('fake_data_driver')
|
||||||
|
self.drv.ext_mgr = stevedore.NamedExtensionManager.make_test_instance(
|
||||||
|
[fake_ext], namespace='TESTING')
|
||||||
|
self.drv.execute_flow()
|
||||||
|
self.assertEqual(['foo'], self.drv.ext_mgr.names())
|
||||||
|
fake_ext.validate.assert_called_once_with()
|
||||||
|
fake_ext.execute.assert_called_once_with()
|
||||||
|
|
||||||
|
@mock.patch('stevedore.named.NamedExtensionManager')
|
||||||
|
def test_init(self, mock_stevedore):
|
||||||
|
fake_data_driver = mock.Mock()
|
||||||
|
expected_flow = ['action1', 'action3']
|
||||||
|
fake_data_driver.flow = expected_flow
|
||||||
|
self.drv = flow.Flow(fake_data_driver)
|
||||||
|
mock_stevedore.assert_called_once_with(
|
||||||
|
'bareon.do_actions', names=expected_flow,
|
||||||
|
invoke_on_load=True, invoke_args=(fake_data_driver,),
|
||||||
|
name_order=True)
|
@ -37,6 +37,7 @@ bareon.drivers.deploy =
|
|||||||
nailgun = bareon.drivers.deploy.nailgun:Manager
|
nailgun = bareon.drivers.deploy.nailgun:Manager
|
||||||
swift = bareon.drivers.deploy.swift:Swift
|
swift = bareon.drivers.deploy.swift:Swift
|
||||||
rsync = bareon.drivers.deploy.rsync:Rsync
|
rsync = bareon.drivers.deploy.rsync:Rsync
|
||||||
|
flow = bareon.drivers.deploy.flow:Flow
|
||||||
|
|
||||||
oslo.config.opts =
|
oslo.config.opts =
|
||||||
bareon.manager = bareon.manager:list_opts
|
bareon.manager = bareon.manager:list_opts
|
||||||
|
Loading…
Reference in New Issue
Block a user