File: openstack_spec.rb

package info (click to toggle)
puppet-module-nova 25.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,100 kB
  • sloc: ruby: 11,433; python: 38; sh: 10; makefile: 10
file content (209 lines) | stat: -rw-r--r-- 6,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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
require 'puppet'
require 'spec_helper'
require 'puppet/provider/nova_flavor/openstack'

describe Puppet::Type.type(:nova_flavor).provider(:openstack) do

  let(:set_env) do
    ENV['OS_USERNAME']     = 'test'
    ENV['OS_PASSWORD']     = 'abc123'
    ENV['OS_PROJECT_NAME'] = 'test'
    ENV['OS_AUTH_URL']     = 'http://127.0.0.1:5000/v3'
  end

  describe 'managing flavors' do
    let(:flavor_attrs) do
      {
        :name   => 'example',
        :id     => '1',
        :ram    => '512',
        :disk   => '1',
        :vcpus  => '1',
        :ensure => 'present',
      }
    end

    let :resource do
      Puppet::Type::Nova_flavor.new(flavor_attrs)
    end

    let(:provider) do
      described_class.new(resource)
    end

    before(:each) do
      set_env
    end

    describe '#create' do
      context 'with defaults' do
        it 'creates flavor' do
          expect(provider.class).to receive(:openstack)
            .with('flavor', 'create', '--format', 'shell', ['example', '--public', '--id', '1', '--ram', '512', '--disk', '1', '--vcpus', '1'])
            .and_return('os-flv-disabled:disabled="False"
os-flv-ext-data:ephemeral="0"
disk="1"
id="1"
name="example"
os-flavor-access:is_public="True"
ram="512"
rxtx_factor="1.0"
swap=""
vcpus="1"')
          provider.create
          expect(provider.exists?).to be_truthy
        end
      end

      context 'with project' do
        before do
          flavor_attrs.merge!(
            :project => '3073e17b-fb7f-4524-bdcd-c54bc70e9da9'
          )
        end

        it 'creates flavor' do
          expect(provider.class).to receive(:openstack)
            .with('flavor', 'create', '--format', 'shell', ['example', '--public', '--id', '1', '--ram', '512', '--disk', '1', '--vcpus', '1'])
            .and_return('os-flv-disabled:disabled="False"
os-flv-ext-data:ephemeral="0"
disk="1"
id="1"
name="example"
os-flavor-access:is_public="True"
ram="512"
rxtx_factor="1.0"
swap=""
vcpus="1"')
          expect(provider.class).to receive(:openstack)
            .with('flavor', 'set', ['example', '--project', '3073e17b-fb7f-4524-bdcd-c54bc70e9da9'])
          expect(provider.class).to receive(:openstack)
            .with('project', 'show', '--format', 'shell', '3073e17b-fb7f-4524-bdcd-c54bc70e9da9')
            .and_return('enabled="True"
name="admin"
id="3073e17b-fb7f-4524-bdcd-c54bc70e9da9"
domain_id="domain_one_id"
')
          provider.create
          expect(provider.exists?).to be_truthy
          expect(provider.project).to eq('3073e17b-fb7f-4524-bdcd-c54bc70e9da9')
          expect(provider.project_name).to eq('admin')
        end
      end

      context 'with project_name' do
        before do
          flavor_attrs.merge!(
            :project_name => 'admin'
          )
        end

        it 'creates flavor with project_name' do
          expect(provider.class).to receive(:openstack)
            .with('flavor', 'create', '--format', 'shell', ['example', '--public', '--id', '1', '--ram', '512', '--disk', '1', '--vcpus', '1'])
            .and_return('os-flv-disabled:disabled="False"
os-flv-ext-data:ephemeral="0"
disk="1"
id="1"
name="example"
os-flavor-access:is_public="True"
ram="512"
rxtx_factor="1.0"
swap=""
vcpus="1"')
          expect(provider.class).to receive(:openstack)
            .with('flavor', 'set', ['example', '--project', 'admin'])
          expect(provider.class).to receive(:openstack)
            .with('project', 'show', '--format', 'shell', 'admin')
            .and_return('enabled="True"
name="admin"
id="3073e17b-fb7f-4524-bdcd-c54bc70e9da9"
domain_id="domain_one_id"
')
          provider.create
          expect(provider.exists?).to be_truthy
          expect(provider.project).to eq('3073e17b-fb7f-4524-bdcd-c54bc70e9da9')
          expect(provider.project_name).to eq('admin')
        end
      end
    end

    describe '#destroy' do
      it 'removes flavor' do
        expect(described_class).to receive(:openstack)
          .with('flavor', 'delete', '1')
        provider.instance_variable_set(:@property_hash, flavor_attrs)
        provider.destroy
        expect(provider.exists?).to be_falsey
      end
    end

    describe '#instances' do
      it 'finds existing services' do
        expect(described_class).to receive(:openstack)
          .with('flavor', 'list', '--quiet', '--format', 'csv', ['--long', '--all'])
          .and_return('"ID","Name","RAM","Disk","Ephemeral","VCPUs","Is Public","Swap","RXTX Factor","Properties"
"1","m1.tiny",128,2,0,1,True,0,1.0,"{}"
"42","m1.nano",256,2,0,1,False,0,1.0,"{\'key1\': \'val1\', \'key2\': \'val2\'}"
')

        expect(described_class).to receive(:openstack)
          .with('flavor', 'show', '--format', 'shell', ['1', '-c', 'access_project_ids'])
          .and_return('access_project_ids="None"
')
        expect(described_class).to receive(:openstack)
          .with('flavor', 'show', '--format', 'shell', ['42', '-c', 'access_project_ids'])
          .and_return('access_project_ids="None"
')

        instances = described_class.instances
        expect(instances.count).to eq(2)
        expect(instances[0].name).to eq('m1.tiny')
        expect(instances[0].id).to eq('1')
        expect(instances[0].ram).to eq('128')
        expect(instances[0].disk).to eq('2')
        expect(instances[0].ephemeral).to eq('0')
        expect(instances[0].vcpus).to eq('1')
        expect(instances[0].is_public).to eq(true)
        expect(instances[0].swap).to eq('0')
        expect(instances[0].rxtx_factor).to eq('1.0')
        expect(instances[0].properties).to eq({})
        expect(instances[0].project).to eq('')
        expect(instances[0].project_name).to eq('')
        expect(instances[1].name).to eq('m1.nano')
        expect(instances[1].id).to eq('42')
        expect(instances[1].ram).to eq('256')
        expect(instances[1].disk).to eq('2')
        expect(instances[1].ephemeral).to eq('0')
        expect(instances[1].vcpus).to eq('1')
        expect(instances[1].is_public).to eq(false)
        expect(instances[1].swap).to eq('0')
        expect(instances[1].rxtx_factor).to eq('1.0')
        expect(instances[1].properties).to eq({'key1' => 'val1', 'key2' => 'val2'})
        expect(instances[1].project).to eq('')
        expect(instances[1].project_name).to eq('')
      end
    end

    describe '#flush' do
      context '.project' do
        it 'updates flavor' do
          expect(provider.class).to receive(:openstack)
            .with('flavor', 'set', ['example', '--project', '3073e17b-fb7f-4524-bdcd-c54bc70e9da9'])
          provider.project = '3073e17b-fb7f-4524-bdcd-c54bc70e9da9'
          provider.flush
        end
      end

      context '.project_name' do
        it 'updates flavor' do
          expect(provider.class).to receive(:openstack)
            .with('flavor', 'set', ['example', '--project', 'admin'])
          provider.project_name = 'admin'
          provider.flush
        end
      end
    end
  end
end