Added generate_network_scheme for 7.0
This change adds generate_network_scheme method for 7.0 instead of inherit it. Now generate_network_scheme for 7.0 supports non-default network groups. Change-Id: Ib89594867c57b3aeb1b6503fed87c291ca3fd308 Closes-bug: #1483307
This commit is contained in:
parent
f5e86f7922
commit
1158c2eddb
@ -88,6 +88,31 @@ NEUTRON_SEGMENT_TYPES = Enum(
|
||||
'tun'
|
||||
)
|
||||
|
||||
BRIDGE_NAME_MAX_LEN = 15
|
||||
|
||||
DEFAULT_BRIDGES_NAMES = Enum(
|
||||
'br-fw-admin',
|
||||
'br-storage',
|
||||
'br-mgmt',
|
||||
'br-prv',
|
||||
'br-floating',
|
||||
'br-int',
|
||||
'br-ex',
|
||||
'br-mesh',
|
||||
'br-aux',
|
||||
names=(
|
||||
'br_fw_admin',
|
||||
'br_storage',
|
||||
'br_mgmt',
|
||||
'br_prv',
|
||||
'br_floating',
|
||||
'br_int',
|
||||
'br_ex',
|
||||
'br_mesh',
|
||||
'br_aux'
|
||||
)
|
||||
)
|
||||
|
||||
NODE_STATUSES = Enum(
|
||||
'ready',
|
||||
'discover',
|
||||
|
@ -30,6 +30,7 @@ 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):
|
||||
@ -829,19 +830,69 @@ class NeutronNetworkDeploymentSerializer61(
|
||||
class NeutronNetworkDeploymentSerializer70(
|
||||
NeutronNetworkDeploymentSerializer61
|
||||
):
|
||||
RE_BRIDGE_NAME = re.compile('^br-[0-9a-z\-]{0,11}[0-9a-z]$')
|
||||
|
||||
@classmethod
|
||||
def get_default_network_to_endpoint_mapping(cls, node):
|
||||
def get_node_non_default_networks(cls, node):
|
||||
"""Returns list of non-default networks assigned to node.
|
||||
"""
|
||||
nm = Cluster.get_network_manager(node.cluster)
|
||||
return filter(lambda net: net['name'] not in consts.NETWORKS,
|
||||
nm.get_node_networks(node))
|
||||
|
||||
@classmethod
|
||||
def get_bridge_name(cls, name, suffix=0):
|
||||
"""Generates linux bridge name based on network name and suffix.
|
||||
"""
|
||||
if not name.startswith('br-'):
|
||||
name = 'br-' + name
|
||||
if suffix:
|
||||
return (name[0:consts.BRIDGE_NAME_MAX_LEN][:-len(str(suffix))] +
|
||||
str(suffix))
|
||||
else:
|
||||
return name[0:consts.BRIDGE_NAME_MAX_LEN]
|
||||
|
||||
@classmethod
|
||||
def is_valid_non_default_bridge_name(cls, name):
|
||||
"""Validate bridge name for non-default network.
|
||||
"""
|
||||
if name in consts.DEFAULT_BRIDGES_NAMES:
|
||||
return False
|
||||
return bool(cls.RE_BRIDGE_NAME.match(name))
|
||||
|
||||
@classmethod
|
||||
def get_node_non_default_bridge_mapping(cls, node):
|
||||
"""Returns dict of non-default networks assigned to node with
|
||||
generated bridges names.
|
||||
"""
|
||||
mapping = {}
|
||||
for net in cls.get_node_non_default_networks(node):
|
||||
brname = cls.get_bridge_name(net['name'])
|
||||
suffix = 1
|
||||
while (brname in mapping.values() or
|
||||
not cls.is_valid_non_default_bridge_name(brname)):
|
||||
brname = cls.get_bridge_name(net['name'], suffix)
|
||||
suffix += 1
|
||||
mapping[net['name']] = brname
|
||||
return mapping
|
||||
|
||||
@classmethod
|
||||
def get_network_to_endpoint_mapping(cls, node):
|
||||
mapping = {
|
||||
consts.NETWORKS.fuelweb_admin: 'br-fw-admin',
|
||||
consts.NETWORKS.storage: 'br-storage',
|
||||
consts.NETWORKS.management: 'br-mgmt',
|
||||
consts.NETWORKS.private: 'br-prv'}
|
||||
consts.NETWORKS.management: 'br-mgmt'}
|
||||
|
||||
# roles can be assigned to br-ex only in case it has a public IP
|
||||
if Node.should_have_public_with_ip(node):
|
||||
mapping[consts.NETWORKS.public] = 'br-ex'
|
||||
|
||||
if node.cluster.network_config.segmentation_type in \
|
||||
(consts.NEUTRON_SEGMENT_TYPES.gre,
|
||||
consts.NEUTRON_SEGMENT_TYPES.tun):
|
||||
mapping[consts.NETWORKS.private] = 'br-mesh'
|
||||
|
||||
mapping.update(cls.get_node_non_default_bridge_mapping(node))
|
||||
return mapping
|
||||
|
||||
@classmethod
|
||||
@ -850,7 +901,7 @@ class NeutronNetworkDeploymentSerializer70(
|
||||
|
||||
mapping = dict()
|
||||
networks = nm.get_node_networks(node)
|
||||
for net in cls.get_default_network_to_endpoint_mapping(node):
|
||||
for net in cls.get_network_to_endpoint_mapping(node):
|
||||
netgroup = nm.get_network_by_netname(net, networks)
|
||||
if netgroup.get('ip'):
|
||||
mapping[net] = netgroup['ip'].split('/')[0]
|
||||
@ -877,7 +928,7 @@ class NeutronNetworkDeploymentSerializer70(
|
||||
:param node: instance of db.sqlalchemy.models.node.Node
|
||||
:return: dict of network roles mapping
|
||||
"""
|
||||
mapping = cls.get_default_network_to_endpoint_mapping(node)
|
||||
mapping = cls.get_network_to_endpoint_mapping(node)
|
||||
return cls._get_network_role_mapping(node, mapping)
|
||||
|
||||
@classmethod
|
||||
@ -893,16 +944,106 @@ class NeutronNetworkDeploymentSerializer70(
|
||||
roles['neutron/private'] = None
|
||||
return roles
|
||||
|
||||
@classmethod
|
||||
def generate_transformations(cls, node, nm, nets_by_ifaces, is_public,
|
||||
prv_base_ep):
|
||||
transformations = (super(NeutronNetworkDeploymentSerializer70, cls)
|
||||
.generate_transformations(node, nm, nets_by_ifaces,
|
||||
is_public, prv_base_ep))
|
||||
for brname in six.itervalues(cls.get_node_non_default_bridge_mapping(
|
||||
node)):
|
||||
transformations.insert(0, cls.add_bridge(brname))
|
||||
return transformations
|
||||
|
||||
@classmethod
|
||||
def generate_network_scheme(cls, node, networks):
|
||||
attrs = super(NeutronNetworkDeploymentSerializer70,
|
||||
cls).generate_network_scheme(node, networks)
|
||||
# Create a data structure and fill it with static values.
|
||||
attrs = {
|
||||
'version': '1.1',
|
||||
'provider': 'lnx',
|
||||
'interfaces': {},
|
||||
'endpoints': {},
|
||||
'roles': cls.get_network_role_mapping_to_interfaces(node),
|
||||
}
|
||||
|
||||
mapping = cls.get_network_role_mapping_to_interfaces(node)
|
||||
is_public = Node.should_have_public(node)
|
||||
if is_public:
|
||||
attrs['endpoints']['br-ex'] = {'IP': 'none'}
|
||||
attrs['endpoints']['br-floating'] = {'IP': 'none'}
|
||||
attrs['roles']['ex'] = 'br-ex'
|
||||
attrs['roles']['neutron/floating'] = 'br-floating'
|
||||
|
||||
old_mapping_6_1 = attrs['roles']
|
||||
mapping.update(old_mapping_6_1)
|
||||
attrs['roles'] = mapping
|
||||
nm = Cluster.get_network_manager(node.cluster)
|
||||
|
||||
# Populate IP and GW information to endpoints.
|
||||
netgroup_mapping = (cls.get_network_to_endpoint_mapping(node)
|
||||
.items())
|
||||
|
||||
if node.cluster.network_config.segmentation_type in \
|
||||
(consts.NEUTRON_SEGMENT_TYPES.gre,
|
||||
consts.NEUTRON_SEGMENT_TYPES.tun):
|
||||
attrs['endpoints']['br-mesh'] = {}
|
||||
attrs['roles']['neutron/mesh'] = 'br-mesh'
|
||||
|
||||
netgroups = {}
|
||||
nets_by_ifaces = defaultdict(list)
|
||||
for ngname, brname in netgroup_mapping:
|
||||
# Here we get a dict with network description for this particular
|
||||
# node with its assigned IPs and device names for each network.
|
||||
netgroup = nm.get_network_by_netname(ngname, networks)
|
||||
if netgroup.get('ip'):
|
||||
attrs['endpoints'][brname] = {'IP': [netgroup['ip']]}
|
||||
netgroups[ngname] = netgroup
|
||||
nets_by_ifaces[netgroup['dev']].append({
|
||||
'br_name': brname,
|
||||
'vlan_id': netgroup['vlan']
|
||||
})
|
||||
|
||||
# Add gateway.
|
||||
if is_public and netgroups['public'].get('gateway'):
|
||||
attrs['endpoints']['br-ex']['gateway'] = \
|
||||
netgroups['public']['gateway']
|
||||
else:
|
||||
gw = nm.get_default_gateway(node.id)
|
||||
attrs['endpoints']['br-fw-admin']['gateway'] = gw
|
||||
|
||||
# Fill up interfaces.
|
||||
for iface in node.nic_interfaces:
|
||||
if iface.bond:
|
||||
attrs['interfaces'][iface.name] = {}
|
||||
else:
|
||||
attrs['interfaces'][iface.name] = \
|
||||
nm.get_iface_properties(iface)
|
||||
|
||||
# Dance around Neutron segmentation type.
|
||||
prv_base_ep = None
|
||||
if node.cluster.network_config.segmentation_type == \
|
||||
consts.NEUTRON_SEGMENT_TYPES.vlan:
|
||||
attrs['endpoints']['br-prv'] = {'IP': 'none'}
|
||||
attrs['roles']['neutron/private'] = 'br-prv'
|
||||
|
||||
netgroup = nm.get_network_by_netname('private', networks)
|
||||
# create br-aux if there is no untagged network (endpoint) on the
|
||||
# same interface.
|
||||
if netgroup['dev'] in nets_by_ifaces:
|
||||
for ep in nets_by_ifaces[netgroup['dev']]:
|
||||
if not ep['vlan_id']:
|
||||
prv_base_ep = ep['br_name']
|
||||
if not prv_base_ep:
|
||||
nets_by_ifaces[netgroup['dev']].append({
|
||||
'br_name': 'br-aux',
|
||||
'vlan_id': None
|
||||
})
|
||||
|
||||
attrs['transformations'] = cls.generate_transformations(
|
||||
node, nm, nets_by_ifaces, is_public, prv_base_ep)
|
||||
|
||||
if NodeGroupCollection.get_by_cluster_id(
|
||||
node.cluster.id).count() > 1:
|
||||
cls.generate_routes(node, attrs, nm, netgroup_mapping, netgroups,
|
||||
networks)
|
||||
|
||||
attrs = cls.generate_driver_information(node, attrs, nm, networks)
|
||||
|
||||
if node.cluster.network_config.segmentation_type in \
|
||||
(consts.NEUTRON_SEGMENT_TYPES.gre,
|
||||
|
@ -1043,6 +1043,39 @@ class EnvironmentManager(object):
|
||||
nodes,
|
||||
expect_errors)
|
||||
|
||||
def _create_network_group(self, expect_errors=False, cluster=None,
|
||||
**kwargs):
|
||||
if not cluster:
|
||||
cluster = self.clusters[0]
|
||||
ng = {
|
||||
"release": cluster.release.id,
|
||||
"name": "external",
|
||||
"vlan_start": 50,
|
||||
"cidr": "10.3.0.0/24",
|
||||
"gateway": "10.3.0.1",
|
||||
"group_id": Cluster.get_default_group(cluster).id,
|
||||
"meta": {"notation": "cidr", 'map_priority': 2}
|
||||
}
|
||||
ng.update(kwargs)
|
||||
resp = self.app.post(
|
||||
reverse('NetworkGroupCollectionHandler'),
|
||||
jsonutils.dumps(ng),
|
||||
headers=self.default_headers,
|
||||
expect_errors=expect_errors,
|
||||
)
|
||||
return resp
|
||||
|
||||
def _update_network_group(self, ng_data, expect_errors=False):
|
||||
return self.app.put(
|
||||
reverse(
|
||||
'NetworkGroupHandler',
|
||||
kwargs={'obj_id': ng_data['id']}
|
||||
),
|
||||
jsonutils.dumps(ng_data),
|
||||
headers=self.default_headers,
|
||||
expect_errors=expect_errors
|
||||
)
|
||||
|
||||
|
||||
class BaseTestCase(TestCase):
|
||||
|
||||
|
@ -70,7 +70,7 @@ class BaseTestDeploymentAttributesSerialization70(BaseDeploymentSerializer):
|
||||
|
||||
def setUp(self):
|
||||
super(BaseTestDeploymentAttributesSerialization70, self).setUp()
|
||||
self.cluster = self.create_env('ha_compact')
|
||||
self.cluster = self.create_env(consts.CLUSTER_MODES.ha_compact)
|
||||
|
||||
self.prepare_for_deployment(self.env.nodes)
|
||||
self.cluster_db = self.db.query(models.Cluster).get(self.cluster['id'])
|
||||
@ -85,7 +85,7 @@ class BaseTestDeploymentAttributesSerialization70(BaseDeploymentSerializer):
|
||||
release_kwargs={'version': self.env_version},
|
||||
cluster_kwargs={
|
||||
'mode': mode,
|
||||
'net_provider': 'neutron',
|
||||
'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
|
||||
'net_segment_type': self.segmentation_type},
|
||||
nodes_kwargs=[
|
||||
{'roles': ['controller'],
|
||||
@ -108,6 +108,115 @@ class TestDeploymentAttributesSerialization70(
|
||||
BaseTestDeploymentAttributesSerialization70
|
||||
):
|
||||
segmentation_type = consts.NEUTRON_SEGMENT_TYPES.vlan
|
||||
custom_network = {
|
||||
'name': 'baremetal',
|
||||
'role': 'ironic/baremetal',
|
||||
'cidr': '192.168.3.0/24',
|
||||
'vlan_start': 50,
|
||||
'bridge': 'br-baremetal',
|
||||
}
|
||||
plugin_network_roles = yaml.safe_load("""
|
||||
- id: "{role}"
|
||||
default_mapping: "{name}"
|
||||
properties:
|
||||
subnet: true
|
||||
gateway: false
|
||||
vip:
|
||||
- name: "{name}"
|
||||
namespace: "haproxy"
|
||||
""".format(**custom_network))
|
||||
|
||||
def _add_plugin_network_roles(self):
|
||||
plugin_data = self.env.get_default_plugin_metadata()
|
||||
plugin_data['network_roles_metadata'] = self.plugin_network_roles
|
||||
plugin = objects.Plugin.create(plugin_data)
|
||||
self.cluster_db.plugins.append(plugin)
|
||||
self.db.commit()
|
||||
|
||||
def test_non_default_bridge_mapping(self):
|
||||
expected_mapping = {
|
||||
u'test': u'br-test',
|
||||
u'testnetwork1': u'br-testnetwork1',
|
||||
u'testnetwork13': u'br-testnetwork2',
|
||||
u'my-super-network': u'br-my-super-net',
|
||||
u'uplink-network-east': u'br-uplink-netw2',
|
||||
u'uplink-network-west': u'br-uplink-netwo',
|
||||
u'uplink-network-south': u'br-uplink-netw1',
|
||||
u'12345uplink-network-south': u'br-12345uplink1',
|
||||
u'fw-admin': u'br-fw-admi1'
|
||||
}
|
||||
cluster = self.env.create(
|
||||
cluster_kwargs={
|
||||
'release_id': self.env.releases[0].id,
|
||||
'mode': consts.CLUSTER_MODES.ha_compact,
|
||||
'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
|
||||
'net_segment_type': self.segmentation_type})
|
||||
self.cluster_db = objects.Cluster.get_by_uid(cluster['id'])
|
||||
for name in expected_mapping:
|
||||
self.env._create_network_group(cluster=self.cluster_db,
|
||||
name=name)
|
||||
self.env.create_node(
|
||||
api=True,
|
||||
cluster_id=cluster['id'],
|
||||
pending_roles=['controller'],
|
||||
pending_addition=True)
|
||||
net_serializer = self.serializer.get_net_provider_serializer(
|
||||
self.cluster_db)
|
||||
self.prepare_for_deployment(self.cluster_db.nodes)
|
||||
mapping = net_serializer.get_node_non_default_bridge_mapping(
|
||||
self.cluster_db.nodes[0])
|
||||
self.assertDictEqual(mapping, expected_mapping)
|
||||
|
||||
def test_network_scheme_custom_networks(self):
|
||||
cluster = self.env.create(
|
||||
cluster_kwargs={
|
||||
'release_id': self.env.releases[0].id,
|
||||
'mode': consts.CLUSTER_MODES.ha_compact,
|
||||
'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
|
||||
'net_segment_type': self.segmentation_type})
|
||||
self.cluster_db = objects.Cluster.get_by_uid(cluster['id'])
|
||||
self.env._create_network_group(cluster=self.cluster_db,
|
||||
name=self.custom_network['name'],
|
||||
cidr=self.custom_network['cidr'],
|
||||
vlan_start=
|
||||
self.custom_network['vlan_start'])
|
||||
self._add_plugin_network_roles()
|
||||
self.env.create_node(
|
||||
api=True,
|
||||
cluster_id=cluster['id'],
|
||||
pending_roles=['controller'],
|
||||
pending_addition=True)
|
||||
self.prepare_for_deployment(self.cluster_db.nodes)
|
||||
serializer_type = get_serializer_for_cluster(self.cluster_db)
|
||||
serializer = serializer_type(AstuteGraph(self.cluster_db))
|
||||
serialized_for_astute = serializer.serialize(
|
||||
self.cluster_db, self.cluster_db.nodes)
|
||||
for node in serialized_for_astute:
|
||||
vips = node['network_metadata']['vips']
|
||||
roles = node['network_scheme']['roles']
|
||||
transformations = node['network_scheme']['transformations']
|
||||
node_network_roles = (node['network_metadata']['nodes']
|
||||
['node-' + node['uid']]['network_roles'])
|
||||
baremetal_ip = node_network_roles.get(self.custom_network['role'],
|
||||
'0.0.0.0')
|
||||
baremetal_brs = filter(lambda t: t.get('name') ==
|
||||
self.custom_network['bridge'],
|
||||
transformations)
|
||||
baremetal_ports = filter(lambda t: t.get('name') ==
|
||||
("eth0.%s" %
|
||||
self.custom_network['vlan_start']),
|
||||
transformations)
|
||||
self.assertEqual(roles.get(self.custom_network['role']),
|
||||
self.custom_network['bridge'])
|
||||
self.assertEqual(vips.get(self.custom_network['name'],
|
||||
{}).get('network_role'),
|
||||
self.custom_network['role'])
|
||||
self.assertTrue(netaddr.IPAddress(baremetal_ip) in
|
||||
netaddr.IPNetwork(self.custom_network['cidr']))
|
||||
self.assertEqual(len(baremetal_brs), 1)
|
||||
self.assertEqual(len(baremetal_ports), 1)
|
||||
self.assertEqual(baremetal_ports[0]['bridge'],
|
||||
self.custom_network['bridge'])
|
||||
|
||||
def test_network_scheme(self):
|
||||
for node in self.serialized_for_astute:
|
||||
@ -436,8 +545,8 @@ class TestPluginDeploymentTasksInjection(base.BaseIntegrationTest):
|
||||
'deployment_tasks': self.release_deployment_tasks,
|
||||
},
|
||||
cluster_kwargs={
|
||||
'mode': 'ha_compact',
|
||||
'net_provider': 'neutron',
|
||||
'mode': consts.CLUSTER_MODES.ha_compact,
|
||||
'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
|
||||
'net_segment_type': consts.NEUTRON_SEGMENT_TYPES.vlan,
|
||||
},
|
||||
nodes_kwargs=[
|
||||
@ -774,9 +883,9 @@ class TestRolesSerializationWithPlugins(BaseDeploymentSerializer):
|
||||
'version': self.env_version,
|
||||
},
|
||||
cluster_kwargs={
|
||||
'mode': 'ha_compact',
|
||||
'net_provider': 'neutron',
|
||||
'net_segment_type': 'vlan',
|
||||
'mode': consts.CLUSTER_MODES.ha_compact,
|
||||
'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
|
||||
'net_segment_type': consts.NEUTRON_SEGMENT_TYPES.vlan,
|
||||
})
|
||||
self.cluster = self.env.clusters[0]
|
||||
|
||||
@ -1360,39 +1469,18 @@ class TestCustomNetGroupIpAllocation(BaseDeploymentSerializer):
|
||||
release_kwargs={'version': self.env_version},
|
||||
cluster_kwargs={
|
||||
'api': False,
|
||||
'net_provider': 'neutron',
|
||||
'net_segment_type': 'gre'},
|
||||
'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron,
|
||||
'net_segment_type': consts.NEUTRON_SEGMENT_TYPES.gre},
|
||||
nodes_kwargs=[
|
||||
{'roles': ['controller']},
|
||||
{'roles': ['compute']},
|
||||
])
|
||||
|
||||
def _create_network_group(self, **kwargs):
|
||||
ng = {
|
||||
'release': self.cluster.release.id,
|
||||
'name': 'test',
|
||||
'vlan_start': 50,
|
||||
'cidr': '172.16.122.0/24',
|
||||
'gateway': '172.16.122.1',
|
||||
'group_id': objects.Cluster.get_default_group(self.cluster).id,
|
||||
'meta': {
|
||||
'notation': 'ip_ranges'
|
||||
}
|
||||
}
|
||||
ng.update(kwargs)
|
||||
|
||||
net_group = models.NetworkGroup(**ng)
|
||||
ip_range = models.IPAddrRange(
|
||||
first='172.16.122.2',
|
||||
last='172.16.122.255'
|
||||
)
|
||||
ip_range.network_group = net_group
|
||||
|
||||
db().add(ip_range)
|
||||
db().flush()
|
||||
|
||||
def test_ip_allocation(self):
|
||||
self._create_network_group()
|
||||
self.env._create_network_group(
|
||||
cluster=self.cluster, name='test', cidr='172.16.122.0/24',
|
||||
meta={'notation': 'ip_ranges',
|
||||
'ip_range': ['172.16.122.2', '172.16.122.255']})
|
||||
self.prepare_for_deployment(self.env.nodes)
|
||||
|
||||
ip_addrs_count = db().query(models.IPAddr).filter(
|
||||
|
@ -16,8 +16,6 @@
|
||||
|
||||
import mock
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from nailgun import consts
|
||||
from nailgun import objects
|
||||
from nailgun.test.base import BaseIntegrationTest
|
||||
@ -30,41 +28,8 @@ class TestHandlers(BaseIntegrationTest):
|
||||
super(TestHandlers, self).setUp()
|
||||
self.cluster = self.env.create_cluster(api=False)
|
||||
|
||||
def _create_network_group(self, expect_errors=False, **kwargs):
|
||||
ng = {
|
||||
"release": self.cluster.release.id,
|
||||
"name": "external",
|
||||
"vlan_start": 50,
|
||||
"cidr": "10.3.0.0/24",
|
||||
"gateway": "10.3.0.1",
|
||||
"group_id": objects.Cluster.get_default_group(self.cluster).id,
|
||||
"meta": {"notation": consts.NETWORK_NOTATION.cidr}
|
||||
}
|
||||
|
||||
ng.update(kwargs)
|
||||
|
||||
resp = self.app.post(
|
||||
reverse('NetworkGroupCollectionHandler'),
|
||||
jsonutils.dumps(ng),
|
||||
headers=self.default_headers,
|
||||
expect_errors=expect_errors,
|
||||
)
|
||||
|
||||
return resp
|
||||
|
||||
def _update_network_group(self, ng_data, expect_errors=False):
|
||||
return self.app.put(
|
||||
reverse(
|
||||
'NetworkGroupHandler',
|
||||
kwargs={'obj_id': ng_data['id']}
|
||||
),
|
||||
jsonutils.dumps(ng_data),
|
||||
headers=self.default_headers,
|
||||
expect_errors=expect_errors
|
||||
)
|
||||
|
||||
def test_create_network_group_w_cidr(self):
|
||||
resp = self._create_network_group()
|
||||
resp = self.env._create_network_group()
|
||||
self.assertEqual(201, resp.status_code)
|
||||
ng_data = resp.json_body
|
||||
ng = objects.NetworkGroup.get_by_uid(ng_data['id'])
|
||||
@ -73,7 +38,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
self.assertEqual(ng.ip_ranges[0].last, "10.3.0.254")
|
||||
|
||||
def test_create_network_group_w_ip_range(self):
|
||||
resp = self._create_network_group(
|
||||
resp = self.env._create_network_group(
|
||||
meta={
|
||||
"notation": consts.NETWORK_NOTATION.ip_ranges,
|
||||
"ip_range": ["10.3.0.33", "10.3.0.158"]
|
||||
@ -87,14 +52,14 @@ class TestHandlers(BaseIntegrationTest):
|
||||
self.assertEqual(ng.ip_ranges[0].last, "10.3.0.158")
|
||||
|
||||
def test_create_network_group_wo_notation(self):
|
||||
resp = self._create_network_group(meta={"notation": None})
|
||||
resp = self.env._create_network_group(meta={"notation": None})
|
||||
self.assertEqual(201, resp.status_code)
|
||||
ng_data = resp.json_body
|
||||
ng = objects.NetworkGroup.get_by_uid(ng_data['id'])
|
||||
self.assertEqual(len(ng.ip_ranges), 0)
|
||||
|
||||
def test_create_network_group_error(self):
|
||||
resp = self._create_network_group(
|
||||
resp = self.env._create_network_group(
|
||||
meta={"notation": "new"},
|
||||
expect_errors=True
|
||||
)
|
||||
@ -104,7 +69,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
"IPAddrRange object cannot be created for network "
|
||||
"'external' with notation='new', ip_range='None'")
|
||||
|
||||
resp = self._create_network_group(
|
||||
resp = self.env._create_network_group(
|
||||
meta={"notation": consts.NETWORK_NOTATION.ip_ranges},
|
||||
expect_errors=True
|
||||
)
|
||||
@ -114,7 +79,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
"'external' with notation='ip_ranges', "
|
||||
"ip_range='None'")
|
||||
|
||||
resp = self._create_network_group(
|
||||
resp = self.env._create_network_group(
|
||||
meta={"notation": consts.NETWORK_NOTATION.ip_ranges,
|
||||
"ip_range": ["10.3.0.33"]},
|
||||
expect_errors=True
|
||||
@ -126,7 +91,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
"ip_range='[u'10.3.0.33']'")
|
||||
|
||||
def test_get_network_group(self):
|
||||
resp = self._create_network_group(name='test')
|
||||
resp = self.env._create_network_group(name='test')
|
||||
self.assertEqual(201, resp.status_code)
|
||||
new_ng = resp.json_body
|
||||
|
||||
@ -143,7 +108,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
self.assertEqual(resp.json_body, new_ng)
|
||||
|
||||
def test_delete_network_group(self):
|
||||
resp = self._create_network_group(name='test')
|
||||
resp = self.env._create_network_group(name='test')
|
||||
self.assertEqual(201, resp.status_code)
|
||||
|
||||
net_group = resp.json_body
|
||||
@ -172,7 +137,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
'Default Admin-pxe network cannot be deleted')
|
||||
|
||||
def test_cannot_delete_locked_cluster_network_group(self):
|
||||
resp = self._create_network_group(name='test')
|
||||
resp = self.env._create_network_group(name='test')
|
||||
self.assertEqual(201, resp.status_code)
|
||||
|
||||
net_group = resp.json_body
|
||||
@ -192,64 +157,64 @@ class TestHandlers(BaseIntegrationTest):
|
||||
'Networks cannot be deleted after deployment')
|
||||
|
||||
def test_create_network_group_non_default_name(self):
|
||||
resp = self._create_network_group(name='test')
|
||||
resp = self.env._create_network_group(name='test')
|
||||
new_ng = resp.json_body
|
||||
self.assertEqual(201, resp.status_code)
|
||||
self.assertEqual('test', new_ng['name'])
|
||||
|
||||
def test_modify_network_group(self):
|
||||
resp = self._create_network_group(name='test')
|
||||
resp = self.env._create_network_group(name='test')
|
||||
new_ng = resp.json_body
|
||||
|
||||
new_ng['name'] = 'test2'
|
||||
|
||||
resp = self._update_network_group(new_ng)
|
||||
resp = self.env._update_network_group(new_ng)
|
||||
updated_ng = resp.json_body
|
||||
|
||||
self.assertEquals('test2', updated_ng['name'])
|
||||
|
||||
def test_duplicate_network_name_on_creation(self):
|
||||
resp = self._create_network_group()
|
||||
resp = self.env._create_network_group()
|
||||
self.assertEqual(201, resp.status_code)
|
||||
resp = self._create_network_group(expect_errors=True)
|
||||
resp = self.env._create_network_group(expect_errors=True)
|
||||
self.assertEqual(409, resp.status_code)
|
||||
self.assertRegexpMatches(resp.json_body["message"],
|
||||
'Network with name .* already exists')
|
||||
|
||||
def test_duplicate_network_name_on_change(self):
|
||||
resp = self._create_network_group(name='test')
|
||||
resp = self.env._create_network_group(name='test')
|
||||
new_ng = resp.json_body
|
||||
|
||||
new_ng['name'] = 'public'
|
||||
|
||||
resp = self._update_network_group(new_ng, expect_errors=True)
|
||||
resp = self.env._update_network_group(new_ng, expect_errors=True)
|
||||
self.assertEqual(409, resp.status_code)
|
||||
self.assertRegexpMatches(resp.json_body["message"],
|
||||
'Network with name .* already exists')
|
||||
|
||||
def test_invalid_group_id_on_creation(self):
|
||||
resp = self._create_network_group(expect_errors=True, group_id=-1)
|
||||
resp = self.env._create_network_group(expect_errors=True, group_id=-1)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
self.assertRegexpMatches(resp.json_body["message"],
|
||||
'Node group with ID -1 does not exist')
|
||||
|
||||
def test_invalid_group_id_on_change(self):
|
||||
resp = self._create_network_group(name='test')
|
||||
resp = self.env._create_network_group(name='test')
|
||||
new_ng = resp.json_body
|
||||
|
||||
new_ng['group_id'] = -1
|
||||
|
||||
resp = self._update_network_group(new_ng, expect_errors=True)
|
||||
resp = self.env._update_network_group(new_ng, expect_errors=True)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
self.assertRegexpMatches(resp.json_body["message"],
|
||||
'Node group with ID -1 does not exist')
|
||||
|
||||
def test_create_network_group_without_vlan(self):
|
||||
resp = self._create_network_group(vlan=None)
|
||||
resp = self.env._create_network_group(vlan=None)
|
||||
self.assertEqual(201, resp.status_code)
|
||||
|
||||
def test_modify_network_no_ip_ranges(self):
|
||||
resp = self._create_network_group(
|
||||
resp = self.env._create_network_group(
|
||||
name='test',
|
||||
meta={"notation": consts.NETWORK_NOTATION.ip_ranges,
|
||||
"ip_range": ["10.3.0.33", "10.3.0.158"]},
|
||||
@ -264,7 +229,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
db_ng.ip_ranges = []
|
||||
self.db.flush()
|
||||
|
||||
resp = self._update_network_group(new_ng, expect_errors=True)
|
||||
resp = self.env._update_network_group(new_ng, expect_errors=True)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
self.assertRegexpMatches(
|
||||
resp.json_body['message'],
|
||||
@ -272,7 +237,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
)
|
||||
|
||||
def test_modify_network_no_cidr(self):
|
||||
resp = self._create_network_group(name='test', expect_errors=True)
|
||||
resp = self.env._create_network_group(name='test', expect_errors=True)
|
||||
new_ng = resp.json_body
|
||||
|
||||
new_ng['meta']['notation'] = consts.NETWORK_NOTATION.ip_ranges
|
||||
@ -284,7 +249,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
db_ng.cidr = None
|
||||
self.db.flush()
|
||||
|
||||
resp = self._update_network_group(new_ng, expect_errors=True)
|
||||
resp = self.env._update_network_group(new_ng, expect_errors=True)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
self.assertRegexpMatches(
|
||||
resp.json_body['message'],
|
||||
@ -292,7 +257,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
)
|
||||
|
||||
def test_modify_network_no_gateway(self):
|
||||
resp = self._create_network_group(
|
||||
resp = self.env._create_network_group(
|
||||
meta={"use_gateway": True},
|
||||
gateway=None,
|
||||
expect_errors=True
|
||||
@ -307,7 +272,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
db_ng.gateway = None
|
||||
self.db.flush()
|
||||
|
||||
resp = self._update_network_group(new_ng, expect_errors=True)
|
||||
resp = self.env._update_network_group(new_ng, expect_errors=True)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
self.assertRegexpMatches(
|
||||
resp.json_body['message'],
|
||||
@ -315,13 +280,13 @@ class TestHandlers(BaseIntegrationTest):
|
||||
)
|
||||
|
||||
def test_modify_network_release(self):
|
||||
resp = self._create_network_group(name='test', expect_errors=True)
|
||||
resp = self.env._create_network_group(name='test', expect_errors=True)
|
||||
new_ng = resp.json_body
|
||||
|
||||
new_ng['release'] = 100
|
||||
new_ng.pop('name', None)
|
||||
|
||||
resp = self._update_network_group(new_ng, expect_errors=True)
|
||||
resp = self.env._update_network_group(new_ng, expect_errors=True)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
self.assertRegexpMatches(resp.json_body['message'],
|
||||
'Network release could not be changed.')
|
||||
@ -333,7 +298,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
'group_id': objects.Cluster.get_default_group(self.cluster).id,
|
||||
'meta': admin.meta
|
||||
}
|
||||
resp = self._update_network_group(admin_network_data,
|
||||
resp = self.env._update_network_group(admin_network_data,
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
self.assertRegexpMatches(
|
||||
|
Loading…
Reference in New Issue
Block a user