diff --git a/CHANGELOG.md b/CHANGELOG.md index f68e041..a63a4d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. +## Release 1.0.0 + +First Major Release + +**Features** + +- Add unit tests + ## Release 0.1.4 **Bug fixes** diff --git a/README.md b/README.md index 8e00ae3..1e378d5 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ storj::storage: '[THE DEDICATED ANOUT OF STORAGE]' storj::storage_path: '[THE DEDICATED STORAGE LOCATION]' ``` -### Examples +## Examples #### Default installation diff --git a/REFERENCE.md b/REFERENCE.md index c033846..ac98f7b 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -172,7 +172,7 @@ Group under which storj is running. Default value: 'storj' -##### `usershell` +##### `user_shell` Data type: `Stdlib::Absolutepath` @@ -406,13 +406,13 @@ Group under which storj is running. Default value: $storj::group -##### `usershell` +##### `user_shell` Data type: `Stdlib::Absolutepath` if requested, we create a user for storj. The default shell is false. It can be overwritten to any valid path. -Default value: $storj::usershell +Default value: $storj::user_shell ##### `extra_groups` diff --git a/manifests/init.pp b/manifests/init.pp index c265e8b..5f2d071 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -40,7 +40,7 @@ # User running storj. # @param group # Group under which storj is running. -# @param usershell +# @param user_shell # if requested, we create a user for storj. The default shell is false. It can be overwritten to any valid path. # @param extra_groups # Add other groups to the managed user. @@ -82,7 +82,7 @@ Boolean $manage_group = true, String $user = 'storj', String $group = 'storj', - Stdlib::Absolutepath $usershell = '/bin/false', + Stdlib::Absolutepath $user_shell = '/bin/false', Array[String] $extra_groups = [], # Service diff --git a/manifests/install.pp b/manifests/install.pp index 7830880..0471e8d 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -26,7 +26,7 @@ # User running storj. # @param group # Group under which storj is running. -# @param usershell +# @param user_shell # if requested, we create a user for storj. The default shell is false. It can be overwritten to any valid path. # @param extra_groups # Add other groups to the managed user. @@ -48,7 +48,7 @@ Boolean $manage_group = $storj::manage_group, String $user = $storj::user, String $group = $storj::group, - Stdlib::Absolutepath $usershell = $storj::usershell, + Stdlib::Absolutepath $user_shell = $storj::user_shell, Array[String] $extra_groups = $storj::extra_groups, ) { ensure_packages('unzip', { ensure => 'present' }) @@ -65,7 +65,10 @@ } file { "${base_dir}/storj-${version}.${os}-${arch}": - ensure => 'directory'; + ensure => 'directory', + owner => 'root', + group => 0, # 0 instead of root because OS X uses "wheel". + mode => '0755'; "${base_dir}/storj-${version}.${os}-${arch}/identity": owner => 'root', group => 0, # 0 instead of root because OS X uses "wheel". @@ -85,7 +88,7 @@ ensure => 'present', system => true, groups => concat([$group, 'docker'], $extra_groups), - shell => $usershell, + shell => $user_shell, }) User[$user] -> File[$config_dir] diff --git a/manifests/service.pp b/manifests/service.pp index ae50e4c..1b63684 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -37,7 +37,7 @@ String $mail = $storj::mail, Stdlib::Host $host = $storj::host, String $storage = $storj::storage, - Stdlib::Absolutepath $config_dir = $storj::config_dir, + Stdlib::Absolutepath $config_dir = $storj::config_dir, Stdlib::Absolutepath $storage_path = $storj::storage_path, String $docker_tag = $storj::docker_tag, ) { diff --git a/metadata.json b/metadata.json index a2cff61..d4a9878 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "maeq-storj", - "version": "0.1.4", + "version": "1.0.0", "author": "maeq", "summary": "This module install and configure Storj storagenode", "license": "Apache-2.0", diff --git a/spec/classes/storj_spec.rb b/spec/classes/storj_spec.rb index deabcba..84bb426 100644 --- a/spec/classes/storj_spec.rb +++ b/spec/classes/storj_spec.rb @@ -25,10 +25,189 @@ parameters end + s_os = os_facts[:kernel].downcase + + s_arch = case os_facts[:architecture] + when 'aarch64' + 'arm64' + when 'armv7l' + 'arm' + else + 'amd64' + end + + authorization_token = parameters[:authorization_token] + wallet = parameters[:wallet] + mail = parameters[:mail] + host = parameters[:host] + storage = parameters[:storage] + storage_path = parameters[:storage_path] + version = parameters[:version] + base_dir = parameters[:base_dir] || '/opt' + bin_dir = parameters[:bin_dir] || '/usr/local/bin' + base_url = parameters[:base_url] || 'https://github.com/storj/storj/releases/download' + download_extension = parameters[:download_extension] || 'zip' + download_url = parameters[:download_url] || "#{base_url}/v#{version}/identity_#{s_os}_#{s_arch}.#{download_extension}" + extract_command = parameters[:extract_command] || nil + config_dir = parameters[:config_dir] || '/etc/storj' + manage_user = parameters[:manage_user].nil? ? true : parameters[:manage_user] + manage_group = parameters[:manage_group].nil? ? true : parameters[:manage_group] + user = parameters[:user] || 'storj' + group = parameters[:group] || 'storj' + user_shell = parameters[:user_shell] || '/bin/false' + extra_groups = parameters[:extra_groups] || [] + service_ensure = parameters[:service_ensure] || 'running' + docker_tag = parameters[:docker_tag] || 'beta' + port = parameters[:port] || 28_967 + dashboard_port = parameters[:dashboard_port] || 14_002 + manage_docker = parameters[:manage_docker].nil? ? true : parameters[:manage_docker] + + case service_ensure + when 'running' + file_ensure = 'file' + service_ensure = 'running' + when 'stopped' + file_ensure = 'file' + service_ensure = 'stopped' + else + file_ensure = 'absent' + service_ensure = 'stopped' + end + # Compilation it { is_expected.to compile } + + # Implementation + it { + is_expected.to contain_class('storj::install') + is_expected.to contain_class('storj::config') + is_expected.to contain_class('storj::service') + + if manage_docker + is_expected.to contain_class('docker') + else + is_expected.not_to contain_class('docker') + end + } + + # Install + it { + is_expected.to contain_file("#{base_dir}/storj-#{version}.#{s_os}-#{s_arch}").with( + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => '0', + 'mode' => '0755', + ) + is_expected.to contain_archive("/tmp/identity_#{version}.#{download_extension}").with( + 'ensure' => 'present', + 'extract' => true, + 'extract_path' => "#{base_dir}/storj-#{version}.#{s_os}-#{s_arch}", + 'source' => download_url, + 'checksum_verify' => false, + 'creates' => "#{base_dir}/storj-#{version}.#{s_os}-#{s_arch}/identity", + 'cleanup' => true, + 'extract_command' => extract_command, + ) + is_expected.to contain_file("#{base_dir}/storj-#{version}.#{s_os}-#{s_arch}/identity").with( + 'owner' => 'root', + 'group' => '0', + 'mode' => '0555', + ) + is_expected.to contain_file("#{bin_dir}/identity").with( + 'ensure' => 'link', + 'target' => "#{base_dir}/storj-#{version}.#{s_os}-#{s_arch}/identity", + ) + + # User + if manage_user + is_expected.to contain_user(user).with( + 'ensure' => 'present', + 'system' => true, + 'groups' => [group, 'docker'] + extra_groups, + 'shell' => user_shell, + ) + else + is_expected.not_to contain_user(user) + end + # Group + if manage_group + is_expected.to contain_group(group).with( + 'ensure' => 'present', + 'system' => true, + ) + else + is_expected.not_to contain_group(group) + end + + is_expected.to contain_file(config_dir).with( + 'ensure' => 'directory', + 'owner' => user, + 'group' => group, + ) + } + + # Config + it { + is_expected.to contain_exec('Request authorization command').with( + 'command' => "#{bin_dir}/identity authorize storagenode #{authorization_token} --identity-dir #{config_dir} --config-dir #{config_dir}", + 'onlyif' => "/usr/bin/test `grep -c BEGIN #{config_dir}/storagenode/identity.cert` != 3", + 'user' => group, + 'group' => user, + 'logoutput' => true, + ).that_notifies('Service[storagenode]') + + is_expected.to contain_exec('Check certs integrity command').with( + 'command' => "/usr/bin/test `grep -c BEGIN #{config_dir}/storagenode/ca.cert` == 2 && + /usr/bin/test `grep -c BEGIN #{config_dir}/storagenode/identity.cert` == 3", + 'logoutput' => true, + 'returns' => 0, + ) + } + + # Service + it { + is_expected.to contain_file('/lib/systemd/system/storagenode.service').with( + 'ensure' => file_ensure, + ).with_content( + "# THIS FILE IS MANAGED BY PUPPET +[Unit] +Description=Storj storagenode service +BindsTo=docker.service +After=docker.service + +[Service] +User=#{user} +Group=#{group} +Environment=NAME=storagenode +Restart=on-failure +RestartSec=10 +ExecStartPre=-/usr/bin/docker kill ${NAME} +ExecStartPre=-/usr/bin/docker rm ${NAME} +ExecStart=/usr/bin/docker run --name ${NAME} \\ +--stop-timeout 300 \\ +-p #{port}:28967 \\ +-p #{dashboard_port}:14002 \\ +-e WALLET=\"#{wallet}\" \\ +-e EMAIL=\"#{mail}\" \\ +-e ADDRESS=\"#{host}:#{port}\" \\ +-e STORAGE=\"#{storage}\" \\ +--mount type=bind,source=\"#{config_dir}/storagenode\",destination=/app/identity \\ +--mount type=bind,source=\"#{storage_path}\",destination=/app/config \\ +storjlabs/storagenode:#{docker_tag} +ExecStop=/usr/bin/docker stop ${NAME} + +[Install] +WantedBy=multi-user.target +", + ).that_notifies('Service[storagenode]') + + is_expected.to contain_service('storagenode').with( + 'ensure' => service_ensure, + 'enable' => true, + ) + } end end end