-
Notifications
You must be signed in to change notification settings - Fork 3
add trivial acceptance tests #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| require 'spec_helper_acceptance' | ||
|
|
||
| describe 'basic installation' do | ||
| it_behaves_like 'an idempotent resource' do | ||
| let(:manifest) do | ||
| <<-PUPPET | ||
| include iop_advisor_engine | ||
| PUPPET | ||
| end | ||
| end | ||
|
|
||
| include_examples 'the default iop-advisor-engine application' | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| class { 'foreman::repo': | ||
| repo => 'nightly', | ||
| } | ||
|
|
||
| stdlib::ensure_packages(['podman']) | ||
|
|
||
| $container_file = "[Unit] | ||
| Description=Advisor Engine | ||
| After=network-online.target | ||
| [Container] | ||
| Image=registry.access.redhat.com/ubi9/python-312 | ||
| Exec=python /usr/local/bin/python-https-server | ||
|
Comment on lines
+11
to
+12
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is obviously still a fake, but a much more elaborate one :D We should be able to replace this with the "real" deal once a build is available. |
||
| Network=host | ||
| Volume=/usr/local/bin/python-https-server:/usr/local/bin/python-https-server | ||
| [Service] | ||
| Restart=always | ||
| [Install] | ||
| WantedBy=default.target | ||
| " | ||
|
|
||
| $python_server = " | ||
| from http.server import HTTPServer, SimpleHTTPRequestHandler | ||
| import ssl | ||
| import os | ||
| context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) | ||
| context.load_cert_chain(certfile='/opt/app-root/src/cert.pem', keyfile='/opt/app-root/src/key.pem') | ||
| context.check_hostname = False | ||
| port=int(os.environ.get('IOP_ADVISOR_ENGINE_PORT', 8000)) | ||
| with HTTPServer(('localhost', port), SimpleHTTPRequestHandler) as httpd: | ||
| httpd.socket = context.wrap_socket(httpd.socket, server_side=True) | ||
| httpd.serve_forever() | ||
| " | ||
|
|
||
| file { '/etc/containers/systemd/iop-advisor-engine.container': | ||
| ensure => present, | ||
| content => $container_file, | ||
| require => Package['podman'], | ||
| } | ||
|
|
||
| file { '/usr/local/bin/python-https-server': | ||
| ensure => present, | ||
| content => $python_server, | ||
| } | ||
|
|
||
| file { '/etc/foreman-proxy': | ||
| ensure => directory, | ||
| } | ||
|
|
||
| group { 'foreman-proxy': | ||
| ensure => present, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # https://github.com/mizzy/serverspec/pull/611 was rejected so adding it here. | ||
|
||
| begin | ||
| require 'serverspec' | ||
|
|
||
| module Serverspec | ||
| module Type | ||
| class CurlCommand < Command | ||
| def response_code | ||
| m = /Response-Code: (?<code>\d+)/.match(stderr) | ||
| return 0 unless m | ||
| m[:code].to_i | ||
| end | ||
|
|
||
| def body | ||
| command_result.stdout | ||
| end | ||
|
|
||
| def body_as_json | ||
| MultiJson.load(body) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def curl_command | ||
| # curl on EL8 is too old to support --write-out %stderr | ||
| command = "/opt/puppetlabs/puppet/bin/curl --silent --write-out '%{stderr}Response-Code: %{response_code}\\n' '#{@name}'" | ||
|
||
|
|
||
| @options.each do |option, value| | ||
| case option | ||
| when :cacert, :cert, :key | ||
| command += " --#{option} '#{value}'" | ||
| when :headers | ||
| value.each do |header, header_value| | ||
| if header_value | ||
| command += " --header '#{header}: #{header_value}'" | ||
| else | ||
| command += " --header '#{header};'" | ||
| end | ||
| end | ||
| else | ||
| raise "Unknown option #{option} (value: #{value})" | ||
| end | ||
| end | ||
|
|
||
| command | ||
| end | ||
|
|
||
| def command_result | ||
| @command_result ||= @runner.run_command(curl_command) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| module Helper | ||
| module Type | ||
| def curl_command(*args) | ||
| Serverspec::Type::CurlCommand.new(*args) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| rescue LoadError | ||
| # serverspec not present - usually in unit tests | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| shared_examples 'the default iop-advisor-engine application' do | ||
| engine_port = 8000 | ||
|
|
||
| describe port(engine_port) do | ||
| it { is_expected.to be_listening } | ||
| end | ||
|
|
||
| # FIXME: this needs to call the right "ping" endpoint once we have one | ||
| describe curl_command("https://localhost:#{engine_port}/", cacert: "/etc/pki/katello/certs/katello-default-ca.crt") do | ||
| its(:response_code) { is_expected.to eq(200) } | ||
| its(:exit_status) { is_expected.to eq 0 } | ||
| end | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.