Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions .github/workflows/publish-gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -30,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}}"
20 changes: 18 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 21 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
72 changes: 72 additions & 0 deletions integration/ona_spec.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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