Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
* Add complete spec test coverage
* Default values for hyperglass::server no longer contain bogus devices
* Simplify the classes
* Make managing users and groups optional
* Make each of the service dependencies for the server optional
  • Loading branch information
ghoneycutt committed Sep 28, 2020
1 parent 6dc8d80 commit 82e2a7a
Show file tree
Hide file tree
Showing 23 changed files with 719 additions and 399 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Style/TrailingCommaInLiteral:
Enabled: false
inherit_gem:
voxpupuli-test: rubocop.yml
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,43 @@ class { 'hyperglass::server':
}
```

An example showing devices populated.

```puppet
class { 'hyperglass::server':
data => {...},
commands => {...},
devices => {
'routers' => [
{
'name' => 'atl_router01',
'address' => '10.0.0.2',
'network' => {
'name' => 'secondary',
'display_name' => 'That Other Network',
},
'credential' => {
'username' => 'user2',
'password' => ' secret2',
},
'display_name' => 'Atlanta, GA',
'port' => 22,
'nos' => 'juniper',
'vrfs' => [
{
'name' => 'default',
'display_name' => 'Global',
'ipv4' => {
'source_address' => '192.0.2.2',
},
},
],
},
],
},
}
```

Please take a look at the official
[hyperglass documentation](https://hyperglass.io/docs/parameters).

Expand Down
22 changes: 22 additions & 0 deletions data/beaker/true.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
hyperglass::server::data:
listen_address: 0.0.0.0

hyperglass::server::devices:
routers:
- name: atl_router01
address: 10.0.0.2
network:
name: secondary
display_name: That Other Network
credential:
username: user2
password: " secret2"
display_name: Atlanta, GA
port: 22
nos: juniper
vrfs:
- name: default
display_name: Global
ipv4:
source_address: 192.0.2.2
1 change: 1 addition & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--- {}
11 changes: 11 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: 5
defaults:
datadir: data
data_hash: yaml_data
hierarchy:
- name: "Acceptance testing with Beaker"
path: "beaker/%{facts.beaker}.yaml"
- name: "common"
path: "common.yaml"

103 changes: 90 additions & 13 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# @summary installs the hyperglass linux agent
#
# @param manage_python installs python3
# @param manage_gcc installs gcc
# @param data generic hyperglass configuration hash.
# @param manage_python
# installs python3
# @param manage_gcc
# installs gcc
# @param manage_user
# When true, the user 'hyperglass-agent' is managed.
# @param manage_group
# When true, the group 'hyperglass-agent' is managed.
# @param data
# generic hyperglass configuration hash.
#
# @see https://github.com/checktheroads/hyperglass-agent
#
# @author Tim Meusel <[email protected]>
class hyperglass::agent (
Boolean $manage_python = true,
Boolean $manage_gcc = true,
Hash $data = {
Boolean $manage_gcc = true,
Boolean $manage_user = true,
Boolean $manage_group = true,
Hash $data = {
'debug' => true,
'listen_address' => '127.0.0.1',
'mode' => 'bird',
Expand All @@ -20,11 +28,80 @@
},
},
) {
require hyperglass::hyperglassdir
contain hyperglass::agent::install
contain hyperglass::agent::config
contain hyperglass::agent::service
Class['hyperglass::agent::install']
-> Class['hyperglass::agent::config']
~> Class['hyperglass::agent::service']
include hyperglass

if $manage_python {
ensure_resource('class', 'python', { 'version' => '3', 'dev' => 'present' })
}

if $manage_gcc {
ensure_resource('package', 'gcc', { 'ensure' => 'installed' })
}

if $manage_user {
user { 'hyperglass-agent':
ensure => 'present',
managehome => true,
purge_ssh_keys => true,
system => true,
home => '/opt/hyperglass/hyperglass-agent',
}
}

if $manage_group {
group { 'hyperglass-agent':
ensure => 'present',
system => true,
}
}

file { '/opt/hyperglass/hyperglass-agent':
ensure => 'directory',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
mode => '0700',
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

# we need to explicitly set the version here. During the first puppet run, python3 will be installed but isn't present yet
# due to that the fact is undef and fails. the default of the `version` attribute is the fact. We workaround this by hardcoding
# the python version
python::pyvenv { '/opt/hyperglass/hyperglass-agent/virtualenv':
ensure => 'present',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
systempkgs => false,
version => pick($facts['python3_version'], '3.6'),
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

python::pip { 'hyperglass-agent':
virtualenv => '/opt/hyperglass/hyperglass-agent/virtualenv',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

file { '/opt/hyperglass/hyperglass-agent/hyperglass-agent':
ensure => 'directory',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
mode => '0755',
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

file { '/opt/hyperglass/hyperglass-agent/hyperglass-agent/config.yaml':
ensure => 'file',
owner => 'hyperglass-agent',
group => 'hyperglass-agent',
mode => '0400',
content => to_yaml($data),
notify => Systemd::Unit_file['hyperglass-agent.service'],
}

systemd::unit_file { 'hyperglass-agent.service':
source => 'puppet:///modules/hyperglass/hyperglass-agent.service',
enable => true,
active => true,
}
}
17 changes: 0 additions & 17 deletions manifests/agent/config.pp

This file was deleted.

58 changes: 0 additions & 58 deletions manifests/agent/install.pp

This file was deleted.

13 changes: 0 additions & 13 deletions manifests/agent/service.pp

This file was deleted.

11 changes: 0 additions & 11 deletions manifests/gcc.pp

This file was deleted.

14 changes: 0 additions & 14 deletions manifests/hyperglassdir.pp

This file was deleted.

12 changes: 12 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# @summary Manage the Hyperglass bits that are common to both agent and server.
#
# @api private
#
class hyperglass {
file { '/opt/hyperglass':
ensure => 'directory',
owner => 'root',
group => 'root',
mode => '0755',
}
}
13 changes: 0 additions & 13 deletions manifests/python.pp

This file was deleted.

Loading

0 comments on commit 82e2a7a

Please sign in to comment.