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:
slava 2016-02-02 02:11:44 +03:00
parent 54f6f83bb4
commit 35726f4e9b
5 changed files with 132 additions and 2 deletions

View File

@ -28,6 +28,11 @@ NETWORK_SCHEME = {
"roles": {
"id": "roles",
"type": "object"
},
"priority": {
"id": "priority",
"type": "number",
"optional": True
}
},
"required": [

View File

@ -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"
],

View File

@ -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

View File

@ -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,

View File

@ -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)