From 4abd2a3345c7c3cf43905092786ff2a2b4677384 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 11 Nov 2024 13:02:02 +0100 Subject: [PATCH 1/6] Use the GPL-3.0-only license tag instead of deprecated GPL-3.0 --- smart_proxy_ansible.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smart_proxy_ansible.gemspec b/smart_proxy_ansible.gemspec index 431a6c4..1c8692b 100644 --- a/smart_proxy_ansible.gemspec +++ b/smart_proxy_ansible.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |gem| gem.extra_rdoc_files = ['README.md', 'LICENSE'] gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ['lib'] - gem.license = 'GPL-3.0' + gem.license = 'GPL-3.0-only' gem.required_ruby_version = '>= 2.5' gem.add_development_dependency 'rake', '~> 13.0' From 46c7b22b8feee553a7fd58b5977821b581c0f3b6 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 11 Nov 2024 13:04:10 +0100 Subject: [PATCH 2/6] Raise minimum Ruby version to 2.7 --- smart_proxy_ansible.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smart_proxy_ansible.gemspec b/smart_proxy_ansible.gemspec index 1c8692b..6e93879 100644 --- a/smart_proxy_ansible.gemspec +++ b/smart_proxy_ansible.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ['lib'] gem.license = 'GPL-3.0-only' - gem.required_ruby_version = '>= 2.5' + gem.required_ruby_version = '>= 2.7' gem.add_development_dependency 'rake', '~> 13.0' gem.add_development_dependency('mocha', '~> 1') From 79bf2a9caeae14d8f21022ed30eff5064d175a14 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 11 Nov 2024 13:06:34 +0100 Subject: [PATCH 3/6] Remove unused net-ssh runtime dependency This has been unused since c7cad93ea0f8eabad4f3ce12df92426b05069242. Fixes: c7cad93ea0f8 ("Fixes #32709 - Drop all code related to ansible-playbook") --- smart_proxy_ansible.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/smart_proxy_ansible.gemspec b/smart_proxy_ansible.gemspec index 6e93879..959b838 100644 --- a/smart_proxy_ansible.gemspec +++ b/smart_proxy_ansible.gemspec @@ -33,7 +33,6 @@ Gem::Specification.new do |gem| gem.add_development_dependency('rack-test', '~> 0') gem.add_development_dependency('logger') gem.add_development_dependency('smart_proxy') - gem.add_runtime_dependency('net-ssh') gem.add_runtime_dependency('smart_proxy_dynflow', '~> 0.8') gem.add_runtime_dependency('smart_proxy_remote_execution_ssh', '~> 0.4') end From f07cd3432260ab768fa4541a5d60c3dcffa74c95 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 11 Nov 2024 13:07:56 +0100 Subject: [PATCH 4/6] Remove redundant development dependencies mocha and smart_proxy are already specified in Gemfile and others aren't used at all. --- smart_proxy_ansible.gemspec | 5 ----- 1 file changed, 5 deletions(-) diff --git a/smart_proxy_ansible.gemspec b/smart_proxy_ansible.gemspec index 959b838..5644042 100644 --- a/smart_proxy_ansible.gemspec +++ b/smart_proxy_ansible.gemspec @@ -28,11 +28,6 @@ Gem::Specification.new do |gem| gem.required_ruby_version = '>= 2.7' gem.add_development_dependency 'rake', '~> 13.0' - gem.add_development_dependency('mocha', '~> 1') - gem.add_development_dependency('webmock', '~> 3') - gem.add_development_dependency('rack-test', '~> 0') - gem.add_development_dependency('logger') - gem.add_development_dependency('smart_proxy') gem.add_runtime_dependency('smart_proxy_dynflow', '~> 0.8') gem.add_runtime_dependency('smart_proxy_remote_execution_ssh', '~> 0.4') end From cbc0ce94247fec69e463072bf59a207ba66b2244 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 11 Nov 2024 12:55:37 +0100 Subject: [PATCH 5/6] Use GitHub Actions for CI --- .github/workflows/test.yml | 12 ++++++++++++ Gemfile | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..56ed051 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,12 @@ +name: CI + +on: pull_request + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + test: + name: Tests + uses: theforeman/actions/.github/workflows/smart_proxy_plugin.yml@v0 diff --git a/Gemfile b/Gemfile index 6642277..eadcb93 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,7 @@ source 'https://rubygems.org' gemspec group :development do - gem 'smart_proxy', git: 'https://github.com/theforeman/smart-proxy', - branch: 'develop' + gem 'smart_proxy', github: 'theforeman/smart-proxy', branch: ENV['SMART_PROXY_BRANCH'] #gem 'smart_proxy', path: '../smart-proxy' gem 'pry' gem 'pry-byebug' From 4f20065c673da3054da2d118320a3822e6847c1b Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 11 Nov 2024 16:30:38 +0100 Subject: [PATCH 6/6] Correct globbing code handling in tests This makes a change to always use glob_path in the runtime code so it can be easily stubbed in tests. Stubbing Dir.glob creates problems if other code also runs it. It also makes the tests more explicit by providing a correct path and asserting the resulting parsed result is correct. Previously it only returned filenames, which isn't how Dir.glob works. --- lib/smart_proxy_ansible/playbooks_reader.rb | 10 ++++++++-- lib/smart_proxy_ansible/roles_reader.rb | 2 +- test/playbooks_reader_test.rb | 15 +++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/smart_proxy_ansible/playbooks_reader.rb b/lib/smart_proxy_ansible/playbooks_reader.rb index f88db8b..e381240 100644 --- a/lib/smart_proxy_ansible/playbooks_reader.rb +++ b/lib/smart_proxy_ansible/playbooks_reader.rb @@ -14,13 +14,13 @@ def playbooks(playbooks_to_import) end def get_playbooks_names(collections_path) - Dir.glob("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| + glob_path("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| ReaderHelper.playbook_or_role_full_name(path) end end def read_collection_playbooks(collections_path, playbooks_to_import = nil) - Dir.glob("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| + glob_path("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| name = ReaderHelper.playbook_or_role_full_name(path) { name: name, @@ -31,6 +31,12 @@ def read_collection_playbooks(collections_path, playbooks_to_import = nil) message = "Could not read Ansible playbooks #{collections_path} - #{e.message}" raise ReadPlaybooksException, message end + + private + + def glob_path(path) + Dir.glob path + end end end end diff --git a/lib/smart_proxy_ansible/roles_reader.rb b/lib/smart_proxy_ansible/roles_reader.rb index b690caf..e6181da 100644 --- a/lib/smart_proxy_ansible/roles_reader.rb +++ b/lib/smart_proxy_ansible/roles_reader.rb @@ -44,7 +44,7 @@ def glob_path(path) end def read_collection_roles(collections_path) - Dir.glob("#{collections_path}/ansible_collections/*/*/roles/*").map do |path| + glob_path("#{collections_path}/ansible_collections/*/*/roles/*").map do |path| ReaderHelper.playbook_or_role_full_name(path) end rescue Errno::ENOENT, Errno::EACCES => e diff --git a/test/playbooks_reader_test.rb b/test/playbooks_reader_test.rb index 8190de1..5a1a026 100644 --- a/test/playbooks_reader_test.rb +++ b/test/playbooks_reader_test.rb @@ -54,24 +54,23 @@ class PlaybooksReaderTest < Minitest::Test end describe 'playbooks_names method' do - let(:playbooks_names) { %w[xprazak2.forklift_collection.freeipa_server.yml xprazak2.forklift_collection.upgrade.yaml] } before do - Dir.expects(:glob).with('/usr/share/ansible/collections/ansible_collections/*/*/playbooks/*').returns([]) - Dir.expects(:glob).with('/etc/ansible/collections/ansible_collections/*/*/playbooks/*').returns(playbooks_names) + Proxy::Ansible::PlaybooksReader.expects(:glob_path).with('/usr/share/ansible/collections/ansible_collections/*/*/playbooks/*').returns([]) + collection_playbooks = [ + '/etc/ansible/collections/ansible_collections/xprazak2/forklift_collection/playbooks/freeipa_server.yml', + '/etc/ansible/collections/ansible_collections/xprazak2/forklift_collection/playbooks/upgrade.yaml', + ] + Proxy::Ansible::PlaybooksReader.expects(:glob_path).with('/etc/ansible/collections/ansible_collections/*/*/playbooks/*').returns(collection_playbooks) end it 'should return playbooks names as an array' do res = Proxy::Ansible::PlaybooksReader.playbooks_names assert_equal Array, res.class - assert_equal 2, res.count end it 'should return playbooks names with no .yml or .yaml extension' do res = Proxy::Ansible::PlaybooksReader.playbooks_names - assert_equal Array, res.class - assert_equal 2, res.count - assert not(res.first.match(/.ya?ml/)) - assert not(res.last.match(/.ya?ml/)) + assert_equal %w[xprazak2.forklift_collection.freeipa_server xprazak2.forklift_collection.upgrade], res end end end