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
This commit is contained in:
parent
54fed9cda4
commit
1410c5e75f
|
@ -28,6 +28,11 @@ NETWORK_SCHEME = {
|
|||
"roles": {
|
||||
"id": "roles",
|
||||
"type": "object"
|
||||
},
|
||||
"priority": {
|
||||
"id": "priority",
|
||||
"type": "number",
|
||||
"optional": True
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
},
|
||||
"network_scheme": {
|
||||
"storage": {
|
||||
"priority": 300,
|
||||
"endpoints": [
|
||||
"br-storage"
|
||||
],
|
||||
|
@ -74,6 +75,7 @@
|
|||
}
|
||||
},
|
||||
"common": {
|
||||
"priority": 200,
|
||||
"endpoints": [
|
||||
"br-mgmt",
|
||||
"br-fw-admin"
|
||||
|
@ -158,6 +160,7 @@
|
|||
}
|
||||
},
|
||||
"public": {
|
||||
"priority": 100,
|
||||
"endpoints": [
|
||||
"br-ex"
|
||||
],
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
from collections import defaultdict
|
||||
from ordereddict import OrderedDict
|
||||
import re
|
||||
import six
|
||||
|
||||
from nailgun import consts
|
||||
|
@ -30,7 +31,6 @@ from nailgun.objects import NodeGroupCollection
|
|||
from nailgun.orchestrator.base_serializers import NetworkDeploymentSerializer
|
||||
from nailgun.settings import settings
|
||||
from nailgun import utils
|
||||
import re
|
||||
|
||||
|
||||
class NeutronNetworkDeploymentSerializer(NetworkDeploymentSerializer):
|
||||
|
@ -1153,11 +1153,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
|
||||
|
|
|
@ -1023,6 +1023,83 @@ class TestNetworkTemplateSerializer70(BaseDeploymentSerializer):
|
|||
net_serializer = serializer.get_net_provider_serializer(self.cluster)
|
||||
self.assertIs(net_serializer, NeutronNetworkTemplateSerializer70)
|
||||
|
||||
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"
|
||||
},
|
||||
{
|
||||
"action": "add-br",
|
||||
"name": "br-storage"
|
||||
},
|
||||
{
|
||||
"action": "add-port",
|
||||
"bridge": "br-storage",
|
||||
"name": "eth2"
|
||||
},
|
||||
{
|
||||
"action": "add-port",
|
||||
"bridge": "br-mgmt",
|
||||
"name": "eth3"
|
||||
}
|
||||
]
|
||||
|
||||
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'])
|
||||
|
||||
def test_ip_assignment_according_to_template(self):
|
||||
self.create_more_nodes()
|
||||
# according to the template different node roles have different sets of
|
||||
|
@ -1261,7 +1338,7 @@ class TestNetworkTemplateSerializer70(BaseDeploymentSerializer):
|
|||
# Templates are applied in the order as defined in the template.
|
||||
# storage network template is applied after the 4 transformations
|
||||
# in common
|
||||
self.assertEqual('br-storage', transformations[4]['name'])
|
||||
self.assertEqual('br-fw-admin', transformations[4]['name'])
|
||||
|
||||
# Ensure all ports connected to br-mgmt happen after the bridge
|
||||
# has been created
|
||||
|
|
|
@ -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,
|
||||
dict(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)
|
||||
|
|
Loading…
Reference in New Issue