def update(cls, instance, data): # Plugin name can't be changed. Plugins sync operation uses # name for searching plugin data on the file system. new_name = data.get('name') if new_name is not None and instance.name != new_name: raise errors.InvalidData( "Plugin can't be renamed. Trying to change name " "of the plugin {0} to {1}".format(instance.name, new_name)) graphs = {} data_graphs = data.pop("graphs", []) for graph in data_graphs: graphs[graph.pop('type')] = graph data.pop("deployment_tasks", []) # could not be updated # We must save tags info in the roles_metadata on the update data = cls._process_tags(data) super(Plugin, cls).update(instance, data) for graph_type, graph_data in six.iteritems(graphs): existing_graph = DeploymentGraph.get_for_model( instance, graph_type=graph_type) if existing_graph: DeploymentGraph.update(existing_graph, graph_data) else: DeploymentGraph.create_for_model(graph_data, instance, graph_type)
def create(cls, data): """Create Release instance with specified parameters in DB. :param data: dictionary of key-value pairs as object fields :returns: Release instance """ # in order to be compatible with old API, let's drop input # roles array. since fuel 7.0 we don't use it anymore, and # we don't require it even for old releases. data.pop("roles", None) # process graphs graphs = {} graphs_list = data.pop('graphs', []) for graph in graphs_list: graphs[graph.pop('type')] = graph deployment_tasks = data.pop("deployment_tasks", []) if not graphs.get(consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE): graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \ {'tasks': deployment_tasks} release_obj = super(Release, cls).create(data) for graph_type, graph_data in six.iteritems(graphs): DeploymentGraph.create_for_model(graph_data, release_obj, graph_type) return release_obj
def update(cls, instance, data): """Update existing Release instance with specified parameters. :param instance: Release instance :param data: dictionary of key-value pairs as object fields :returns: Release instance """ # in order to be compatible with old API, let's drop input # roles array. since fuel 7.0 we don't use it anymore, and # we don't require it even for old releases. data.pop("roles", None) graphs = data.pop("graphs", {}) deployment_tasks = data.pop("deployment_tasks", []) existing_default_graph = DeploymentGraph.get_for_model( instance, consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE) if (existing_default_graph and len(deployment_tasks)) \ or not existing_default_graph: graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \ {'tasks': deployment_tasks} release_obj = super(Release, cls).update(instance, data) for graph_type, graph_data in six.iteritems(graphs): g = DeploymentGraph.get_for_model(instance, graph_type) if g: DeploymentGraph.update(g, graph_data) else: DeploymentGraph.create_for_model( graph_data, instance, graph_type) return release_obj
def create(cls, data): """Create Release instance with specified parameters in DB. :param data: dictionary of key-value pairs as object fields :returns: Release instance """ # in order to be compatible with old API, let's drop input # roles array. since fuel 7.0 we don't use it anymore, and # we don't require it even for old releases. data.pop("roles", None) # process graphs graphs = {} graphs_list = data.pop('graphs', []) for graph in graphs_list: graphs[graph.pop('type')] = graph deployment_tasks = data.pop("deployment_tasks", []) if not graphs.get(consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE): graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \ {'tasks': deployment_tasks} release_obj = super(Release, cls).create(data) for graph_type, graph_data in six.iteritems(graphs): DeploymentGraph.create_for_model( graph_data, release_obj, graph_type) cls.create_tags(release_obj) return release_obj
def create(cls, data): # accidental because i've seen this way of tasks creation only in tests deployment_tasks = data.pop('deployment_tasks', []) new_plugin = super(Plugin, cls).create(data) # create default graph in any case DeploymentGraph.create_for_model( {'tasks': deployment_tasks}, new_plugin) plugin_adapter = wrap_plugin(new_plugin) cls.update(new_plugin, plugin_adapter.get_metadata()) ClusterPlugin.add_compatible_clusters(new_plugin) return new_plugin
def create(cls, data): # accidental because i've seen this way of tasks creation only in tests deployment_tasks = data.pop('deployment_tasks', []) new_plugin = super(Plugin, cls).create(data) # create default graph in any case DeploymentGraph.create_for_model({'tasks': deployment_tasks}, new_plugin) plugin_adapter = wrap_plugin(new_plugin) cls.update(new_plugin, plugin_adapter.get_metadata()) ClusterPlugins.add_compatible_clusters(new_plugin) return new_plugin
def create(cls, data): """Create Release instance with specified parameters in DB. :param data: dictionary of key-value pairs as object fields :returns: Release instance """ # in order to be compatible with old API, let's drop input # roles array. since fuel 7.0 we don't use it anymore, and # we don't require it even for old releases. data.pop("roles", None) deployment_tasks = data.pop("deployment_tasks", []) release_obj = super(Release, cls).create(data) DeploymentGraph.create_for_model( {'tasks': deployment_tasks}, release_obj) return release_obj
def create(cls, data): """Create Release instance with specified parameters in DB. :param data: dictionary of key-value pairs as object fields :returns: Release instance """ # in order to be compatible with old API, let's drop input # roles array. since fuel 7.0 we don't use it anymore, and # we don't require it even for old releases. data.pop("roles", None) deployment_tasks = data.pop("deployment_tasks", []) release_obj = super(Release, cls).create(data) DeploymentGraph.create_for_model({'tasks': deployment_tasks}, release_obj) return release_obj
def setUp(self): super(TestGraphHandlers, self).setUp() self.cluster = self.env.create_cluster(api=False) plugin_data = { 'releases': [ { 'repository_path': 'repositories/ubuntu', 'version': self.cluster.release.version, 'os': self.cluster.release.operating_system.lower(), 'mode': [self.cluster.mode], } ], 'cluster': self.cluster, 'enabled': True, } self.plugin = self.env.create_plugin(**plugin_data) self.custom_graph = DeploymentGraph.create_for_model( { 'name': 'custom-graph-name', 'tasks': [{ 'id': 'custom-task', 'type': 'puppet' }] }, self.cluster, graph_type='custom-graph' ) self.env.db().commit()
def setUp(self): super(TestGraphHandlers, self).setUp() self.cluster = self.env.create_cluster(api=False) plugin_data = { 'releases': [{ 'repository_path': 'repositories/ubuntu', 'version': self.cluster.release.version, 'os': self.cluster.release.operating_system.lower(), 'mode': [self.cluster.mode], }], 'cluster': self.cluster, 'enabled': True, } self.plugin = self.env.create_plugin(**plugin_data) self.custom_graph = DeploymentGraph.create_for_model( { 'name': 'custom-graph-name', 'tasks': [{ 'id': 'custom-task', 'type': 'puppet' }] }, self.cluster, graph_type='custom-graph') self.env.db().commit()
def update(cls, instance, data): graphs = {} data_graphs = data.pop("graphs", []) for graph in data_graphs: graphs[graph.pop('type')] = graph data.pop("deployment_tasks", []) # could not be updated super(Plugin, cls).update(instance, data) for graph_type, graph_data in six.iteritems(graphs): existing_graph = DeploymentGraph.get_for_model( instance, graph_type=graph_type) if existing_graph: DeploymentGraph.update(existing_graph, graph_data) else: DeploymentGraph.create_for_model(graph_data, instance, graph_type)
def update(cls, instance, data): graphs = {} data_graphs = data.pop("graphs", []) for graph in data_graphs: graphs[graph.pop('type')] = graph data.pop("deployment_tasks", []) # could not be updated super(Plugin, cls).update(instance, data) for graph_type, graph_data in six.iteritems(graphs): existing_graph = DeploymentGraph.get_for_model( instance, graph_type=graph_type) if existing_graph: DeploymentGraph.update(existing_graph, graph_data) else: DeploymentGraph.create_for_model( graph_data, instance, graph_type)
def get_deployment_tasks(cls, instance, graph_type=None): """Get deployment graph based on release version. :param instance: Release instance :type instance: models.Release :param graph_type: deployment graph type :type graph_type: basestring|None :returns: list of deployment tasks :rtype: list """ if graph_type is None: graph_type = consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE env_version = instance.environment_version deployment_graph = DeploymentGraph.get_for_model(instance, graph_type) if deployment_graph: deployment_tasks = DeploymentGraph.get_tasks(deployment_graph) else: # deployment tasks list should always be returned deployment_tasks = [] if graph_type == consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE and \ not deployment_tasks: # upload default legacy graphs if env_version.startswith('5.0'): deployment_tasks = yaml.load( graph_configuration.DEPLOYMENT_50) elif env_version.startswith('5.1') \ or env_version.startswith('6.0'): deployment_tasks = yaml.load( graph_configuration.DEPLOYMENT_51_60) if deployment_graph: if deployment_tasks: DeploymentGraph.update( deployment_graph, {'tasks': deployment_tasks}) else: # create graph anyway DeploymentGraph.create_for_model( {'tasks': deployment_tasks}, instance) return deployment_tasks
def get_deployment_tasks(cls, instance, graph_type=None): """Get deployment graph based on release version. :param instance: Release instance :type instance: models.Release :param graph_type: deployment graph type :type graph_type: basestring|None :returns: list of deployment tasks :rtype: list """ if graph_type is None: graph_type = consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE env_version = instance.environment_version deployment_graph = DeploymentGraph.get_for_model(instance, graph_type) if deployment_graph: deployment_tasks = DeploymentGraph.get_tasks(deployment_graph) else: # deployment tasks list should always be returned deployment_tasks = [] if graph_type == consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE and \ not deployment_tasks: # upload default legacy graphs if env_version.startswith('5.0'): deployment_tasks = yaml.load( graph_configuration.DEPLOYMENT_50) elif env_version.startswith('5.1') \ or env_version.startswith('6.0'): deployment_tasks = yaml.load( graph_configuration.DEPLOYMENT_51_60) if deployment_graph: if deployment_tasks: DeploymentGraph.update( deployment_graph, {'tasks': deployment_tasks}) else: # create graph anyway DeploymentGraph.create_for_model( {'tasks': deployment_tasks}, instance) return deployment_tasks
def create(cls, data): """Create plugin. WARNING: don't pass keys with none to non nullable fields. :param data: data :type data: dict :return: plugin instance :rtype: models.Plugin """ graphs = {} for graph in data.pop("graphs", []): graphs[graph.pop('type')] = graph deployment_tasks = data.pop("deployment_tasks", []) data['releases'] = [ r for r in data.pop("releases", []) if not r.get('is_release', False) ] plugin_obj = super(Plugin, cls).create(data) if not graphs.get(consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE): graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \ {'tasks': deployment_tasks} for graph_type, graph_data in six.iteritems(graphs): DeploymentGraph.create_for_model(graph_data, plugin_obj, graph_type) plugin_adapter = plugins.wrap_plugin(plugin_obj) # todo(ikutukov): this update is a smell from the current plugins # installation schema. Remove it. plugin_meta = cls._process_tags(plugin_adapter.get_metadata()) cls.update(plugin_obj, plugin_meta) ClusterPlugin.add_compatible_clusters(plugin_obj) return plugin_obj
def create(cls, data): """Create plugin. WARNING: don't pass keys with none to non nullable fields. :param data: data :type data: dict :return: plugin instance :rtype: models.Plugin """ graphs = {} for graph in data.pop("graphs", []): graphs[graph.pop('type')] = graph deployment_tasks = data.pop("deployment_tasks", []) data['releases'] = [ r for r in data.pop("releases", []) if not r.get('is_release', False) ] plugin_obj = super(Plugin, cls).create(data) if not graphs.get(consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE): graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \ {'tasks': deployment_tasks} for graph_type, graph_data in six.iteritems(graphs): DeploymentGraph.create_for_model( graph_data, plugin_obj, graph_type) plugin_adapter = plugins.wrap_plugin(plugin_obj) # todo(ikutukov): this update is a smell from the current plugins # installation schema. Remove it. cls.update(plugin_obj, plugin_adapter.get_metadata()) ClusterPlugin.add_compatible_clusters(plugin_obj) return plugin_obj
def setUp(self): super(TestGraphHandlers, self).setUp() self.cluster = self.env.create_cluster(api=False) self.custom_graph = DeploymentGraph.create_for_model( { 'name': 'custom-graph-name', 'tasks': [{ 'id': 'custom-task', 'type': 'puppet' }] }, self.cluster, graph_type='custom-graph')
def create(cls, data): graphs = data.pop("graphs", {}) deployment_tasks = data.pop("deployment_tasks", []) if not graphs.get(consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE): graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \ {'tasks': deployment_tasks} plugin_obj = super(Plugin, cls).create(data) for graph_type, graph_data in six.iteritems(graphs): DeploymentGraph.create_for_model( graph_data, plugin_obj, graph_type) plugin_adapter = plugins.wrap_plugin(plugin_obj) # todo(ikutukov): this update is a smell from the current plugins # todo: installation schema. Remove it. cls.update(plugin_obj, plugin_adapter.get_metadata()) ClusterPlugin.add_compatible_clusters(plugin_obj) return plugin_obj
def setUp(self): super(TestGraphHandlers, self).setUp() self.cluster = self.env.create_cluster(api=False) self.custom_graph = DeploymentGraph.create_for_model( { 'name': 'custom-graph-name', 'tasks': [{ 'id': 'custom-task', 'type': 'puppet' }] }, self.cluster, graph_type='custom-graph' )
def update(cls, instance, data): """Update existing Release instance with specified parameters. :param instance: Release instance :param data: dictionary of key-value pairs as object fields :returns: Release instance """ # in order to be compatible with old API, let's drop input # roles array. since fuel 7.0 we don't use it anymore, and # we don't require it even for old releases. data.pop("roles", None) graphs = {} graphs_list = data.pop('graphs', []) for graph in graphs_list: graphs[graph.pop('type')] = graph deployment_tasks = data.pop("deployment_tasks", []) existing_default_graph = DeploymentGraph.get_for_model( instance, consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE) if (existing_default_graph and len(deployment_tasks)) \ or not existing_default_graph: graphs[consts.DEFAULT_DEPLOYMENT_GRAPH_TYPE] = \ {'tasks': deployment_tasks} release_obj = super(Release, cls).update(instance, data) for graph_type, graph_data in six.iteritems(graphs): g = DeploymentGraph.get_for_model(instance, graph_type) if g: DeploymentGraph.update(g, graph_data) else: DeploymentGraph.create_for_model(graph_data, instance, graph_type) return release_obj
def setUp(self): super(TestCustomGraphAction, self).setUp() self.custom_tasks = [{ 'id': 'first-custom-task', 'type': 'stage', 'requires': ['pre_deployment_end'] }, { 'id': 'second-custom-task', 'type': 'stage', 'requires': ['deploy_start'] }] self.custom_graph = DeploymentGraph.create_for_model( { 'name': 'custom-graph-name', 'tasks': self.custom_tasks }, self.cluster, graph_type='custom-graph') self.env.db().commit()
def setUp(self): super(TestCustomGraphAction, self).setUp() self.custom_tasks = [ { 'id': 'first-custom-task', 'type': 'stage', 'requires': ['pre_deployment_end'] }, { 'id': 'second-custom-task', 'type': 'stage', 'requires': ['deploy_start'] } ] self.custom_graph = DeploymentGraph.create_for_model( { 'name': 'custom-graph-name', 'tasks': self.custom_tasks }, self.cluster, graph_type='custom-graph' ) self.env.db().commit()
def setUp(self): super(TestLinkedGraphHandlers, self).setUp() self.cluster = self.env.create_cluster(api=False) plugin_data = { 'releases': [{ 'repository_path': 'repositories/ubuntu', 'version': self.cluster.release.version, 'os': self.cluster.release.operating_system.lower(), 'mode': [self.cluster.mode], }], 'cluster': self.cluster, 'enabled': True, } self.plugin = self.env.create_plugin(**plugin_data) self.env.db().commit() custom_graph1_data = { 'name': 'custom-graph-name1', 'tasks': [{ 'id': 'custom-task1', 'type': 'puppet' }] } custom_graph2_data = { 'name': 'custom-graph-name2', 'tasks': [{ 'id': 'custom-task2', 'type': 'puppet' }] } # replace default release graph with empty version to avoid # because it's default graph have special content DeploymentGraph.delete( DeploymentGraph.get_for_model(self.cluster.release)) DeploymentGraph.create_for_model({}, self.cluster.release) self.custom_graphs = { 'Cluster': { 'model': self.cluster, 'graphs': [ DeploymentGraph.create_for_model( custom_graph1_data, self.cluster, graph_type='custom-graph1'), DeploymentGraph.create_for_model( custom_graph2_data, self.cluster, graph_type='custom-graph2') ] }, 'Release': { 'model': self.cluster.release, 'graphs': [ DeploymentGraph.create_for_model( custom_graph1_data, self.cluster.release, graph_type='custom-graph1'), DeploymentGraph.create_for_model( custom_graph2_data, self.cluster.release, graph_type='custom-graph2'), ] }, 'Plugin': { 'model': self.plugin, 'graphs': [ DeploymentGraph.create_for_model( custom_graph1_data, self.plugin, graph_type='custom-graph1'), DeploymentGraph.create_for_model( custom_graph2_data, self.plugin, graph_type='custom-graph2') ] } }
def setUp(self): super(TestLinkedGraphHandlers, self).setUp() self.cluster = self.env.create_cluster(api=False) plugin_data = { 'releases': [ { 'repository_path': 'repositories/ubuntu', 'version': self.cluster.release.version, 'os': self.cluster.release.operating_system.lower(), 'mode': [self.cluster.mode], } ], 'cluster': self.cluster, 'enabled': True, } self.plugin = self.env.create_plugin(**plugin_data) self.env.db().commit() custom_graph1_data = { 'name': 'custom-graph-name1', 'tasks': [{ 'id': 'custom-task1', 'type': 'puppet' }] } custom_graph2_data = { 'name': 'custom-graph-name2', 'tasks': [{ 'id': 'custom-task2', 'type': 'puppet' }] } # replace default release graph with empty version to avoid # because it's default graph have special content DeploymentGraph.delete( DeploymentGraph.get_for_model(self.cluster.release)) DeploymentGraph.create_for_model({}, self.cluster.release) self.custom_graphs = { 'Cluster': { 'model': self.cluster, 'graphs': [ DeploymentGraph.create_for_model( custom_graph1_data, self.cluster, graph_type='custom-graph1'), DeploymentGraph.create_for_model( custom_graph2_data, self.cluster, graph_type='custom-graph2') ] }, 'Release': { 'model': self.cluster.release, 'graphs': [ DeploymentGraph.create_for_model( custom_graph1_data, self.cluster.release, graph_type='custom-graph1'), DeploymentGraph.create_for_model( custom_graph2_data, self.cluster.release, graph_type='custom-graph2'), ] }, 'Plugin': { 'model': self.plugin, 'graphs': [ DeploymentGraph.create_for_model( custom_graph1_data, self.plugin, graph_type='custom-graph1'), DeploymentGraph.create_for_model( custom_graph2_data, self.plugin, graph_type='custom-graph2') ] } }