From 3f7df5a91060e74698ad41729557588c16d52ea7 Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Sun, 2 Feb 2025 14:36:03 +0100 Subject: [PATCH 1/4] ci: Configure setup-ruby action properly --- .github/workflows/publish-gem.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish-gem.yml b/.github/workflows/publish-gem.yml index 18956f9..c37ece5 100644 --- a/.github/workflows/publish-gem.yml +++ b/.github/workflows/publish-gem.yml @@ -17,6 +17,9 @@ jobs: - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true - name: Publish to GPR run: | From 333b94e3c36597b36deb5e0ac21323c03d829152 Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Sun, 2 Feb 2025 15:28:12 +0100 Subject: [PATCH 2/4] ci: Disable publishing to RubyGems --- .github/workflows/publish-gem.yml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish-gem.yml b/.github/workflows/publish-gem.yml index c37ece5..70383bf 100644 --- a/.github/workflows/publish-gem.yml +++ b/.github/workflows/publish-gem.yml @@ -33,13 +33,14 @@ jobs: GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}" OWNER: ${{ github.repository_owner }} - - name: Publish to RubyGems - run: | - mkdir -p $HOME/.gem - touch $HOME/.gem/credentials - chmod 0600 $HOME/.gem/credentials - printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials - gem build *.gemspec - gem push *.gem - env: - GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" + # Disable for now. May not be automatable because of 2FA + # - name: Publish to RubyGems + # run: | + # mkdir -p $HOME/.gem + # touch $HOME/.gem/credentials + # chmod 0600 $HOME/.gem/credentials + # printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + # gem build *.gemspec + # gem push *.gem + # env: + # GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" From fe957e127759047fdd87610e70f122a8b9432c4b Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Sun, 2 Feb 2025 17:24:58 +0100 Subject: [PATCH 3/4] test: Add integration testing --- Rakefile | 22 ++++++++++++- integration/ona_spec.rb | 72 +++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 2 ++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 integration/ona_spec.rb diff --git a/Rakefile b/Rakefile index daf3f11..2442f72 100644 --- a/Rakefile +++ b/Rakefile @@ -9,4 +9,24 @@ RuboCop::RakeTask.new do |task| end RSpec::Core::RakeTask.new(:spec) -task default: %i[rubocop spec] +task default: %i[rubocop spec integration] + +desc 'Build the ONA development container with podman' +task :build_onadev_container do + unless system('podman image exists localhost/ona-dev:latest') + `podman login docker.io` + `git clone https://github.com/opennetadmin/ona onadev` + `podman build --build-arg UBUNTU_VERSION=24.04 -t ona-dev:latest onadev` + `rm -rf onadev` + end +end + +desc 'Publish ONA development container to ghcr.io' +task publish_onadev_container_to_ghcr: :build_onadev_container do + `podman login ghcr.io` + `podman image push localhost/ona-dev:latest docker://ghcr.io/gsi-hpc/ona-dev:latest` +end + +RSpec::Core::RakeTask.new(:integration) do |task| + task.pattern = 'integration/**{,/*/**}/*_spec.rb' +end diff --git a/integration/ona_spec.rb b/integration/ona_spec.rb new file mode 100644 index 0000000..cd576cc --- /dev/null +++ b/integration/ona_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'ona' +require 'net/http' + +# Generate new port number each time asked +class PortManager + @next_port = 11_080 + + def self.next_port + port = @next_port + @next_port += 1 + port + end +end + +def with_retries(max_retries = 30) + (1..max_retries).each do + begin + yield + return + rescue StandardError + # do nothing + end + sleep(0.2) + end + raise "max retries #{max_retries} reached, aborting" +end + +def ephemeral_onadev_container + host = 'localhost' + port = PortManager.next_port + container_prefix = 'onadev_' + dcm_path = '/ona/dcm.php' + @dcm_endpoint = "http://#{host}:#{port}#{dcm_path}" + name = "#{container_prefix}#{port}" + + # define and start ephemeral (--rm) container + `podman container create -p #{port}:80 --name #{name} --rm docker://ghcr.io/gsi-hpc/ona-dev:latest` + `podman container start #{name}` + + # wait for webserver + with_retries do + res = Net::HTTP.start(host, port).get(dcm_path) + raise unless res.is_a?(Net::HTTPSuccess) + end + + yield +ensure + `podman container kill #{name}` +end + +describe ONA do + subject(:ona) { described_class.new(@dcm_endpoint, 'admin', 'admin') } # rubocop:disable RSpec/InstanceVariable + + around { |ex| ephemeral_onadev_container(&ex) } + + describe 'get_module_list' do + subject(:result) { ona.query('get_module_list', { type: 'array' }) } + + it 'returns the module list' do + expect(result).to be_an_instance_of(Hash).and \ + include('domain_display') + end + end + + describe 'domain_display' do + subject(:result) { ona.query('domain_display', { domain: 'example.com' }) } + + it { is_expected.to include('fqdn' => 'example.com') } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b43258b..ffad16b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,4 +29,6 @@ # inherited by the metadata hash of host groups and examples, rather than # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups + + config.formatter = :documentation end From a27ebf15b8e53e6b5bdf3ab558574097be44afbb Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Mon, 3 Feb 2025 12:38:39 +0100 Subject: [PATCH 4/4] ci: Run integration testing in separate job --- .github/workflows/test.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 97df996..f7b3f4d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,5 +24,21 @@ jobs: with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - - name: Run tests - run: bundle exec rake + - name: Run Rubocop + run: bundle exec rake rubocop + - name: Run Unit Tests + run: bundle exec rake spec + + integration: + runs-on: ubuntu-latest + name: Integration + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.4' + bundler-cache: true + - name: Run Integration Tests + run: bundle exec rake integration