Merge "if hwm host lost some network interface ,the host pxe discover fail." into stable/mitaka

This commit is contained in:
Jenkins
2017-02-25 04:40:28 +00:00
committed by Gerrit Code Review
2 changed files with 147 additions and 26 deletions

View File

@@ -602,7 +602,9 @@ class Controller(controller.BaseController):
if host_meta.get('os_status', None) == 'init':
self._set_pxe_interface_for_host(req, host_meta)
self._check_add_host_interfaces(req, host_meta)
result = self._check_add_host_interfaces(req, host_meta)
if result:
return result
if 'resource_type' in host_meta:
if host_meta['resource_type'] not in self.support_resource_type:
@@ -919,10 +921,6 @@ class Controller(controller.BaseController):
"""
# If true, the host need update, not add and update is successful.
self._verify_interface_in_same_host(host_meta['interfaces'])
# host pxe interface info
input_host_pxe_info = self._count_host_pxe_info(
host_meta['interfaces'])
# verify interface between exist host and input host in cluster
list_params = {
'sort_key': u'name',
@@ -932,31 +930,32 @@ class Controller(controller.BaseController):
for id in [host['id'] for host in all_hosts]:
host_meta_list = registry.get_host_metadata(req.context, id)
exist_nodes.append(host_meta_list)
if input_host_pxe_info:
input_host_pxe_info = input_host_pxe_info[0]
interfaces = list(eval(host_meta['interfaces']))
for host_interface in interfaces:
host_mac = host_interface.get('mac', None)
if not host_mac:
continue
for exist_node in exist_nodes:
id = exist_node.get('id', None)
os_status = exist_node.get('os_status', None)
exist_node_info = self.get_host(req, id).get('host_meta', None)
exist_node_info = self.get_host(req, id).get('host_meta',
None)
if not exist_node_info.get('interfaces', None):
continue
for interface in exist_node_info['interfaces']:
if interface.get(
'mac', None) != input_host_pxe_info.get(
'mac', None) or interface.get(
'type', None) == "bond":
if interface.get('type', None) == "bond":
continue
if exist_node.get('dmi_uuid') \
and exist_node.get('dmi_uuid') != \
host_meta.get('dmi_uuid'):
msg = "The 'mac' of host interface is exist in " \
"db, but 'dmi_uuid' is different.We think " \
"you want update the host, but the host " \
"can't find."
LOG.error(msg)
raise HTTPForbidden(explanation=msg)
return (id, os_status)
if interface.get('mac', None) == host_mac:
if exist_node.get('dmi_uuid') \
and exist_node.get('dmi_uuid') != \
host_meta.get('dmi_uuid'):
msg = "The 'mac' of host interface is exist " \
"in db, but 'dmi_uuid' is different.We" \
" think you want update the host, but " \
"the host can't find."
LOG.error(msg)
raise HTTPForbidden(explanation=msg)
return (id, os_status)
return (None, None)
def _get_swap_lv_size_m(self, memory_size_m):
@@ -1371,9 +1370,26 @@ class Controller(controller.BaseController):
self._verify_host_name(req, id, orig_host_meta, host_meta)
orig_mac_list = \
self._check_interface_on_update_host(req,
host_meta,
self._check_interface_on_update_host(req, host_meta,
orig_host_meta)
new_mac_list = []
if "interfaces" in host_meta:
interfaces = eval(host_meta['interfaces'])
new_mac_list = [interface['mac'] for interface in
interfaces if interface.get('mac')]
if orig_mac_list:
orig_min_mac = min(orig_mac_list)
if new_mac_list:
new_min_mac = min(new_mac_list)
if orig_mac_list and new_mac_list and \
(min(new_min_mac, orig_min_mac) != orig_min_mac):
ironic_data = utils.get_host_hw_info(interfaces)
orig_host_meta['disks'] = ironic_data.get('disks')
orig_host_meta['memory'] = ironic_data.get('memory')
orig_host_meta['devices'] = ironic_data.get('devices')
orig_host_meta['pci'] = ironic_data.get('pci')
orig_host_meta['system'] = ironic_data.get('system')
orig_host_meta['cpu'] = ironic_data.get('cpu')
self._verify_host_cluster(req, id, orig_host_meta, host_meta)
if ('resource_type' in host_meta and
host_meta['resource_type'] not in self.support_resource_type):
@@ -1894,7 +1910,6 @@ class Controller(controller.BaseController):
host_meta)
if orig_mac_list:
orig_min_mac = min(orig_mac_list)
discover_host = self._get_discover_host_by_mac(req,
orig_min_mac)
if discover_host:

View File

@@ -6,6 +6,7 @@ import webob
import json as jsonutils
import daisy.registry.client.v1.api as registry
import daisy.api.backends.common as daisy_cmn
from daisy.common import utils
from daisy.tests.api import fakes
from daisy.db.sqlalchemy import api
@@ -1986,6 +1987,111 @@ class TestHostsApiConfig(test.TestCase):
self.controller.discover_host_bin(req, host_meta)
self.assertTrue(mock_update_discover_host.called)
def test__verify_interface_among_hosts(self):
host_meta = {
'cluster': '1',
'dmi_uuid': '03000200-0400-0500-0006-000700080009',
'interfaces':
"[{'name': 'enp132s0f2292','ip': '192.168.1.2',"
"'mac': '4c:09:b4:b2:80:8c','pci': '0000:03:02.0',"
"'assigned_networks': [],"
"'host_id': '1','type': 'ether'},"
"{'name': 'bond0','bond_type': '',"
"'mode': 'active-backup;off',"
"'slaves': ['enp2s0', 'enp132s0f2292'],"
"'assigned_networks':[{'ip': '192.168.1.5',"
"'name': 'PUBLICAPI'}],'host_id': '1','type': 'bond'},"
"{'name': 'enp2s0','ip': '10.43.178.21',"
"'mac': '00:24:21:74:8a:56','pci': '0000:02:00.0',"
"'assigned_networks': [],'host_id': '1',"
"'type': 'ether'}, {'name': 'enp3s1', "
"'mac': '00:23:cd:96:53:97', 'pci': '0000:03:02.1', "
"'type': 'ether'}]"}
req = webob.Request.blank('/')
req.context = RequestContext(is_admin=True,
user='fake user',
tenant='fake tenamet')
self.controller._verify_interface_in_same_host = \
mock.Mock(return_value={})
registry.get_hosts_detail = \
mock.Mock(return_value=[self.orig_host_meta])
registry.get_host_metadata = \
mock.Mock(return_value=self.orig_host_meta)
self.controller.get_host = \
mock.Mock(return_value={'host_meta': self.orig_host_meta})
id = ""
os_status = ""
(id, status) = self.controller._verify_interface_among_hosts(
req, host_meta)
self.assertEqual("4b6970c5-ef1d-4599-a1d7-70175a888e6d", id)
def test_add_host_with_same_host(self):
req = webob.Request.blank('/')
req.context = RequestContext(is_admin=True,
user='fake user',
tenant='fake tenamet')
self.controller._check_add_host_interfaces = \
mock.Mock(return_value="samehost")
result = self.controller.add_host(req, self.host_meta)
self.assertEqual('samehost', result)
def test_update_host_with_same_host(self):
host_meta = {
'id': '4b6970c5-ef1d-4599-a1d7-70175a888e6d',
'cluster': '1',
'dmi_uuid': '03000200-0400-0500-0006-000700080009',
'root_disk': 'sda',
'os_status': 'init',
'interfaces':
"[{'name': 'enp132s0f2292','ip': '192.168.1.2',"
"'mac': '4c:09:b4:b2:80:8c','pci': '0000:03:02.0',"
"'assigned_networks': [],"
"'host_id': '1','type': 'ether'},"
"{'name': 'bond0','bond_type': '',"
"'mode': 'active-backup;off',"
"'slaves': ['enp2s0', 'enp132s0f2292'],"
"'assigned_networks':[{'ip': '192.168.1.5',"
"'name': 'PUBLICAPI'}],'host_id': '1',"
"'type': 'bond'},"
"{'name': 'enp2s0','ip': '10.43.178.21',"
"'mac': '00:24:21:74:8a:56','pci': '0000:02:00.0',"
"'assigned_networks': [],'host_id': '1',"
"'type': 'ether'}, {'name': 'enp3s1', "
"'mac': '00:23:cd:96:53:97', 'pci': '0000:03:02.1', "
"'type': 'ether'}]",
'disks': """{u'sda':
{u'name': u'sda',
u'extra': [u'scsi-3500003956831a6d8',
u'wwn-0x500003956831a6d8'],
u'removable': u'',
u'model': u'',
u'disk': u'pci-0000:01:00.0-sas-'
u'0x500003956831a6da-lun-0',
u'size': u' 200127266816 bytes'}}"""
}
req = webob.Request.blank('/')
req.context = RequestContext(is_admin=True,
user='fake user',
tenant='fake tenamet')
self.controller.get_host_meta_or_404 = mock.Mock(
return_value=self.orig_host_meta)
self.controller._check_interface_on_update_host = mock.Mock(
return_value=['4c:09:b4:b2:80:8c', '00:24:21:74:8a:56'])
self.controller._verify_host_cluster = mock.Mock(return_value={})
hw_info = {'disks': {'sda': {'name': 'sda',
'size': '200127266816',
'disk': u'pci-0000:01:00.0',
'removable': u''}},
'cpu': {'real': 1, 'spec_1': {}, 'total': 1}}
utils.get_host_hw_info = mock.Mock(return_value=hw_info)
id = '4b6970c5-ef1d-4599-a1d7-70175a888e6d'
registry.get_roles_detail = mock.Mock(return_value={})
registry.get_clusters_detail = mock.Mock(return_value={})
registry.get_discover_hosts_detail = mock.Mock(return_value={})
registry.update_host_metadata = mock.Mock(return_value=host_meta)
result = self.controller.update_host(req, id, host_meta)
self.assertEqual(host_meta, result['host_meta'])
class TestGetClusterNetworkInfo(test.TestCase):
_log_handler = MockLoggingHandler()