From ecc63a0a28c362ddf4797d3be27a1660c1fa0d94 Mon Sep 17 00:00:00 2001 From: Rafael Chicoli Date: Tue, 26 Jan 2016 19:26:29 +0100 Subject: fix all puppet-lint error messages --- .fixtures.yml | 4 ++ manifests/config.pp | 14 +++--- manifests/init.pp | 43 ++++++++++++----- manifests/install.pp | 7 +-- manifests/params.pp | 16 ++++--- manifests/repo.pp | 30 +++++++++++- manifests/repo/apt.pp | 24 ---------- manifests/runner.pp | 73 +++++++++++++++++++---------- manifests/service.pp | 5 +- spec/classes/example_spec.rb | 35 -------------- spec/classes/gitlab_ci_multi_runner_spec.rb | 50 ++++++++++++++++++++ 11 files changed, 184 insertions(+), 117 deletions(-) delete mode 100644 manifests/repo/apt.pp delete mode 100644 spec/classes/example_spec.rb create mode 100644 spec/classes/gitlab_ci_multi_runner_spec.rb diff --git a/.fixtures.yml b/.fixtures.yml index a5e0e10..9de578d 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,9 @@ fixtures: repositories: + concat: "git://github.com/puppetlabs/puppetlabs-concat.git" stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" + apt: + repo: "git://github.com/puppetlabs/puppetlabs-apt.git" + ref: 2.2.1 symlinks: gitlab_ci_multi_runner: "#{source_dir}" diff --git a/manifests/config.pp b/manifests/config.pp index 5cf7525..c8a6fbd 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -7,19 +7,21 @@ class gitlab_ci_multi_runner::config ( $runners = $gitlab_ci_multi_runner::runners, ) { - concat { $::gitlab_ci_multi_runner::config_file: + concat { $gitlab_ci_multi_runner::config_file: ensure => present, - owner => $::gitlab_ci_multi_runner::user, - group => $::gitlab_ci_multi_runner::group, + owner => $gitlab_ci_multi_runner::user, + group => $gitlab_ci_multi_runner::group, require => Package[$gitlab_ci_multi_runner::package_name], notify => Service[$gitlab_ci_multi_runner::service_name], } - concat::fragment { "header_$::gitlab_ci_multi_runner::config_file": - target => $::gitlab_ci_multi_runner::config_file, + concat::fragment { "header_${::gitlab_ci_multi_runner::config_file}": + target => $gitlab_ci_multi_runner::config_file, content => template('gitlab_ci_multi_runner/fragment_header_config.toml.erb'), order => '01', } - create_resources(gitlab_ci_multi_runner::runner, $runners) + if $gitlab_ci_multi_runner::runners { + create_resources(gitlab_ci_multi_runner::runner, $runners) + } } diff --git a/manifests/init.pp b/manifests/init.pp index 77dcf73..0b71778 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,32 +4,49 @@ # # === Parameters # -# [*package_name*] - Specify gitlab multi runner package name -# Defaults to gitlab-ci-multi-runner -# [*service_name*] - Specify the service name for gitlab multi runner -# Defaults to gitlab-runner -# [*manage_package_repo*] - Manage package repository for multi runner -# Defaults to undef -# [*user*] - Default user for multi runner -# Defaults to gitlab-runner -# [*group*] - Default group for multi runner -# Defaults to gitlab-runner -# [*concurrent*] - Number of concurrents jobs -# Defaults to 1 +# [*package_name*] +# Specify gitlab multi runner package name +# Defaults to gitlab-ci-multi-runner +# +# [*service_name*] +# Specify the service name for gitlab multi runner +# Defaults to gitlab-runner +# +# [*manage_package_repo*] +# Manage package repository for multi runner +# Defaults to undef +# +# [*user*] +# Default user for multi runner +# Defaults to gitlab-runner +# +# [*group*] +# Default group for multi runner +# Defaults to gitlab-runner +# +# [*concurrent*] +# Number of concurrents jobs +# Defaults to 1 +# class gitlab_ci_multi_runner ( $package_name = $gitlab_ci_multi_runner::params::package_name, $service_name = $gitlab_ci_multi_runner::params::service_name, + $service_ensure = $gitlab_ci_multi_runner::params::service_ensure, + $service_enable = $gitlab_ci_multi_runner::params::service_enable, $manage_package_repo = $gitlab_ci_multi_runner::params::manage_package_repo, $user = $gitlab_ci_multi_runner::params::user, $group = $gitlab_ci_multi_runner::params::group, $concurrent = $gitlab_ci_multi_runner::params::concurrent, $runners = $gitlab_ci_multi_runner::params::runners, + $config_file = $gitlab_ci_multi_runner::params::config_file, ) inherits gitlab_ci_multi_runner::params { # validate parameters here + anchor { 'before_gitlab_ci_multi_runner': } -> class { 'gitlab_ci_multi_runner::install': } -> class { 'gitlab_ci_multi_runner::config': } ~> class { 'gitlab_ci_multi_runner::service': } -> - Class['gitlab_ci_multi_runner'] + anchor { 'after_gitlab_ci_multi_runner': } + } diff --git a/manifests/install.pp b/manifests/install.pp index 128b5a1..3fb8a0a 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -2,11 +2,8 @@ # class gitlab_ci_multi_runner::install { - ensure_packages('apt-transport-https') - - if($::gitlab_ci_multi_runner::manage_package_repo) { - class { 'gitlab_ci_multi_runner::repo': - } + if( $gitlab_ci_multi_runner::manage_package_repo ) { + class { 'gitlab_ci_multi_runner::repo': } } package { $gitlab_ci_multi_runner::package_name: diff --git a/manifests/params.pp b/manifests/params.pp index 8913977..2f94a7c 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -6,21 +6,25 @@ class gitlab_ci_multi_runner::params { $config_file = '/etc/gitlab-runner/config.toml' - $manage_package_repo = undef $user = 'gitlab-runner' $group = 'gitlab-runner' $concurrent = 1 - $runnners = undef + $runners = undef + + $service_ensure = true + $service_enable = true case $::osfamily { 'Debian': { - $package_name = 'gitlab-ci-multi-runner' - $service_name = 'gitlab-runner' + $package_name = 'gitlab-ci-multi-runner' + $service_name = 'gitlab-runner' + $manage_package_repo = true } 'RedHat': { - $package_name = 'gitlab_ci_multi_runner' - $service_name = 'gitlab_ci_multi_runner' + $package_name = 'gitlab_ci_multi_runner' + $service_name = 'gitlab_ci_multi_runner' + $manage_package_repo = false } default: { fail("${::operatingsystem} not supported") diff --git a/manifests/repo.pp b/manifests/repo.pp index 2263170..55e73df 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -5,7 +5,33 @@ class gitlab_ci_multi_runner::repo { case $::osfamily { 'Debian': { - class { 'gitlab_ci_multi_runner::repo::apt': } + + include apt + # apt-transport-https is required by the apt to get the sources + ensure_packages('apt-transport-https') + + Package['apt-transport-https'] -> + Apt::Source['gitlab-ci-multi-runner'] -> + Package['gitlab-ci-multi-runner'] + + apt::source { 'gitlab-ci-multi-runner': + comment => 'This is an officiel apt repo for Gitlab Ci Multi Runner', + location => 'https://packages.gitlab.com/runner/gitlab-ci-multi-runner/debian/', + release => $::lsbdistcodename, + repos => 'main', + key => { + 'id' => '1A4C919DB987D435939638B914219A96E15E78F4', + 'source' => 'https://packages.gitlab.com/gpg.key', + }, + include => { + 'src' => true, + 'deb' => true, + }, + } + } + default: { + fail("${::operatingsystem} not supported") } } -} \ No newline at end of file + +} diff --git a/manifests/repo/apt.pp b/manifests/repo/apt.pp deleted file mode 100644 index af7b073..0000000 --- a/manifests/repo/apt.pp +++ /dev/null @@ -1,24 +0,0 @@ -# == Class gitlab_ci_multi_runner::repo::apt -# -# This class is private, do not use directly -# -class gitlab_ci_multi_runner::repo::apt { - include apt - - apt::source { 'gitlab-ci-multi-runner': - comment => 'This is an officiel apt repo for Gitlab Ci Multi Runner', - location => 'https://packages.gitlab.com/runner/gitlab-ci-multi-runner/debian/', - release => $::lsbdistcodename, - repos => 'main', - key => { - 'id' => '1A4C919DB987D435939638B914219A96E15E78F4', - 'source' => 'https://packages.gitlab.com/gpg.key', - }, - include => { - 'src' => true, - 'deb' => true, - }, - } - - Apt::Source['gitlab-ci-multi-runner']->Package<|tag == 'gitlab-ci-multi-runner'|> -} \ No newline at end of file diff --git a/manifests/runner.pp b/manifests/runner.pp index f14cd06..2af8271 100644 --- a/manifests/runner.pp +++ b/manifests/runner.pp @@ -2,28 +2,53 @@ # # Class for creating runners in multi-runner's config file. # -# [*url*] - CI URL -# Defaults to http://gitlab.example.com -# [*token*] - runner token -# Defaults to 'XXXX' -# [*limit*] - limit how many jobs can be handled concurrently by this token. 0 simply means don't limit -# Defaults to undef -# [*shell*] - the name of shell to generate the script (default value is platform dependent) (bash, cmd, powershell) -# Defaults to undef -# [*executor*] - select how a project should be built (shell, docker, docker-ssh, ssh, parallels) -# Defaults to shell -# [*builds_dir*] - directory where builds will be stored in context of selected executor (Locally, Docker, SSH) -# Defaults to undef -# [*environment*] - append or overwrite environment variables -# Defaults to undef -# [*disable_verbose*] - don't print run commands -# Defaults to undef -# [*output_limit*] - set maximum build log size in kilobytes, by default set to 4096 (4MB) -# Defaults to undef -# [*docker_params*] - Docker params (image, allowed_images, allowed_services, volumes, ...). Need executor_docker to true. -# Defaults to undef +# [*url*] +# CI URL +# Defaults to http://gitlab.example.com +# [*token*] +# runner token +# Defaults to 'XXXX' +# +# [*limit*] +# limit how many jobs can be handled concurrently by this token. +# 0 simply means don't limit +# Defaults to undef +# +# [*shell*] +# the name of shell to generate the script +# (default value is platform dependent) (bash, cmd, powershell) +# Defaults to undef +# +# [*executor*] +# select how a project should be built +# (shell, docker, docker-ssh, ssh, parallels) +# Defaults to shell +# +# [*builds_dir*] +# directory where builds will be stored in context of selected executor +# (Locally, Docker, SSH) +# Defaults to undef +# +# [*environment*] +# append or overwrite environment variables +# Defaults to undef +# +# [*disable_verbose*] +# don't print run commands +# Defaults to undef +# +# [*output_limit*] +# set maximum build log size in kilobytes, by default set to 4096 (4MB) +# Defaults to undef +# +# [*docker_params*] +# Docker params (image, allowed_images, allowed_services, volumes, ...). +# Need executor_docker to true. +# Defaults to undef +# # [*config_file*] - Path for Gitlab Multi Runner config file -# Default value in params. +# Default value in params. +# define gitlab_ci_multi_runner::runner ( $url = 'http://gitlab.example.com', $token = 'XXXX', @@ -39,9 +64,9 @@ define gitlab_ci_multi_runner::runner ( $config_file = $gitlab_ci_multi_runner::params::config_file, ){ - concat::fragment { "${name}_$::gitlab_ci_multi_runner::config_file": - target => $::gitlab_ci_multi_runner::config_file, + concat::fragment { "${name}_${gitlab_ci_multi_runner::config_file}": + target => $gitlab_ci_multi_runner::config_file, content => template('gitlab_ci_multi_runner/fragment_runner_config.toml.erb'), } -} \ No newline at end of file +} diff --git a/manifests/service.pp b/manifests/service.pp index 8ac2727..7785699 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -6,9 +6,10 @@ class gitlab_ci_multi_runner::service { service { $gitlab_ci_multi_runner::service_name: - ensure => running, - enable => true, + ensure => $gitlab_ci_multi_runner::service_ensure, + enable => $gitlab_ci_multi_runner::service_enable, hasstatus => true, hasrestart => true, } + } diff --git a/spec/classes/example_spec.rb b/spec/classes/example_spec.rb deleted file mode 100644 index 7dc8942..0000000 --- a/spec/classes/example_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'spec_helper' - -describe 'gitlab_ci_multi_runner' do - context 'supported operating systems' do - ['Debian', 'RedHat'].each do |osfamily| - describe "gitlab_ci_multi_runner class without any parameters on #{osfamily}" do - let(:params) {{ }} - let(:facts) {{ - :osfamily => osfamily, - }} - - it { should compile.with_all_deps } - - it { should contain_class('gitlab_ci_multi_runner::params') } - it { should contain_class('gitlab_ci_multi_runner::install').that_comes_before('gitlab_ci_multi_runner::config') } - it { should contain_class('gitlab_ci_multi_runner::config') } - it { should contain_class('gitlab_ci_multi_runner::service').that_subscribes_to('gitlab_ci_multi_runner::config') } - - it { should contain_service('gitlab_ci_multi_runner') } - it { should contain_package('gitlab_ci_multi_runner').with_ensure('present') } - end - end - end - - context 'unsupported operating system' do - describe 'gitlab_ci_multi_runner class without any parameters on Solaris/Nexenta' do - let(:facts) {{ - :osfamily => 'Solaris', - :operatingsystem => 'Nexenta', - }} - - it { expect { should contain_package('gitlab_ci_multi_runner') }.to raise_error(Puppet::Error, /Nexenta not supported/) } - end - end -end diff --git a/spec/classes/gitlab_ci_multi_runner_spec.rb b/spec/classes/gitlab_ci_multi_runner_spec.rb new file mode 100644 index 0000000..f23ab90 --- /dev/null +++ b/spec/classes/gitlab_ci_multi_runner_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'gitlab_ci_multi_runner', :type => :class do + + ['Debian', 'RedHat'].each do |osfamily| + context "on #{osfamily}" do + + if osfamily == 'Debian' + describe "gitlab_ci_multi_runner class without any parameters on #{osfamily}" do + let(:params) {{ }} + let(:facts) {{ + :osfamily => 'Debian', + :concat_basedir => '/dne', + :operatingsystem => 'Debian', + :lsbdistid => 'Debian', + :lsbdistcodename => 'jessie', + :operatingsystemmajrelease => '8', + }} + + it { should compile.with_all_deps } + + it { should contain_class('gitlab_ci_multi_runner::params') } + it { should contain_class('gitlab_ci_multi_runner::install').that_comes_before('gitlab_ci_multi_runner::config') } + it { should contain_class('gitlab_ci_multi_runner::config') } + it { should contain_class('gitlab_ci_multi_runner::service').that_subscribes_to('gitlab_ci_multi_runner::config') } + + it { should contain_class('apt') } + it { should contain_package('apt-transport-https').that_comes_before('Apt::Source[gitlab-ci-multi-runner]').that_comes_before('Package[gitlab-ci-multi-runner]') } + it { should contain_apt__source('gitlab-ci-multi-runner').with_location('https://packages.gitlab.com/runner/gitlab-ci-multi-runner/debian/') } + + it { should contain_service('gitlab-runner') } + it { should contain_package('gitlab-ci-multi-runner').with_name('gitlab-ci-multi-runner').with_ensure('present') } + + it { should contain_package('apt-transport-https').with_ensure('present') } + end + end + end + end + + context 'unsupported operating system' do + describe 'gitlab_ci_multi_runner class without any parameters on Solaris/Nexenta' do + let(:facts) {{ + :osfamily => 'Solaris', + :operatingsystem => 'Nexenta', + }} + + it { expect { should contain_package('gitlab_ci_multi_runner') }.to raise_error(Puppet::Error, /Nexenta not supported/) } + end + end +end -- cgit v1.2.3