[PTP dual NIC config] Puppet generate ptp configs

This commit adds the puppet manifests and templates required to generate
the ptp config files and start the ptp services.

The changes here are currently benign, as they are not included in the
system worker manifest at /etc/puppet/manifests/worker.pp

It is required to merge these changes without activating them in order
to support further development work.
A future commit will enable these changes once further development and
testing has been completed.

In order to test these changes, edit /etc/puppet/manifests/worker.pp
and add:
include ::platform::ptpinstance

Test Plan:

PASS: Build and deploy on hardware lab
PASS: Configure multiple ptp instances in virtual box and hardware lab

Regression:

PASS: The code in this commit has no effect until a subsequent commit
updates the worker manifest. Existing PTP functionality is unchanged at
this time.

Story: 2009248
Task: 43964

Depends-On: https://review.opendev.org/817822

Signed-off-by: Cole Walker <cole.walker@windriver.com>
Change-Id: Ie7d9f40fcd321577921c6899ef7e36105a0dec8d
This commit is contained in:
Cole Walker 2021-11-12 15:52:19 -05:00
parent 6b91bc5160
commit c6be1ca3a3
8 changed files with 210 additions and 0 deletions

View File

@ -0,0 +1,128 @@
define ptp_config_files(
$_name,
$service,
$global_parameters,
$interfaces,
$ensure,
$enable
) {
file { $_name:
ensure => file,
path => "/etc/${service}-${_name}.conf",
mode => '0644',
content => template('platform/ptpinstance.conf.erb')
}
-> service { $_name:
ensure => $ensure,
enable => $enable,
name => "${service}@${_name}",
hasstatus => true,
hasrestart => true,
}
if $enable {
exec { "enable-${_name}":
command => "/usr/bin/systemctl enable \
${service}@${_name}",
}
} else {
exec { "disable-${_name}":
command => "/usr/bin/systemctl disable \
${service}@${_name}",
require => Exec['systemctl-daemon-reload'],
}
-> exec { "stop-${_name}":
command => "/usr/bin/systemctl stop \
${service}@${_name}",
}
}
}
class platform::ptpinstance (
$enabled = false,
$runtime = false,
$config = []
) {
if $enabled {
$ptp_state = {
'ensure' => 'running',
'enable' => true
}
}
if $runtime {
# During runtime we set first_step_threshold to 0. This ensures that there are
# no large time changes to a running host
$phc2sys_cmd_opts = '-F 0'
} else {
$phc2sys_cmd_opts = ''
}
file { 'ptp4l_service':
ensure => file,
path => '/etc/systemd/system/ptp4l@.service',
mode => '0644',
content => template('platform/ptp4l-instance.service.erb')
}
-> file { 'ptp4l_sysconfig':
ensure => file,
path => '/etc/sysconfig/ptp4l-instance',
mode => '0644',
content => template('platform/ptp4l-instance.erb'),
}
-> file { 'phc2sys_service':
ensure => file,
path => '/etc/systemd/system/phc2sys@.service',
mode => '0644',
content => template('platform/phc2sys-instance.service.erb'),
}
-> file { 'phc2sys_sysconfig':
ensure => file,
path => '/etc/sysconfig/phc2sys-instance',
mode => '0644',
content => template('platform/phc2sys-instance.erb'),
}
-> file { 'ts2phc_service':
ensure => file,
path => '/etc/systemd/system/ts2phc@.service',
mode => '0644',
content => template('platform/ts2phc-instance.service.erb'),
}
-> file { 'ts2phc_sysconfig':
ensure => file,
path => '/etc/sysconfig/ts2phc-instance',
mode => '0644',
content => template('platform/ts2phc-instance.erb'),
}
-> exec { 'systemctl-daemon-reload':
command => '/usr/bin/systemctl daemon-reload',
}
if $enabled {
create_resources('ptp_config_files', $config, $ptp_state)
} else {
exec { 'disable-ptp4l':
command => '/usr/bin/systemctl disable ptp4l@*',
require => Exec['systemctl-daemon-reload'],
}
-> exec { 'disable-phc2sys':
command => '/usr/bin/systemctl disable phc2sys@*',
}
-> exec { 'disable-ts2phc':
command => '/usr/bin/systemctl disable ts2phc@*',
}
-> exec { 'stop-ptp4l':
command => '/usr/bin/systemctl stop ptp4l@*',
}
-> exec { 'stop-phc2sys':
command => '/usr/bin/systemctl stop phc2sys@*',
}
-> exec { 'stop-ts2phc':
command => '/usr/bin/systemctl stop ts2phc@*',
}
}
}
class platform::ptp::runtime {
class { 'platform::ptp': runtime => true }
}

View File

@ -0,0 +1 @@
OPTIONS="-a -r <%= @phc2sys_cmd_opts %>"

View File

@ -0,0 +1,17 @@
[Unit]
Description=Synchronize system clock or PTP hardware clock (PHC)
After=ptp4l.service
[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/phc2sys-instance
ExecStart=/usr/sbin/phc2sys -f /etc/phc2sys-%i.conf $OPTIONS
ExecStartPost=/bin/bash -c 'echo $MAINPID > /var/run/phc2sys-%i.pid'
ExecStopPost=/bin/rm -f /var/run/phc2sys-%i.pid
Restart=on-failure
RestartPreventExitStatus=SIGTERM SIGINT SIGKILL SIGABRT 255
CPUSchedulingPolicy=fifo
CPUSchedulingPriority=70
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1 @@
OPTIONS=""

View File

@ -0,0 +1,18 @@
[Unit]
Description=Precision Time Protocol (PTP) service
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/ptp4l-instance
ExecStart=/usr/sbin/ptp4l -f /etc/ptp4l-%i.conf $OPTIONS
ExecStartPost=/bin/bash -c 'echo $MAINPID > /var/run/ptp4l-%i.pid'
ExecStopPost=/bin/rm -f /var/run/ptp4l-%i.pid
Restart=on-failure
RestartPreventExitStatus=SIGTERM SIGINT SIGKILL SIGABRT 255
CPUSchedulingPolicy=fifo
CPUSchedulingPriority=70
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,26 @@
[global]
#
## Default Data Set
##
#<%- if @global_parameters -%>
#<%- @global_parameters.each do |key,value| -%>
#<%= key %> <%= value %>
#<%- end -%>
#<%- end -%>
#
#<%- if @interfaces -%>
#<%- @interfaces.each do |interface| %>
#<%- interface['port_names'].each do |port| -%>
#[<%= port %>]
##
## Associated interface: <%= interface['_ifname'] %>
##
#<%- interface['parameters'].each do |key,value| -%>
#<%= key %> <%= value %>
#
#
#
#<%- end -%>
#<%- end -%>
#<%- end -%>
#<%- end -%>

View File

@ -0,0 +1 @@
OPTIONS=""

View File

@ -0,0 +1,18 @@
[Unit]
Description=ts2phc service
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/ts2phc-instance
ExecStart=/usr/sbin/ts2phc -f /etc/ts2phc-%i.conf $OPTIONS
ExecStartPost=/bin/bash -c 'echo $MAINPID > /var/run/ts2phc-%i.pid'
ExecStopPost=/bin/rm -f /var/run/ts2phc-%i.pid
Restart=on-failure
RestartPreventExitStatus=SIGTERM SIGINT SIGKILL SIGABRT 255
CPUSchedulingPolicy=fifo
CPUSchedulingPriority=70
[Install]
WantedBy=multi-user.target