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

add plugin foreman_column_view #601

Merged
merged 1 commit into from Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions manifests/plugin/column_view.pp
@@ -0,0 +1,15 @@
# @summary Install the column view plugin and optionally manage the configuration file
#
# @param columns
# an hash of columns to add to the configuration
#
class foreman::plugin::column_view (
Hash[String, Hash] $columns = {},
){
# https://projects.theforeman.org/issues/21398
assert_type(Hash[String, Foreman::Column_view_column], $columns)

foreman::plugin { 'column_view':
config => template('foreman/foreman_column_view.yaml.erb'),
}
}
63 changes: 63 additions & 0 deletions spec/classes/plugin/column_view_spec.rb
@@ -0,0 +1,63 @@
require 'spec_helper'

describe 'foreman::plugin::column_view' do
include_examples 'basic foreman plugin tests', 'column_view'

context 'with columns hash architecture' do
let(:params) do
{
'columns' => {
'architecture' => {
'title' => 'Architecture',
'after' => 'last_report',
'content' => 'facts_hash["architecture"]',
}
}
}
end

ekohl marked this conversation as resolved.
Show resolved Hide resolved
it { is_expected.to contain_file('/etc/foreman/plugins/foreman_column_view.yaml').with_content(/.*:title: Architecture.*/) }

it { is_expected.to compile.with_all_deps }
end

context 'with columns hash architecture and console' do
let(:params) do
{
'columns' => {
'architecture' => {
'title' => 'Architecture',
'after' => 'last_report',
'content' => 'facts_hash["architecture"]',
},
'console' => {
'title' => 'Console',
'after' => '0',
'content' => 'link_to(_("Console"), "https://#{host.interfaces.first.name}.domainname", { :class => "btn btn-info" } )',
'conditional' => ':bmc_available?',
'eval_content' => 'true',
'view' => ':hosts_properties',
}
}
}
end

it { is_expected.to contain_file('/etc/foreman/plugins/foreman_column_view.yaml').with_content(/.*:title: Console.*/) }

it { is_expected.to compile.with_all_deps }
end

context 'with columns hash broken' do
let(:params) do
{
'columns' => {
'broken' => {
'title' => 'Broken',
}
}
}
end

it { is_expected.to compile.and_raise_error(%r{broken}) }
end
end
12 changes: 12 additions & 0 deletions templates/foreman_column_view.yaml.erb
@@ -0,0 +1,12 @@
<%= ERB.new(File.read(File.expand_path("_header.erb",File.dirname(file)))).result(binding) -%>
#
# See tfm-rubygem-foreman_column_view-doc and /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_column_view-0.3.0/README.md for more information
:column_view:
<% if @columns -%>
<% @columns.each do |column, hash| -%>
:<%= column %>:
<% hash.each do |key,value| -%>
:<%= key %>: <%= value %>
<% end -%>
<% end -%>
<% end -%>
12 changes: 12 additions & 0 deletions types/column_view_column.pp
@@ -0,0 +1,12 @@
type Foreman::Column_view_column = Struct[
{
title => String[1],
after => String[1],
content => String[1],
Optional['conditional'] => String[1],
Optional['eval_content'] => String[1],
Optional['view'] => String[1],
Optional['width'] => String[1],
Optional['custom_method'] => String[1],
}
]