Fix net-nic default assignment
Forbid to assign admin network to non-pxe interface Change-Id: Iddd57f74bf12cd18f1b973319849a7b426dcd884 Closes-Bug: #1474330
This commit is contained in:
parent
f3e65381dc
commit
5f3ce3ea71
|
@ -247,7 +247,7 @@ class NodeAgent
|
|||
:memory => (_dmi_memory or _ohai_memory),
|
||||
}
|
||||
|
||||
admin_mac = _master_ip_and_mac[:mac] rescue nil
|
||||
admin_mac = (_master_ip_and_mac[:mac] or @os[:macaddress]) rescue nil
|
||||
begin
|
||||
(@os[:network][:interfaces] or {} rescue {}).each do |int, intinfo|
|
||||
# Send info about physical interfaces only
|
||||
|
|
|
@ -418,7 +418,7 @@ class NetworkManager(object):
|
|||
db_interfaces = node.nic_interfaces
|
||||
pxe = next((
|
||||
i for i in node.meta['interfaces'] if i.get('pxe') or
|
||||
i.get('mac') == node.mac),
|
||||
i.get('mac').lower() == node.mac.lower()),
|
||||
None)
|
||||
if pxe:
|
||||
return pxe.get('name')
|
||||
|
@ -477,6 +477,10 @@ class NetworkManager(object):
|
|||
ng_ids = set(ng.id for ng in ngs)
|
||||
ng_wo_admin_ids = \
|
||||
ng_ids ^ set([cls.get_admin_network_group_id(node.id)])
|
||||
pxe_iface = next(six.moves.filter(
|
||||
lambda i: i.pxe == True,
|
||||
node.nic_interfaces
|
||||
), None)
|
||||
for nic in node.nic_interfaces:
|
||||
nic_dict = NodeInterfacesSerializer.serialize(nic)
|
||||
if 'interface_properties' in nic_dict:
|
||||
|
@ -486,7 +490,7 @@ class NetworkManager(object):
|
|||
|
||||
if to_assign_ids:
|
||||
allowed_ids = \
|
||||
ng_wo_admin_ids if nic != cls.get_admin_interface(node) \
|
||||
ng_wo_admin_ids if nic != pxe_iface \
|
||||
else ng_ids
|
||||
can_assign = [ng_id for ng_id in to_assign_ids
|
||||
if ng_id in allowed_ids]
|
||||
|
@ -922,9 +926,9 @@ class NetworkManager(object):
|
|||
logger.debug(u'Cannot find interface with assigned admin '
|
||||
'network group on %s', node.full_name)
|
||||
|
||||
for interface in node.nic_interfaces:
|
||||
if cls.is_ip_belongs_to_admin_subnet(interface.ip_addr):
|
||||
return interface
|
||||
for iface in node.nic_interfaces:
|
||||
if cls.is_ip_belongs_to_admin_subnet(iface.ip_addr):
|
||||
return iface
|
||||
|
||||
logger.warning(u'Cannot find admin interface for node '
|
||||
'return first interface: "%s"', node.full_name)
|
||||
|
|
|
@ -692,8 +692,11 @@ class Node(NailgunObject):
|
|||
if admin_iface.type != consts.NETWORK_INTERFACE_TYPES.bond:
|
||||
return admin_iface
|
||||
|
||||
iface = filter(lambda i: i.mac == instance.mac, admin_iface.slaves)
|
||||
return iface[0] if iface else admin_iface.slaves[-1]
|
||||
for slave in admin_iface.slaves:
|
||||
if slave.pxe or slave.mac == instance.mac:
|
||||
return slave
|
||||
|
||||
return admin_iface.slaves[-1]
|
||||
|
||||
@classmethod
|
||||
def remove_from_cluster(cls, instance):
|
||||
|
|
|
@ -87,10 +87,10 @@ class TestHandlers(BaseIntegrationTest):
|
|||
|
||||
'management_interface': 'eth0.101',
|
||||
'fixed_interface': 'eth0.103',
|
||||
'fuelweb_admin_interface': 'eth1',
|
||||
'fuelweb_admin_interface': 'eth0',
|
||||
'storage_interface': 'eth0.102',
|
||||
'public_interface': 'eth0',
|
||||
'floating_interface': 'eth0',
|
||||
'public_interface': 'eth1',
|
||||
'floating_interface': 'eth1',
|
||||
'tasks': [],
|
||||
|
||||
'master_ip': '127.0.0.1',
|
||||
|
@ -193,8 +193,8 @@ class TestHandlers(BaseIntegrationTest):
|
|||
'priority': 100,
|
||||
|
||||
'network_data': {
|
||||
'eth0': {
|
||||
'interface': 'eth0',
|
||||
'eth1': {
|
||||
'interface': 'eth1',
|
||||
'ipaddr': ['%s/24' % ips['public']],
|
||||
'gateway': '172.16.0.1',
|
||||
'default_gateway': True},
|
||||
|
@ -210,8 +210,8 @@ class TestHandlers(BaseIntegrationTest):
|
|||
'lo': {
|
||||
'interface': 'lo',
|
||||
'ipaddr': ['127.0.0.1/8']},
|
||||
'eth1': {
|
||||
'interface': 'eth1',
|
||||
'eth0': {
|
||||
'interface': 'eth0',
|
||||
'ipaddr': [ips['admin']]}
|
||||
}}
|
||||
|
||||
|
@ -656,11 +656,11 @@ class TestHandlers(BaseIntegrationTest):
|
|||
"tags": [101, 0]},
|
||||
{
|
||||
"action": "add-patch",
|
||||
"bridges": [u"br-eth1", "br-fw-admin"],
|
||||
"bridges": [u"br-eth0", "br-fw-admin"],
|
||||
"trunks": [0]},
|
||||
{
|
||||
"action": "add-patch",
|
||||
"bridges": [u"br-eth0", "br-ex"],
|
||||
"bridges": [u"br-eth1", "br-ex"],
|
||||
"trunks": [0]},
|
||||
]
|
||||
}
|
||||
|
@ -1123,11 +1123,11 @@ class TestHandlers(BaseIntegrationTest):
|
|||
"vlan_ids": [101, 0]},
|
||||
{
|
||||
"action": "add-patch",
|
||||
"bridges": [u"br-eth1", "br-fw-admin"],
|
||||
"bridges": [u"br-eth0", "br-fw-admin"],
|
||||
"trunks": [0]},
|
||||
{
|
||||
"action": "add-patch",
|
||||
"bridges": [u"br-eth0", "br-ex"],
|
||||
"bridges": [u"br-eth1", "br-ex"],
|
||||
"trunks": [0]},
|
||||
]
|
||||
}
|
||||
|
|
|
@ -462,10 +462,10 @@ class TestNodeNICAdminAssigning(BaseIntegrationTest):
|
|||
mac1, mac2 = (self.env.generate_random_mac(),
|
||||
self.env.generate_random_mac())
|
||||
meta = self.env.default_metadata()
|
||||
meta['interfaces'] = [{'name': 'eth0', 'mac': mac1},
|
||||
{'name': 'eth1', 'mac': mac2, 'ip': admin_ip,
|
||||
'pxe': True}]
|
||||
self.env.create_node(api=True, meta=meta, mac=mac1,
|
||||
meta['interfaces'] = [{'name': 'eth1', 'mac': mac2, 'ip': admin_ip,
|
||||
'pxe': True},
|
||||
{'name': 'eth0', 'mac': mac1}]
|
||||
self.env.create_node(api=True, meta=meta, mac=mac2,
|
||||
cluster_id=cluster['id'])
|
||||
node_db = self.env.nodes[0]
|
||||
admin_iface = self.env.network_manager.get_admin_interface(node_db)
|
||||
|
|
|
@ -671,3 +671,46 @@ class TestHandlers(BaseIntegrationTest):
|
|||
# check the node is visible for api
|
||||
nodes_data = get_nodes()
|
||||
self.assertEqual(len(nodes_data), 1)
|
||||
|
||||
def test_pxe_for_admin_nws_restriction(self):
|
||||
meta = self.env.default_metadata()
|
||||
# We are using reverse ordered by iface name list
|
||||
# for reproducing bug #1474330
|
||||
meta['interfaces'] = [
|
||||
{'name': 'eth1', 'mac': self.env.generate_random_mac(),
|
||||
'pxe': False},
|
||||
{'name': 'eth0', 'mac': self.env.generate_random_mac(),
|
||||
'pxe': False},
|
||||
]
|
||||
self.env.create(nodes_kwargs=[{'api': False, 'meta': meta}])
|
||||
|
||||
cluster = self.env.clusters[0]
|
||||
node = cluster.nodes[0]
|
||||
|
||||
# Processing data through NodeHandler
|
||||
resp = self.app.get(
|
||||
reverse('NodeHandler', kwargs={'obj_id': node.id}),
|
||||
headers=self.default_headers,
|
||||
)
|
||||
data = resp.json_body
|
||||
|
||||
resp = self.app.put(
|
||||
reverse('NodeHandler', kwargs={'obj_id': data['id']}),
|
||||
jsonutils.dumps(data),
|
||||
headers=self.default_headers,
|
||||
)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
# Processing data through NICsHander
|
||||
resp = self.app.get(
|
||||
reverse("NodeNICsHandler", kwargs={"node_id": node.id}),
|
||||
headers=self.default_headers)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
data = resp.json_body
|
||||
|
||||
resp = self.app.put(
|
||||
reverse("NodeNICsHandler", kwargs={"node_id": node.id}),
|
||||
jsonutils.dumps(data),
|
||||
headers=self.default_headers,
|
||||
)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
|
|
@ -389,15 +389,16 @@ class TestNovaOrchestratorSerializer(OrchestratorSerializerTestBase):
|
|||
},
|
||||
'eth1': {
|
||||
'interface': 'eth1',
|
||||
'ipaddr': ['10.20.0.129/24']
|
||||
'ipaddr': ['172.16.0.2/24'],
|
||||
'gateway': '172.16.0.1',
|
||||
'default_gateway': True
|
||||
|
||||
},
|
||||
'eth0': {
|
||||
'interface': 'eth0',
|
||||
'ipaddr': ['172.16.0.2/24',
|
||||
'192.168.0.1/24',
|
||||
'192.168.1.1/24'],
|
||||
'gateway': '172.16.0.1',
|
||||
'default_gateway': True
|
||||
'ipaddr': ['192.168.0.1/24',
|
||||
'192.168.1.1/24',
|
||||
'10.20.0.129/24'],
|
||||
}
|
||||
}
|
||||
self.datadiff(expected_interfaces, interfaces, ignore_keys=['ipaddr'])
|
||||
|
@ -1791,7 +1792,7 @@ class TestNeutronOrchestratorSerializer(OrchestratorSerializerTestBase):
|
|||
self.assertEqual(
|
||||
{
|
||||
'action': 'add-patch',
|
||||
'bridges': ['br-eth0', 'br-ex'],
|
||||
'bridges': ['br-eth1', 'br-ex'],
|
||||
'trunks': [0]
|
||||
} in node['network_scheme']['transformations'],
|
||||
is_public
|
||||
|
|
Loading…
Reference in New Issue