From bf788f78d90f9312f4d9a280e4befefb4d31f0b4 Mon Sep 17 00:00:00 2001 From: Gildas Le Nadan <3ntr0p13+github@gmail.com> Date: Wed, 18 Dec 2024 23:07:53 +1000 Subject: [PATCH 1/4] transcribed serverspec tests to goss --- goss/goss.yaml | 8 +++++++ goss/goss_docker.yaml | 10 +++++++++ goss/goss_ini2env.yaml | 7 ++++++ goss/goss_pimba.yaml | 14 ++++++++++++ goss/goss_pimusicbox.yaml | 46 +++++++++++++++++++++++++++++++++++++++ goss/goss_rclocal.yaml | 9 ++++++++ goss/goss_ssh.yaml | 6 +++++ goss/goss_system.yaml | 29 ++++++++++++++++++++++++ 8 files changed, 129 insertions(+) create mode 100644 goss/goss.yaml create mode 100644 goss/goss_docker.yaml create mode 100644 goss/goss_ini2env.yaml create mode 100644 goss/goss_pimba.yaml create mode 100644 goss/goss_pimusicbox.yaml create mode 100644 goss/goss_rclocal.yaml create mode 100644 goss/goss_ssh.yaml create mode 100644 goss/goss_system.yaml diff --git a/goss/goss.yaml b/goss/goss.yaml new file mode 100644 index 0000000..22c809d --- /dev/null +++ b/goss/goss.yaml @@ -0,0 +1,8 @@ +gossfile: + goss_docker.yaml: {} + goss_ini2env.yaml: {} + goss_pimba.yaml: {} + goss_pimusicbox.yaml: {} + goss_rclocal.yaml: {} + goss_ssh.yaml: {} + goss_system.yaml: {} diff --git a/goss/goss_docker.yaml b/goss/goss_docker.yaml new file mode 100644 index 0000000..7c878ce --- /dev/null +++ b/goss/goss_docker.yaml @@ -0,0 +1,10 @@ +package: + docker-ce: + installed: true + name: docker-ce + docker-ce-cli: + installed: true + containerd.io: + installed: true + docker-compose: + installed: true diff --git a/goss/goss_ini2env.yaml b/goss/goss_ini2env.yaml new file mode 100644 index 0000000..da6d317 --- /dev/null +++ b/goss/goss_ini2env.yaml @@ -0,0 +1,7 @@ +file: + /usr/local/bin/ini2env: + exists: true + mode: 755 + owner: root + group: root + filetype: file diff --git a/goss/goss_pimba.yaml b/goss/goss_pimba.yaml new file mode 100644 index 0000000..ca15f6c --- /dev/null +++ b/goss/goss_pimba.yaml @@ -0,0 +1,14 @@ +file: + /boot/pimba: + exists: true + filetype: directory + /boot/pimba/docker-compose.yaml: + exists: true + filetype: file + /etc/systemd/system/pimba.service: + exists: true + filetype: file + +service: + pimba.service: + enabled: true diff --git a/goss/goss_pimusicbox.yaml b/goss/goss_pimusicbox.yaml new file mode 100644 index 0000000..dc63271 --- /dev/null +++ b/goss/goss_pimusicbox.yaml @@ -0,0 +1,46 @@ +file: + # pimusicbox configuration + /boot/config/settings.ini: + exists: true + filetype: file + + # pimusicbox dependencies + /sbin/wpa_cli: + exists: true + # FIXME: it should be executable + filetype: file + /etc/wpa_supplicant: + exists: true + filetype: directory + + # pimusicbox directory + /opt/musicbox: + exists: true + mode: 755 + owner: root + group: root + filetype: directory + /opt/musicbox/startup.sh: + exists: true + mode: 755 + owner: root + group: root + filetype: file + /opt/musicbox/bin/network.sh: + exists: true + mode: 755 + owner: root + group: root + filetype: file + /opt/musicbox/bin/system.sh: + exists: true + mode: 755 + owner: root + group: root + filetype: file + /opt/musicbox/bin/setsound.sh: + exists: true + mode: 755 + owner: root + group: root + filetype: file diff --git a/goss/goss_rclocal.yaml b/goss/goss_rclocal.yaml new file mode 100644 index 0000000..21fcfd5 --- /dev/null +++ b/goss/goss_rclocal.yaml @@ -0,0 +1,9 @@ +file: + /etc/rc.local: + exists: true + mode: 755 + owner: root + group: root + filetype: file + # should not contain 'By default this script does nothing.' + contents: ['/opt/musicbox/startup.sh'] diff --git a/goss/goss_ssh.yaml b/goss/goss_ssh.yaml new file mode 100644 index 0000000..3ebdf29 --- /dev/null +++ b/goss/goss_ssh.yaml @@ -0,0 +1,6 @@ +package: + openssh-server: + installed: true +service: + ssh: + enabled: false diff --git a/goss/goss_system.yaml b/goss/goss_system.yaml new file mode 100644 index 0000000..c40fea1 --- /dev/null +++ b/goss/goss_system.yaml @@ -0,0 +1,29 @@ +file: + /etc/environment: + exists: true + owner: root + group: root + filetype: file + # readable by owner, group and others + contents: ['TZ=:/etc/localtime'] + /etc/init.d/resize2fs_once: + exists: false + /etc/fstab: + exists: true + owner: root + group: root + filetype: file + mode: 644 + contents: [ + 'LABEL=boot /boot', + 'LABEL=rootfs /' + ] + /boot/cmdline.txt: + exists: true + owner: root + group: root + filetype: file + # should not contain 'init=/usr/lib/raspi-config/init_resize.sh' + contents: [ + 'root=/dev/mmcblk0p2' + ] From e55d8731674cd2710edb5198fd5e12393a4069ee Mon Sep 17 00:00:00 2001 From: Gildas Le Nadan <3ntr0p13+github@gmail.com> Date: Wed, 18 Dec 2024 23:55:24 +1000 Subject: [PATCH 2/4] use goss to run tests rather than serverspec --- test.json | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/test.json b/test.json index 0196fe3..7a8c3e5 100644 --- a/test.json +++ b/test.json @@ -10,27 +10,14 @@ "image_type": "raspberrypi", "target_image_size" : 5368709120, "output_filename" : "/tmp/testimage", - "mount_path": "{{ user `img_mount_path` }}" + "mount_path": "{{ user `img_mount_path` }}", + "goss_version": "v0.4.9" }], "provisioners": [ - { - "type": "shell", - "inline": [ "mkdir -p /tmp/serverspec" ] - }, - { - "type": "file", - "source": "Rakefile", - "destination": "/tmp/serverspec/Rakefile" - }, - { - "type": "file", - "source": ".rspec", - "destination": "/tmp/serverspec/.rspec" - }, { "type": "file", - "source": "spec", - "destination": "/tmp/serverspec/" + "source": "goss", + "destination": "/tmp/" }, { "type": "shell", @@ -39,12 +26,8 @@ "LC_ALL=C" ], "inline": [ - "apt-get update", - "apt-get install -y ruby", - "gem install net-ssh -N -v 6.1.0", - "gem install rspec-its -N -v 1.3.1", - "gem install serverspec -N -v 2.41.8", - "cd /tmp/serverspec && rake spec" + "curl -L https://github.com/goss-org/goss/releases/download/{{ user `goss_version` }}/goss-linux-arm -o /tmp/goss-linux-arm && chmod a+x /tmp/goss-linux-arm", + "cd /tmp/goss && /tmp/goss-linux-arm validate --format documentation --color" ] } ], From 84b9c727a616d66c86dc80c0eeb324efb972d016 Mon Sep 17 00:00:00 2001 From: Gildas Le Nadan <3ntr0p13+github@gmail.com> Date: Wed, 18 Dec 2024 23:58:39 +1000 Subject: [PATCH 3/4] goss_version belongs in variables not builders --- test.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test.json b/test.json index 7a8c3e5..20ea445 100644 --- a/test.json +++ b/test.json @@ -1,7 +1,8 @@ { "variables": { "img_mount_path": "/mnt/pimbatest", - "sha256_checksum": "" + "sha256_checksum": "", + "goss_version": "v0.4.9" }, "builders": [{ "type": "arm-image", @@ -10,8 +11,7 @@ "image_type": "raspberrypi", "target_image_size" : 5368709120, "output_filename" : "/tmp/testimage", - "mount_path": "{{ user `img_mount_path` }}", - "goss_version": "v0.4.9" + "mount_path": "{{ user `img_mount_path` }}" }], "provisioners": [ { From d4184768fe9fe904f34f425430d17a6f95dd9f39 Mon Sep 17 00:00:00 2001 From: Gildas Le Nadan <3ntr0p13+github@gmail.com> Date: Thu, 19 Dec 2024 00:11:37 +1000 Subject: [PATCH 4/4] Remove serverspec. Fix whitespace damage and only expose the version for goss as version, removing the v --- .rspec | 2 -- Rakefile | 27 --------------- spec/localhost/docker_spec.rb | 18 ---------- spec/localhost/ini2env_spec.rb | 8 ----- spec/localhost/pimba_spec.rb | 19 ----------- spec/localhost/pimusicbox_spec.rb | 57 ------------------------------- spec/localhost/rclocal_spec.rb | 10 ------ spec/localhost/ssh_spec.rb | 9 ----- spec/localhost/system_spec.rb | 34 ------------------ spec/spec_helper.rb | 3 -- test.json | 4 +-- 11 files changed, 2 insertions(+), 189 deletions(-) delete mode 100644 .rspec delete mode 100644 Rakefile delete mode 100644 spec/localhost/docker_spec.rb delete mode 100644 spec/localhost/ini2env_spec.rb delete mode 100644 spec/localhost/pimba_spec.rb delete mode 100644 spec/localhost/pimusicbox_spec.rb delete mode 100644 spec/localhost/rclocal_spec.rb delete mode 100644 spec/localhost/ssh_spec.rb delete mode 100644 spec/localhost/system_spec.rb delete mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec deleted file mode 100644 index e5d704c..0000000 --- a/.rspec +++ /dev/null @@ -1,2 +0,0 @@ ---format documentation ---require './spec/spec_helper' diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 11ba867..0000000 --- a/Rakefile +++ /dev/null @@ -1,27 +0,0 @@ -require 'rake' -require 'rspec/core/rake_task' - -task :spec => 'spec:all' -task :default => :spec - -namespace :spec do - targets = [] - Dir.glob('./spec/*').each do |dir| - next unless File.directory?(dir) - target = File.basename(dir) - target = "_#{target}" if target == "default" - targets << target - end - - task :all => targets - task :default => :all - - targets.each do |target| - original_target = target == "_default" ? target[1..-1] : target - desc "Run serverspec tests to #{original_target}" - RSpec::Core::RakeTask.new(target.to_sym) do |t| - ENV['TARGET_HOST'] = original_target - t.pattern = "spec/#{original_target}/*_spec.rb" - end - end -end diff --git a/spec/localhost/docker_spec.rb b/spec/localhost/docker_spec.rb deleted file mode 100644 index b916e57..0000000 --- a/spec/localhost/docker_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -context 'docker' do - describe package('docker-ce') do - it { should be_installed } - end - - describe package('docker-ce-cli') do - it { should be_installed } - end - - describe package('containerd.io') do - it { should be_installed } - end - - describe package('docker-compose') do - it { should be_installed } - end - -end diff --git a/spec/localhost/ini2env_spec.rb b/spec/localhost/ini2env_spec.rb deleted file mode 100644 index 5f7cede..0000000 --- a/spec/localhost/ini2env_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -context 'ini2env' do - describe file('/usr/local/bin/ini2env') do - it { should be_file } - it { should be_mode 755 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - end -end diff --git a/spec/localhost/pimba_spec.rb b/spec/localhost/pimba_spec.rb deleted file mode 100644 index 71b47e2..0000000 --- a/spec/localhost/pimba_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -context 'pimba' do - - describe file('/boot/pimba') do - it { should be_directory } - end - - describe file('/boot/pimba/docker-compose.yaml') do - it { should be_file } - end - - describe file('/etc/systemd/system/pimba.service') do - it { should be_file } - end - - describe service('pimba.service') do - it { should be_enabled } - end - -end diff --git a/spec/localhost/pimusicbox_spec.rb b/spec/localhost/pimusicbox_spec.rb deleted file mode 100644 index e2b14e2..0000000 --- a/spec/localhost/pimusicbox_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -context 'pimusicbox configuration' do - describe file('/boot/config/settings.ini') do - it { should be_file } - end -end - -context 'pimusicbox dependencies' do - - describe file('/sbin/wpa_cli') do - it { should be_file } - it { should be_executable } - end - - describe file('/etc/wpa_supplicant/') do - it { should be_directory } - end - -end - -context 'pimusicbox directory' do - - describe file('/opt/musicbox') do - it { should be_directory } - it { should be_mode 755 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - end - - describe file('/opt/musicbox/startup.sh') do - it { should be_file } - it { should be_mode 755 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - end - - describe file('/opt/musicbox/bin/network.sh') do - it { should be_file } - it { should be_mode 755 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - end - - describe file('/opt/musicbox/bin/system.sh') do - it { should be_file } - it { should be_mode 755 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - end - - describe file('/opt/musicbox/bin/setsound.sh') do - it { should be_file } - it { should be_mode 755 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - end - -end diff --git a/spec/localhost/rclocal_spec.rb b/spec/localhost/rclocal_spec.rb deleted file mode 100644 index 1b5d021..0000000 --- a/spec/localhost/rclocal_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -context 'rc.local' do - describe file('/etc/rc.local') do - it { should be_file } - it { should be_mode 755 } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should_not contain 'By default this script does nothing.' } - it { should contain '/opt/musicbox/startup.sh' } - end -end diff --git a/spec/localhost/ssh_spec.rb b/spec/localhost/ssh_spec.rb deleted file mode 100644 index e884328..0000000 --- a/spec/localhost/ssh_spec.rb +++ /dev/null @@ -1,9 +0,0 @@ -context 'ssh' do - describe package('openssh-server') do - it { should be_installed } - end - - describe service('ssh') do - it { should_not be_enabled } - end -end diff --git a/spec/localhost/system_spec.rb b/spec/localhost/system_spec.rb deleted file mode 100644 index 2d4aee9..0000000 --- a/spec/localhost/system_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -context 'system' do - - describe file('/etc/environment') do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_readable.by('owner') } - it { should be_readable.by('group') } - it { should be_readable.by('others') } - it { should contain 'TZ=:/etc/localtime' } - end - - describe file('/etc/init.d/resize2fs_once') do - it { should_not exist } - end - - describe file('/etc/fstab') do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should be_mode 644 } - it { should contain 'LABEL=boot /boot' } - it { should contain 'LABEL=rootfs /' } - end - - describe file('/boot/cmdline.txt') do - it { should be_file } - it { should be_owned_by 'root' } - it { should be_grouped_into 'root' } - it { should contain 'root=/dev/mmcblk0p2' } - it { should_not contain 'init=/usr/lib/raspi-config/init_resize.sh' } - end - -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index 37af1b4..0000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'serverspec' - -set :backend, :exec diff --git a/test.json b/test.json index 20ea445..0def2f3 100644 --- a/test.json +++ b/test.json @@ -2,7 +2,7 @@ "variables": { "img_mount_path": "/mnt/pimbatest", "sha256_checksum": "", - "goss_version": "v0.4.9" + "goss_version": "0.4.9" }, "builders": [{ "type": "arm-image", @@ -26,7 +26,7 @@ "LC_ALL=C" ], "inline": [ - "curl -L https://github.com/goss-org/goss/releases/download/{{ user `goss_version` }}/goss-linux-arm -o /tmp/goss-linux-arm && chmod a+x /tmp/goss-linux-arm", + "curl -L https://github.com/goss-org/goss/releases/download/v{{ user `goss_version` }}/goss-linux-arm -o /tmp/goss-linux-arm && chmod a+x /tmp/goss-linux-arm", "cd /tmp/goss && /tmp/goss-linux-arm validate --format documentation --color" ] }