try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / neutron / spec / unit / provider / neutron_subnet / neutron_spec.rb
1 require 'puppet'
2 require 'spec_helper'
3 require 'puppet/provider/neutron_subnet/neutron'
4
5 provider_class = Puppet::Type.type(:neutron_subnet).provider(:neutron)
6
7 describe provider_class do
8
9   let :subnet_name do
10     'net1'
11   end
12
13   let :subnet_attrs do
14     {
15       :name             => subnet_name,
16       :ensure           => 'present',
17       :cidr             => '10.0.0.0/24',
18       :ip_version       => '4',
19       :gateway_ip       => '10.0.0.1',
20       :enable_dhcp      => 'False',
21       :network_name     => 'net1',
22       :tenant_id        => '',
23       :allocation_pools => 'start=7.0.0.1,end=7.0.0.10',
24       :dns_nameservers  => '8.8.8.8',
25       :host_routes      => 'destination=12.0.0.0/24,nexthop=10.0.0.1',
26     }
27   end
28
29   describe 'when updating a subnet' do
30     let :resource do
31       Puppet::Type::Neutron_subnet.new(subnet_attrs)
32     end
33
34     let :provider do
35       provider_class.new(resource)
36     end
37
38     it 'should call subnet-update to change gateway_ip' do
39       provider.expects(:auth_neutron).with('subnet-update',
40                                            '--gateway-ip=10.0.0.2',
41                                            subnet_name)
42       provider.gateway_ip=('10.0.0.2')
43     end
44
45     it 'should call subnet-update to remove gateway_ip with empty string' do
46       provider.expects(:auth_neutron).with('subnet-update',
47                                            '--no-gateway',
48                                            subnet_name)
49       provider.gateway_ip=('')
50     end
51
52     it 'should call subnet-update to change enable_dhcp' do
53       provider.expects(:auth_neutron).with('subnet-update',
54                                            '--enable-dhcp',
55                                            subnet_name)
56       provider.enable_dhcp=('True')
57     end
58
59     it 'should call subnet-update to change dns_nameservers' do
60       provider.expects(:auth_neutron).with('subnet-update',
61                                            [subnet_name,
62                                            '--dns-nameservers',
63                                            'list=true',
64                                            '9.9.9.9'])
65       provider.dns_nameservers=(['9.9.9.9'])
66     end
67
68     it 'should call subnet-update to change host_routes' do
69       provider.expects(:auth_neutron).with('subnet-update',
70                                            [subnet_name,
71                                             '--host-routes',
72                                             'type=dict',
73                                             'list=true',
74                                             'destination=12.0.0.0/24,nexthop=10.0.0.2'])
75       provider.host_routes=(['destination=12.0.0.0/24,nexthop=10.0.0.2'])
76     end
77
78     it 'should not update if dns_nameservers are empty' do
79       provider.dns_nameservers=('')
80     end
81
82     it 'should not update if host_routes are empty' do
83       provider.host_routes=('')
84     end
85   end
86
87   describe 'when updating a subnet (reverse)' do
88     let :subnet_attrs_mod do
89       subnet_attrs.merge!({:enable_dhcp => 'True'})
90     end
91     let :resource do
92       Puppet::Type::Neutron_subnet.new(subnet_attrs_mod)
93     end
94
95     let :provider do
96       provider_class.new(resource)
97     end
98
99
100     it 'should call subnet-update to change enable_dhcp' do
101       provider.expects(:auth_neutron).with('subnet-update',
102                                            '--disable-dhcp',
103                                            subnet_name)
104       provider.enable_dhcp=('False')
105     end
106   end
107 end