Merge "solve upgrade os problem" into stable/mitaka

This commit is contained in:
Jenkins
2017-02-23 11:22:44 +00:00
committed by Gerrit Code Review
4 changed files with 124 additions and 39 deletions

View File

@@ -760,6 +760,10 @@ def update_db_host_status(req, host_id, host_status, version_id=None):
def get_local_deployment_ip(tecs_deployment_ips):
if not isinstance(tecs_deployment_ips, list):
msg = "%s must be converted to list" % tecs_deployment_ips
LOG.error(msg)
raise exception.InvalidIP(msg)
(status, output) = commands.getstatusoutput('ifconfig')
netcard_pattern = re.compile('\S*: ')
ip_str = '([0-9]{1,3}\.){3}[0-9]{1,3}'

View File

@@ -1017,7 +1017,7 @@ class OSInstall():
def _os_thread_bin(req, host_ip, host_id, update_file, update_script):
host_meta = {}
password = "ossdbg1"
LOG.info(_("Begin update os for host %s." % (host_ip)))
LOG.info(_("Begin upgrade os for host %s." % (host_ip)))
cmd = 'mkdir -p /var/log/daisy/daisy_update/'
daisy_cmn.subprocess_call(cmd)
@@ -1066,12 +1066,10 @@ def _os_thread_bin(req, host_ip, host_id, update_file, update_script):
else:
host_meta['os_progress'] = 100
host_meta['os_status'] = host_os_status['ACTIVE']
host_meta['messages'] = "upgrade OS successfully"
host_meta['messages'] = "OS upgraded successfully"
daisy_cmn.update_db_host_status(req, host_id, host_meta)
LOG.info(_("Upgrade OS for %s successfully!" % host_ip))
fp.write(exc_result)
if "reboot" in exc_result:
daisy_cmn.check_reboot_ping(host_ip)
# this will be raise raise all the exceptions of the thread to log file
@@ -1153,7 +1151,7 @@ def upgrade(self, req, cluster_id, version_id, version_patch_id,
host_meta = daisy_cmn.get_host_detail(req, host_id)
host_ip = daisy_cmn.get_host_network_ip(
req, host_meta, cluster_networks, 'MANAGEMENT')
if daisy_cmn.get_local_deployment_ip(host_ip):
if daisy_cmn.get_local_deployment_ip([host_ip]):
LOG.exception("%s host os upgrade by hand" % host_ip)
continue
host_set = set()

View File

@@ -3,9 +3,10 @@ import unittest
import webob
import exceptions
import subprocess
from daisy.api.backends.osinstall.pxe import install as os
from daisy.api.backends.osinstall.pxe import install
from daisy.context import RequestContext
from daisy.common import exception
import daisy.api.backends.common as daisy_cmn
from daisy import test
@@ -61,8 +62,8 @@ class TestOs(unittest.TestCase):
host_id = ''
update_file = ''
update_script = ''
os._os_thread_bin(self.req, host_ip, host_id, update_file,
update_script)
install._os_thread_bin(self.req, host_ip, host_id, update_file,
update_script)
log_file = '/var/log/daisy/daisy_update/127.0.0.1_update_os.log'
all_the_text = open('%s' % log_file).read()
self.assertIn('upgrade OS successfully', all_the_text)
@@ -78,7 +79,7 @@ class TestOs(unittest.TestCase):
"id": "123456789"
}
mock_check_output.return_value = "chassis-1/blade-1"
location = os.get_host_location_of_cisco(host_detail)
location = install.get_host_location_of_cisco(host_detail)
self.assertRaises(mock_check_output.called)
self.assertEqual("1/1", location)
@@ -94,7 +95,7 @@ class TestOs(unittest.TestCase):
mock_check_output.side_effect = exceptions.Exception
self.assertRaises(mock_check_output.called)
self.assertRaises(exceptions.Exception,
os.get_host_location_of_cisco,
install.get_host_location_of_cisco,
host_detail)
@mock.patch('subprocess.check_output')
@@ -106,7 +107,7 @@ class TestOs(unittest.TestCase):
"id": "123456789"
}
mock_check_output.return_value = "ok"
os.set_pxe_start_of_cisco(host_detail)
install.set_pxe_start_of_cisco(host_detail)
self.assertRaises(mock_check_output.called)
@mock.patch('subprocess.check_output')
@@ -120,7 +121,7 @@ class TestOs(unittest.TestCase):
mock_check_output.side_effect = exceptions.Exception
self.assertRaises(mock_check_output.called)
self.assertRaises(exceptions.Exception,
os.set_pxe_start_of_cisco,
install.set_pxe_start_of_cisco,
host_detail)
@mock.patch('subprocess.check_output')
@@ -132,7 +133,7 @@ class TestOs(unittest.TestCase):
"id": "123456789"
}
mock_check_output.return_value = "ok"
os.set_reboot_of_cisco(host_detail)
install.set_reboot_of_cisco(host_detail)
self.assertRaises(mock_check_output.called)
@mock.patch('subprocess.check_output')
@@ -146,7 +147,7 @@ class TestOs(unittest.TestCase):
mock_check_output.side_effect = exceptions.Exception
self.assertRaises(mock_check_output.called)
self.assertRaises(exceptions.Exception,
os.set_reboot_of_cisco,
install.set_reboot_of_cisco,
host_detail)
@mock.patch('subprocess.check_output')
@@ -158,7 +159,7 @@ class TestOs(unittest.TestCase):
"id": "123456789"
}
mock_check_output.return_value = "ok"
os.set_disk_start_of_cisco(host_detail)
install.set_disk_start_of_cisco(host_detail)
self.assertRaises(mock_check_output.called)
@mock.patch('subprocess.check_output')
@@ -172,7 +173,7 @@ class TestOs(unittest.TestCase):
mock_check_output.side_effect = exceptions.Exception
self.assertRaises(mock_check_output.called)
self.assertRaises(exceptions.Exception,
os.set_disk_start_of_cisco,
install.set_disk_start_of_cisco,
host_detail)
@@ -227,8 +228,8 @@ class TestInstall(test.TestCase):
mock_log.side_effect = self._log_handler
mock_update_host.side_effect = update_host_meta
mock_set_role.side_effect = set_role
os.OSInstall(req, cluster_id)._begin_install_os(hosts_detail,
cluster_id)
install.OSInstall(req, cluster_id)._begin_install_os(hosts_detail,
cluster_id)
self.assertTrue(mock_set_role.called)
@mock.patch("daisy.api.backends.common.subprocess_call")
@@ -246,5 +247,82 @@ class TestInstall(test.TestCase):
mock_subprocess.side_effect = subprocess_return
self.assertRaises(
exception.NotFound,
os.OSInstall(req, cluster_id)._install_os_for_baremetal,
install.OSInstall(req, cluster_id)._install_os_for_baremetal,
host_detail)
@mock.patch('daisy.api.backends.common.update_db_host_status')
def test_upgrade_no_local_ip(self, mock_update_db_host):
req = webob.Request.blank('/')
cluster_id = "123"
version_id = "1"
version_patch_id = "12"
update_script = "test.txt"
update_file = "test"
hosts_list = ['123', '345']
update_object = "redhat"
daisy_cmn.get_cluster_networks_detail = mock.Mock(return_value={})
daisy_cmn.get_host_detail = mock.Mock(return_value={})
daisy_cmn.get_host_network_ip = mock.Mock(return_value="1.1.1.1")
daisy_cmn.check_ping_hosts = mock.Mock(return_value={})
daisy_cmn.get_local_deployment_ip = mock.Mock(return_value="")
mock_update_db_host.return_value = 'ok'
install.upgrade_os = mock.Mock(return_value={})
install.upgrade(self, req, cluster_id, version_id, version_patch_id,
update_file, update_script, hosts_list, update_object)
self.assertTrue(mock_update_db_host.called)
@mock.patch('daisy.api.backends.common.update_db_host_status')
def test_upgrade_has_local_ip(self, mock_update_db_host):
req = webob.Request.blank('/')
cluster_id = "123"
version_id = "1"
version_patch_id = "12"
update_script = "test.txt"
update_file = "test"
hosts_list = ['123', '345']
update_object = "redhat"
daisy_cmn.get_cluster_networks_detail = mock.Mock(return_value={})
daisy_cmn.get_host_detail = mock.Mock(return_value={})
daisy_cmn.get_host_network_ip = mock.Mock(return_value="1.1.1.1")
daisy_cmn.check_ping_hosts = mock.Mock(return_value={})
daisy_cmn.get_local_deployment_ip = mock.Mock(return_value="1.1.1.1")
mock_update_db_host.return_value = 'ok'
install.upgrade_os = mock.Mock(return_value={})
install.upgrade(self, req, cluster_id, version_id, version_patch_id,
update_file, update_script, hosts_list, update_object)
self.assertFalse(mock_update_db_host.called)
@mock.patch("daisy.api.backends.common.subprocess_call")
@mock.patch("subprocess.check_output")
@mock.patch('daisy.api.backends.common.update_db_host_status')
@mock.patch('daisy.api.backends.common.check_reboot_ping')
def test_os_thread_bin_nomal(self, mock_do_reboot_ping,
mock_do_update_db_status,
mock_check_output, mock_subprocess_call):
def mock_reboot_ping():
return
def mock_update_db_status(req, host_id, host_meta):
return
mock_do_reboot_ping.side_effect = mock_reboot_ping
mock_do_update_db_status.side_effect = mock_update_db_status
mock_subprocess_call.return_value = None
cmd = 'mkdir -p /var/log/daisy/daisy_update/'
subprocesscall(cmd)
cmd1 = "touch /var/log/daisy/daisy_update/10.43.177.1_update" \
"_os.log"
subprocesscall(cmd1)
host_ip = "10.43.177.1"
host_meta = {'id': '123', 'root_pwd': 'ossdbg1'}
log_file = '/var/log/daisy/daisy_update/%s_update_os.log' \
% host_ip
update_file = "test.txt"
update_object = "vplat"
vpatch_id = ""
exec_result = 'upgrade successfully'
mock_check_output.return_value = exec_result
install._os_thread_bin(self.req, host_ip, host_meta['id'], update_file,
update_object)
self.assertEqual(6, mock_subprocess_call.call_count)
self.assertEqual(1, mock_check_output.call_count)

View File

@@ -3,6 +3,7 @@ from daisy.api.backends import common
from daisy import test
import webob
from daisy.context import RequestContext
from daisy.common import exception
class DottableDict(dict):
@@ -90,6 +91,27 @@ class TestCommon(test.TestCase):
use_share_disk = common.if_used_shared_storage(req, '123')
self.assertEqual(use_share_disk, False)
@mock.patch('daisy.registry.client.v1.api.'
'update_role_host_metadata')
@mock.patch('daisy.registry.client.v1.api.get_role_host_metadata')
@mock.patch('daisy.registry.client.v1.api.get_roles_detail')
def test_set_role_status_and_progress_with_host_id(
self, mock_get_roles, mock_get_role_host, mock_update_role_host):
req = webob.Request.blank('/')
req.context = RequestContext(is_admin=True, user='fake user',
tenant='fake tenant')
host_id = '2'
cluster_id = '1'
opera = 'install'
status = {}
backend_name = 'tecs'
mock_get_roles.return_value = [{'id': '1',
'deployment_backend': 'tecs'}]
mock_get_role_host.return_value = [{'host_id': '1'}]
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):
@@ -175,23 +197,6 @@ class TestCommon(test.TestCase):
host_info = common.update_db_host_status(req, host_id, host_status)
self.assertEqual("456", host_info['version_patch_id'])
@mock.patch('daisy.registry.client.v1.api.'
'update_role_host_metadata')
@mock.patch('daisy.registry.client.v1.api.get_role_host_metadata')
@mock.patch('daisy.registry.client.v1.api.get_roles_detail')
def test_set_role_status_and_progress_with_host_id(
self, mock_get_roles, mock_get_role_host, mock_update_role_host):
req = webob.Request.blank('/')
req.context = RequestContext(is_admin=True, user='fake user',
tenant='fake tenant')
host_id = '2'
cluster_id = '1'
opera = 'install'
status = {}
backend_name = 'tecs'
mock_get_roles.return_value = [{'id': '1',
'deployment_backend': 'tecs'}]
mock_get_role_host.return_value = [{'host_id': '1'}]
common.set_role_status_and_progress(req, cluster_id, opera, status,
backend_name, host_id)
self.assertFalse(mock_update_role_host.called)
def test_get_local_deployment_ip_with_string(self):
self.assertRaises(exception.InvalidIP,
common.get_local_deployment_ip, '192.168.1.5')