File: ruby_spec.rb

package info (click to toggle)
puppet-module-tempest 25.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,000 kB
  • sloc: ruby: 1,268; python: 38; sh: 10; makefile: 10
file content (146 lines) | stat: -rw-r--r-- 3,497 bytes parent folder | download | duplicates (3)
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
143
144
145
146
require 'spec_helper'
require 'puppet'

describe 'Providers' do
  glance_provider_class =
    Puppet::Type.type(:tempest_glance_id_setter).provider(:openstack)
  network_provider_class =
    Puppet::Type.type(:tempest_neutron_net_id_setter).provider(:openstack)

  include PuppetlabsSpec::Files
  let(:tmpfile) { tmpfilename('ini_setting_test') }

  context 'When getting image or network name' do
    before :each do
      File.open(tmpfile, 'w') do |fh|
        fh.write(orig_content)
      end
    end

    def validate_file(expected_content, file = tmpfile)
      expect(File.read(file)).to eq(expected_content)
    end

    let(:glance_params) do
      {
        title:             'image_ref',
        image_name:        'cirros',
        tempest_conf_path: tmpfile
      }
    end

    let(:neutron_params) do
      {
        title:             'public_network_id',
        network_name:      'public',
        tempest_conf_path: tmpfile
      }
    end

    context 'With an existing tempest conf' do
      let(:orig_content) do
        <<-EOS
# This is a comment
[compute]
; This is also a comment
foo=foovalue
bar = barvalue
master = true
[network]
foo= foovalue2
[blah]

EOS
      end

      describe glance_provider_class do
        it 'should put the glance entry in the right place' do
          resource = Puppet::Type::Tempest_glance_id_setter.new(glance_params)
          provider = glance_provider_class.new(resource)
          provider.instance_variable_set(:'@image_id', 'abcdef')
          provider.create
          validate_file(<<-EOS
# This is a comment
[compute]
; This is also a comment
foo=foovalue
bar = barvalue
master = true
image_ref=abcdef
[network]
foo= foovalue2
[blah]

EOS
          )
        end
      end
      describe network_provider_class do
        it 'should put the neutron entry in the right place' do
          resource =
            Puppet::Type::Tempest_neutron_net_id_setter.new(neutron_params)
          provider = network_provider_class.new(resource)
          provider.instance_variable_set(:'@network_id', 'abcdef')
          provider.create
          validate_file(<<-EOS
# This is a comment
[compute]
; This is also a comment
foo=foovalue
bar = barvalue
master = true
[network]
foo= foovalue2
public_network_id=abcdef
[blah]

EOS
          )
        end

        context 'With an empty tempest conf' do
          let(:orig_content) do
        <<-EOS
# This is a comment

EOS
          end

          describe glance_provider_class do
            it 'should put the glance entry in the right place' do
              resource = Puppet::Type::Tempest_glance_id_setter.new(glance_params)
              provider = glance_provider_class.new(resource)
              provider.instance_variable_set(:'@image_id', 'abcdef')
              provider.create
              validate_file(<<-EOS
# This is a comment


[compute]
image_ref=abcdef
EOS
              )
            end
          end
          describe network_provider_class do
            it 'should put the neutron entry in the right place' do
              resource =
                Puppet::Type::Tempest_neutron_net_id_setter.new(neutron_params)
              provider = network_provider_class.new(resource)
              provider.instance_variable_set(:'@network_id', 'abcdef')
              provider.create
              validate_file(<<-EOS
# This is a comment


[network]
public_network_id=abcdef
EOS
              )
            end
          end
        end
      end
    end
  end
end