Merge "When begin to install os by pxe, progress is 100%"
This commit is contained in:
commit
1332f1a2de
@ -729,26 +729,27 @@ def get_ctl_ha_nodes_min_mac(req, cluster_id):
|
||||
return ctl_ha_nodes_min_mac
|
||||
|
||||
|
||||
def update_db_host_status(req, host_id, host_status, version_id=None,
|
||||
version_patch_id=None):
|
||||
def update_db_host_status(req, host_id, host_status, version_id=None):
|
||||
"""
|
||||
Update host status and intallation progress to db.
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
host_meta = {}
|
||||
if host_status.get('os_progress', None):
|
||||
if "os_progress" in host_status:
|
||||
host_meta['os_progress'] = host_status['os_progress']
|
||||
if host_status.get('os_status', None):
|
||||
if "os_status" in host_status:
|
||||
host_meta['os_status'] = host_status['os_status']
|
||||
if host_status.get('messages', None):
|
||||
if "messages" in host_status:
|
||||
host_meta['messages'] = host_status['messages']
|
||||
if host_status.get('tecs_version_id', None):
|
||||
if "tecs_version_id" in host_status:
|
||||
host_meta['tecs_version_id'] = host_status['tecs_version_id']
|
||||
if "tecs_patch_id" in host_status:
|
||||
host_meta['tecs_patch_id'] = host_status['tecs_patch_id']
|
||||
if "version_patch_id" in host_status:
|
||||
host_meta['version_patch_id'] = host_status['version_patch_id']
|
||||
if version_id:
|
||||
host_meta['os_version_id'] = version_id
|
||||
if version_patch_id:
|
||||
host_meta['version_patch_id'] = version_patch_id
|
||||
hostinfo = registry.update_host_metadata(req.context,
|
||||
host_id,
|
||||
host_meta)
|
||||
|
@ -68,3 +68,88 @@ class TestCommon(test.TestCase):
|
||||
common.set_role_status_and_progress(req, cluster_id, opera, status,
|
||||
backend_name, host_id)
|
||||
self.assertFalse(mock_update_role_host.called)
|
||||
|
||||
@mock.patch('daisy.registry.client.v1.api.update_host_metadata')
|
||||
def test_update_db_host_status(self, mock_do_update_host):
|
||||
def mock_update_host(*args, **kwargs):
|
||||
return host_status
|
||||
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True, user='fake user',
|
||||
tenant='fake tenant')
|
||||
host_id = '123'
|
||||
host_status = {"os_progress": 100, "os_status": "active",
|
||||
"messages": "test"}
|
||||
mock_do_update_host.side_effect = mock_update_host
|
||||
host_info = common.update_db_host_status(req, host_id, host_status)
|
||||
self.assertEqual(100, host_info['os_progress'])
|
||||
self.assertEqual("active", host_info['os_status'])
|
||||
self.assertEqual("test", host_info['messages'])
|
||||
|
||||
@mock.patch('daisy.registry.client.v1.api.update_host_metadata')
|
||||
def test_update_db_host_status_with_progress_is_zero(self,
|
||||
mock_do_update_host):
|
||||
def mock_update_host(*args, **kwargs):
|
||||
return host_status
|
||||
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True, user='fake user',
|
||||
tenant='fake tenant')
|
||||
host_id = '123'
|
||||
host_status = {"os_progress": 0, "os_status": "init",
|
||||
"messages": "test"}
|
||||
mock_do_update_host.side_effect = mock_update_host
|
||||
host_info = common.update_db_host_status(req, host_id, host_status)
|
||||
self.assertEqual(0, host_info['os_progress'])
|
||||
self.assertEqual("init", host_info['os_status'])
|
||||
self.assertEqual("test", host_info['messages'])
|
||||
|
||||
@mock.patch('daisy.registry.client.v1.api.update_host_metadata')
|
||||
def test_update_db_host_status_with_version_id(self, mock_do_update_host):
|
||||
def mock_update_host(*args, **kwargs):
|
||||
return host_status
|
||||
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True, user='fake user',
|
||||
tenant='fake tenant')
|
||||
host_id = '123'
|
||||
version_id = "456"
|
||||
host_status = {"os_progress": 100, "os_status": "active",
|
||||
"os_version_id": version_id}
|
||||
mock_do_update_host.side_effect = mock_update_host
|
||||
host_info = common.update_db_host_status(req, host_id, host_status,
|
||||
version_id)
|
||||
self.assertEqual("456", host_info['os_version_id'])
|
||||
|
||||
@mock.patch('daisy.registry.client.v1.api.update_host_metadata')
|
||||
def test_update_db_host_status_with_tecs_patch_id(self,
|
||||
mock_do_update_host):
|
||||
def mock_update_host(*args, **kwargs):
|
||||
return host_status
|
||||
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True, user='fake user',
|
||||
tenant='fake tenant')
|
||||
host_id = '123'
|
||||
tecs_patch_id = "456"
|
||||
host_status = {"os_progress": 100, "os_status": "active",
|
||||
"tecs_patch_id": tecs_patch_id}
|
||||
mock_do_update_host.side_effect = mock_update_host
|
||||
host_info = common.update_db_host_status(req, host_id, host_status)
|
||||
self.assertEqual("456", host_info['tecs_patch_id'])
|
||||
|
||||
@mock.patch('daisy.registry.client.v1.api.update_host_metadata')
|
||||
def test_update_db_host_status_with_os_patch_id(self, mock_do_update_host):
|
||||
def mock_update_host(*args, **kwargs):
|
||||
return host_status
|
||||
|
||||
req = webob.Request.blank('/')
|
||||
req.context = RequestContext(is_admin=True, user='fake user',
|
||||
tenant='fake tenant')
|
||||
host_id = '123'
|
||||
version_patch_id = "456"
|
||||
host_status = {"os_progress": 100, "os_status": "active",
|
||||
"version_patch_id": version_patch_id}
|
||||
mock_do_update_host.side_effect = mock_update_host
|
||||
host_info = common.update_db_host_status(req, host_id, host_status)
|
||||
self.assertEqual("456", host_info['version_patch_id'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user