48 Commits

Author SHA1 Message Date
Tobias Urdin
1c99679e07 Revert "Revert "Use puppet4 functions-api""
This reverts commit 0bd97be465516fa607f5aa0db6f5450513dc292a.

Change-Id: I8e3cb42a60621fc6f791ee61b595546efd79c491
2018-11-12 10:19:15 +01:00
Sagi Shnaidman
0bd97be465 Revert "Use puppet4 functions-api"
This reverts commit fd3156bc60ec537ffc53aea1d0e0035c9fe17638.
Closes-Bug: #1802083

Change-Id: I7705744cab62f432e2e09bf1ee88bba809609cda
2018-11-07 10:17:37 +00:00
Tobias Urdin
fd3156bc60 Use puppet4 functions-api
Change-Id: I07a6ad9dba09c664e0b95901a442b165a29a8852
2018-11-04 13:10:28 +01:00
Sofer Athlan-Guyot
124daec7bb Making immutable config setting when using <_IMMUTABLE_>.
Similar to what is done with os_service_default, but here we have the
possibility to tell puppet to not change the existing value, whatever
this is.

The associated fact for syntactic sugar in the module is
`::os_immutable`.

Partial-Bug: #1763322
Change-Id: Iaea44309db9b1b075425fa15890ba592d8bc9b7e
2018-06-29 22:13:55 +02:00
Alex Schultz
61044892ad Ignore extra bash code from openrc
If a user has additional code in their openrc file that isn't just bash
variables, the auth provider might fail while parsing it. This change
updates the logic to only try and parse lines with OS_ in it to make
sure that extra things like bash code are ignored.

Change-Id: Id6f5406dcf15642bc0d70caeac30224114bb0669
Closes-Bug: #1699950
2017-06-23 08:48:10 -06:00
Carlos Camacho
b3d0590022 Allow integer port in os_transport_url
Currently we only allow to use strings
as the data type for ports.

Due to this we need to cast the data type
in the puppet modules because from THT
this is configured as a Number.

This submission allow to use either string
or numbers for the port parameter in the
os_transport_url function.

Change-Id: I9e56f8e2de542b20fe9e6995506cff5bb435e220
Closes-Bug: #1664561
2017-02-22 10:40:31 +01:00
Andrew Smith
f9672b062f Enable alternative transport in os_transport_url
Change-Id: Ie6965dc5f7896587b5625e38cc758b5564e59bd4
Closes-Bug: 1651215
2016-12-20 10:00:55 -05:00
Alex Schultz
cbeb29e69b Improve os_transport_url ssl support
The ssl paramter of the os_transport_url should be 0/1 but we do not
ensure that this is the value being used in the creation of the
transport_url. This change leverages the stdlib str2bool and bool2num to
ensure that when provided the ssl paramter ends up being 0/1 which is
the correct format for the transport url.  Additionally this also allows
for string booleans to be passed into the ssl parameter and it should
still work correctly.

Change-Id: I278559ba98ba48974ae590dc1e0bb99b6ab961d7
2016-12-19 11:43:07 -07:00
Alex Schultz
8d37c059d2 Fix os_transport_url with single hosts array
If an array with a single host is passed into the hosts param, the
function was erroring because the host was getting converted to a string
when it was checking for bracketing for ipv6. This change checks the
type and fixes the case where a single host is being passed so it
continues to function.

Change-Id: I91b9959a6f71b4e6885e55a568116cc28cf16ddd
Closes-Bug: #1650042
2016-12-14 15:21:03 -07:00
Alex Schultz
7ef2f7b0d7 os_transport_url parser function
This change adds a os_transport_url function that can be used to
generate correct URIs for the transport_url setting used by
oslo.messaging.

Change-Id: If83c0f0e61a08061334536399a42767a305966b7
2016-11-10 16:17:30 -07:00
Arnoud de Jonge
3670d9255e Added interface parameter for auth
I want to be able to use the internal API endpoints from Puppet.  This is done
by setting $OS_INTERFACE to internal for use with the openstack CLI. This
change will do this by also reading OS_INTERFACE from the environment or
/root/openrc.

Change-Id: Id826836ccfe8f61780a6201ef2851068d75391ab
2016-11-02 13:44:14 +01:00
Clayton O'Neill
f705fd6f4d Add region support to credentials
This fixes the credentials classes to properly accept region as a
property to manage.  This allows OS_REGION_NAME to be set properly if
the child class passes it in.

Change-Id: I3345dac8bebd68f93290c1d45aa9a4d80bf3fb34
Partial-Bug: #1517220
2016-10-03 20:49:31 +00:00
Emilien Macchi
435c50fe88 normalize_ip_for_uri: allow to give an array of IP addresses
Allow to give an array of IP addresses to normalize_ip_for_url function.
Each IP in the list will be normalized like it would be for a string.

Change-Id: I8d361ce9cfcfe6a3f8592b2b7991971a3c748c75
Co-Authored-By: Athlan-Guyot sofer <sathlang@redhat.com>
2016-09-20 12:55:11 +02:00
Brent Eagles
72150f2202 Add missing namevar method to openstack_config provider
openstack_config contains a method 'self.instances' that is required for
purging unmanaged resources that references a static namevar method that
is not defined in openstack_config and may not be provided by base
classes. The 'namevar' method doesn't require any information from the
derived class so a default implementation in the base provider type
suffices.

Closes-Bug: #1612009

Change-Id: If27152863b9df5a28bf45e23ca989019666a958c
2016-08-12 02:00:08 +00:00
Sofer Athlan-Guyot
2075930b90 Add a way for provider to transform value in config.
For instance this would enable this:

    neutron_l3_agent_config {
        'DEFAULT/router_id': value => $router_name, transform_to => 'uuid';
    }

The neutron_l3_agent_config would only have to implement this:

    def to_uuid(name)
      # code to get the uuid
    end

    def from_uuid(uuid)
      # code to return the name
    end

Change-Id: I3b7c17590b27cd3a22c5458342d049969ade2281
Co-Authored-By: Drew Fisher <drew.fisher@oracle.com>
2016-08-04 12:53:50 -07:00
John Trowbridge
c628427575 Increase command_timeout for openstackclient commands
We recently patched the openstackclient code to increase the number
of retries when running commands[1], but I think what we really wanted
was to increase the amount of time to wait on each retry.

The original approach did help somewhat, but it is doing so by just
racing more times. Instead, it would be better to win the race more
often.

This is mostly a CI or developer environment issue where we are
deploying with the minimal amount of computing resources to get
a functioning cloud.

[1] https://git.openstack.org/cgit/openstack/puppet-openstacklib/commit/?id=489099632446b1903986549e5feb80b509f9b77d

Change-Id: I0707165a9e8054c1b3e0ad299604356cecc9f99f
2016-07-25 12:16:29 -04:00
Sofer Athlan-Guyot
806f31d740 Add optional exceptions regex to avoid to retry.
This is useful when the user (a puppet provider) is expecting a error.
With this it doesn't have to wait for the long retry cycle to have its
error back.  This replace the awkward mechanism in
self.request_without_retry which was dynamically mangling
request_timeout and disabled even legit retry.

Examples of such function are self.fetch_user, self.fetch_project in the
keystone provider.

Change-Id: I589da0100ad3ccf3abf17ac8b26c827793ace484
Related-Bug: 1597357
2016-06-29 15:42:13 -04:00
Sofer Athlan-Guyot
4890996324 DEBUG: testing increase timeout for tripleo CI.
If that's working maybe do https://review.openstack.org/334011

Change-Id: Id428b112eeaa22ecef78a21032b0c1dcc0ac0592
2016-06-28 18:22:59 +02:00
Denis Egorenko
85d8296030 Set policy-rc.d file as executable
Policy-rc.d requires to be set with +x chmod.

Change-Id: I1bad3301729fa6310d9d1a50c22c621ffe44e24a
2016-06-21 18:56:19 +03:00
Denis Egorenko
ec58851c44 Add provider for managing policy-rc.d
Use provider for managing policy-rc.d file to be sure that
services stopped right after package installed.

Also added tests.

Change-Id: Ic54b9707b6ef36032d71fe9dc04a7e310293f127
2016-06-20 21:36:50 +03:00
Matthew J Black
06a9784af4 Fixed require statements for puppet 4
This change updates the require statements in the providers
to resolve the issues with the autoloader in puppet. This
issue technically always existed but was masked prior to the
split with puppet server and puppet agent because both used to
share the same loadpath. Documentation on this issue can be
read at https://tickets.puppetlabs.com/browse/PUP-4450.

Change-Id: I72a27fe92a41a5eb845adba6b82252b8aac1c164
2016-05-16 12:51:59 -04:00
Sofer Athlan-Guyot
fedb3152c9 Add the possibility to execute without retry.
It may be useful to be able to execute a command without a retry.

A good use case is provider in [1], where the keystone_user resource try
to get an user by fetching it.  It is expected to fail when the user is
absent.  With the current implementation, it will takes 60 seconds for
the provider to give up on the user.

[1] https://review.openstack.org/299301

Closes-Bug: #1563898

Change-Id: I5b334e3ffd26df4ba8584d77a5e41b56e73536c8
2016-04-13 14:06:03 +00:00
Matt Fischer
adb0b1d012 Log the correct command_timeout value
For the no-retry_actions we need to log the correct, longer, timeout.

Change-Id: I035c1eee84f0db5f04e3b63f8bb12a13738d4327
2016-03-31 10:20:13 -06:00
Matt Fischer
579ad2d370 Adjust timeout for non-retry calls
Give non-retry calls the full timeout seconds to finish and also
don't log that you're going to retry them when you are not.

Change-Id: I51cbe3905b55f035718245b45bfc34536b8ce602
2016-03-30 08:31:55 -06:00
Jenkins
73d9983c08 Merge "Utility to handle IPv6 address brackets." 2016-02-11 18:13:16 +00:00
Sofer Athlan-Guyot
af2aefbd74 Utility to handle IPv6 address brackets.
This add the function normalize_ip_for_uri to the parser.  It encloses
into brackets any valid IPv6 address thrown at it.

Change-Id: I093dd5a4e6294e20761cb3d33373652eeadeac36
Closes-bug: 1531960
2016-02-11 13:41:14 +01:00
Martin Mágr
3e43f5ddcf openstackconfig idempotency fix
- fixed idempotency issues with single string values
- fixed deletion of multiple values

This patch is required for I95cf32c3211bc4498eaa68e6e748a27dfd9af0fa to pass
acceptance tests

Change-Id: I619de3038cd2690bebe47cd601c085692506ac3d
2016-01-08 13:27:32 +01:00
Martin Mágr
b3f0b0a810 Fix handling of ensure_absent_val
When :array_matching => :all is used for value, the values comes
in form of array even when they are passed as single string and
so <SERVICE DEFAULT> mechanism does not currently work without hack
on each inherited resource.

This is required for I95cf32c3211bc4498eaa68e6e748a27dfd9af0fa to pass
acceptance tests.

Change-Id: Ibbc8a376496b8120d7c1d87f7a9005024ae14984
2016-01-07 11:50:49 +01:00
Michael Polenchuk
bad1c6514a Update os_database_connection with extra param
Add support for providing additional parameters to be used when
constructing the database uri. This change adds an 'extra' parameter
which is a hash that will be joined together when constructing the
database uri. It should be noted that the charset option, which can be
provided as a standalone option, will override charset when passed in
the 'extra' parameter. This is to maintain backwards compatibility.

Usage Example:
  os_database_connection({
    ...
    extra => { 'charset' => 'utf-8', 'read_timeout' => 60 }
  })

Change-Id: I7ef078b76ac6cd7bea42a0ac92b383cefd47167a
Co-Authored-By: Alex Schultz <aschultz@mirantis.com>
2015-12-28 15:05:33 -07:00
Jenkins
6cbf40bdc1 Merge "Add retries to the openstack command" 2015-12-23 10:07:18 +00:00
Dmitry Ilyin
701b6fe0ac Add retries to the openstack command
Sometimes openstackclient can hang if Keystone
API fails to respond to requests.
This patch adds retries to work around these
situations.

* Retry and timeouts for openstack command
  -'command_timeout=20':
    after this timeout openstack command is retried
    untill the request_timeout.
    (The value of command_timeout parameter was updated
    from 10 to 20 as it was observed that "10" value is
    not enough when sytem was overloaded.)
  -'request_timeout=60':
    timeout of the entire request.
  -'retry_sleep=3':
    interval between command retries
* Does not retry non-idempotent actions.
* Improve specs

Change-Id: Ifd8ae1b00321366e3a54fd6fe4a68db46bb743c7
2015-12-21 16:34:50 +02:00
Jenkins
f84baa1f69 Merge "OpenStackConfig provider" 2015-12-10 17:56:58 +00:00
Michael Polenchuk
92b92aa4c9 Catch HTTP 403 response
Also catch not authorized requests with HTTP 403 response in order to
handle it further.

Change-Id: Ib922bd5892f0204566656303e6a484daa8d2d5e7
2015-11-30 20:11:33 +03:00
Martin Mágr
029c6a74cc OpenStackConfig provider
This patch add support for parsing configuration files of projects
which use oslo.config.cfg.MultiStrOpt (currently Neutron LBaaSv2).

For details see:
http://docs.openstack.org/developer/oslo.config/api/oslo.config.cfg.html#oslo.config.cfg.MultiStrOpt

Change-Id: If782aa4bf83712ac2a5f4d2f4e8ace782409182d
2015-11-04 16:06:04 +01:00
Michael Polenchuk
086c8806c0 Fallback to default rcfile
For missing HOME env variable set rcfile to /root/openrc by default.

Change-Id: Icd13f7ce46a999f3def18131042a83de574ffed8
2015-10-26 18:54:53 +03:00
Alex Schultz
74de9e1d34 Create is_service_default function
This change creates a parser function that can be used to check if a
value is set to the '<SERVICE DEFAULT>' string. The is_service_default
function will return true if the parameter passed in is '<SERVICE
DEFAULT>' otherwise it returns false.

Checks like:
  if ($our_param == '<SERVICE DEFAULT>') { ... }

Should be replaced with:
  if is_service_default($our_param) { ... }

This change will also be useful if we ever refactor the default value
string or have different values as this function could be updated to
support multiple values without having to adjust the calling code.

Change-Id: I07b8b9b54ed1e88891f74da9b930e4f39876a607
2015-09-15 12:23:08 -05:00
Yanis Guenane
3b85306d04 Allow the use of an ensure_absent_val param
This commit aims to add a new feature for the ini_setting provider, this
feature aims to simulate the ensure => absent behavior when a specific
keyword is specified.

Currently a pattern we have is

if $myvar {
  keystone_config { 'SECTION/setting' : value => $myvar }
} else {
  keystone_config { 'SECTION/setting' : ensure => absent }
}

If one has dozens or hundreds of parameters to handle then it can easily
make the manifest hard to read.

The solution offer here would turn the above example in something like

Keystone_config {
  ensure_absent_val = '<SERVICE DEFAULT>' # It is the default
}

keystone_config { 'SECTION/setting' : value => $myvar }

If `$myvar` is '<SERVICE DEFAULT>' then it will act as if `ensure => absent` would
have been specified.

Also added new tests for openstack_config provider

Co-Authored-By: Denis Egorenko <degorenko@mirantis.com>

Change-Id: I0eeebde3aac2662cc7e69bfad7f8d2481463a218
2015-08-18 09:46:19 +02:00
Yanis Guenane
f754ef3bcf Add a proxy inifile provider
Create a proxy inifile provider that will sit between the openstack
configuration providers (ie. keystone_config) and the actual ini_setting
provider.

Adding such a component will give us more flexibility on the ini_setting
provider. With that in place we could :

 * Test new feature with the provider - merge them upstream when validated
 * Bypass upstream limit if our queries are not valid for upstream.

By inheriting the provider we don't fork and hence should remain
compatible with the next releases of puppetlabs-inifile

Change-Id: I061371d8cf2faf928019161e635e1b4252a6b433
2015-07-16 15:59:16 +02:00
Gilles Dubreuil
61da0090d8 Credentials#unset method
* Unset was broken, not resetting the variables
* Also added a rspec example

It worked but wasn't clean as if an authentication method failed some fields
could have been left un-blanked, creating bad side effects.

In addition:
* Added tests for #set with both valid and invalid values
* Added negative tests for #service_token_set? and user_password_set?
* Added test for #version
* Fixed #unset test
* Fixed #to_env test
* In several tests, added an OS_NOT_VALID parameter to make sure the
  credentials code correctly ignores it
* Added tests to make sure the fallback in Auth.request works properly
* Added additional tests to make sure the @credentials object is set
  correctly
* Fixed some formatting/alignment issues

Change-Id: I64cb492dc244b975827d2d0d86b4b97d7129088f
2015-06-24 16:51:07 -06:00
Rich Megginson
8441feb39d support for Keystone v3 authentication
This adds the class Puppet::Provider::Openstack::CredentialsV3
that implements support for Keystone v3 authentication and all
of the new id and domain authentication parameters.

Implements: blueprint api-v3-support

Change-Id: Icafc4cb8ed000fd9d3ed6ffde2afe1a1250d90af
2015-06-10 04:17:14 +00:00
Gilles Dubreuil
67d1c38703 Restructures authentication for resource providers
Workflow to find credentials details from:
  1. The environment variables (ENV['OS_*'])
  2. If not enough, credentials available from the environment RC file
     to be used. Default RC file must be in current user homedir: ~/openrc

  - Adds module Puppet::Provider::Openstack::Auth providing class methods for
  providers instead of relying on superclass inheritance.
  As discussed [1], this purposefully removes the possibility to pass authenti-
  cation details as parameters to Puppet resources instances.

  - Wraps credentials information with object:
    Puppet::Provider::Openstack::Credentials

  - The credentials information is used in a withenv block

  Review for puppet-keystone needs to be merged at same time:
  https://review.openstack.org/#/c/181299/

  [1] http://lists.openstack.org/pipermail/openstack-dev/2015-May/063352.html

Change-Id: If628f4ad95f3aac3392475d4ea6857fb858f8755
Implements: blueprint auth-restructure
2015-05-28 09:44:54 +10:00
Gilles Dubreuil
54f3a0be5c Added openstack/OSC option os-identity-api-version
- Default to version 3

Change-Id: I53f6bdec003ca0ee770a9b91fc2a83eb30480efe
2015-04-27 16:53:36 +00:00
Gilles Dubreuil
d4073c2721 Targeting Keystone V3 API support
The default domain (id 'default', name 'Default') is where the V2
tenants/users are defined. So V3, which is now the default API's version
can and should be used.  Beeing able to use V3 domains needs to be
supported by specifying the domain name for a project/user.

This patch :
- Adds project and user domain names
- Renames tenant (v2) as project (v3)
- Renames os-auth-url to os-url, when using an authicated token against a
  service url, to distinct them from each other, as in OSC
(opentackclient)
- Updates newparam(:auth) accordingly to describe v2/v3 credential
  examples

Note: Keystone API v2 is deprecated [1]

[1] http://docs.openstack.org/developer/keystone/http-api.html#should-i-use-v2-0-or-v3

Change-Id: I72f79129a6875eb433eeb8a62f928e7210db134a
2015-04-03 13:17:25 +11:00
Clayton O'Neill
efa9181201 Properly handle embedded newlines in csv
When parsing the response from the OpenStack client values (like
keystone tenant descriptions) can have embedded newline. To avoid this
issue, we drop lines that don't start with a double quoted value until
the first one we find.

Change-Id: Ie952161b503d2c46637e6a6e1c83b2dfce1c03a7
2015-03-17 09:57:35 +00:00
Colleen Murphy
ed58789665 Move openstackclient parent provider to openstacklib
This patch abandons the use of the Aviator library for interacting with
the openstack APIs in favor of the universal openstack client[1]. This
work has already been implemented in the keystone module. This patch
moves that work into openstacklib in order to make it available for the
other modules.

[1] https://wiki.openstack.org/wiki/OpenStackClient

Change-Id: I68705c28955a54e26d98f1de718016691c64e4b1
2015-03-05 11:39:19 -08:00
Jenkins
5ddb8ea169 Merge "Implement base aviator provider" 2014-10-01 23:41:40 +00:00
Colleen Murphy
612fa7e121 Implement base aviator provider
This patch adds a dependency on the aimonb/aviator module and adds
functionality to support interactions with the OpenStack services' API
via aviator.

The patch adds a parent provider that is intended for other providers
to inherit from. The parent provider has methods to authenticate to
openstack services, create session objects, and make requests. The
authenticate method can accept credentials as an argument hash or infer
credentials from the environment.

It also adds a stub type parameter that allows types to incorporate
basic parameters they need in order to support using aviator.

Change-Id: I56b0d07ae8f4738037eda486b75a0f6e24fe80e7
Implements: blueprint use-aviator-in-module-resources
2014-09-30 21:01:28 -07:00
Mathieu Gagné
0536a214f4 Add os_database_connection function
The os_database_connection function is an helper used to build
database connection URI from various parameters.

Example:

  os_database_connection({
    dialect  => 'mysql',
    host     => '127.0.0.1',
    port     => '3306',
    username => 'guest',
    password => 's3cr3t',
    database => 'test',
    charset  => 'utf-8'
  })

Result:

  mysql://guest:s3cr3t@127.0.0.1:3306/test?charset=utf-8

Change-Id: Id0bde33891112e36f13d3f8fdf0ff89820c09c01
2014-07-09 14:20:34 -04:00