Skip to content

Commit fecb3df

Browse files
committed
<fix>[ansible]: Optimize kvm host reconnection
Pass the host_info retrieved from kvm.py to zstacklib to avoid zstacklib repeatedlly retrieving host_info. Set variable IS_REMOTE_PIP_READY in zstacklib to record whether remote host pip is available or not, to avoid checking whether pip exists every time during pip install python package. Optimize gather facts, add gather_subset=machine,processor to get only the required info, and specify the required fields in the fitler param to avoid excessive logging. Resolves: ZSTAC-56230 Change-Id: I686771727a6278746165757374646579676f6879
1 parent 1375428 commit fecb3df

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

kvmagent/ansible/kvm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def check_nested_kvm(host_post_info):
148148
modprobe_arg.state = 'present'
149149
modprobe(modprobe_arg, host_post_info)
150150

151+
151152
def load_zstacklib():
152153
"""include zstacklib.py"""
153154
zstacklib_args = ZstackLibArgs()
@@ -160,6 +161,7 @@ def load_zstacklib():
160161
zstacklib_args.pip_url = pip_url
161162
zstacklib_args.zstack_releasever = releasever
162163
zstacklib_args.trusted_host = trusted_host
164+
zstacklib_args.host_info = host_info
163165
if host_info.distro in DEB_BASED_OS:
164166
zstacklib_args.apt_server = yum_server
165167
zstacklib_args.zstack_apt_source = zstack_repo

zstacklib/ansible/zstacklib.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def __init__(self):
229229
self.host_post_info = None
230230
self.pip_url = None
231231
self.require_python_env = "true"
232+
self.host_info = None
232233

233234

234235
class Msg(object):
@@ -1022,7 +1023,11 @@ def apt_update_packages(name_list, host_post_info):
10221023
host_post_info.host))
10231024

10241025

1026+
IS_REMOTE_PIP_READY = {}
1027+
1028+
10251029
def pip_install_package(pip_install_arg, host_post_info):
1030+
global IS_REMOTE_PIP_READY
10261031
start_time = datetime.datetime.now()
10271032
host_post_info.start_time = start_time
10281033
name = pip_install_arg.name
@@ -1043,8 +1048,10 @@ def pip_install_package(pip_install_arg, host_post_info):
10431048
host_post_info.post_label_param = name
10441049
handle_ansible_info("INFO: pip installing package %s ..." %
10451050
name, host_post_info, "INFO")
1046-
command = "which pip || ln -s /usr/bin/pip2 /usr/bin/pip"
1047-
run_remote_command(command, host_post_info)
1051+
if host not in IS_REMOTE_PIP_READY.keys() or not IS_REMOTE_PIP_READY[host]:
1052+
command = "which pip || ln -s /usr/bin/pip2 /usr/bin/pip"
1053+
run_remote_command(command, host_post_info)
1054+
IS_REMOTE_PIP_READY[host] = True
10481055
param_dict = {}
10491056
param_dict_raw = dict(version=version,
10501057
extra_args=extra_args,
@@ -1542,7 +1549,9 @@ def get_remote_host_info_obj(host_post_info):
15421549
runner_args = ZstackRunnerArg()
15431550
runner_args.host_post_info = host_post_info
15441551
runner_args.module_name = 'setup'
1545-
runner_args.module_args = 'filter=ansible*'
1552+
runner_args.module_args = ('gather_subset=machine,processor '
1553+
'filter=ansible_dist*,ansible_machine,'
1554+
'ansible_processor,ansible_kernel')
15461555
zstack_runner = ZstackRunner(runner_args)
15471556
result = zstack_runner.run()
15481557
logger.debug(result)
@@ -2171,7 +2180,9 @@ def __init__(self, args):
21712180
check_umask(self.host_post_info)
21722181
configure_hosts(self.host_post_info)
21732182

2174-
host_info = get_remote_host_info_obj(self.host_post_info)
2183+
host_info = args.host_info
2184+
if not host_info:
2185+
host_info = get_remote_host_info_obj(self.host_post_info)
21752186

21762187
if self.distro in RPM_BASED_OS:
21772188
install_release_on_host(True, host_info, self.host_post_info)

0 commit comments

Comments
 (0)