Merge "Jira: Daisy-592 host discovered by PXE can not change discover_mode when discover another host with SSH" into stable/mitaka
This commit is contained in:
@@ -2035,7 +2035,8 @@ class Controller(controller.BaseController):
|
||||
LOG.info('existed_host_ip**: %s', existed_host_ip)
|
||||
|
||||
for discover_host in discover_host_meta_list:
|
||||
if discover_host['status'] != 'DISCOVERY_SUCCESSFUL':
|
||||
if discover_host['status'] != 'DISCOVERY_SUCCESSFUL' and \
|
||||
discover_host['ip']:
|
||||
update_info = {}
|
||||
update_info['status'] = 'DISCOVERING'
|
||||
update_info['message'] = 'DISCOVERING'
|
||||
@@ -2043,7 +2044,8 @@ class Controller(controller.BaseController):
|
||||
self.update_progress_to_db(req, update_info, discover_host)
|
||||
threads = []
|
||||
for discover_host_meta in discover_host_meta_list:
|
||||
if discover_host_meta['ip'] in existed_host_ip:
|
||||
if discover_host_meta['ip'] \
|
||||
and discover_host_meta['ip'] in existed_host_ip:
|
||||
update_info = {}
|
||||
update_info['status'] = 'DISCOVERY_SUCCESSFUL'
|
||||
update_info['message'] = "discover host for %s successfully!" \
|
||||
@@ -2055,7 +2057,8 @@ class Controller(controller.BaseController):
|
||||
self.update_progress_to_db(
|
||||
req, update_info, discover_host_meta)
|
||||
continue
|
||||
if discover_host_meta['status'] != 'DISCOVERY_SUCCESSFUL':
|
||||
if discover_host_meta['ip'] and discover_host_meta['status'] \
|
||||
!= 'DISCOVERY_SUCCESSFUL':
|
||||
t = threading.Thread(
|
||||
target=self.thread_bin, args=(
|
||||
req, cluster_id, discover_host_meta))
|
||||
@@ -2118,52 +2121,55 @@ class Controller(controller.BaseController):
|
||||
raise HTTPBadRequest(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
|
||||
discover_hosts_ip = self._get_discover_host_ip(req)
|
||||
host_interfaces = []
|
||||
if host_meta.get('mac'):
|
||||
filters = {'mac': host_meta['mac']}
|
||||
host_interfaces = registry.get_all_host_interfaces(req.context,
|
||||
filters)
|
||||
if host_meta['ip'] in discover_hosts_ip:
|
||||
host = self._get_discover_host_filter_by_ip(req, host_meta['ip'])
|
||||
if host and host['status'] != 'DISCOVERY_SUCCESSFUL':
|
||||
host_info = {}
|
||||
host_info['ip'] = host_meta.get('ip', host.get('ip'))
|
||||
host_info['passwd'] = \
|
||||
host_meta.get('passwd', host.get('passwd'))
|
||||
host_info['user'] = host_meta.get('user', host.get('user'))
|
||||
host_info['status'] = 'init'
|
||||
host_info['message'] = 'None'
|
||||
if host_interfaces:
|
||||
host_info['host_id'] = host_interfaces[0]['host_id']
|
||||
discover_host_info = \
|
||||
registry.update_discover_host_metadata(req.context,
|
||||
host['id'],
|
||||
host_info)
|
||||
else:
|
||||
msg = (_("ip %s already existed and this host has been "
|
||||
"discovered successfully. " % host_meta['ip']))
|
||||
LOG.error(msg)
|
||||
raise HTTPForbidden(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
else:
|
||||
discover_hosts_ip = self._get_discover_host_ip(req)
|
||||
if host_meta['ip'] in discover_hosts_ip:
|
||||
host = self._get_discover_host_filter_by_ip(req,
|
||||
host_meta['ip'])
|
||||
if host and host['status'] != 'DISCOVERY_SUCCESSFUL':
|
||||
host_info = {}
|
||||
host_info['ip'] = host_meta.get('ip', host.get('ip'))
|
||||
host_info['passwd'] =\
|
||||
host_meta.get('passwd', host.get('passwd'))
|
||||
host_info['user'] = \
|
||||
host_meta.get('user', host.get('user'))
|
||||
host_info['status'] = 'init'
|
||||
host_info['message'] = 'None'
|
||||
host_meta = \
|
||||
registry.update_discover_host_metadata(req.context,
|
||||
host['id'],
|
||||
host_info)
|
||||
return {'host_meta': host_meta}
|
||||
else:
|
||||
msg = (_("ip %s already existed and this host has "
|
||||
"been discovered successfully. "
|
||||
% host_meta['ip']))
|
||||
LOG.error(msg)
|
||||
raise HTTPForbidden(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
self.validate_ip_format(host_meta['ip'])
|
||||
|
||||
if not host_meta.get('user', None):
|
||||
host_meta['user'] = 'root'
|
||||
|
||||
if not host_meta.get('passwd', None):
|
||||
msg = "PASSWD parameter can not be None."
|
||||
LOG.error(msg)
|
||||
raise HTTPBadRequest(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
if not host_meta.get('status', None):
|
||||
host_meta['status'] = 'init'
|
||||
|
||||
try:
|
||||
discover_host_info = \
|
||||
registry.add_discover_host_metadata(req.context, host_meta)
|
||||
except exception.Invalid as e:
|
||||
raise HTTPBadRequest(explanation=e.msg, request=req)
|
||||
if not host_meta.get('user', None):
|
||||
host_meta['user'] = 'root'
|
||||
if not host_meta.get('passwd', None):
|
||||
msg = "PASSWD parameter can not be None."
|
||||
LOG.error(msg)
|
||||
raise HTTPBadRequest(explanation=msg,
|
||||
request=req,
|
||||
content_type="text/plain")
|
||||
if not host_meta.get('status', None):
|
||||
host_meta['status'] = 'init'
|
||||
if host_interfaces:
|
||||
host_meta['host_id'] = host_interfaces[0]['host_id']
|
||||
try:
|
||||
discover_host_info = \
|
||||
registry.add_discover_host_metadata(req.context, host_meta)
|
||||
except exception.Invalid as e:
|
||||
raise HTTPBadRequest(explanation=e.msg, request=req)
|
||||
return {'host_meta': discover_host_info}
|
||||
|
||||
@utils.mutating
|
||||
|
||||
@@ -7,6 +7,7 @@ import json as jsonutils
|
||||
import daisy.registry.client.v1.api as registry
|
||||
import daisy.api.backends.common as daisy_cmn
|
||||
from daisy.tests.api import fakes
|
||||
from daisy.db.sqlalchemy import api
|
||||
|
||||
|
||||
def set_host_meta():
|
||||
@@ -1837,6 +1838,154 @@ class TestHostsApiConfig(test.TestCase):
|
||||
self.controller._check_interface_on_update_host,
|
||||
req, host_meta, orig_host_meta)
|
||||
|
||||
@mock.patch('logging.Logger')
|
||||
@mock.patch('daisy.registry.client.v1.api.'
|
||||
'update_discover_host_metadata')
|
||||
@mock.patch('daisy.registry.client.v1.api.'
|
||||
'get_all_host_interfaces')
|
||||
@mock.patch('daisy.registry.client.v1.api.'
|
||||
'get_discover_hosts_detail')
|
||||
def test_add_discover_host_with_exist_host_with_mac(
|
||||
self, mock_get_discovered_hosts,
|
||||
mock_get_all_host_interfaces,
|
||||
mock_update_discover_host, mock_log):
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True,
|
||||
user='fake user',
|
||||
tenant='fake tenant')
|
||||
|
||||
def update_discover_host(context, host_id, host_info):
|
||||
discover_host_meta = {'ip': '1.2.3.4',
|
||||
'status': 'init',
|
||||
'user': 'root',
|
||||
'passwd': 'ossdbg1'
|
||||
}
|
||||
discover_host = api.discover_host_add(context, discover_host_meta)
|
||||
discover_host_id = discover_host['id']
|
||||
api.discover_host_update(context, discover_host_id, host_info)
|
||||
discover_hosts = api.discover_host_get_all(context)
|
||||
discover_host_id = discover_hosts[0]['id']
|
||||
discover_host_info = api.discover_host_get(context,
|
||||
discover_host_id)
|
||||
api.discover_host_destroy(context, discover_host_id)
|
||||
return discover_host_info
|
||||
|
||||
host_meta = {'ip': '1.2.3.4',
|
||||
'passwd': 'ossdbg1',
|
||||
'user': 'root',
|
||||
'mac': '4c:09:b4:b1:c1:f0'}
|
||||
mock_get_discovered_hosts.return_value = [{'ip': '1.2.3.4',
|
||||
'status': 'init',
|
||||
'id': '1'}]
|
||||
mock_get_all_host_interfaces.return_value = [{'host_id': '1'}]
|
||||
mock_update_discover_host.side_effect = update_discover_host
|
||||
mock_log.side_effect = self._log_handler
|
||||
update_discover_host = self.controller.add_discover_host(req,
|
||||
host_meta)
|
||||
self.assertEqual('1', update_discover_host['host_meta']['host_id'])
|
||||
|
||||
@mock.patch('daisy.api.v1.hosts.Controller.'
|
||||
'_get_discover_host_filter_by_ip')
|
||||
@mock.patch('daisy.api.v1.hosts.Controller._get_discover_host_ip')
|
||||
@mock.patch('logging.Logger')
|
||||
def test_add_discover_host_with_exist_host(self, mock_log,
|
||||
mock_get_discover_host_ip,
|
||||
mock_get_discover_host):
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True,
|
||||
user='fake user',
|
||||
tenant='fake tenant')
|
||||
mock_get_discover_host_ip.return_value = ['1.2.3.4']
|
||||
mock_get_discover_host.return_value = {
|
||||
'ip': '1.2.3.4', 'status': 'DISCOVERY_SUCCESSFUL'}
|
||||
host_meta = {'ip': '1.2.3.4',
|
||||
'passwd': 'ossdbg1',
|
||||
'user': 'root'}
|
||||
mock_log.side_effect = self._log_handler
|
||||
self.assertRaises(webob.exc.HTTPForbidden,
|
||||
self.controller.add_discover_host, req, host_meta)
|
||||
|
||||
@mock.patch('daisy.api.v1.hosts.Controller._get_discover_host_ip')
|
||||
@mock.patch('logging.Logger')
|
||||
def test_add_discover_host_with_not_exist_host_without_password(
|
||||
self, mock_log, mock_get_discover_host_ip):
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True,
|
||||
user='fake user',
|
||||
tenant='fake tenant')
|
||||
mock_get_discover_host_ip.return_value = []
|
||||
mock_log.side_effect = self._log_handler
|
||||
host_meta = {'ip': '1.2.3.4'}
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.add_discover_host, req, host_meta)
|
||||
|
||||
@mock.patch('logging.Logger')
|
||||
@mock.patch('daisy.registry.client.v1.api.'
|
||||
'add_discover_host_metadata')
|
||||
@mock.patch('daisy.registry.client.v1.api.'
|
||||
'get_all_host_interfaces')
|
||||
@mock.patch('daisy.registry.client.v1.api.'
|
||||
'get_discover_hosts_detail')
|
||||
def test_add_discover_host_with_not_exist_host_with_mac(
|
||||
self, mock_get_discovered_hosts,
|
||||
mock_get_all_host_interfaces,
|
||||
mock_add_discover_host, mock_log):
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True,
|
||||
user='fake user',
|
||||
tenant='fake tenant')
|
||||
|
||||
def add_new_discover_host(context, host_info):
|
||||
return api.discover_host_add(context, host_info)
|
||||
|
||||
host_meta = {'ip': '1.2.3.4',
|
||||
'passwd': 'ossdbg1',
|
||||
'user': 'root',
|
||||
'mac': '4c:09:b4:b1:c1:f0'}
|
||||
mock_get_discovered_hosts.return_value = [{'ip': '1.2.3.6',
|
||||
'status': 'init',
|
||||
'id': '1'}]
|
||||
mock_get_all_host_interfaces.return_value = [{'host_id': '2'}]
|
||||
mock_add_discover_host.side_effect = add_new_discover_host
|
||||
mock_log.side_effect = self._log_handler
|
||||
add_host_info = self.controller.add_discover_host(req, host_meta)
|
||||
self.assertEqual('2', add_host_info['host_meta']['host_id'])
|
||||
|
||||
@mock.patch('logging.Logger')
|
||||
@mock.patch('daisy.registry.client.v1.api.'
|
||||
'update_discover_host_metadata')
|
||||
@mock.patch('daisy.registry.client.v1.api.'
|
||||
'get_all_host_interfaces')
|
||||
@mock.patch('daisy.registry.client.v1.api.'
|
||||
'get_discover_hosts_detail')
|
||||
def test_discover_host_bin_with_discovered_host(
|
||||
self, mock_get_discover_hosts_detail,
|
||||
mock_get_all_host_interfaces, mock_update_discover_host, mock_log):
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True,
|
||||
user='fake user',
|
||||
tenant='fake tenant')
|
||||
host_meta = {}
|
||||
|
||||
def get_discover_hosts(context, **params):
|
||||
discover_host_meta1 = {'ip': '1.2.3.4',
|
||||
'user': 'root',
|
||||
'passwd': 'ossdbg1'}
|
||||
api.discover_host_add(context, discover_host_meta1)
|
||||
return api.discover_host_get_all(context)
|
||||
|
||||
def update_discover_host(context, host_id, host_info):
|
||||
api.discover_host_update(context, host_id, host_info)
|
||||
api.discover_host_destroy(context, host_id)
|
||||
|
||||
mock_get_discover_hosts_detail.side_effect = get_discover_hosts
|
||||
mock_get_all_host_interfaces.return_value = [{'ip': '1.2.3.4',
|
||||
'host_id': '3'}]
|
||||
mock_update_discover_host.side_effect = update_discover_host
|
||||
mock_log.side_effect = self._log_handler
|
||||
self.controller.discover_host_bin(req, host_meta)
|
||||
self.assertTrue(mock_update_discover_host.called)
|
||||
|
||||
|
||||
class TestGetClusterNetworkInfo(test.TestCase):
|
||||
_log_handler = MockLoggingHandler()
|
||||
|
||||
@@ -341,6 +341,9 @@ class HostManager(base.ManagerWithFind):
|
||||
msg = 'create() got an unexpected keyword argument \'%s\''
|
||||
raise TypeError(msg % field)
|
||||
|
||||
if fields.get('hwm_id'):
|
||||
params = self.get_min_mac(fields['hwm_id'])
|
||||
fields['mac'] = params.get('mac')
|
||||
hdrs = self._host_meta_to_headers(fields)
|
||||
|
||||
resp, body = self.client.post('/v1/discover/nodes',
|
||||
|
||||
Reference in New Issue
Block a user