From d0ee5c2cf417987a89150059d9cc3082de649598 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Fri, 22 Jun 2018 21:28:02 +0200 Subject: [PATCH] Add beaker tests for nodepool Add tests for the nodepool launcher and builder. Since by default this uses the nodepool configuration found in openstack-infra/project-config, fudge the hostnames so that it can find a real config file. Depends-On: https://review.openstack.org/577519 Change-Id: I036c1afc0414f846c9112ef5bc5f3abd486f3147 --- .../nodepool/builder-postconditions.pp | 3 ++ .../nodepool/builder-preconditions.pp | 16 ++++++ spec/acceptance/fixtures/nodepool/builder.pp | 16 ++++++ .../nodepool/launcher-postconditions.pp | 3 ++ .../nodepool/launcher-preconditions.pp | 8 +++ spec/acceptance/fixtures/nodepool/launcher.pp | 17 +++++++ spec/acceptance/nodepool_builder_spec.rb | 51 +++++++++++++++++++ spec/acceptance/nodepool_launcher_spec.rb | 51 +++++++++++++++++++ 8 files changed, 165 insertions(+) create mode 100644 spec/acceptance/fixtures/nodepool/builder-postconditions.pp create mode 100644 spec/acceptance/fixtures/nodepool/builder-preconditions.pp create mode 100644 spec/acceptance/fixtures/nodepool/builder.pp create mode 100644 spec/acceptance/fixtures/nodepool/launcher-postconditions.pp create mode 100644 spec/acceptance/fixtures/nodepool/launcher-preconditions.pp create mode 100644 spec/acceptance/fixtures/nodepool/launcher.pp create mode 100644 spec/acceptance/nodepool_builder_spec.rb create mode 100644 spec/acceptance/nodepool_launcher_spec.rb diff --git a/spec/acceptance/fixtures/nodepool/builder-postconditions.pp b/spec/acceptance/fixtures/nodepool/builder-postconditions.pp new file mode 100644 index 0000000..7775d5f --- /dev/null +++ b/spec/acceptance/fixtures/nodepool/builder-postconditions.pp @@ -0,0 +1,3 @@ +service { 'nodepool-builder': + ensure => running, +} diff --git a/spec/acceptance/fixtures/nodepool/builder-preconditions.pp b/spec/acceptance/fixtures/nodepool/builder-preconditions.pp new file mode 100644 index 0000000..432d9cb --- /dev/null +++ b/spec/acceptance/fixtures/nodepool/builder-preconditions.pp @@ -0,0 +1,16 @@ +exec { 'change hostname': + command => '/bin/hostname nb03' +} + +host { 'nb01.openstack.org': + host_aliases => 'nb01', + ip => '127.0.1.1', +} + +# The cloud-utils package (specifically its euca2ools dependency) on an Ubuntu +# Trusty image created by DIB pulls in python[3]-six, which causes conflicts +# when used with pip 10. We don't need cloud-utils once the image has been +# built, so remove it and allow pip to manage six. +package { ['python-six', 'python3-six']: + ensure => absent, +} diff --git a/spec/acceptance/fixtures/nodepool/builder.pp b/spec/acceptance/fixtures/nodepool/builder.pp new file mode 100644 index 0000000..39de31b --- /dev/null +++ b/spec/acceptance/fixtures/nodepool/builder.pp @@ -0,0 +1,16 @@ +$public_key = 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEGQmNT7NQLsyTyFBJnYe5RR/yrvsE1VYB+hF6LmRjo14oiC7aZsmDhbe9JRRM/2JvDBhlGlM7bNcUmXAVSp0c8=' + +$clouds_yaml = '' + +class { '::openstackci::nodepool_builder': + nodepool_ssh_public_key => $public_key, + vhost_name => $::fqdn, + enable_build_log_via_http => true, + project_config_repo => 'https://git.openstack.org/openstack-infra/project-config', + oscc_file_contents => $clouds_yaml, + statsd_host => 'graphite.openstack.org', + upload_workers => '16', + revision => 'master', + python_version => 3, + zuulv3 => true, +} diff --git a/spec/acceptance/fixtures/nodepool/launcher-postconditions.pp b/spec/acceptance/fixtures/nodepool/launcher-postconditions.pp new file mode 100644 index 0000000..29936e9 --- /dev/null +++ b/spec/acceptance/fixtures/nodepool/launcher-postconditions.pp @@ -0,0 +1,3 @@ +service { 'nodepool-launcher': + ensure => running, +} diff --git a/spec/acceptance/fixtures/nodepool/launcher-preconditions.pp b/spec/acceptance/fixtures/nodepool/launcher-preconditions.pp new file mode 100644 index 0000000..161b8a8 --- /dev/null +++ b/spec/acceptance/fixtures/nodepool/launcher-preconditions.pp @@ -0,0 +1,8 @@ +exec { 'change hostname': + command => '/bin/hostname nl04' +} + +host { 'nl04.openstack.org': + host_aliases => 'nl04', + ip => '127.0.1.1', +} diff --git a/spec/acceptance/fixtures/nodepool/launcher.pp b/spec/acceptance/fixtures/nodepool/launcher.pp new file mode 100644 index 0000000..cd58145 --- /dev/null +++ b/spec/acceptance/fixtures/nodepool/launcher.pp @@ -0,0 +1,17 @@ +$private_key = '-----BEGIN EC PRIVATE KEY----- +MHcCAQEEILEJO9HQBHkih1m+w+VA9YmoKvuyeHlg8rE1M48swE2roAoGCCqGSM49 +AwEHoUQDQgAEQZCY1Ps1AuzJPIUEmdh7lFH/Ku+wTVVgH6EXouZGOjXiiILtpmyY +OFt70lFEz/Ym8MGGUaUzts1xSZcBVKnRzw== +-----END EC PRIVATE KEY-----' + +$clouds_yaml = '' + +class { '::openstackci::nodepool_launcher': + nodepool_ssh_private_key => $private_key, + project_config_repo => 'https://git.openstack.org/openstack-infra/project-config', + oscc_file_contents => $clouds_yaml, + statsd_host => 'graphite.openstack.org', + revision => 'master', + python_version => 3, + enable_webapp => true, +} diff --git a/spec/acceptance/nodepool_builder_spec.rb b/spec/acceptance/nodepool_builder_spec.rb new file mode 100644 index 0000000..b027e2f --- /dev/null +++ b/spec/acceptance/nodepool_builder_spec.rb @@ -0,0 +1,51 @@ +require 'puppet-openstack_infra_spec_helper/spec_helper_acceptance' + +describe 'nodepool builder', :if => ( + ['debian', 'ubuntu'].include?(os[:family]) && + # builder is not expected to work with python < 3.5 since its config + # depends on math.inf + os[:release] >= '16.04' + ) do + + def pp_path + base_path = File.dirname(__FILE__) + File.join(base_path, 'fixtures', 'nodepool') + end + + def preconditions_puppet_manifest + module_path = File.join(pp_path, 'builder-preconditions.pp') + File.read(module_path) + end + + def postconditions_puppet_manifest + module_path = File.join(pp_path, 'builder-postconditions.pp') + File.read(module_path) + end + + before(:all) do + apply_manifest(preconditions_puppet_manifest, catch_failures: true) + end + + def puppet_manifest + module_path = File.join(pp_path, 'builder.pp') + File.read(module_path) + end + + it 'should work with no errors' do + apply_manifest(puppet_manifest, catch_failures: true) + end + + it 'should be idempotent' do + apply_manifest(puppet_manifest, catch_changes: true) + end + + it 'should start' do + apply_manifest(postconditions_puppet_manifest, catch_failures: true) + end + + describe command("systemctl status nodepool-builder") do + its(:stdout) { should contain('Active: active') } + its(:stdout) { should_not contain('dead') } + end + +end diff --git a/spec/acceptance/nodepool_launcher_spec.rb b/spec/acceptance/nodepool_launcher_spec.rb new file mode 100644 index 0000000..78886d7 --- /dev/null +++ b/spec/acceptance/nodepool_launcher_spec.rb @@ -0,0 +1,51 @@ +require 'puppet-openstack_infra_spec_helper/spec_helper_acceptance' + +describe 'nodepool launcher', :if => ( + ['debian', 'ubuntu'].include?(os[:family]) && + # launcher is not expected to work with python < 3.5 since its config + # depends on math.inf + os[:release] >= '16.04' + ) do + + def pp_path + base_path = File.dirname(__FILE__) + File.join(base_path, 'fixtures', 'nodepool') + end + + def preconditions_puppet_manifest + module_path = File.join(pp_path, 'launcher-preconditions.pp') + File.read(module_path) + end + + def postconditions_puppet_manifest + module_path = File.join(pp_path, 'launcher-postconditions.pp') + File.read(module_path) + end + + before(:all) do + apply_manifest(preconditions_puppet_manifest, catch_failures: true) + end + + def puppet_manifest + module_path = File.join(pp_path, 'launcher.pp') + File.read(module_path) + end + + it 'should work with no errors' do + apply_manifest(puppet_manifest, catch_failures: true) + end + + it 'should be idempotent' do + apply_manifest(puppet_manifest, catch_changes: true) + end + + it 'should start' do + apply_manifest(postconditions_puppet_manifest, catch_failures: true) + end + + describe command("systemctl status nodepool-launcher") do + its(:stdout) { should contain('Active: active') } + its(:stdout) { should_not contain('dead') } + end + +end