From 35726f4e9bba16327229355c6f5d90ead5867854 Mon Sep 17 00:00:00 2001 From: slava Date: Tue, 2 Feb 2016 02:11:44 +0300 Subject: [PATCH] Introduce priorities for network_schemes Currently we have no way to control templates applying order for set of roles(cinder+compute). This patch introduces ability to specify absolute priority for template to make it possible for operator to manage templates order. Patch doesn't affect order of templates where 'priority' field is not specified. Change-Id: I4348d3dea2c382837eb7f96e5b0ae3eb0312c8ad Closes-bug: 1540374 --- .../json_schema/network_template.py | 5 ++ .../nailgun/fixtures/network_template_80.json | 3 + .../orchestrator/neutron_serializers.py | 13 +++- .../test_orchestrator_serializer_80.py | 72 +++++++++++++++++++ .../test/unit/test_network_template.py | 41 +++++++++++ 5 files changed, 132 insertions(+), 2 deletions(-) diff --git a/nailgun/nailgun/api/v1/validators/json_schema/network_template.py b/nailgun/nailgun/api/v1/validators/json_schema/network_template.py index 7c4de8c578..2356c0764f 100644 --- a/nailgun/nailgun/api/v1/validators/json_schema/network_template.py +++ b/nailgun/nailgun/api/v1/validators/json_schema/network_template.py @@ -28,6 +28,11 @@ NETWORK_SCHEME = { "roles": { "id": "roles", "type": "object" + }, + "priority": { + "id": "priority", + "type": "number", + "optional": True } }, "required": [ diff --git a/nailgun/nailgun/fixtures/network_template_80.json b/nailgun/nailgun/fixtures/network_template_80.json index 4814d7c19f..317ecc985d 100644 --- a/nailgun/nailgun/fixtures/network_template_80.json +++ b/nailgun/nailgun/fixtures/network_template_80.json @@ -47,6 +47,7 @@ }, "network_scheme": { "storage": { + "priority": 300, "endpoints": [ "br-storage" ], @@ -69,6 +70,7 @@ } }, "common": { + "priority": 200, "endpoints": [ "br-mgmt", "br-fw-admin" @@ -157,6 +159,7 @@ } }, "public": { + "priority": 100, "endpoints": [ "br-ex" ], diff --git a/nailgun/nailgun/orchestrator/neutron_serializers.py b/nailgun/nailgun/orchestrator/neutron_serializers.py index 23aeef8a3e..83e7aa2a6f 100644 --- a/nailgun/nailgun/orchestrator/neutron_serializers.py +++ b/nailgun/nailgun/orchestrator/neutron_serializers.py @@ -1105,11 +1105,20 @@ class NeutronNetworkTemplateSerializer70( # ordered set. The order of transformations is important which # is why we can't just use a set. The list needs to be unique # because duplicated transformations will break deployment. + # If some template contains 'priority' property, than node's + # templates order should be based on it, in other case, all node's + # templates will have zero priority and have the same order as + # there is no property field. for role in roles: for t in template['templates_for_node_role'][role]: - role_templates[t] = True + role_templates[t] = template['templates'][t].get( + 'priority', 0) - for t in role_templates: + # sort network schemes by priority + sorted_role_templates = sorted(role_templates.iteritems(), + key=lambda x: x[1]) + + for t, p in sorted_role_templates: txs.extend(template['templates'][t]['transformations']) return txs diff --git a/nailgun/nailgun/test/integration/test_orchestrator_serializer_80.py b/nailgun/nailgun/test/integration/test_orchestrator_serializer_80.py index aa0757ee66..5bb908e0a6 100644 --- a/nailgun/nailgun/test/integration/test_orchestrator_serializer_80.py +++ b/nailgun/nailgun/test/integration/test_orchestrator_serializer_80.py @@ -113,6 +113,78 @@ class TestNetworkTemplateSerializer80( self.serializer = serializer_type(AstuteGraph(self.cluster)) self._check_baremetal_neutron_attrs(self.cluster) + def test_network_schemes_priorities(self): + expected = [ + { + "action": "add-br", + "name": "br-prv", + "provider": "ovs" + }, + { + "action": "add-br", + "name": "br-aux" + }, + { + "action": "add-patch", + "bridges": [ + "br-prv", + "br-aux" + ], + "provider": "ovs", + "mtu": 65000 + }, + { + "action": "add-port", + "bridge": "br-aux", + "name": "eth3.101" + }, + { + "action": "add-br", + "name": "br-fw-admin" + }, + { + "action": "add-port", + "bridge": "br-fw-admin", + "name": "eth0" + }, + { + "action": "add-br", + "name": "br-mgmt" + }, + { + "action": "add-port", + "bridge": "br-mgmt", + "name": "eth1.104" + }, + { + "action": "add-br", + "name": "br-storage" + }, + { + "action": "add-port", + "bridge": "br-storage", + "name": "eth2" + } + ] + + objects.Cluster.set_network_template( + self.cluster, + self.net_template + ) + + node = self.env.create_nodes_w_interfaces_count( + 1, 8, roles=['compute', 'cinder'], + cluster_id=self.cluster.id + )[0] + + serializer = get_serializer_for_cluster(self.cluster) + net_serializer = serializer.get_net_provider_serializer(self.cluster) + + nm = objects.Cluster.get_network_manager(self.cluster) + network_scheme = net_serializer.generate_network_scheme( + node, nm.get_node_networks(node)) + self.assertEqual(expected, network_scheme['transformations']) + class TestDeploymentTasksSerialization80( TestSerializer80Mixin, diff --git a/nailgun/nailgun/test/unit/test_network_template.py b/nailgun/nailgun/test/unit/test_network_template.py index f992653cb6..c8d6a2fa9b 100644 --- a/nailgun/nailgun/test/unit/test_network_template.py +++ b/nailgun/nailgun/test/unit/test_network_template.py @@ -14,10 +14,13 @@ # License for the specific language governing permissions and limitations # under the License. +import mock from unittest2.case import TestCase from nailgun.network.template import NetworkTemplate +from nailgun.orchestrator.neutron_serializers import \ + NeutronNetworkTemplateSerializer70 class TestNetworkTemplate(TestCase): @@ -58,3 +61,41 @@ class TestNetworkTemplate(TestCase): self.assertRaises(KeyError, template.substitute, b='bbb') + + def test_schemes_order(self): + template = { + "templates_for_node_role": { + "cinder": [ + "common", + "storage" + ], + "compute": [ + "common", + "private", + "storage" + ] + }, + "templates": { + "storage": { + "transformations": [ + "storage" + ] + }, + "common": { + "transformations": [ + "common" + ] + }, + "private": { + "transformations": [ + "private" + ] + }, + } + } + + node = mock.Mock(network_template=template, + all_roles=['cinder', 'compute']) + transformations = \ + NeutronNetworkTemplateSerializer70.generate_transformations(node) + self.assertEqual(["common", "storage", "private"], transformations)