File: murano_spec.rb

package info (click to toggle)
puppet-module-murano 23.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 928 kB
  • sloc: ruby: 2,856; python: 38; sh: 10; makefile: 10
file content (142 lines) | stat: -rw-r--r-- 4,958 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require 'puppet'
require 'spec_helper'
require 'puppet/provider/murano'
require 'tempfile'

describe Puppet::Provider::Murano do

  def klass
    described_class
  end

  let :credential_hash do
    {
      'auth_url'            => 'https://192.168.56.210:5000',
      'project_name'        => 'admin_tenant',
      'username'            => 'admin',
      'password'            => 'password',
      'project_domain_name' => 'Default',
      'user_domain_name'    => 'Default',

    }
  end

  let :credential_error do
    /Murano types will not work/
  end

  after :each do
    klass.reset
  end

  describe 'when determining credentials' do

    it 'should fail if config is empty' do
      conf = {}
      expect(klass).to receive(:murano_conf).and_return(conf)
      expect do
        klass.murano_credentials
      end.to raise_error(Puppet::Error, credential_error)
    end

    it 'should fail if config does not have keystone_authtoken section.' do
      conf = {'foo' => 'bar'}
      expect(klass).to receive(:murano_conf).and_return(conf)
      expect do
        klass.murano_credentials
      end.to raise_error(Puppet::Error, credential_error)
    end

    it 'should fail if config does not contain all auth params' do
      conf = {'keystone_authtoken' => {'invalid_value' => 'foo'}}
      expect(klass).to receive(:murano_conf).and_return(conf)
      expect do
        klass.murano_credentials
      end.to raise_error(Puppet::Error, credential_error)
    end

  end

  describe 'when invoking the murano cli' do

    it 'should set auth credentials in the environment' do
      authenv = {
        :OS_AUTH_URL            => credential_hash['auth_url'],
        :OS_USERNAME            => credential_hash['username'],
        :OS_TENANT_NAME         => credential_hash['project_name'],
        :OS_PASSWORD            => credential_hash['password'],
        :OS_ENDPOINT_TYPE       => 'internalURL',
        :OS_PROJECT_DOMAIN_NAME => credential_hash['project_domain_name'],
        :OS_USER_DOMAIN_NAME    => credential_hash['user_domain_name'],

      }
      expect(klass).to receive(:get_murano_credentials).with(no_args).and_return(credential_hash)
      expect(klass).to receive(:withenv).with(authenv)
      klass.auth_murano('test_retries')
    end

    it 'should read auth credentials with specified package service' do
      mock = {
        'keystone_authtoken' => {
          'auth_url'          => 'https://192.168.56.210:5000',
          'project_name'      => 'admin_tenant',
          'username'          => 'admin',
          'password'          => 'password',
        },
        'engine' => {
          'packages_service' => 'glance',
        }
      }
      creds = {
         'auth_url'            => 'https://192.168.56.210:5000',
         'project_name'        => 'admin_tenant',
         'username'            => 'admin',
         'password'            => 'password',
         'packages_service'    => 'glance',
         'project_domain_name' => 'Default',
         'user_domain_name'    => 'Default',
      }
      expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock)
      expect(mock).to receive(:read).with('/etc/murano/murano.conf')
      expect(klass.murano_credentials).to eq(creds)
    end

    it 'should set auth env credentials with specified package service' do
      creds = {
         'auth_url'            => 'https://192.168.56.210:5000',
         'project_name'        => 'admin_tenant',
         'username'            => 'admin',
         'password'            => 'password',
         'packages_service'    => 'glance',
         'project_domain_name' => 'Default',
         'user_domain_name'    => 'Default',
      }
      authenv = {
        :OS_AUTH_URL             => creds['auth_url'],
        :OS_USERNAME             => creds['username'],
        :OS_TENANT_NAME          => creds['project_name'],
        :OS_PASSWORD             => creds['password'],
        :OS_ENDPOINT_TYPE        => 'internalURL',
        :MURANO_PACKAGES_SERVICE => creds['packages_service'],
        :OS_PROJECT_DOMAIN_NAME  => creds['project_domain_name'],
        :OS_USER_DOMAIN_NAME     => creds['user_domain_name'],
      }
      expect(klass).to receive(:get_murano_credentials).with(no_args).and_return(creds)
      expect(klass).to receive(:withenv).with(authenv)
      klass.auth_murano('test_retries')
    end

    ['[Errno 111] Connection refused',
     '(HTTP 400)'].reverse.each do |valid_message|
      it "should retry when murano cli returns with error #{valid_message}" do
        expect(klass).to receive(:get_murano_credentials).with(no_args).and_return({})
        expect(klass).to receive(:sleep).with(10).and_return(nil)
        expect(klass).to receive(:murano).with(['test_retries']).and_invoke(
          lambda { |*args| raise Exception, valid_message},
          lambda { |*args| return '' }
        )
        klass.auth_murano('test_retries')
      end
    end
  end
end