Fixing NTP issues for CDH plugin

First, we are fixing the adding of a new NTP server to ntp.conf.
The way it is currently done the server is added to the end of the
file and we fixed it to add it to the beginning of the config file.
Second, we are changing the order of when we set up ntp and the
service is started, because CDH fails to detect the sync'd time if
it has be synchronized after the start of the service.

Story: #2004981
Task: #29440

Change-Id: Ic2d7697a4036f5f689f065db081d53d4b37532cf
This commit is contained in:
Telles Nobrega 2019-02-11 13:43:30 -03:00
parent 2e09de9c82
commit 8f62975a8a
5 changed files with 46 additions and 3 deletions

View File

@ -0,0 +1,6 @@
---
fixes:
- |
This fixes the issue with NTP configuration where a prefered server
provided by the user is added to the end of the file and the defaults
are not deleted. Here we add the prefered server to the top of the file.

View File

@ -78,8 +78,8 @@ def _configure_ntp_on_instance(instance, url):
LOG.warning("Unable to configure NTP service")
return
r.append_to_file(
"/etc/ntp.conf", "server {url}".format(url=url),
r.prepend_to_file(
"/etc/ntp.conf", "server {url} iburst\n".format(url=url),
run_as_root=True)
_restart_ntp(r)
try:

View File

@ -298,6 +298,7 @@ def _provision_cluster(cluster_id):
cluster = conductor.cluster_get(ctx, cluster_id)
context.set_step_type(_("Engine: create cluster"))
INFRA.create_cluster(cluster)
ntp_service.configure_ntp(cluster_id)
# configure cluster
cluster = c_u.change_cluster_status(
@ -309,7 +310,6 @@ def _provision_cluster(cluster_id):
plugin.configure_cluster(cluster)
# starting prepared and configured cluster
ntp_service.configure_ntp(cluster_id)
cluster = c_u.change_cluster_status(
cluster, c_u.CLUSTER_STATUS_STARTING)

View File

@ -45,6 +45,9 @@ class FakeRemote(object):
def append_to_file(self, file, text, run_as_root=False):
return self.execute_command(file, run_as_root)
def prepend_to_file(self, file, text, run_as_root=False):
return self.execute_command(file, run_as_root)
def get_os_distrib(self):
return self.execute_command('get_os_distrib')

View File

@ -301,6 +301,19 @@ def _append_file(sftp, remote_file, data, run_as_root):
_append_fl(sftp, remote_file, data)
def _prepend_file(sftp, remote_file, data, run_as_root):
if run_as_root:
temp_file = 'temp-file-%s' % uuidutils.generate_uuid()
temp_remote_file = 'temp-remote-file-%s' % uuidutils.generate_uuid()
_write_fl(sftp, temp_file, data)
_execute_command(
'cat %s > %s' % (remote_file, temp_remote_file))
_execute_command(
'cat %s %s > %s' % (
temp_file, temp_remote_file, remote_file), run_as_root=True)
_execute_command('rm -f %s %s' % (temp_file, temp_remote_file))
def _write_file_to(remote_file, data, run_as_root=False):
global _ssh
@ -331,6 +344,21 @@ def _append_to_files(files, run_as_root=False):
_append_file(sftp, fl, data, run_as_root)
def _prepend_to_file(remote_file, data, run_as_root=False):
global _ssh
_prepend_file(_ssh.open_sftp(), remote_file, data, run_as_root)
def _prepend_to_files(files, run_as_root=False):
global _ssh
sftp = _ssh.open_sftp()
for fl, data in six.iteritems(files):
_prepend_file(sftp, fl, data, run_as_root)
def _read_file(sftp, remote_file):
fl = sftp.file(remote_file, 'r')
data = fl.read()
@ -878,6 +906,12 @@ class InstanceInteropHelper(remote.Remote):
self._log_command(description)
self._run_s(_append_to_files, timeout, description, files, run_as_root)
def prepend_to_file(self, r_file, data, run_as_root=False, timeout=None):
description = _('Prepending to file "%s"') % r_file
self._log_command(description)
self._run_s(_prepend_to_file, timeout, description,
r_file, data, run_as_root)
def read_file_from(self, remote_file, run_as_root=False, timeout=None):
description = _('Reading file "%s"') % remote_file
self._log_command(description)