本文整理汇总了Python中nailgun.objects.Plugin类的典型用法代码示例。如果您正苦于以下问题:Python Plugin类的具体用法?Python Plugin怎么用?Python Plugin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Plugin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_all_newest
def test_all_newest(self):
for version in ['1.0.0', '2.0.0', '0.0.1']:
plugin_data = self.env.get_default_plugin_metadata(
version=version,
name='multiversion_plugin')
Plugin.create(plugin_data)
single_plugin_data = self.env.get_default_plugin_metadata(
name='single_plugin')
Plugin.create(single_plugin_data)
newest_plugins = PluginCollection.all_newest()
self.assertEqual(len(newest_plugins), 2)
single_plugin = filter(
lambda p: p.name == 'single_plugin',
newest_plugins)
multiversion_plugin = filter(
lambda p: p.name == 'multiversion_plugin',
newest_plugins)
self.assertEqual(len(single_plugin), 1)
self.assertEqual(len(multiversion_plugin), 1)
self.assertEqual(multiversion_plugin[0].version, '2.0.0')
示例2: setUp
def setUp(self):
super(TestMigrationPluginsClusterAttrs, self).setUp()
self.cluster = self.env.create()
self.plugins = [
Plugin.create(self.env.get_default_plugin_metadata(
name='plugin_name_1')),
Plugin.create(self.env.get_default_plugin_metadata(
name='plugin_name_2'))]
示例3: test_get_metadata
def test_get_metadata(self):
plugin_metadata = self.env.get_default_plugin_metadata()
attributes_metadata = self.env.get_default_plugin_env_config()
roles_metadata = self.env.get_default_plugin_node_roles_config()
volumes_metadata = self.env.get_default_plugin_volumes_config()
network_roles_metadata = self.env.get_default_network_roles_config()
deployment_tasks = self.env.get_default_plugin_deployment_tasks()
tasks = self.env.get_default_plugin_tasks()
components_metadata = self.env.get_default_components()
mocked_metadata = {
self._find_path('metadata'): plugin_metadata,
self._find_path('environment_config'): attributes_metadata,
self._find_path('node_roles'): roles_metadata,
self._find_path('volumes'): volumes_metadata,
self._find_path('network_roles'): network_roles_metadata,
self._find_path('deployment_tasks'): deployment_tasks,
self._find_path('tasks'): tasks,
self._find_path('components'): components_metadata
}
with mock.patch.object(
self.plugin_adapter, '_load_config') as load_conf:
load_conf.side_effect = lambda key: mocked_metadata[key]
Plugin.update(self.plugin, self.plugin_adapter.get_metadata())
for key, val in six.iteritems(plugin_metadata):
self.assertEqual(
getattr(self.plugin, key), val)
self.assertEqual(
self.plugin.attributes_metadata,
attributes_metadata['attributes'])
self.assertEqual(
self.plugin.roles_metadata, roles_metadata)
self.assertEqual(
self.plugin.volumes_metadata, volumes_metadata)
self.assertEqual(
self.plugin.tasks, tasks)
self.assertEqual(
self.plugin.components_metadata, components_metadata)
# deployment tasks returning all non-defined fields, so check
# should differ from JSON-stored fields
plugin_tasks = self.env.get_default_plugin_deployment_tasks()
self.assertGreater(len(plugin_tasks), 0)
for k, v in six.iteritems(plugin_tasks[0]):
# this field is updated by plugin adapter
if k is 'parameters':
v.update({
'cwd': '/etc/fuel/plugins/testing_plugin-0.1/'
})
self.assertEqual(
self.plugin_adapter.get_deployment_tasks()[0][k],
v)
示例4: test_get_metadata
def test_get_metadata(self):
plugin_metadata = self.env.get_default_plugin_metadata()
attributes_metadata = self.env.get_default_plugin_env_config()
roles_metadata = self.env.get_default_plugin_node_roles_config()
volumes_metadata = self.env.get_default_plugin_volumes_config()
network_roles_metadata = self.env.get_default_network_roles_config()
deployment_tasks = self.env.get_default_plugin_deployment_tasks()
tasks = self.env.get_default_plugin_tasks()
components_metadata = self.env.get_default_components()
plugin_metadata.update({
'attributes_metadata': attributes_metadata,
'roles_metadata': roles_metadata,
'volumes_metadata': volumes_metadata,
'network_roles_metadata': network_roles_metadata,
'deployment_tasks': deployment_tasks,
'tasks': tasks,
'components_metadata': components_metadata
})
with mock.patch.object(
self.plugin_adapter, 'loader') as loader:
loader.load.return_value = (plugin_metadata, ReportNode())
Plugin.update(self.plugin, self.plugin_adapter.get_metadata())
for key, val in six.iteritems(plugin_metadata):
if key not in ('deployment_tasks', 'graphs'):
self.assertEqual(getattr(self.plugin, key), val)
self.assertEqual(
self.plugin.attributes_metadata,
attributes_metadata['attributes'])
self.assertEqual(
self.plugin.roles_metadata, roles_metadata)
self.assertEqual(
self.plugin.volumes_metadata, volumes_metadata)
self.assertEqual(
self.plugin.tasks, tasks)
self.assertEqual(
self.plugin.components_metadata, components_metadata)
# deployment tasks returning all non-defined fields, so check
# should differ from JSON-stored fields
plugin_tasks = self.env.get_default_plugin_deployment_tasks()
self.assertGreater(len(plugin_tasks), 0)
for k, v in six.iteritems(plugin_tasks[0]):
# this field is updated by plugin adapter
if k is 'parameters':
v.update({
'cwd': '/etc/fuel/plugins/testing_plugin-0.1/'
})
self.assertEqual(
self.plugin_adapter.get_deployment_tasks()[0][k],
v)
示例5: validate
def validate(cls, data):
if data:
parsed = super(PluginSyncValidator, cls).validate(data)
cls.validate_schema(parsed, plugin.SYNC_SCHEMA)
# Check plugin with given id exists in DB
# otherwise raise ObjectNotFound exception
for plugin_id in parsed.get('ids'):
Plugin.get_by_uid(plugin_id, fail_if_not_found=True)
return parsed
else:
return {}
示例6: _create_test_plugins
def _create_test_plugins(self):
plugin_ids = []
for version in ['1.0.0', '2.0.0', '0.0.1', '3.0.0']:
plugin_data = self.env.get_default_plugin_metadata(
version=version,
name='multiversion_plugin')
plugin = Plugin.create(plugin_data)
plugin_ids.append(plugin.id)
single_plugin_data = self.env.get_default_plugin_metadata(
name='single_plugin')
plugin = Plugin.create(single_plugin_data)
plugin_ids.append(plugin.id)
return plugin_ids
示例7: setUp
def setUp(self):
super(TestNailgunReceiver, self).setUp()
self.env.create(
status=consts.CLUSTER_STATUSES.operational,
nodes_kwargs=[
{'roles': ['controller'],
'status': consts.NODE_STATUSES.ready}])
self.cluster = self.env.clusters[0]
for i in range(2):
meta = self.env.get_default_plugin_metadata(
name='name{0}'.format(i),
title='title{0}'.format(i),
description='description{0}'.format(i))
self.plugin = Plugin.create(meta)
self.cluster.plugins.append(self.plugin)
ClusterPlugins.set_attributes(self.cluster.id,
self.plugin.id,
enabled=True)
self.task = self.env.create_task(
name=consts.TASK_NAMES.deployment,
status=consts.TASK_STATUSES.ready,
cluster_id=self.cluster.id)
示例8: test_add_nodes_for_cluster_plugin_with_empty_attributes
def test_add_nodes_for_cluster_plugin_with_empty_attributes(self):
meta = base.reflect_db_metadata()
self.env.create_node(
cluster_id=self.cluster.id,
roles=['compute']
)
plugin = Plugin.create({
'name': 'plugin_a_with_node_attributes',
'title': 'Test Plugin',
'package_version': '5.0.0',
'version': '1.0.0',
'node_attributes_metadata': {}
})
cluster_plugin = ClusterPlugin.create({
'cluster_id': self.cluster.id,
'plugin_id': plugin.id,
'enabled': False,
'attributes': plugin.node_attributes_metadata
})
NodeClusterPlugin.add_nodes_for_cluster_plugin(cluster_plugin)
node_cluster_plugins = self.db.execute(
meta.tables['node_cluster_plugins'].select()
).fetchall()
self.assertEqual(0, len(node_cluster_plugins))
示例9: _create_test_plugins
def _create_test_plugins(self):
plugin_ids = []
for version in ["1.0.0", "2.0.0", "0.0.1", "3.0.0", "4.0.0", "5.0.0"]:
plugin_data = self.env.get_default_plugin_metadata(version=version, name="multiversion_plugin")
plugin = Plugin.create(plugin_data)
plugin_ids.append(plugin.id)
single_plugin_data = self.env.get_default_plugin_metadata(name="single_plugin")
plugin = Plugin.create(single_plugin_data)
plugin_ids.append(plugin.id)
incompatible_plugin_data = self.env.get_default_plugin_metadata(name="incompatible_plugin", releases=[])
plugin = Plugin.create(incompatible_plugin_data)
plugin_ids.append(plugin.id)
return plugin_ids
示例10: setUp
def setUp(self):
super(TestClusterCompatibilityValidation, self).setUp()
self.plugin = Plugin.create(self.env.get_default_plugin_metadata(
releases=[{
'version': '2014.2-6.0',
'os': 'ubuntu',
'mode': ['ha']}]))
self.plugin_adapter = adapters.PluginAdapterV1(self.plugin)
示例11: setUp
def setUp(self):
super(TestClusterCompatiblityValidation, self).setUp()
self.plugin = Plugin.create(self.env.get_default_plugin_metadata(
releases=[{
'version': '2014.2-6.0',
'os': 'ubuntu',
'mode': ['ha']}]))
self.attr_plugin = attr_plugin.ClusterAttributesPluginV1(self.plugin)
示例12: create_plugin
def create_plugin(self, api=False, cluster=None, **kwargs):
plugin_data = self.get_default_plugin_metadata()
plugin_data.update(kwargs)
if api:
resp = self.app.post(
reverse("PluginCollectionHandler"),
jsonutils.dumps(plugin_data),
headers=self.default_headers,
expect_errors=False,
)
plugin = Plugin.get_by_uid(resp.json_body["id"])
self.plugins.append(plugin)
else:
plugin = Plugin.create(plugin_data)
self.plugins.append(plugin)
# Enable plugin for specific cluster
if cluster:
cluster.plugins.append(plugin)
return plugin
示例13: setUp
def setUp(self):
super(TestPluginBase, self).setUp()
self.plugin_metadata = self.env.get_default_plugin_metadata(
package_version=self.package_version,
roles_metadata={
'role_x': {
'name': 'Role X',
'description': 'Role X is ...',
},
'role_y': {
'name': 'Role Y',
'description': 'Role Y is ...',
'restrictions': [],
'fault_tolerance': '5%'
},
'role_z': {
'name': 'Role Z',
'description': 'Role Z is ...',
'restrictions': [
'settings:some.stuff.value == false'
],
'fault_tolerance': '10%'
}
}
)
self.plugin = Plugin.create(self.plugin_metadata)
self.cluster = self.env.create(
cluster_kwargs={'mode': consts.CLUSTER_MODES.multinode},
release_kwargs={
'version': '2015.1-8.0',
'operating_system': 'Ubuntu',
'modes': [consts.CLUSTER_MODES.multinode,
consts.CLUSTER_MODES.ha_compact]})
self.plugin_adapter = plugins.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()
示例14: test_graphs_creation
def test_graphs_creation(self):
metadata_update = {
'name': 'graphs_plugin',
'description': 'testing graphs',
'package_version': '5.0.0',
'graphs': [
{
'type': 'default',
'name': 'default',
'tasks': [
{'id': 'default', 'type': 'puppet'}
]
},
{
'type': 'custom',
'name': 'custom',
'tasks': [
{'id': 'custom', 'type': 'puppet'}
]
}
]}
metadata = self.env.get_default_plugin_metadata()
metadata.update(metadata_update)
plugin = Plugin.create(metadata)
def_graph = DeploymentGraph.get_for_model(
plugin, graph_type='default'
)
self.assertEqual(def_graph.name, 'default')
self.assertEqual(
DeploymentGraph.get_tasks(def_graph),
[
{
'id': 'default',
'task_name': 'default',
'type': 'puppet',
'version': '1.0.0'
}
]
)
custom_graph = DeploymentGraph.get_for_model(
plugin, graph_type='custom'
)
self.assertEqual(custom_graph.name, 'custom')
self.assertEqual(
DeploymentGraph.get_tasks(custom_graph),
[
{
'id': 'custom',
'task_name': 'custom',
'type': 'puppet',
'version': '1.0.0'
}
]
)
Plugin.update(plugin, metadata)
def_graph = DeploymentGraph.get_for_model(
plugin, graph_type='default'
)
self.assertEqual(def_graph.name, 'default')
self.assertEqual(
DeploymentGraph.get_tasks(def_graph),
[
{
'id': 'default',
'task_name': 'default',
'type': 'puppet',
'version': '1.0.0'
}
]
)
custom_graph = DeploymentGraph.get_for_model(
plugin, graph_type='custom'
)
self.assertEqual(custom_graph.name, 'custom')
self.assertEqual(
DeploymentGraph.get_tasks(custom_graph),
[
{
'id': 'custom',
'task_name': 'custom',
'type': 'puppet',
'version': '1.0.0'
}
]
)
示例15: test_tags_saved_on_plugins_update
def test_tags_saved_on_plugins_update(self):
Plugin.update(self.plugin,
{'roles_metadata': self.plugin.roles_metadata})
for role, meta in self.plugin.roles_metadata.items():
self.assertIn('tags', meta)