Skip to content

Commit

Permalink
Merge pull request #9 from canihavethisone/master
Browse files Browse the repository at this point in the history
Add openstack_project_id logic etc, expand example nodeset in readme
  • Loading branch information
genebean authored Jun 22, 2021
2 parents 46ddb67 + 15a5791 commit bb43275
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 14 deletions.
98 changes: 90 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,115 @@ We run beaker's base acceptance tests with this library to see if the hypervisor

2. `OPENSTACK_KEY` - Path to private key that is used to SSH into Openstack VMs

You will need two hosts with same platform. A template of what hosts file is below:
You will need at least two hosts defined in a nodeset file. An example comprehensive nodeset is below (note that not all parameters are required):

```yaml

HOSTS:
host-1:
master:
roles:
- agent
- master
- dashboard
- database
hypervisor: openstack
platform: <my_platform>
user: <host_username>
image: <host_image>
flavor: <host_flavor>
ssh:
user: cloud-user
password: <cloud-user_password>
auth_methods:
- password
- publickey
keys:
- <relative_path/public_key>
user_data: |
#cloud-config
output: {all: '| tee -a /var/log/cloud-init-output.log'}
disable_root: <True/False>
ssh_pwauth: <True/False>
chpasswd:
list: |
root:<root_password>
cloud-user:<cloud-user_password>
expire: False
runcmd:
- <my_optional_commands>
agent_1:
roles:
- agent
- master
- dashboard
- database
- default
host-2:
hypervisor: openstack
platform: <my_platform>
user: <host_username>
image: <host_image>
roles:
- agent
flavor: <host_flavor>
ssh:
user: cloud-user
password: <cloud-user_password>
auth_methods:
- publickey
keys:
- <relative_path/public_key>
number_of_password_prompts: 0
keepalive: true
keepalive_interval: 5
user_data: |
#cloud-config
output: {all: '| tee -a /var/log/cloud-init-output.log'}
disable_root: <True/False>
ssh_pwauth: <True/False>
chpasswd:
list: |
root:<root_password>
cloud-user:<cloud-user_password>
expire: False
runcmd:
- <my_optional_commands>
CONFIG:
log_level: <trace/debug/verbose/info/notify/warn>
trace_limit: 50
timesync: <true/false>
nfs_server: none
consoleport: 443
openstack_username: <insert_username>
openstack_api_key: <insert_password>
# openstack_project_name: <insert_project_name> # alternatively use openstack_project_id
openstack_project_id: <insert_id>
# openstack_user_domain: <insert user_domain> # alternatively use openstack_user_domain_id
openstack_user_domain_id: <insert_id>
# openstack_project_domain: <insert_project_domain> # alternatively use openstack_project_domain_id
openstack_project_domain_id: <insert_id>
openstack_auth_url: http://<keystone_ip>:5000/v3/
openstack_network: <insert_network>
openstack_keyname: <insert_key>
openstack_floating_ip: <true/false>
openstack_volume_support: <true/false>
security_group: ['default']
preserve_hosts: <always/onfail/onpass/never>
run_in_parallel: ['configure', 'install']
type: <foss/git/pe>
```
Note that when using _id parameters, you must also match the parameter type across the following when domain is specified:
- openstack_project_id
- openstack_user_domain_id
- openstack_project_domain_id
Further, you can opt to use a static master by setting the master's hypervisor to none, and identifying its location thus:
```yaml
hypervisor: none
hostname: <master_hostname>
vmhostname: <master_hostname>
ip: <master_ip>
```
Additional parameter information is available at https://github.com/voxpupuli/beaker/blob/master/docs/concepts/argument_processing_and_precedence.md
There is a simple rake task to invoke acceptance test for the library once the two environment variables are set:
```bash
bundle exec rake test:acceptance
Expand Down
34 changes: 28 additions & 6 deletions lib/beaker/hypervisor/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class Openstack < Beaker::Hypervisor
#@option options [String] :openstack_auth_url The URL to access the OpenStack instance with (required)
#@option options [String] :openstack_tenant The tenant to access the OpenStack instance with (either this or openstack_project_name is required)
#@option options [String] :openstack_project_name The project name to access the OpenStack instance with (either this or openstack_tenant is required)
#@option options [String] :openstack_project_id The project id to access the OpenStack instance with (alternative to openstack_project_name)
#@option options [String] :openstack_user_domain The user domain name to access the OpenStack instance with
#@option options [String] :openstack_user_domain_id The user domain id to access the OpenStack instance with (alternative to openstack_user_domain)
#@option options [String] :openstack_project_domain The project domain to access the OpenStack instance with
#@option options [String] :openstack_project_domain_id The project domain id to access the OpenStack instance with (alternative to openstack_project_domain)
#@option options [String] :openstack_region The region that each OpenStack instance should be provisioned on (optional)
#@option options [String] :openstack_network The network that each OpenStack instance should be contacted through (required)
#@option options [Bool] :openstack_floating_ip Whether a floating IP should be allocated (required)
Expand All @@ -38,16 +43,25 @@ def initialize(openstack_hosts, options)
raise 'You must specify whether a floating IP (:openstack_floating_ip) should be used for OpenStack instances!' unless !@options[:openstack_floating_ip].nil?

is_v3 = @options[:openstack_auth_url].include?('/v3/')
raise 'You must specify an Openstack project name (:openstack_project_name) for OpenStack instances!' if is_v3 and !@options[:openstack_project_name]
raise 'You must specify an Openstack tenant (:openstack_tenant) for OpenStack instances!' if !is_v3 and !@options[:openstack_tenant]
raise 'Invalid option specified: v3 API expects :openstack_project_name, not :openstack_tenant for OpenStack instances!' if is_v3 and @options[:openstack_tenant]
raise 'Invalid option specified: v2 API expects :openstack_tenant, not :openstack_project_name for OpenStack instances!' if !is_v3 and @options[:openstack_project_name]
raise 'You must specify an Openstack project name (:openstack_project_name) or Openstack project id (:openstack_project_id) for OpenStack instances!' if is_v3 and (!@options[:openstack_project_name] and !@options[:openstack_project_id])
raise 'You must specify either Openstack project name (:openstack_project_name) or Openstack project id (:openstack_project_id) not both!' if is_v3 and (@options[:openstack_project_name] and @options[:openstack_project_id])
raise 'You may specify either Openstack user domain (:openstack_user_domain) or Openstack user domain id (:openstack_user_domain_id) not both!' if is_v3 and (@options[:openstack_user_domain] and @options[:openstack_user_domain_id])
raise 'You may specify either Openstack project domain (:openstack_project_domain) or Openstack project domain id (:openstack_project_domain_id) not both!' if is_v3 and (@options[:openstack_project_domain] and @options[:openstack_project_domain_id])
raise 'Invalid option specified: v3 API expects :openstack_project_name or :openstack_project_id, not :openstack_tenant for OpenStack instances!' if is_v3 and @options[:openstack_tenant]
raise 'Invalid option specified: v2 API expects :openstack_tenant, not :openstack_project_name or :openstack_project_id for OpenStack instances!' if !is_v3 and (@options[:openstack_project_name] or @options[:openstack_project_id])
# Ensure that _id and non _id params are not mixed (due to bug in fog-openstack)
raise 'You must not mix _id values non _id (name) values. Please use the same type for (:openstack_project_), (:openstack_user_domain) and (:openstack_project_domain)!' if is_v3 and (@options[:openstack_project_name] or @options[:openstack_user_domain] or @options[:openstack_project_domain]) and (@options[:openstack_project_id] or @options[:openstack_user_domain_id] or @options[:openstack_project_domain_id])

# Keystone version 3 changed the parameter names
if !is_v3
extra_credentials = {:openstack_tenant => @options[:openstack_tenant]}
else
extra_credentials = {:openstack_project_name => @options[:openstack_project_name]}
if @options[:openstack_project_id]
extra_credentials = {:openstack_project_id => @options[:openstack_project_id]}
else
extra_credentials = {:openstack_project_name => @options[:openstack_project_name]}
end
end

# Common keystone authentication credentials
Expand All @@ -62,8 +76,16 @@ def initialize(openstack_hosts, options)

# Keystone version 3 requires users and projects to be scoped
if is_v3
@credentials[:openstack_user_domain] = @options[:openstack_user_domain] || 'Default'
@credentials[:openstack_project_domain] = @options[:openstack_project_domain] || 'Default'
if @options[:openstack_user_domain_id]
@credentials[:openstack_user_domain_id] = @options[:openstack_user_domain_id]
else
@credentials[:openstack_user_domain] = @options[:openstack_user_domain] || 'Default'
end
if @options[:openstack_project_domain_id]
@credentials[:openstack_project_domain_id] = @options[:openstack_project_domain_id]
else
@credentials[:openstack_project_domain] = @options[:openstack_project_domain] || 'Default'
end
end

@compute_client ||= Fog::Compute.new(@credentials)
Expand Down

0 comments on commit bb43275

Please sign in to comment.