Class: Kitchen::Driver::Openstack

Inherits:
Base
  • Object
show all
Includes:
Clouds, Config, Helpers, Networking, ServerHelper
Defined in:
lib/kitchen/driver/openstack.rb,
lib/kitchen/driver/openstack/clouds.rb,
lib/kitchen/driver/openstack/config.rb,
lib/kitchen/driver/openstack/volume.rb,
lib/kitchen/driver/openstack/helpers.rb,
lib/kitchen/driver/openstack/networking.rb,
lib/kitchen/driver/openstack/server_helper.rb

Overview

Test Kitchen driver for OpenStack Nova.

Creates and destroys Nova instances, optionally attaching floating IPs, Cinder volumes and specific Neutron networks. Credentials come from kitchen.yml, OS_* environment variables, or a standard clouds.yaml -- see Clouds for the precedence rules.

Defined Under Namespace

Modules: Clouds, Config, Helpers, Networking, ServerHelper Classes: Volume

Constant Summary collapse

FOG_STRING_SETTINGS =

Settings Fog requires as Strings. Fog re-coerces anything that looks numeric back to an Integer, so these are stringified on the way in.

Returns:

  • (Array<Symbol>)
%i{
  openstack_username
  openstack_api_key
  openstack_auth_url
  openstack_project_name
  openstack_project_id
  openstack_user_domain
  openstack_user_domain_id
  openstack_project_domain
  openstack_project_domain_id
  openstack_domain_id
  openstack_domain_name
  openstack_region
  openstack_endpoint_type
  openstack_identity_api_version
  openstack_application_credential_id
  openstack_application_credential_secret
  openstack_tenant
  openstack_tenant_id
}.freeze

Constants included from ServerHelper

ServerHelper::OPTIONAL_SERVER_KEYS

Constants included from Networking

Networking::IP_POOL_LOCK

Constants included from Helpers

Helpers::COUNTDOWN_TICK

Constants included from Config

Config::MAX_PREFIX_LENGTH, Config::MAX_SERVER_NAME_LENGTH, Config::NAME_HOSTNAME_LENGTH, Config::NAME_INSTANCE_LENGTH, Config::NAME_RANDOM_LENGTH, Config::NAME_USERNAME_LENGTH, Config::PREFIX_SUFFIX_LENGTH

Constants included from Clouds

Clouds::CLOUDS_YAML_AUTH_MAP, Clouds::CLOUDS_YAML_TOP_MAP, Clouds::ENV_VAR_MAP, Clouds::STRING_CONFIG_KEYS

Instance Method Summary collapse

Methods included from Config

#config_server_name

Instance Method Details

#create(state) ⇒ void

This method returns an undefined value.

Creates a Nova instance and waits until it is reachable.

Idempotent: returns immediately if state already names a server.

Parameters:

  • state (Hash)

    mutable instance state; gains :server_id and :hostname

Raises:

  • (Kitchen::ActionFailed)

    on any Fog or Excon failure

  • (Kitchen::InstanceFailure)

    if the server builds to ERROR state



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/kitchen/driver/openstack.rb', line 130

def create(state)
  config_server_name
  if state[:server_id]
    info "#{config[:server_name]} (#{state[:server_id]}) already exists."
    return
  end
  disable_ssl_validation if config[:disable_ssl_validation]
  server = create_server
  state[:server_id] = server.id

  # this is due to the glance_caching issues. Annoying yes, but necessary.
  debug "Waiting for a max time of:#{config[:glance_cache_wait_timeout]} seconds for OpenStack server to be in ACTIVE state"
  server.wait_for(config[:glance_cache_wait_timeout]) do
    sleep(1)
    if failed?
      raise(Kitchen::InstanceFailure,
        "OpenStack server ID <#{state[:server_id]}> build failed to ERROR state")
    end

    ready?
  end
  info "OpenStack server ID <#{state[:server_id]}> created"

  if config[:floating_ip]
    attach_ip(server, config[:floating_ip])
  elsif config[:floating_ip_pool]
    attach_ip_from_pool(server, config[:floating_ip_pool])
  end
  state[:hostname] = get_ip(server)
  wait_for_server(state)
  add_ohai_hint(state)
rescue Fog::Errors::Error, Excon::Errors::Error => e
  raise ActionFailed, e.message
end

#destroy(state) ⇒ void

This method returns an undefined value.

Destroys the Nova instance named by state, releasing its floating IP first when this driver allocated one.

Safe to call when the server is already gone.

Parameters:

  • state (Hash)

    mutable instance state; loses :server_id and :hostname



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/kitchen/driver/openstack.rb', line 173

def destroy(state)
  return if state[:server_id].nil?

  disable_ssl_validation if config[:disable_ssl_validation]
  server = compute.servers.get(state[:server_id])

  unless server.nil?
    if config[:floating_ip_pool] && config[:allocate_floating_ip]
      info "Retrieve the floating IP"
      pub, priv = get_public_private_ips(server)
      pub, = parse_ips(pub, priv)
      pub_ip = pub[config[:public_ip_order].to_i] || nil
      release_floating_ip(pub_ip) if pub_ip
    end
    server.destroy
  end
  info "OpenStack instance <#{state[:server_id]}> destroyed."
  state.delete(:server_id)
  state.delete(:hostname)
end

#finalize_config!(instance) ⇒ self

Merges clouds.yaml and OS_* values into the config hash.

Done at finalize time rather than lazily so the resolved values show up in kitchen diagnose and are available to every driver method.

Parameters:

  • instance (Kitchen::Instance)

    the instance this driver serves

Returns:

  • (self)


115
116
117
118
119
# File 'lib/kitchen/driver/openstack.rb', line 115

def finalize_config!(instance)
  super
  apply_clouds_config
  self
end