Files
puppet-nova/spec/unit/provider/nova_network/nova_spec.rb
Denis Egorenko 21a7a682e9 Rewrite nova_network provider with using only nova client
Currently nova_network provider uses admin tool nova-manage for
managing nova-networks, but this tool doesn't have any authentication
and doesn't provide all features of nova client. This patch avoids
problem with authentication by using nova client for managing networks.

Another goal of this patch, with using nova client, is that all
providers should use one way for authentication, based on
openstack client and openstacklib [1] But the problem is that
openstack client doesn't provide possibility to manage nova-networks.
So, this provider will be used with nova client, until nova-network
exists.

Also added new tests.

[1] blueprint use-openstackclient-in-module-resources

Change-Id: I34c88ab9601b8b0bbf77588005422620eb575d6a
2015-12-10 17:25:48 +00:00

64 lines
2.7 KiB
Ruby

require 'puppet'
require 'puppet/provider/nova_network/nova'
require 'tempfile'
provider_class = Puppet::Type.type(:nova_network).provider(:nova)
describe provider_class do
let :net_attrs do
{
:network => '10.20.0.0/16',
:label => 'novanetwork',
:ensure => 'present',
}
end
let :resource do
Puppet::Type::Nova_network.new(net_attrs)
end
let :provider do
provider_class.new(resource)
end
shared_examples 'nova_network' do
describe '#exists?' do
it 'should check non-existsing network' do
provider.expects(:auth_nova).with("network-list")
.returns('"+--------------------------------------+-------------+-------------+\n| ID | Label | Cidr |\n+--------------------------------------+-------------+-------------+\n| 703edc62-36ab-4c41-9d73-884b30e9acbd | novanetwork | 10.0.0.0/16 |\n+--------------------------------------+-------------+-------------+\n"
')
expect(provider.exists?).to be_falsey
end
it 'should check existsing network' do
provider.expects(:auth_nova).with("network-list")
.returns('"+--------------------------------------+-------------+-------------+\n| ID | Label | Cidr |\n+--------------------------------------+-------------+-------------+\n| 703edc62-36ab-4c41-9d73-884b30e9acbd | novanetwork | 10.20.0.0/16 |\n+--------------------------------------+-------------+-------------+\n"
')
expect(provider.exists?).to be_truthy
end
end
describe '#create' do
it 'should create network' do
provider.expects(:auth_nova).with("network-create", ['novanetwork', '--fixed-range-v4', '10.20.0.0/16'] )
.returns('"+--------------------------------------+-------------+-------------+\n| ID | Label | Cidr |\n+--------------------------------------+-------------+-------------+\n| 703edc62-36ab-4c41-9d73-88sdfsdfsdfsd | nova-network | 10.20.0.0/16 |\n+--------------------------------------+-------------+-------------+\n"
')
provider.create
end
end
describe '#destroy' do
it 'should destroy network' do
resource[:ensure] = :absent
provider.expects(:auth_nova).with("network-delete", "10.20.0.0/16")
.returns('"+--------------------------------------+-------------+-------------+\n| ID | Label | Cidr |\n+--------------------------------------+-------------+-------------+\n
')
provider.destroy
end
end
end
it_behaves_like('nova_network')
end