<commit_before>#
# Copyright (C) 2014 eNovance SAS <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# Unit tests for cloud::identity class
#

require 'spec_helper'

describe 'cloud::identity' do

  shared_examples_for 'openstack identity' do

    let :params do
      { :identity_roles_addons        => ['SwiftOperator', 'ResellerAdmin'],
        :swift_enabled                => true,
        :keystone_db_host             => '10.0.0.1',
        :keystone_db_user             => 'keystone',
        :keystone_db_password         => '<PASSWORD>',
        :ks_admin_email               => '<EMAIL>',
        :ks_admin_password            => '<PASSWORD>',
        :ks_admin_tenant              => 'admin',
        :ks_admin_token               => '<PASSWORD>',
        :ks_ceilometer_admin_host     => '10.0.0.1',
        :ks_ceilometer_internal_host  => '10.0.0.1',
        :ks_ceilometer_password       => '<PASSWORD>',
        :ks_ceilometer_public_host    => '10.0.0.1',
        :ks_ceilometer_public_port    => '8777',
        :ks_ceilometer_public_proto   => 'http',
        :ks_cinder_admin_host         => '10.0.0.1',
        :ks_cinder_internal_host      => '10.0.0.1',
        :ks_cinder_password           => '<PASSWORD>',
        :ks_cinder_public_host        => '10.0.0.1',
        :ks_cinder_public_proto       => 'http',
        :ks_cinder_public_port        => '8776',
        :ks_glance_admin_host         => '10.0.0.1',
        :ks_glance_internal_host      => '10.0.0.1',
        :ks_glance_password           => '<PASSWORD>',
        :ks_glance_public_host        => '10.0.0.1',
        :ks_glance_public_proto       => 'http',
        :ks_heat_admin_host           => '10.0.0.1',
        :ks_heat_internal_host        => '10.0.0.1',
        :ks_heat_password             => '<PASSWORD>',
        :ks_heat_public_host          => '10.0.0.1',
        :ks_heat_public_proto         => 'http',
        :ks_heat_public_port          => '8004',
        :ks_heat_cfn_public_port      => '8000',
        :ks_keystone_admin_host       => '10.0.0.1',
        :ks_keystone_admin_port       => '35357',
        :ks_keystone_internal_host    => '10.0.0.1',
        :ks_keystone_internal_port    => '5000',
        :ks_keystone_public_host      => '10.0.0.1',
        :ks_keystone_public_port      => '5000',
        :ks_keystone_public_proto     => 'http',
        :ks_neutron_admin_host        => '10.0.0.1',
        :ks_neutron_internal_host     => '10.0.0.1',
        :ks_neutron_password          => '<PASSWORD>',
        :ks_neutron_public_host       => '10.0.0.1',
        :ks_neutron_public_proto      => 'http',
        :ks_neutron_public_port       => '9696',
        :ks_nova_admin_host           => '10.0.0.1',
        :ks_nova_internal_host        => '10.0.0.1',
        :ks_nova_password             => '<PASSWORD>',
        :ks_nova_public_host          => '10.0.0.1',
        :ks_nova_public_proto         => 'http',
        :ks_nova_public_port          => '8774',
        :ks_ec2_public_port           => '8773',
        :ks_swift_dispersion_password => '<PASSWORD>',
        :ks_swift_internal_host       => '10.0.0.1',
        :ks_swift_password            => '<PASSWORD>',
        :ks_swift_public_host         => '10.0.0.1',
        :ks_swift_public_port         => '8080',
        :ks_swift_public_proto        => 'http',
        :ks_swift_admin_host          => '10.0.0.1',
        :region                       => 'BigCloud',
        :verbose                      => true,
        :debug                        => true,
        :log_facility                 => 'LOG_LOCAL0',
        :use_syslog                   => true,
        :ks_token_expiration          => '3600',
        :api_eth                      => '10.0.0.1' }
    end

    it 'configure keystone server' do
      should contain_class('keystone').with(
        :enabled             => true,
        :admin_token         => '<PASSWORD>',
        :compute_port        => '8774',
        :debug               => true,
        :verbose             => true,
        :idle_timeout        => '60',
        :log_facility        => 'LOG_LOCAL0',
        :sql_connection      => 'mysql://keystone:secrete@10.0.0.1/keystone',
        :token_provider      => 'keystone.token.providers.uuid.Provider',
        :use_syslog          => true,
        :bind_host           => '10.0.0.1',
        :public_port         => '5000',
        :admin_port          => '35357',
        :token_expiration    => '3600',
        :log_dir             => false
      )
      should contain_keystone_config('ec2/driver').with('value' => 'keystone.contrib.ec2.backends.sql.Ec2')
      should contain_keystone_config('DEFAULT/log_file').with_ensure('absent')
    end

    it 'checks if Keystone DB is populated' do
      should contain_exec('keystone_db_sync').with(
        :command => '/usr/bin/keystone-manage db_sync',
        :unless  => '/usr/bin/mysql keystone -h 10.0.0.1 -u keystone -psecrete -e "show tables" | /bin/grep Tables'
      )
    end

    it 'configure keystone admin role' do
      should contain_class('keystone::roles::admin').with(
        :email        => '<EMAIL>',
        :password     => '<PASSWORD>',
        :admin_tenant => 'admin'<commit_msg>Keystone / Rspec: Ensure we have SQL backend for tokens<commit_after>#
# Copyright (C) 2014 eNovance SAS <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# Unit tests for cloud::identity class
#

require 'spec_helper'

describe 'cloud::identity' do

  shared_examples_for 'openstack identity' do

    let :params do
      { :identity_roles_addons        => ['SwiftOperator', 'ResellerAdmin'],
        :swift_enabled                => true,
        :keystone_db_host             => '10.0.0.1',
        :keystone_db_user             => 'keystone',
        :keystone_db_password         => '<PASSWORD>',
        :ks_admin_email               => '<EMAIL>',
        :ks_admin_password            => '<PASSWORD>',
        :ks_admin_tenant              => 'admin',
        :ks_admin_token               => '<PASSWORD>',
        :ks_ceilometer_admin_host     => '10.0.0.1',
        :ks_ceilometer_internal_host  => '10.0.0.1',
        :ks_ceilometer_password       => '<PASSWORD>',
        :ks_ceilometer_public_host    => '10.0.0.1',
        :ks_ceilometer_public_port    => '8777',
        :ks_ceilometer_public_proto   => 'http',
        :ks_cinder_admin_host         => '10.0.0.1',
        :ks_cinder_internal_host      => '10.0.0.1',
        :ks_cinder_password           => '<PASSWORD>',
        :ks_cinder_public_host        => '10.0.0.1',
        :ks_cinder_public_proto       => 'http',
        :ks_cinder_public_port        => '8776',
        :ks_glance_admin_host         => '10.0.0.1',
        :ks_glance_internal_host      => '10.0.0.1',
        :ks_glance_password           => '<PASSWORD>',
        :ks_glance_public_host        => '10.0.0.1',
        :ks_glance_public_proto       => 'http',
        :ks_heat_admin_host           => '10.0.0.1',
        :ks_heat_internal_host        => '10.0.0.1',
        :ks_heat_password             => '<PASSWORD>',
        :ks_heat_public_host          => '10.0.0.1',
        :ks_heat_public_proto         => 'http',
        :ks_heat_public_port          => '8004',
        :ks_heat_cfn_public_port      => '8000',
        :ks_keystone_admin_host       => '10.0.0.1',
        :ks_keystone_admin_port       => '35357',
        :ks_keystone_internal_host    => '10.0.0.1',
        :ks_keystone_internal_port    => '5000',
        :ks_keystone_public_host      => '10.0.0.1',
        :ks_keystone_public_port      => '5000',
        :ks_keystone_public_proto     => 'http',
        :ks_neutron_admin_host        => '10.0.0.1',
        :ks_neutron_internal_host     => '10.0.0.1',
        :ks_neutron_password          => '<PASSWORD>',
        :ks_neutron_public_host       => '10.0.0.1',
        :ks_neutron_public_proto      => 'http',
        :ks_neutron_public_port       => '9696',
        :ks_nova_admin_host           => '10.0.0.1',
        :ks_nova_internal_host        => '10.0.0.1',
        :ks_nova_password             => '<PASSWORD>',
        :ks_nova_public_host          => '10.0.0.1',
        :ks_nova_public_proto         => 'http',
        :ks_nova_public_port          => '8774',
        :ks_ec2_public_port           => '8773',
        :ks_swift_dispersion_password => '<PASSWORD>',
        :ks_swift_internal_host       => '10.0.0.1',
        :ks_swift_password            => '<PASSWORD>',
        :ks_swift_public_host         => '10.0.0.1',
        :ks_swift_public_port         => '8080',
        :ks_swift_public_proto        => 'http',
        :ks_swift_admin_host          => '10.0.0.1',
        :region                       => 'BigCloud',
        :verbose                      => true,
        :debug                        => true,
        :log_facility                 => 'LOG_LOCAL0',
        :use_syslog                   => true,
        :ks_token_expiration          => '3600',
        :api_eth                      => '10.0.0.1' }
    end

    it 'configure keystone server' do
      should contain_class('keystone').with(
        :enabled             => true,
        :admin_token         => '<PASSWORD>',
        :compute_port        => '8774',
        :debug               => true,
        :verbose             => true,
        :idle_timeout        => '60',
        :log_facility        => 'LOG_LOCAL0',
        :sql_connection      => 'mysql://keystone:secrete@10.0.0.1/keystone',
        :token_driver        => 'keystone.token.backends.sql.Token',
        :token_provider      => 'keystone.token.providers.uuid.Provider',
        :use_syslog          => true,
        :bind_host           => '10.0.0.1',
        :public_port         => '5000',
        :admin_port          => '35357',
        :token_expiration    => '3<PASSWORD>',
        :log_dir             => false
      )
      should contain_keystone_config('ec2/driver').with('value' => 'keystone.contrib.ec2.backends.sql.Ec2')
      should contain_keystone_config('DEFAULT/log_file').with_ensure('absent')
    end

    it 'checks if Keystone DB is populated' do
      should contain_exec('keystone_db_sync').with(
        :command => '/usr/bin/keystone-manage db_sync',
        :unless  => '/usr/bin/mysql keystone -h 10.0.0.1 -u keystone -psecrete -e "show tables" | /bin/grep Tables'
      )
    end

    it 'configure keystone admin role' do
      should contain_class('keystone::roles::admin').with(
        :email        => '<EMAIL>',
        :password     => '<PASSWORD>',
        :admin_tenant => 'admin'
{'fraction_non_alphanumeric': 0.1338501291989664, 'fraction_numerical': 0.0388458225667528, 'mean_word_length': 1.8012062726176117, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 215, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 58, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '956008', 'n_tokens_mistral': 3948, 'n_tokens_neox': 3711, 'n_words': 653}