From a82578526aecb2ce6562f4285756a7684adfc52e Mon Sep 17 00:00:00 2001 From: David Sullivan Date: Fri, 14 Feb 2020 15:39:23 -0500 Subject: [PATCH] Apply PTP configuration at runtime Allow PTP configuration to be applied at runtime. Introduce a new runtime class in the ptp manifest. Closes-Bug: 1861726 Story: 2006759 Task: 38771 Change-Id: I279cf4f9bf72e19981d4204e8e3b4bab8dcd7ff3 Signed-off-by: David Sullivan --- .../src/modules/platform/manifests/ptp.pp | 64 +++++++++++++------ .../modules/platform/templates/phc2sys.erb | 2 +- .../platform/templates/phc2sys.service.erb | 2 +- .../platform/templates/ptp4l.service.erb | 2 +- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/puppet-manifests/src/modules/platform/manifests/ptp.pp b/puppet-manifests/src/modules/platform/manifests/ptp.pp index d20c84acd..d1cfcb391 100644 --- a/puppet-manifests/src/modules/platform/manifests/ptp.pp +++ b/puppet-manifests/src/modules/platform/manifests/ptp.pp @@ -4,7 +4,8 @@ class platform::ptp ( $transport = 'L2', $phc2sys_options = '', $master_devices = [], - $slave_devices = [] + $slave_devices = [], + $runtime = false ) { if empty($master_devices) { $slave_only = true @@ -12,15 +13,32 @@ class platform::ptp ( $slave_only = false } + if $enabled { + $ensure = 'running' + $enable = true + } else { + $ensure = 'stopped' + $enable = false + } + + if $runtime { + # During runtime we set first_step_threshold to 0. This ensures there are no + # large time changes to a running host + $phc2sys_cmd_opts = "${phc2sys_options} -F 0" + } else { + $phc2sys_cmd_opts = $phc2sys_options + } + file { 'ptp4l_config': ensure => file, path => '/etc/ptp4l.conf', mode => '0644', content => template('platform/ptp4l.conf.erb'), + notify => [ Service['phc2sys'], Service['ptp4l'] ], } -> file { 'ptp4l_service': ensure => file, - path => '/usr/lib/systemd/system/ptp4l.service', + path => '/etc/systemd/system/ptp4l.service', mode => '0644', content => template('platform/ptp4l.service.erb'), } @@ -32,7 +50,7 @@ class platform::ptp ( } -> file { 'phc2sys_service': ensure => file, - path => '/usr/lib/systemd/system/phc2sys.service', + path => '/etc/systemd/system/phc2sys.service', mode => '0644', content => template('platform/phc2sys.service.erb'), } @@ -41,33 +59,33 @@ class platform::ptp ( path => '/etc/sysconfig/phc2sys', mode => '0644', content => template('platform/phc2sys.erb'), + notify => Service['phc2sys'], } -> exec { 'systemctl-daemon-reload': - command => '/usr/bin/systemctl daemon-reload', + command => '/usr/bin/systemctl daemon-reload', + } + -> service { 'ptp4l': + ensure => $ensure, + enable => $enable, + name => 'ptp4l', + hasstatus => true, + hasrestart => true, + } + -> service { 'phc2sys': + ensure => $ensure, + enable => $enable, + name => 'phc2sys', + hasstatus => true, + hasrestart => true, } - if $enabled { exec { 'enable-ptp4l': command => '/usr/bin/systemctl enable ptp4l.service', - require => Exec['systemctl-daemon-reload'], + require => Service['phc2sys'], } -> exec { 'enable-phc2sys': command => '/usr/bin/systemctl enable phc2sys.service', } - -> service { 'ptp4l': - ensure => 'running', - enable => true, - name => 'ptp4l', - hasstatus => true, - hasrestart => true, - } - -> service { 'phc2sys': - ensure => 'running', - enable => true, - name => 'phc2sys', - hasstatus => true, - hasrestart => true, - } } else { exec { 'disable-ptp4l': command => '/usr/bin/systemctl disable ptp4l.service', @@ -76,7 +94,7 @@ class platform::ptp ( -> exec { 'disable-phc2sys': command => '/usr/bin/systemctl disable phc2sys.service', } - exec { 'stop-ptp4l': + -> exec { 'stop-ptp4l': command => '/usr/bin/systemctl stop ptp4l.service', } -> exec { 'stop-phc2sys': @@ -84,3 +102,7 @@ class platform::ptp ( } } } + +class platform::ptp::runtime { + class { 'platform::ptp': runtime => true } +} diff --git a/puppet-manifests/src/modules/platform/templates/phc2sys.erb b/puppet-manifests/src/modules/platform/templates/phc2sys.erb index 93a7adc67..6523013d7 100644 --- a/puppet-manifests/src/modules/platform/templates/phc2sys.erb +++ b/puppet-manifests/src/modules/platform/templates/phc2sys.erb @@ -1 +1 @@ -OPTIONS="-a -r -f /etc/ptp4l.conf <%= @phc2sys_options %>" +OPTIONS="-a -r -f /etc/ptp4l.conf <%= @phc2sys_cmd_opts %>" diff --git a/puppet-manifests/src/modules/platform/templates/phc2sys.service.erb b/puppet-manifests/src/modules/platform/templates/phc2sys.service.erb index 5af0e3a2e..02cf492c0 100644 --- a/puppet-manifests/src/modules/platform/templates/phc2sys.service.erb +++ b/puppet-manifests/src/modules/platform/templates/phc2sys.service.erb @@ -5,7 +5,7 @@ After=ptp4l.service [Service] Type=simple EnvironmentFile=-/etc/sysconfig/phc2sys -ExecStart=-/usr/sbin/phc2sys $OPTIONS +ExecStart=/usr/sbin/phc2sys $OPTIONS ExecStartPost=/bin/bash -c 'echo $MAINPID > /var/run/phc2sys.pid' ExecStopPost=/bin/rm -f /var/run/phc2sys.pid Restart=on-failure diff --git a/puppet-manifests/src/modules/platform/templates/ptp4l.service.erb b/puppet-manifests/src/modules/platform/templates/ptp4l.service.erb index 87b749f06..342340712 100644 --- a/puppet-manifests/src/modules/platform/templates/ptp4l.service.erb +++ b/puppet-manifests/src/modules/platform/templates/ptp4l.service.erb @@ -6,7 +6,7 @@ Wants=network-online.target [Service] Type=simple EnvironmentFile=-/etc/sysconfig/ptp4l -ExecStart=-/usr/sbin/ptp4l $OPTIONS +ExecStart=/usr/sbin/ptp4l $OPTIONS ExecStartPost=/bin/bash -c 'echo $MAINPID > /var/run/ptp4l.pid' ExecStopPost=/bin/rm -f /var/run/ptp4l.pid Restart=on-failure