Merge "Removes deprecated type midonet_network"

This commit is contained in:
Jenkins 2016-11-04 16:45:06 +00:00 committed by Gerrit Code Review
commit 83039d8ff2
4 changed files with 0 additions and 417 deletions

View File

@ -1,148 +0,0 @@
if RUBY_VERSION == '1.8.7'
require 'rubygems'
end
require 'uri'
require 'faraday' if Puppet.features.faraday?
require 'json'
Puppet::Type.type(:midonet_network).provide(:midonet_api_caller) do
confine :feature => :faraday
def create
define_connection(resource[:midonet_api_url])
tenants = call_get_tenant(resource[:tenant_name])
if tenants.empty?
raise "Tenant with specified name #{resource[:tenant_name]} does not exist"
end
tenant_id = tenants[0]['id']
network = call_get_network(resource[:netname],tenant_id)
if !network.empty?
raise "Network #{resource[:netname]} for tenant #{resource[:tenant_name]} already exists"
end
message = Hash.new
message['name'] = resource[:netname]
message['tenant_id'] = tenant_id
message['shared'] = resource[:shared]
message['external'] = resource[:external]
call_create_network(message)
end
def destroy
define_connection(resource[:midonet_api_url])
tenants = call_get_tenant(resource[:tenant_name])
if tenants.empty?
return
end
tenant_id = tenants[0]['id']
network = call_get_network(resource[:netname],tenant_id)
if network.empty?
return
else
call_delete_network(network)
end
end
def exists?
define_connection(resource[:midonet_api_url])
tenants = call_get_tenant(resource[:tenant_name])
if tenants.empty?
raise "Tenant with specified name #{resource[:tenant_name]} does not exist"
end
tenant_id = tenant[0]['id']
network = call_get_network(resource[:netname],tenant_id)
if network.empty?
return false
else
return true
end
end
def define_connection(url)
@connection = Faraday.new(:url => url,
:ssl => { :verify =>false }) do |builder|
builder.request(:retry, {
:max => 5,
:interval => 0.05,
:exceptions => [
Faraday::Error::TimeoutError,
Faraday::ConnectionFailed,
Errno::ETIMEDOUT,
'Timeout::Error',
],
})
builder.request(:basic_auth, resource[:username], resource[:password])
builder.adapter(:net_http)
end
@connection.headers['X-Auth-Token'] = call_get_token()
end
def call_get_token()
res = @connection.get do |req|
req.url "/midonet-api/login"
end
return JSON.parse(res.body)['key']
end
def call_get_tenant(tenant_name)
res = @connection.get do |req|
req.url "/midonet-api/tenants"
end
output = JSON.parse(res.body)
return output.select{ |tenant| tenant['name'] == tenant_name.to_s }
end
def call_get_network(network_name,tenant_id)
res = @connection.get do |req|
req.url "/midonet-api/neutron/networks"
end
output = JSON.parse(res.body)
return output.select{ |network| network['name'] == network_name.to_s and network['tenant_id'] == tenant_id }
end
def call_get_networks()
res = @connection.get do |req|
req.url "/midonet-api/neutron/networks"
end
output = JSON.parse(res.body)
return output
end
def call_create_network(message)
res = @connection.post do |req|
req.url "/midonet-api/neutron/networks"
req.headers['Content-Type'] = "application/vnd.org.midonet.Network-v1+json"
req.body = message.to_json
end
return call_get_networks()
end
def call_delete_network(network_id)
res = @connection.delete do |req|
req.url "/midonet-api/neutron/networks/#{network_id}"
end
end
private :call_create_network,
:call_delete_network,
:call_get_tenant,
:call_get_network,
:define_connection
end

View File

@ -1,77 +0,0 @@
require 'uri'
require 'facter'
require 'puppet/parameter/boolean'
Puppet::Type.newtype(:midonet_network) do
@doc = %q{Register a Network to a Neutron
through the MidoNet API
Example:
midonet_network {'netname':
$midonet_api_url => 'http://controller:8080',
$username => 'admin',
$password => 'admin',
$tenant_name => 'admin',
$shared => true,
$external => true,
}
}
ensurable
newparam(:netname, :namevar => true) do
desc 'Name of the networks that wants to be created in Neutron'
validate do |value|
unless value =~ /\w+/
raise ArgumentError, "'%s' is not a valid network name" % value
end
end
end
newparam(:midonet_api_url) do
desc 'MidoNet API endpoint to connect to'
validate do |value|
unless value =~ /\A#{URI::regexp(['http', 'https'])}\z/
raise ArgumentError, "'%s' is not a valid URI" % value
end
end
end
newparam(:username) do
desc 'Username of the admin user in keystone'
validate do |value|
unless value =~ /^[\w\-\_]+$/
raise ArgumentError, "'%s' is not a valid username" % value
end
end
end
newparam(:password) do
desc 'Password of the admin user in keystone'
validate do |value|
unless value =~ /^[\w\-\_]+$/
raise ArgumentError, "'%s' is not a valid password" % value
end
end
end
newparam(:tenant_name) do
desc 'Tenant name of the admin user'
defaultto :'admin'
validate do |value|
unless value =~ /^[\w\-\_]+$/
raise ArgumentError, "'%s' is not a tenant name" % value
end
end
end
newparam(:external, :boolean => true, :parent => Puppet::Parameter::Boolean) do
desc "Switch to mark the network as external or not"
end
newparam(:shared, :boolean => true, :parent => Puppet::Parameter::Boolean) do
desc "Switch to mark the network as shared or not"
end
end

View File

@ -1,160 +0,0 @@
require 'spec_helper'
describe Puppet::Type.type(:midonet_network).provider(:midonet_api_caller) do
let(:provider) { described_class.new(resource) }
let(:resource) { Puppet::Type.type(:midonet_network).new(
{
:ensure => :present,
:netname => 'testnet',
:midonet_api_url => 'http://controller:8080',
:username => 'admin',
:password => 'admin',
:tenant_name => 'admin',
:shared => true,
:external => true
}
)}
describe 'network happy path' do
# - Tenant Existing
# - Network not previously existing
let(:tenants) {
[
{
"name" => "admin",
"id" => "bd69f96a-005b-4d58-9f6c-b8dd9fbb6339",
}
]
}
let(:networks) {
[
{
"name" => "testnet",
"id" => "by82a88d-005b-4d58-9f6c-aaaaaaaa1111",
"tenant_id" => "admin",
"shared" => "true",
"external" => "true"
}
]
}
before :each do
allow(provider).to receive(:call_get_tenant).and_return(tenants)
allow(provider).to receive(:call_get_network).and_return(networks)
allow(provider).to receive(:call_delete_network)
allow(provider).to receive(:call_create_network)
allow(provider).to receive(:call_get_token).and_return('thisisafaketoken')
end
it 'registers the network successfully' do
# Expectations over 'create' call
expect(provider).to receive(:call_get_tenant).and_return(tenants)
expect(provider).to receive(:call_get_network).and_return([])
expect(provider).to receive(:call_create_network).with({'name' => 'testnet', 'tenant_id' => 'bd69f96a-005b-4d58-9f6c-b8dd9fbb6339', 'shared' => true, 'external' => true})
provider.create
end
it 'unregisters the network successfully' do
# Expectations over 'create' call
expect(provider).to receive(:call_get_tenant).and_return(tenants)
expect(provider).to receive(:call_get_network).and_return(networks)
expect(provider).to receive(:call_delete_network).and_return([])
provider.destroy
end
end
##
describe 'try to create a network for an unexisting tenant' do
# - Tenant Existing
# - Network not previously existing
let(:tenants) {
[
{
"name" => "admin",
"id" => "bd69f96a-005b-4d58-9f6c-b8dd9fbb6339",
}
]
}
let(:networks) {
[
{
"name" => "testnet",
"id" => "by82a88d-005b-4d58-9f6c-aaaaaaaa1111",
"tenant_id" => "admin",
"shared" => "true",
"external" => "true"
}
]
}
it 'should raise an exception' do
# Expectations over 'create' call
allow(provider).to receive(:call_get_tenant).and_return([])
allow(provider).to receive(:call_get_token).and_return('thisisafaketoken')
expect {
provider.create
}.to raise_error(RuntimeError)
end
end
##
describe 'try to delete a network that does not exist' do
# - Tenant Existing
# - Network not previously existing
let(:tenants) {
[
{
"name" => "admin",
"id" => "bd69f96a-005b-4d58-9f6c-b8dd9fbb6339",
}
]
}
let(:networks) {
[
{
"name" => "testnet",
"id" => "by82a88d-005b-4d58-9f6c-aaaaaaaa1111",
"tenant_id" => "admin",
"shared" => "true",
"external" => "true"
}
]
}
it 'should not fail' do
# Expectations over 'create' call
allow(provider).to receive(:call_get_tenant).and_return(tenants)
allow(provider).to receive(:call_get_network).and_return([])
allow(provider).to receive(:call_get_token).and_return('thisisafaketoken')
expect(provider).not_to receive(:call_delete_network)
provider.destroy
end
end
end

View File

@ -1,32 +0,0 @@
require 'spec_helper'
require 'puppet'
require 'puppet/type/midonet_network'
require 'facter'
describe Puppet::Type::type(:midonet_network) do
context 'on default values' do
let(:resource) do
Puppet::Type.type(:midonet_network).new(
:netname => 'testnet',
:midonet_api_url => 'http://87.23.43.2:8080/midonet-api',
:username => 'admin',
:password => 'admin',
:tenant_name => 'admin',
:shared => true,
:external => true,)
end
it 'assign the default values' do
expect(resource[:midonet_api_url]).to eq 'http://87.23.43.2:8080/midonet-api'
expect(resource[:username]).to eq 'admin'
expect(resource[:password]).to eq 'admin'
expect(resource[:tenant_name]).to eq 'admin'
expect(resource[:shared]).to eq true
expect(resource[:external]).to eq true
end
end
end