[Nailgun] Refactor plugin entities names
Change classes and files with more appropriate names Change-Id: I224bde2f590632ee8a1f9ac671d9c61e19cb8346 Implements: blueprint role-as-a-plugin
This commit is contained in:
parent
976baf8422
commit
e45a488cb3
|
@ -29,7 +29,7 @@ from nailgun.settings import settings
|
|||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class ClusterAttributesPluginBase(object):
|
||||
class PluginAdapterBase(object):
|
||||
"""Implements wrapper for plugin db model to provide
|
||||
logic related to configuration files.
|
||||
1. Uploading plugin provided cluster attributes
|
||||
|
@ -236,7 +236,7 @@ class ClusterAttributesPluginBase(object):
|
|||
release_info['deployment_scripts_path'])
|
||||
|
||||
|
||||
class ClusterAttributesPluginV1(ClusterAttributesPluginBase):
|
||||
class PluginAdapterV1(PluginAdapterBase):
|
||||
"""Plugins attributes class for package version 1.0.0
|
||||
"""
|
||||
|
||||
|
@ -249,7 +249,7 @@ class ClusterAttributesPluginV1(ClusterAttributesPluginBase):
|
|||
return self.full_name
|
||||
|
||||
|
||||
class ClusterAttributesPluginV2(ClusterAttributesPluginBase):
|
||||
class PluginAdapterV2(PluginAdapterBase):
|
||||
"""Plugins attributes class for package version 2.0.0
|
||||
"""
|
||||
|
||||
|
@ -279,7 +279,7 @@ class ClusterAttributesPluginV2(ClusterAttributesPluginBase):
|
|||
return major
|
||||
|
||||
|
||||
class PluginAdapterV3(ClusterAttributesPluginV2):
|
||||
class PluginAdapterV3(PluginAdapterV2):
|
||||
"""Plugin wrapper class for package version >= 3.0.0
|
||||
"""
|
||||
|
||||
|
@ -311,8 +311,8 @@ class PluginAdapterV3(ClusterAttributesPluginV2):
|
|||
|
||||
|
||||
__version_mapping = {
|
||||
'1.0.': ClusterAttributesPluginV1,
|
||||
'2.0.': ClusterAttributesPluginV2,
|
||||
'1.0.': PluginAdapterV1,
|
||||
'2.0.': PluginAdapterV2,
|
||||
'3.0.': PluginAdapterV3
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ import six
|
|||
from nailgun.logger import logger
|
||||
from nailgun.objects.plugin import Plugin
|
||||
from nailgun.objects.plugin import PluginCollection
|
||||
from nailgun.plugins.attr_plugin import wrap_plugin
|
||||
from nailgun.plugins.adapters import wrap_plugin
|
||||
|
||||
|
||||
class PluginManager(object):
|
||||
|
@ -64,21 +64,21 @@ class PluginManager(object):
|
|||
|
||||
@classmethod
|
||||
def get_plugin_attributes(cls, cluster):
|
||||
plugins_attrs = {}
|
||||
plugin_attributes = {}
|
||||
for plugin_db in PluginCollection.all_newest():
|
||||
attr_plugin = wrap_plugin(plugin_db)
|
||||
attrs = attr_plugin.get_plugin_attributes(cluster)
|
||||
plugins_attrs.update(attrs)
|
||||
return plugins_attrs
|
||||
plugin_adapter = wrap_plugin(plugin_db)
|
||||
attributes = plugin_adapter.get_plugin_attributes(cluster)
|
||||
plugin_attributes.update(attributes)
|
||||
return plugin_attributes
|
||||
|
||||
@classmethod
|
||||
def get_cluster_plugins_with_tasks(cls, cluster):
|
||||
attr_plugins = []
|
||||
cluster_plugins = []
|
||||
for plugin_db in cluster.plugins:
|
||||
attr_pl = wrap_plugin(plugin_db)
|
||||
attr_pl.set_cluster_tasks(cluster)
|
||||
attr_plugins.append(attr_pl)
|
||||
return attr_plugins
|
||||
plugin_adapter = wrap_plugin(plugin_db)
|
||||
plugin_adapter.set_cluster_tasks(cluster)
|
||||
cluster_plugins.append(plugin_adapter)
|
||||
return cluster_plugins
|
||||
|
||||
@classmethod
|
||||
def sync_plugins_metadata(cls, plugin_ids=None):
|
||||
|
@ -88,8 +88,8 @@ class PluginManager(object):
|
|||
if plugin_ids:
|
||||
plugins = PluginCollection.get_by_uids(plugin_ids)
|
||||
else:
|
||||
plugins = PluginCollection.all_newest()
|
||||
plugins = PluginCollection.all()
|
||||
|
||||
for plugin in plugins:
|
||||
plugin_wrapper = wrap_plugin(plugin)
|
||||
plugin_wrapper.sync_metadata_to_db()
|
||||
plugin_adapter = wrap_plugin(plugin)
|
||||
plugin_adapter.sync_metadata_to_db()
|
||||
|
|
|
@ -19,7 +19,7 @@ from oslo.serialization import jsonutils
|
|||
import yaml
|
||||
|
||||
from nailgun import objects
|
||||
from nailgun.plugins import attr_plugin
|
||||
from nailgun.plugins import adapters
|
||||
from nailgun.test import base
|
||||
|
||||
|
||||
|
@ -68,9 +68,9 @@ class BasePluginTest(base.BaseIntegrationTest):
|
|||
|
||||
def create_cluster(self, nodes=None):
|
||||
nodes = nodes if nodes else []
|
||||
with mock.patch('nailgun.plugins.attr_plugin.os') as os:
|
||||
with mock.patch('nailgun.plugins.adapters.os') as os:
|
||||
with mock.patch(
|
||||
'nailgun.plugins.attr_plugin.open',
|
||||
'nailgun.plugins.adapters.open',
|
||||
create=True,
|
||||
side_effect=get_config(self.plugin_env_config)):
|
||||
os.access.return_value = True
|
||||
|
@ -105,11 +105,11 @@ class BasePluginTest(base.BaseIntegrationTest):
|
|||
return self.modify_plugin(cluster, plugin_name, False)
|
||||
|
||||
def get_pre_hooks(self, cluster):
|
||||
with mock.patch('nailgun.plugins.attr_plugin.glob') as glob:
|
||||
with mock.patch('nailgun.plugins.adapters.glob') as glob:
|
||||
glob.glob.return_value = ['/some/path']
|
||||
with mock.patch('nailgun.plugins.attr_plugin.os') as os:
|
||||
with mock.patch('nailgun.plugins.adapters.os') as os:
|
||||
with mock.patch(
|
||||
'nailgun.plugins.attr_plugin.open',
|
||||
'nailgun.plugins.adapters.open',
|
||||
create=True,
|
||||
side_effect=get_config(self.TASKS_CONFIG)):
|
||||
os.access.return_value = True
|
||||
|
@ -121,9 +121,9 @@ class BasePluginTest(base.BaseIntegrationTest):
|
|||
return resp
|
||||
|
||||
def get_post_hooks(self, cluster):
|
||||
with mock.patch('nailgun.plugins.attr_plugin.os') as os:
|
||||
with mock.patch('nailgun.plugins.adapters.os') as os:
|
||||
with mock.patch(
|
||||
'nailgun.plugins.attr_plugin.open',
|
||||
'nailgun.plugins.adapters.open',
|
||||
create=True,
|
||||
side_effect=get_config(self.TASKS_CONFIG)):
|
||||
os.access.return_value = True
|
||||
|
@ -251,8 +251,8 @@ class TestPluginsApi(BasePluginTest):
|
|||
resp = self.sync_plugins(params={'ids': ids}, expect_errors=True)
|
||||
self.assertEqual(resp.status_code, 404)
|
||||
|
||||
@mock.patch('nailgun.plugins.attr_plugin.open', create=True)
|
||||
@mock.patch('nailgun.plugins.attr_plugin.os.access')
|
||||
@mock.patch('nailgun.plugins.adapters.open', create=True)
|
||||
@mock.patch('nailgun.plugins.adapters.os.access')
|
||||
def test_sync_with_invalid_yaml_files(self, maccess, mopen):
|
||||
maccess.return_value = True
|
||||
|
||||
|
@ -330,7 +330,7 @@ class TestPrePostHooks(BasePluginTest):
|
|||
self._requests_mock.start()
|
||||
|
||||
resp = self.create_plugin()
|
||||
self.plugin = attr_plugin.wrap_plugin(
|
||||
self.plugin = adapters.wrap_plugin(
|
||||
objects.Plugin.get_by_uid(resp.json['id']))
|
||||
self.cluster = self.create_cluster([
|
||||
{'roles': ['controller'], 'pending_addition': True},
|
||||
|
|
|
@ -21,7 +21,7 @@ import yaml
|
|||
|
||||
from nailgun.db import db
|
||||
from nailgun.objects import Plugin
|
||||
from nailgun.plugins import attr_plugin
|
||||
from nailgun.plugins import adapters
|
||||
from nailgun.settings import settings
|
||||
from nailgun.test import base
|
||||
|
||||
|
@ -45,16 +45,16 @@ class TestPluginBase(base.BaseTestCase):
|
|||
'version': '2014.2-6.0',
|
||||
'operating_system': 'Ubuntu'})
|
||||
self.cluster = self.env.clusters[0]
|
||||
self.attr_plugin = attr_plugin.wrap_plugin(self.plugin)
|
||||
self.plugin_adapter = adapters.wrap_plugin(self.plugin)
|
||||
self.env_config = self.env.get_default_plugin_env_config()
|
||||
self.get_config = lambda *args: mock.mock_open(
|
||||
read_data=yaml.dump(self.env_config))()
|
||||
|
||||
db().flush()
|
||||
|
||||
@mock.patch('nailgun.plugins.attr_plugin.open', create=True)
|
||||
@mock.patch('nailgun.plugins.attr_plugin.os.access')
|
||||
@mock.patch('nailgun.plugins.attr_plugin.os.path.exists')
|
||||
@mock.patch('nailgun.plugins.adapters.open', create=True)
|
||||
@mock.patch('nailgun.plugins.adapters.os.access')
|
||||
@mock.patch('nailgun.plugins.adapters.os.path.exists')
|
||||
def test_get_plugin_attributes(self, mexists, maccess, mopen):
|
||||
"""Should load attributes from environment_config.
|
||||
Attributes should contain provided attributes by plugin and
|
||||
|
@ -63,25 +63,25 @@ class TestPluginBase(base.BaseTestCase):
|
|||
maccess.return_value = True
|
||||
mexists.return_value = True
|
||||
mopen.side_effect = self.get_config
|
||||
attributes = self.attr_plugin.get_plugin_attributes(self.cluster)
|
||||
attributes = self.plugin_adapter.get_plugin_attributes(self.cluster)
|
||||
self.assertEqual(
|
||||
attributes['testing_plugin']['plugin_name_text'],
|
||||
self.env_config['attributes']['plugin_name_text'])
|
||||
self.assertEqual(
|
||||
attributes['testing_plugin']['metadata'],
|
||||
self.attr_plugin.default_metadata)
|
||||
self.plugin_adapter.default_metadata)
|
||||
|
||||
def test_plugin_release_versions(self):
|
||||
"""Helper should return set of all release versions this plugin
|
||||
is applicable to.
|
||||
"""
|
||||
self.assertEqual(
|
||||
self.attr_plugin.plugin_release_versions, set(['2014.2-6.0']))
|
||||
self.plugin_adapter.plugin_release_versions, set(['2014.2-6.0']))
|
||||
|
||||
def test_full_name(self):
|
||||
"""Plugin full name should be made from name and version."""
|
||||
self.assertEqual(
|
||||
self.attr_plugin.full_name,
|
||||
self.plugin_adapter.full_name,
|
||||
'{0}-{1}'.format(self.plugin.name, self.plugin.version))
|
||||
|
||||
def test_get_release_info(self):
|
||||
|
@ -89,47 +89,48 @@ class TestPluginBase(base.BaseTestCase):
|
|||
provided release.
|
||||
"""
|
||||
self.cluster.release.version = '2014.2.2-6.0.1'
|
||||
release = self.attr_plugin.get_release_info(self.cluster.release)
|
||||
release = self.plugin_adapter.get_release_info(self.cluster.release)
|
||||
self.assertEqual(release, self.plugin_metadata['releases'][0])
|
||||
|
||||
def test_slaves_scripts_path(self):
|
||||
expected = settings.PLUGINS_SLAVES_SCRIPTS_PATH.format(
|
||||
plugin_name=self.attr_plugin.path_name)
|
||||
self.assertEqual(expected, self.attr_plugin.slaves_scripts_path)
|
||||
plugin_name=self.plugin_adapter.path_name)
|
||||
self.assertEqual(expected, self.plugin_adapter.slaves_scripts_path)
|
||||
|
||||
@mock.patch('nailgun.plugins.attr_plugin.glob')
|
||||
@mock.patch('nailgun.plugins.adapters.glob')
|
||||
def test_repo_files(self, glob_mock):
|
||||
self.attr_plugin.repo_files(self.cluster)
|
||||
self.plugin_adapter.repo_files(self.cluster)
|
||||
expected_call = os.path.join(
|
||||
settings.PLUGINS_PATH,
|
||||
self.attr_plugin.path_name,
|
||||
self.plugin_adapter.path_name,
|
||||
'repositories/ubuntu',
|
||||
'*')
|
||||
glob_mock.glob.assert_called_once_with(expected_call)
|
||||
|
||||
@mock.patch('nailgun.plugins.attr_plugin.urljoin')
|
||||
@mock.patch('nailgun.plugins.adapters.urljoin')
|
||||
def test_repo_url(self, murljoin):
|
||||
self.attr_plugin.repo_url(self.cluster)
|
||||
self.plugin_adapter.repo_url(self.cluster)
|
||||
repo_base = settings.PLUGINS_REPO_URL.format(
|
||||
master_ip=settings.MASTER_IP,
|
||||
plugin_name=self.attr_plugin.path_name)
|
||||
plugin_name=self.plugin_adapter.path_name)
|
||||
murljoin.assert_called_once_with(repo_base, 'repositories/ubuntu')
|
||||
|
||||
def test_master_scripts_path(self):
|
||||
base_url = settings.PLUGINS_SLAVES_RSYNC.format(
|
||||
master_ip=settings.MASTER_IP,
|
||||
plugin_name=self.attr_plugin.path_name)
|
||||
plugin_name=self.plugin_adapter.path_name)
|
||||
|
||||
expected = '{0}{1}'.format(base_url, 'deployment_scripts/')
|
||||
self.assertEqual(
|
||||
expected, self.attr_plugin.master_scripts_path(self.cluster))
|
||||
expected, self.plugin_adapter.master_scripts_path(self.cluster))
|
||||
|
||||
def test_sync_metadata_to_db(self):
|
||||
plugin_metadata = self.env.get_default_plugin_metadata()
|
||||
|
||||
with mock.patch.object(self.attr_plugin, '_load_config') as load_conf:
|
||||
with mock.patch.object(
|
||||
self.plugin_adapter, '_load_config') as load_conf:
|
||||
load_conf.return_value = plugin_metadata
|
||||
self.attr_plugin.sync_metadata_to_db()
|
||||
self.plugin_adapter.sync_metadata_to_db()
|
||||
|
||||
for key, val in six.iteritems(plugin_metadata):
|
||||
self.assertEqual(
|
||||
|
@ -143,17 +144,18 @@ class TestPluginV1(TestPluginBase):
|
|||
|
||||
def test_primary_added_for_version(self):
|
||||
stub = 'stub'
|
||||
with mock.patch.object(self.attr_plugin, '_load_config') as load_conf:
|
||||
with mock.patch.object(
|
||||
self.plugin_adapter, '_load_config') as load_conf:
|
||||
load_conf.return_value = [{'role': ['controller']}]
|
||||
|
||||
tasks = self.attr_plugin._load_tasks(stub)
|
||||
tasks = self.plugin_adapter._load_tasks(stub)
|
||||
self.assertItemsEqual(
|
||||
tasks[0]['role'], ['primary-controller', 'controller'])
|
||||
|
||||
def test_path_name(self):
|
||||
self.assertEqual(
|
||||
self.attr_plugin.path_name,
|
||||
self.attr_plugin.full_name)
|
||||
self.plugin_adapter.path_name,
|
||||
self.plugin_adapter.full_name)
|
||||
|
||||
|
||||
class TestPluginV2(TestPluginBase):
|
||||
|
@ -163,16 +165,17 @@ class TestPluginV2(TestPluginBase):
|
|||
|
||||
def test_role_not_changed_for_version(self):
|
||||
stub = 'stub'
|
||||
with mock.patch.object(self.attr_plugin, '_load_config') as load_conf:
|
||||
with mock.patch.object(
|
||||
self.plugin_adapter, '_load_config') as load_conf:
|
||||
load_conf.return_value = [{'role': ['controller']}]
|
||||
|
||||
tasks = self.attr_plugin._load_tasks(stub)
|
||||
tasks = self.plugin_adapter._load_tasks(stub)
|
||||
self.assertItemsEqual(
|
||||
tasks[0]['role'], ['controller'])
|
||||
|
||||
def test_path_name(self):
|
||||
self.assertEqual(
|
||||
self.attr_plugin.path_name,
|
||||
self.plugin_adapter.path_name,
|
||||
'{0}-{1}'.format(self.plugin.name, '0.1'))
|
||||
|
||||
|
||||
|
@ -198,9 +201,10 @@ class TestPluginV3(TestPluginBase):
|
|||
self._find_path('tasks'): tasks,
|
||||
}
|
||||
|
||||
with mock.patch.object(self.attr_plugin, '_load_config') as load_conf:
|
||||
with mock.patch.object(
|
||||
self.plugin_adapter, '_load_config') as load_conf:
|
||||
load_conf.side_effect = lambda key: mocked_metadata[key]
|
||||
self.attr_plugin.sync_metadata_to_db()
|
||||
self.plugin_adapter.sync_metadata_to_db()
|
||||
|
||||
for key, val in six.iteritems(plugin_metadata):
|
||||
self.assertEqual(
|
||||
|
@ -219,7 +223,7 @@ class TestPluginV3(TestPluginBase):
|
|||
|
||||
def _find_path(self, config_name):
|
||||
return os.path.join(
|
||||
self.attr_plugin.plugin_path,
|
||||
self.plugin_adapter.plugin_path,
|
||||
'{0}.yaml'.format(config_name))
|
||||
|
||||
|
||||
|
@ -232,7 +236,7 @@ class TestClusterCompatiblityValidation(base.BaseTestCase):
|
|||
'version': '2014.2-6.0',
|
||||
'os': 'ubuntu',
|
||||
'mode': ['ha']}]))
|
||||
self.attr_plugin = attr_plugin.ClusterAttributesPluginV1(self.plugin)
|
||||
self.plugin_adapter = adapters.PluginAdapterV1(self.plugin)
|
||||
|
||||
def cluster_mock(self, os, mode, version):
|
||||
release = mock.Mock(operating_system=os, version=version)
|
||||
|
@ -241,7 +245,7 @@ class TestClusterCompatiblityValidation(base.BaseTestCase):
|
|||
|
||||
def validate_with_cluster(self, **kwargs):
|
||||
cluster = self.cluster_mock(**kwargs)
|
||||
return self.attr_plugin.validate_cluster_compatibility(cluster)
|
||||
return self.plugin_adapter.validate_cluster_compatibility(cluster)
|
||||
|
||||
def test_validation_ubuntu_ha(self):
|
||||
self.assertTrue(self.validate_with_cluster(
|
Loading…
Reference in New Issue