From 5b90157f3d98feabbef4999cede5590c88e3870d Mon Sep 17 00:00:00 2001 From: Carlos Barria Date: Mon, 13 Jan 2025 15:49:36 -0300 Subject: [PATCH] (role/laserrpi) add new udev rule ttyusb --- hieradata/role/laserrpi.yaml | 2 +- site/profile/manifests/pi/ttyusb.pp | 16 ++++++++++++++++ spec/classes/pi/ttyusb_spec.rb | 15 +++++++++++++++ spec/hosts/roles/laserrpi_spec.rb | 2 +- spec/support/spec/ttyusb.rb | 11 +++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 site/profile/manifests/pi/ttyusb.pp create mode 100644 spec/classes/pi/ttyusb_spec.rb create mode 100644 spec/support/spec/ttyusb.rb diff --git a/hieradata/role/laserrpi.yaml b/hieradata/role/laserrpi.yaml index c56dc8af09..f00cfa1b71 100644 --- a/hieradata/role/laserrpi.yaml +++ b/hieradata/role/laserrpi.yaml @@ -4,8 +4,8 @@ classes: - "profile::core::docker" - "profile::core::gpio" - "profile::pi::add_usb" - - "profile::pi::ftdi" - "profile::pi::pigpio" + - "profile::pi::ttyusb" - "profile::ts::dco" files: diff --git a/site/profile/manifests/pi/ttyusb.pp b/site/profile/manifests/pi/ttyusb.pp new file mode 100644 index 0000000000..96a4bac23d --- /dev/null +++ b/site/profile/manifests/pi/ttyusb.pp @@ -0,0 +1,16 @@ +# @summary +# Manages the permissions group for rpi USB devices +# +class profile::pi::ttyusb { + if defined(Class['profile::core::docker']) { + $group = Class['profile::core::docker']['socket_group'] + } else { + $group = '70014' + } + + systemd::udev::rule { '90-tty-usb.rules': + rules => [ + "KERNEL==\"ttyUSB[0-9]*\", GROUP=\"${group}\", MODE=\"0660\"", + ], + } +} diff --git a/spec/classes/pi/ttyusb_spec.rb b/spec/classes/pi/ttyusb_spec.rb new file mode 100644 index 0000000000..6cf39e5154 --- /dev/null +++ b/spec/classes/pi/ttyusb_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'profile::pi::ttyusb' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile.with_all_deps } + + include_examples 'ttyusb' + end + end +end diff --git a/spec/hosts/roles/laserrpi_spec.rb b/spec/hosts/roles/laserrpi_spec.rb index cadaa8776c..e15fe22972 100644 --- a/spec/hosts/roles/laserrpi_spec.rb +++ b/spec/hosts/roles/laserrpi_spec.rb @@ -33,7 +33,7 @@ include_examples 'docker' include_examples('gpio', os_facts:) include_examples 'pigpio' - include_examples 'ftdi' + include_examples 'ttyusb' include_examples 'dco' include_examples 'add_usb' diff --git a/spec/support/spec/ttyusb.rb b/spec/support/spec/ttyusb.rb new file mode 100644 index 0000000000..72acf12973 --- /dev/null +++ b/spec/support/spec/ttyusb.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +shared_examples 'ttyusb' do + it do + is_expected.to contain_systemd__udev__rule('90-tty-usb.rules').with( + rules: [ + 'KERNEL=="ttyUSB[0-9]*", GROUP="70014", MODE="0660"', + ] + ) + end +end