Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to poise python and Chef12+ syntax #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
driver_plugin: vagrant
driver_config:
require_chef_omnibus: 12

provisioner:
name: chef_solo
name: chef_zero

platforms:
- name: centos-7.1
- name: centos-7.6

suites:
- name: source
Expand Down
40 changes: 22 additions & 18 deletions attributes/exabgp.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
default[:exabgp][:local_as] = 12345
default[:exabgp][:peer_as] = 12345
default[:exabgp][:community] = [0]
default['exabgp']['local_as'] = 12345
default['exabgp']['peer_as'] = 12345
default['exabgp']['community'] = [0]

default[:exabgp][:hold_time] = 20
default[:exabgp][:local_preference] = nil
default['exabgp']['hold_time'] = 20
default['exabgp']['local_preference'] = nil

default[:exabgp][:ipv4][:neighbor] = '127.0.0.1'
default[:exabgp][:ipv4][:anycast] = ['127.0.0.1/32', '127.0.0.2/32']
default[:exabgp][:ipv4][:enable_static_route] = true
default['exabgp']['ipv4']['neighbor'] = '127.0.0.1'
default['exabgp']['ipv4']['anycast'] = ['127.0.0.1/32', '127.0.0.2/32']
default['exabgp']['ipv4']['enable_static_route'] = true

default[:exabgp][:ipv6][:neighbor] = nil
default[:exabgp][:ipv6][:anycast] = ['::1/128']
default['exabgp']['ipv6']['neighbor'] = nil
default['exabgp']['ipv6']['anycast'] = ['::1/128']

default[:exabgp][:source_version] = 'master'
default[:exabgp][:bin_path] = '/usr/local/bin/exabgp'
default['exabgp']['source_version'] = 'master'
default['exabgp']['bin_path'] = '/usr/local/bin/exabgp'

default[:exabgp][:watchdog_flag_file] = '/tmp/exabgp-announce'
default['exabgp']['watchdog_flag_file'] = '/tmp/exabgp-announce'

default[:exabgp][:hubot][:enable] = false
default[:exabgp][:hubot][:url] = 'http://localhost:9998'
default[:exabgp][:hubot][:secret] = 'secret'
default[:exabgp][:hubot][:event] = 'sre'
default['exabgp']['hubot'][:enable] = false
default['exabgp']['hubot'][:url] = 'http://localhost:9998'
default['exabgp']['hubot'][:secret] = 'secret'
default['exabgp']['hubot'][:event] = 'sre'

default[:exabgp][:systemd][:after] = %w(network.target)
default['exabgp']['systemd']['after'] = %w(network.target)

# lock pip version, poise-python is broken with later
# https://github.com/vinted/chef/blob/c5af12a421fefbc55e60240329e014f1d7f4a690/cookbooks/vinted-python/attributes/default.rb#L3
default['poise-python']['options']['pip_version'] = '9.0.3'
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
license 'Apache 2.0'
description 'Installs/Configures exabgp'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.3.0'
version '0.4.0'

supports 'ubuntu', '>= 12.04'
supports 'centos', '>= 6.0'

depends 'python'
depends 'poise-python'
depends 'runit'
depends 'systemd', '~> 3.2.2'
42 changes: 23 additions & 19 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,36 @@

systemd_enabled = ::File.open('/proc/1/comm').gets.chomp == 'systemd'

include_recipe 'python'
python_runtime 'system' do
version '2'
provider :system
end

include_recipe 'runit' unless systemd_enabled

python_pip 'exabgp' do
python_package 'exabgp' do
action :install
end unless node[:recipes].include? 'exabgp::source'
end unless node['recipes'].include? 'exabgp::source'

directory '/etc/exabgp'

template 'exabgp: config' do
path '/etc/exabgp/exabgp.conf'
source 'exabgp.conf.erb'
variables( router_id: node.ipaddress,
hold_time: node[:exabgp][:hold_time],
neighbor_ipv4: node[:exabgp][:ipv4][:neighbor],
local_address_ipv4: node.ipaddress,
local_preference: node[:exabgp][:local_preference],
variables( router_id: node['ipaddress'],
hold_time: node['exabgp']['hold_time'],
neighbor_ipv4: node['exabgp']['ipv4']['neighbor'],
local_address_ipv4: node['ipaddress'],
local_preference: node['exabgp']['local_preference'],
route_ipv4: route('ipv4'),
enable_ipv4_static_route: node[:exabgp][:ipv4][:enable_static_route],
enable_hubot: node[:exabgp][:hubot][:enable],
neighbor_ipv6: node[:exabgp][:ipv6][:neighbor],
local_address_ipv6: node[:ip6address],
enable_ipv4_static_route: node['exabgp']['ipv4']['enable_static_route'],
enable_hubot: node['exabgp']['hubot']['enable'],
neighbor_ipv6: node['exabgp']['ipv6']['neighbor'],
local_address_ipv6: node['ip6address'],
route_ipv6: route('ipv6'),
local_as: node[:exabgp][:local_as],
peer_as: node[:exabgp][:peer_as],
community: node[:exabgp][:community].join(' '))
local_as: node['exabgp']['local_as'],
peer_as: node['exabgp']['peer_as'],
community: node['exabgp']['community'].join(' '))
mode '644'
notifies :run, 'execute[reload-exabgp-config]' unless systemd_enabled
notifies :reload, 'service[exabgp]' if systemd_enabled
Expand All @@ -53,9 +57,9 @@
template '/etc/exabgp/neighbor-changes.rb' do
source 'neighbor-changes.rb.erb'
variables hubot_publish: {
url: node[:exabgp][:hubot][:url],
secret: node[:exabgp][:hubot][:secret],
event: node[:exabgp][:hubot][:event]
url: node['exabgp']['hubot']['url'],
secret: node['exabgp']['hubot']['secret'],
event: node['exabgp']['hubot']['event']
}
mode 0755
notifies :run, 'execute[reload-exabgp-config]' unless systemd_enabled
Expand All @@ -74,7 +78,7 @@
systemd_service 'exabgp' do
unit do
description 'ExaBGP service'
after node[:exabgp][:systemd][:after]
after node['exabgp']['systemd']['after']
condition_path_exists '/etc/exabgp/exabgp.conf'
end

Expand Down
4 changes: 2 additions & 2 deletions recipes/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

git '/usr/src/exabgp' do
repository 'https://github.com/Exa-Networks/exabgp.git'
reference node[:exabgp][:source_version]
reference node['exabgp']['source_version']
action :sync
end

node.set[:exabgp][:bin_path] = '/usr/src/exabgp/sbin/exabgp'
node.override['exabgp']['bin_path'] = '/usr/src/exabgp/sbin/exabgp'

include_recipe 'exabgp::default'
2 changes: 1 addition & 1 deletion templates/default/sv-exabgp-run.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
exec 2>&1
exec chpst -u nobody <%= node[:exabgp][:bin_path] %> /etc/exabgp/exabgp.conf
exec chpst -u nobody <%= node['exabgp']['bin_path'] %> /etc/exabgp/exabgp.conf