diff --git a/manifests/init.pp b/manifests/init.pp index 1ccbbc0..2a986db 100755 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,680 +1,680 @@ # == Class: docker # # Module to install an up-to-date version of Docker from package. # # === Parameters # # [*version*] # The package version to install, used to set the package name. # Defaults to undefined # # [*ensure*] # Passed to the docker package. # Defaults to present # # [*prerequired_packages*] # An array of additional packages that need to be installed to support # docker. Defaults change depending on the operating system. # # [*dependent_packages*] # An array of packages installed by the docker-ce package v 18.09 and later. # Used when uninstalling to ensure containers cannot be run on the system. # Defaults change depending on the operating system. # # [*tcp_bind*] # The tcp socket to bind to in the format # tcp://127.0.0.1:4243 # Defaults to undefined # # [*tls_enable*] # Enable TLS. # Defaults to false # # [*tls_verify*] # Use TLS and verify the remote # Defaults to true # # [*tls_cacert*] # Path to TLS CA certificate # Defaults to '/etc/docker/tls/ca.pem on linux and C:/ProgramData/docker/certs.d/ca.pem on Windows' # # [*tls_cert*] # Path to TLS certificate file # Defaults to '/etc/docker/tls/cert.pem on linux and C:/ProgramData/docker/certs.d/server-cert.pem on Windows' # # [*tls_key*] # Path to TLS key file # Defaults to '/etc/docker/tls/key.pem' on linux and C:/ProgramData/docker/certs.d/server-key.pem on Windows # # [*ip_forward*] # Enables IP forwarding on the Docker host. # The default is true. # # [*iptables*] # Enable Docker's addition of iptables rules. # Default is true. # # [*ip_masq*] # Enable IP masquerading for bridge's IP range. # The default is true. # # [*icc*] # Enable or disable Docker's unrestricted inter-container and Docker daemon host communication. # (Requires iptables=true to disable) # Default is undef. (Docker daemon's default is true) # # [*bip*] # Specify docker's network bridge IP, in CIDR notation. # Defaults to undefined. # # [*mtu*] # Docker network MTU. # Defaults to undefined. # # [*bridge*] # Attach containers to a pre-existing network bridge # use 'none' to disable container networking # Defaults to undefined. # # [*fixed_cidr*] # IPv4 subnet for fixed IPs # 10.20.0.0/16 # Defaults to undefined # # [*default_gateway*] # IPv4 address of the container default gateway; # this address must be part of the bridge subnet # (which is defined by bridge) # Defaults to undefined # # [*ipv6*] # Enables ipv6 support for the docker daemon # Defaults to false # # [*ipv6_cidr*] # IPv6 subnet for fixed IPs # # [*default_gateway_ipv6*] # IPv6 address of the container default gateway: # Defaults to undefined # # [*socket_bind*] # The unix socket to bind to. Defaults to # unix:///var/run/docker.sock. # # [*log_level*] # Set the logging level # Defaults to undef: docker defaults to info if no value specified # Valid values: debug, info, warn, error, fatal # # [*log_driver*] # Set the log driver. # Defaults to undef. # Docker default is json-file. # Valid values: none, json-file, syslog, journald, gelf, fluentd # Valid values description: # none : Disables any logging for the container. # docker logs won't be available with this driver. # json-file: Default logging driver for Docker. # Writes JSON messages to file. # syslog : Syslog logging driver for Docker. # Writes log messages to syslog. # journald : Journald logging driver for Docker. # Writes log messages to journald. # gelf : Graylog Extended Log Format (GELF) logging driver for Docker. # Writes log messages to a GELF endpoint: Graylog or Logstash. # fluentd : Fluentd logging driver for Docker. # Writes log messages to fluentd (forward input). # splunk : Splunk logging driver for Docker. # Writes log messages to Splunk (HTTP Event Collector). # awslogs : AWS Cloudwatch Logs logging driver for Docker. # Write log messages to Cloudwatch API # # [*log_opt*] # Set the log driver specific options # Defaults to undef # Valid values per log driver: # none : undef # json-file: # max-size=[0-9+][k|m|g] # max-file=[0-9+] # syslog : # syslog-address=[tcp|udp]://host:port # syslog-address=unix://path # syslog-facility=daemon|kern|user|mail|auth| # syslog|lpr|news|uucp|cron| # authpriv|ftp| # local0|local1|local2|local3| # local4|local5|local6|local7 # syslog-tag="some_tag" # journald : undef # gelf : # gelf-address=udp://host:port # gelf-tag="some_tag" # fluentd : # fluentd-address=host:port # fluentd-tag={{.ID}} - short container id (12 characters)| # {{.FullID}} - full container id # {{.Name}} - container name # splunk : # splunk-token= # splunk-url=https://your_splunk_instance:8088 # awslogs : # awslogs-group= # awslogs-stream= # awslogs-create-group=true|false # awslogs-datetime-format= - strftime expression # awslogs-multiline-pattern=multiline start pattern using a regular expression # tag={{.ID}} - short container id (12 characters)| # {{.FullID}} - full container id # {{.Name}} - container name # # [*selinux_enabled*] # Enable selinux support. Default is false. SELinux does not presently # support the BTRFS storage driver. # Valid values: true, false # # [*use_upstream_package_source*] # Whether or not to use the upstream package source. # If you run your own package mirror, you may set this # to false. # # [*pin_upstream_package_source*] # Pin upstream package source; this option currently only has any effect on # apt-based distributions. Set to false to remove pinning on the upstream # package repository. See also "apt_source_pin_level". # Defaults to true # # [*apt_source_pin_level*] # What level to pin our source package repository to; this only is relevent # if you're on an apt-based system (Debian, Ubuntu, etc) and # $use_upstream_package_source is set to true. Set this to false to disable # pinning, and undef to ensure the apt preferences file apt::source uses to # define pins is removed. # Defaults to 10 # # [*package_source_location*] # If you're using an upstream package source, what is it's # location. Defaults to http://get.docker.com/ubuntu on Debian # # [*service_state*] # Whether you want to docker daemon to start up # Defaults to running # # [*service_enable*] # Whether you want to docker daemon to start up at boot # Defaults to true # # [*manage_service*] # Specify whether the service should be managed. # Valid values are 'true', 'false'. # Defaults to 'true'. # # [*root_dir*] # Custom root directory for containers # Defaults to undefined # # [*dns*] # Custom dns server address # Defaults to undefined # # [*dns_search*] # Custom dns search domains # Defaults to undefined # # [*socket_group*] # Group ownership of the unix control socket. # Default is based on OS (docker, dockerroot, undef) # # [*extra_parameters*] # Any extra parameters that should be passed to the docker daemon. # Defaults to undefined # # [*shell_values*] # Array of shell values to pass into init script config files # # [*proxy*] # Will set the http_proxy and https_proxy env variables in /etc/sysconfig/docker (redhat/centos) or /etc/default/docker (debian) # # [*no_proxy*] # Will set the no_proxy variable in /etc/sysconfig/docker (redhat/centos) or /etc/default/docker (debian) # # [*storage_driver*] # Specify a storage driver to use # Default is undef: let docker choose the correct one # Valid values: aufs, devicemapper, btrfs, overlay, overlay2, vfs, zfs # # [*dm_basesize*] # The size to use when creating the base device, which limits the size of images and containers. # Default value is 10G # # [*dm_fs*] # The filesystem to use for the base image (xfs or ext4) # Defaults to ext4 # # [*dm_mkfsarg*] # Specifies extra mkfs arguments to be used when creating the base device. # # [*dm_mountopt*] # Specifies extra mount options used when mounting the thin devices. # # [*dm_blocksize*] # A custom blocksize to use for the thin pool. # Default blocksize is 64K. # Warning: _DO NOT_ change this parameter after the lvm devices have been initialized. # # [*dm_loopdatasize*] # Specifies the size to use when creating the loopback file for the "data" device which is used for the thin pool # Default size is 100G # # [*dm_loopmetadatasize*] # Specifies the size to use when creating the loopback file for the "metadata" device which is used for the thin pool # Default size is 2G # # [*dm_datadev*] # (deprecated - dm_thinpooldev should be used going forward) # A custom blockdevice to use for data for the thin pool. # # [*dm_metadatadev*] # (deprecated - dm_thinpooldev should be used going forward) # A custom blockdevice to use for metadata for the thin pool. # # [*dm_thinpooldev*] # Specifies a custom block storage device to use for the thin pool. # # [*dm_use_deferred_removal*] # Enables use of deferred device removal if libdm and the kernel driver support the mechanism. # # [*dm_use_deferred_deletion*] # Enables use of deferred device deletion if libdm and the kernel driver support the mechanism. # # [*dm_blkdiscard*] # Enables or disables the use of blkdiscard when removing devicemapper devices. # Defaults to false # # [*dm_override_udev_sync_check*] # By default, the devicemapper backend attempts to synchronize with the udev # device manager for the Linux kernel. This option allows disabling that # synchronization, to continue even though the configuration may be buggy. # Defaults to true # # [*overlay2_override_kernel_check*] # Overrides the Linux kernel version check allowing using overlay2 with kernel < 4.0. # Default value is false # # [*manage_package*] # Won't install or define the docker package, useful if you want to use your own package # Defaults to true # # [*package_name*] # Specify custom package name # Default is set on a per system basis in docker::params # # [*service_name*] # Specify custom service name # Default is set on a per system basis in docker::params # # [*docker_command*] # Specify a custom docker command name # Default is set on a per system basis in docker::params # # [*daemon_subcommand*] # Specify a subcommand/flag for running docker as daemon # Default is set on a per system basis in docker::params # # [*docker_users*] # Specify an array of users to add to the docker group # Default is empty # # [*docker_group*] # Specify a string for the docker group # Default is OS and package specific # # [*daemon_environment_files*] # Specify additional environment files to add to the # service-overrides.conf # # [*repo_opt*] # Specify a string to pass as repository options (RedHat only) # # [*storage_devs*] # A quoted, space-separated list of devices to be used. # # [*storage_vg*] # The volume group to use for docker storage. # # [*storage_root_size*] # The size to which the root filesystem should be grown. # # [*storage_data_size*] # The desired size for the docker data LV # # [*storage_min_data_size*] # The minimum size of data volume otherwise pool creation fails # # [*storage_chunk_size*] # Controls the chunk size/block size of thin pool. # # [*storage_growpart*] # Enable resizing partition table backing root volume group. # # [*storage_auto_extend_pool*] # Enable/disable automatic pool extension using lvm # # [*storage_pool_autoextend_threshold*] # Auto pool extension threshold (in % of pool size) # # [*storage_pool_autoextend_percent*] # Extend the pool by specified percentage when threshold is hit. # # [*tmp_dir_config*] # Whether to set the TMPDIR value in the systemd config file # Default: true (set the value); false will comment out the line. # Note: false is backwards compatible prior to PR #58 # # [*tmp_dir*] # Sets the tmp dir for Docker (path) # # [*registry_mirror*] # Sets the prefered container registry mirror. # Default: undef # # [*nuget_package_provider_version*] # The version of the NuGet Package provider # Default: undef # # [*docker_msft_provider_version*] # The version of the Microsoft Docker Provider Module # Default: undef class docker( Optional[String] $version = $docker::params::version, String $ensure = $docker::params::ensure, Variant[Array[String], Hash] $prerequired_packages = $docker::params::prerequired_packages, Array $dependent_packages = $docker::params::dependent_packages, String $docker_ce_start_command = $docker::params::docker_ce_start_command, Optional[String] $docker_ce_package_name = $docker::params::docker_ce_package_name, Optional[String] $docker_ce_source_location = $docker::params::package_ce_source_location, Optional[String] $docker_ce_key_source = $docker::params::package_ce_key_source, Optional[String] $docker_ce_key_id = $docker::params::package_ce_key_id, Optional[String] $docker_ce_release = $docker::params::package_ce_release, Optional[String] $docker_package_location = $docker::params::package_source_location, Optional[String] $docker_package_key_source = $docker::params::package_key_source, Optional[Boolean] $docker_package_key_check_source = $docker::params::package_key_check_source, Optional[String] $docker_package_key_id = $docker::params::package_key_id, Optional[String] $docker_package_release = $docker::params::package_release, String $docker_engine_start_command = $docker::params::docker_engine_start_command, String $docker_engine_package_name = $docker::params::docker_engine_package_name, String $docker_ce_channel = $docker::params::docker_ce_channel, Optional[Boolean] $docker_ee = $docker::params::docker_ee, Optional[String] $docker_ee_package_name = $docker::params::package_ee_package_name, Optional[String] $docker_ee_source_location = $docker::params::package_ee_source_location, Optional[String] $docker_ee_key_source = $docker::params::package_ee_key_source, Optional[String] $docker_ee_key_id = $docker::params::package_ee_key_id, Optional[String] $docker_ee_repos = $docker::params::package_ee_repos, Optional[String] $docker_ee_release = $docker::params::package_ee_release, Variant[String,Array[String],Undef] $tcp_bind = $docker::params::tcp_bind, Boolean $tls_enable = $docker::params::tls_enable, Boolean $tls_verify = $docker::params::tls_verify, Optional[String] $tls_cacert = $docker::params::tls_cacert, Optional[String] $tls_cert = $docker::params::tls_cert, Optional[String] $tls_key = $docker::params::tls_key, Boolean $ip_forward = $docker::params::ip_forward, Boolean $ip_masq = $docker::params::ip_masq, Optional[Boolean]$ipv6 = $docker::params::ipv6, Optional[String]$ipv6_cidr = $docker::params::ipv6_cidr, Optional[String]$default_gateway_ipv6 = $docker::params::default_gateway_ipv6, Optional[String] $bip = $docker::params::bip, Optional[String] $mtu = $docker::params::mtu, Boolean $iptables = $docker::params::iptables, Optional[Boolean] $icc = $docker::params::icc, String $socket_bind = $docker::params::socket_bind, Optional[String] $fixed_cidr = $docker::params::fixed_cidr, Optional[String] $bridge = $docker::params::bridge, Optional[String] $default_gateway = $docker::params::default_gateway, Optional[String] $log_level = $docker::params::log_level, Optional[String] $log_driver = $docker::params::log_driver, Array $log_opt = $docker::params::log_opt, Optional[Boolean] $selinux_enabled = $docker::params::selinux_enabled, Optional[Boolean] $use_upstream_package_source = $docker::params::use_upstream_package_source, Optional[Boolean] $pin_upstream_package_source = $docker::params::pin_upstream_package_source, Optional[Integer] $apt_source_pin_level = $docker::params::apt_source_pin_level, Optional[String] $package_release = $docker::params::package_release, String $service_state = $docker::params::service_state, Boolean $service_enable = $docker::params::service_enable, Boolean $manage_service = $docker::params::manage_service, Optional[String] $root_dir = $docker::params::root_dir, Optional[Boolean] $tmp_dir_config = $docker::params::tmp_dir_config, Optional[String] $tmp_dir = $docker::params::tmp_dir, Variant[String,Array,Undef] $dns = $docker::params::dns, Variant[String,Array,Undef] $dns_search = $docker::params::dns_search, Variant[String,Boolean,Undef] $socket_group = $docker::params::socket_group, Array $labels = $docker::params::labels, Variant[String,Array,Undef] $extra_parameters = undef, Variant[String,Array,Undef] $shell_values = undef, Optional[String] $proxy = $docker::params::proxy, Optional[String] $no_proxy = $docker::params::no_proxy, Optional[String] $storage_driver = $docker::params::storage_driver, Optional[String] $dm_basesize = $docker::params::dm_basesize, Optional[String] $dm_fs = $docker::params::dm_fs, Optional[String] $dm_mkfsarg = $docker::params::dm_mkfsarg, Optional[String] $dm_mountopt = $docker::params::dm_mountopt, Optional[String] $dm_blocksize = $docker::params::dm_blocksize, Optional[String] $dm_loopdatasize = $docker::params::dm_loopdatasize, Optional[String] $dm_loopmetadatasize = $docker::params::dm_loopmetadatasize, Optional[String] $dm_datadev = $docker::params::dm_datadev, Optional[String] $dm_metadatadev = $docker::params::dm_metadatadev, Optional[String] $dm_thinpooldev = $docker::params::dm_thinpooldev, Optional[Boolean] $dm_use_deferred_removal = $docker::params::dm_use_deferred_removal, Optional[Boolean] $dm_use_deferred_deletion = $docker::params::dm_use_deferred_deletion, Optional[Boolean] $dm_blkdiscard = $docker::params::dm_blkdiscard, Optional[Boolean] $dm_override_udev_sync_check = $docker::params::dm_override_udev_sync_check, Boolean $overlay2_override_kernel_check = $docker::params::overlay2_override_kernel_check, Optional[String] $execdriver = $docker::params::execdriver, Boolean $manage_package = $docker::params::manage_package, Optional[String] $package_source = $docker::params::package_source, Optional[String] $service_name = $docker::params::service_name, Array $docker_users = [], String $docker_group = $docker::params::docker_group, Array $daemon_environment_files = [], Variant[String,Hash,Undef] $repo_opt = $docker::params::repo_opt, Optional[String] $os_lc = $docker::params::os_lc, Optional[String] $storage_devs = $docker::params::storage_devs, Optional[String] $storage_vg = $docker::params::storage_vg, Optional[String] $storage_root_size = $docker::params::storage_root_size, Optional[String] $storage_data_size = $docker::params::storage_data_size, Optional[String] $storage_min_data_size = $docker::params::storage_min_data_size, Optional[String] $storage_chunk_size = $docker::params::storage_chunk_size, Optional[Boolean] $storage_growpart = $docker::params::storage_growpart, Optional[String] $storage_auto_extend_pool = $docker::params::storage_auto_extend_pool, Optional[String] $storage_pool_autoextend_threshold = $docker::params::storage_pool_autoextend_threshold, Optional[String] $storage_pool_autoextend_percent = $docker::params::storage_pool_autoextend_percent, Variant[String,Boolean,Undef] $storage_config = $docker::params::storage_config, Optional[String] $storage_config_template = $docker::params::storage_config_template, Optional[String] $storage_setup_file = $docker::params::storage_setup_file, Optional[String] $service_provider = $docker::params::service_provider, Variant[String,Boolean,Undef] $service_config = $docker::params::service_config, Optional[String] $service_config_template = $docker::params::service_config_template, Variant[String,Boolean,Undef] $service_overrides_template = $docker::params::service_overrides_template, Variant[String,Boolean,Undef] $socket_overrides_template = $docker::params::socket_overrides_template, Optional[Boolean] $socket_override = $docker::params::socket_override, Variant[String,Boolean,Undef] $service_after_override = $docker::params::service_after_override, Optional[Boolean] $service_hasstatus = $docker::params::service_hasstatus, Optional[Boolean] $service_hasrestart = $docker::params::service_hasrestart, Optional[String] $registry_mirror = $docker::params::registry_mirror, Boolean $acknowledge_unsupported_os = false, # Windows specific parameters Optional[String] $docker_msft_provider_version = $docker::params::docker_msft_provider_version, Optional[String] $nuget_package_provider_version = $docker::params::nuget_package_provider_version, ) inherits docker::params { if $::osfamily and !$acknowledge_unsupported_os { assert_type(Pattern[/^(Debian|RedHat|windows)$/], $::osfamily) |$a, $b| { fail(translate('This module only works on Debian, Red Hat or Windows based systems.')) } } if ($::operatingsystem == 'CentOS') and (versioncmp($::operatingsystemmajrelease, '7') < 0) { fail(translate('This module only works on CentOS version 7 and higher based systems.')) } if ($default_gateway) and (!$bridge) { fail(translate('You must provide the $bridge parameter.')) } if $log_level { assert_type(Pattern[/^(debug|info|warn|error|fatal)$/], $log_level) |$a, $b| { fail(translate('log_level must be one of debug, info, warn, error or fatal')) } } if $log_driver { if $::osfamily == 'windows' { assert_type(Pattern[/^(none|json-file|syslog|gelf|fluentd|splunk|awslogs|etwlogs)$/], $log_driver) |$a, $b| { fail(translate('log_driver must be one of none, json-file, syslog, gelf, fluentd, splunk, awslogs or etwlogs')) } } else { assert_type(Pattern[/^(none|json-file|syslog|journald|gelf|fluentd|splunk|awslogs)$/], $log_driver) |$a, $b| { fail(translate('log_driver must be one of none, json-file, syslog, journald, gelf, fluentd, splunk or awslogs')) } } } if $storage_driver { if $::osfamily == 'windows' { assert_type(Pattern[/^(windowsfilter)$/], $storage_driver) |$a, $b| { fail(translate('Valid values for storage_driver on windows are windowsfilter')) } } else { assert_type(Pattern[/^(aufs|devicemapper|btrfs|overlay|overlay2|vfs|zfs)$/], $storage_driver) |$a, $b| { fail(translate('Valid values for storage_driver are aufs, devicemapper, btrfs, overlay, overlay2, vfs, zfs.')) } } } if ($bridge) and ($::osfamily == 'windows') { assert_type(Pattern[/^(none|nat|transparent|overlay|l2bridge|l2tunnel)$/], $bridge) |$a, $b| { fail(translate('bridge must be one of none, nat, transparent, overlay, l2bridge or l2tunnel on Windows.')) } } if $dm_fs { assert_type(Pattern[/^(ext4|xfs)$/], $dm_fs) |$a, $b| { fail(translate('Only ext4 and xfs are supported currently for dm_fs.')) } } if ($dm_loopdatasize or $dm_loopmetadatasize) and ($dm_datadev or $dm_metadatadev) { fail(translate('You should provide parameters only for loop lvm or direct lvm, not both.')) } # lint:ignore:140chars if ($dm_datadev or $dm_metadatadev) and $dm_thinpooldev { fail(translate('You can use the $dm_thinpooldev parameter, or the $dm_datadev and $dm_metadatadev parameter pair, but you cannot use both.')) } # lint:endignore if ($dm_datadev or $dm_metadatadev) { notice('The $dm_datadev and $dm_metadatadev parameter pair are deprecated. The $dm_thinpooldev parameter should be used instead.') } if ($dm_datadev and !$dm_metadatadev) or (!$dm_datadev and $dm_metadatadev) { fail(translate('You need to provide both $dm_datadev and $dm_metadatadev parameters for direct lvm.')) } if ($dm_basesize or $dm_fs or $dm_mkfsarg or $dm_mountopt or $dm_blocksize or $dm_loopdatasize or $dm_loopmetadatasize or $dm_datadev or $dm_metadatadev) and ($storage_driver != 'devicemapper') { fail(translate('Values for dm_ variables will be ignored unless storage_driver is set to devicemapper.')) } if($tls_enable) { if(!$tcp_bind) { fail(translate('You need to provide tcp bind parameter for TLS.')) } } - if ( $version == undef ) or ( $version !~ /^(17[.]0[0-5][.][0-1](~|-|\.)ce|1.\d+)/ ) { + if ( $version == undef ) or ( $version !~ /^(1[7-8][.][0-1][0-9][.][0-1](~|-|\.)ce|1.\d+)/ ) { if ( $docker_ee) { $package_location = $docker::docker_ee_source_location $package_key_source = $docker::docker_ee_key_source $package_key_check_source = true $package_key = $docker::docker_ee_key_id $package_repos = $docker::docker_ee_repos $release = $docker::docker_ee_release $docker_start_command = $docker::docker_ee_start_command $docker_package_name = $docker::docker_ee_package_name } else { case $::osfamily { 'Debian' : { $package_location = $docker_ce_source_location $package_key_source = $docker_ce_key_source $package_key = $docker_ce_key_id $package_repos = $docker_ce_channel $release = $docker_ce_release } 'Redhat' : { $package_location = $docker_ce_source_location $package_key_source = $docker_ce_key_source $package_key_check_source = true } 'windows': { fail(translate('This module only work for Docker Enterprise Edition on Windows.')) } default: { $package_location = $docker_package_location $package_key_source = $docker_package_key_source $package_key_check_source = $docker_package_key_check_source } } $docker_start_command = $docker_ce_start_command $docker_package_name = $docker_ce_package_name } } else { case $::osfamily { 'Debian' : { $package_location = $docker_package_location $package_key_source = $docker_package_key_source $package_key_check_source = $docker_package_key_check_source $package_key = $docker_package_key_id $package_repos = 'main' $release = $docker_package_release } 'Redhat' : { $package_location = $docker_package_location $package_key_source = $docker_package_key_source $package_key_check_source = $docker_package_key_check_source } default : { $package_location = $docker_package_location $package_key_source = $docker_package_key_source $package_key_check_source = $docker_package_key_check_source } } $docker_start_command = $docker_engine_start_command $docker_package_name = $docker_engine_package_name } if ( $version != undef ) and ( $version =~ /^(17[.]0[0-4]|1.\d+)/ ) { $root_dir_flag = '-g' } else { $root_dir_flag = '--data-root' } if $ensure != 'absent' { contain 'docker::repos' contain 'docker::install' contain 'docker::config' contain 'docker::service' Class['docker::repos'] -> Class['docker::install'] -> Class['docker::config'] -> Class['docker::service'] Class['docker'] -> Docker::Registry <||> -> Docker::Image <||> Class['docker'] -> Docker::Image <||> Class['docker'] -> Docker::Run <||> } else { contain 'docker::repos' contain 'docker::install' Class['docker::repos'] -> Class['docker::install'] } } diff --git a/spec/classes/docker_spec.rb b/spec/classes/docker_spec.rb index 09558d1..fa3678d 100755 --- a/spec/classes/docker_spec.rb +++ b/spec/classes/docker_spec.rb @@ -1,1075 +1,1075 @@ require 'spec_helper' describe 'docker', type: :class do ['Debian', 'Ubuntu', 'RedHat'].each do |osfamily| context "on #{osfamily}" do if osfamily == 'Debian' let(:facts) do { architecture: 'amd64', osfamily: 'Debian', operatingsystem: 'Debian', lsbdistid: 'Debian', lsbdistcodename: 'stretch', kernelrelease: '4.9.0-3-amd64', operatingsystemrelease: '9.0', operatingsystemmajrelease: '9', os: { distro: { codename: 'wheezy' }, family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, } end service_config_file = '/etc/default/docker' storage_config_file = '/etc/default/docker-storage' context 'It should include default prerequired_packages' do it { is_expected.to contain_package('cgroupfs-mount').with_ensure('present') } end end if osfamily == 'Ubuntu' let(:facts) do { architecture: 'amd64', osfamily: 'Debian', operatingsystem: 'Ubuntu', lsbdistid: 'Ubuntu', lsbdistcodename: 'xenial', kernelrelease: '4.4.0-21-generic', operatingsystemrelease: '16.04', operatingsystemmajrelease: '16.04', os: { distro: { codename: 'wheezy' }, family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, } end service_config_file = '/etc/default/docker' storage_config_file = '/etc/default/docker-storage' it { is_expected.to contain_service('docker').with_hasrestart('true') } context 'It should include default prerequired_packages' do it { is_expected.to contain_package('cgroup-lite').with_ensure('present') } it { is_expected.to contain_package('apparmor').with_ensure('present') } end end if ['Debian', 'Ubuntu'].include?(osfamily) it { is_expected.to contain_class('apt') } it { is_expected.to contain_package('docker').with_name('docker-ce').with_ensure('present') } it { is_expected.to contain_apt__pin('docker') .with_ensure('present') .with_origin('download.docker.com') .with_priority(500) } it { is_expected.to contain_package('docker').with_install_options(nil) } it { is_expected.to contain_file('/etc/default/docker').without_content(%r{icc=}) } end if osfamily == 'Ubuntu' it { is_expected.to contain_apt__source('docker').with_location('https://download.docker.com/linux/ubuntu') } end if osfamily == 'Debian' it { is_expected.to contain_apt__source('docker').with_location('https://download.docker.com/linux/debian') } end if ['Debian', 'Ubuntu'].include?(osfamily) context 'with a custom version' do let(:params) { { 'version' => '1.7.0' } } it { is_expected.to contain_package('docker').with_ensure('1.7.0').with_name('docker-engine') } end context 'with no upstream package source' do let(:params) { { 'use_upstream_package_source' => false } } it { is_expected.not_to contain_apt__source('docker') } it { is_expected.not_to contain_apt__pin('docker') } it { is_expected.to contain_package('docker').with_name('docker-ce') } end context 'with no upstream package source' do let(:params) { { 'use_upstream_package_source' => false } } it { is_expected.not_to contain_apt__source('docker') } it { is_expected.not_to contain_apt__pin('docker') } it { is_expected.to contain_package('docker') } end context 'with no package pinning' do let(:params) { { 'pin_upstream_package_source' => false } } it { is_expected.to contain_apt__pin('docker').with_ensure('absent') } end context 'with different package pinning priority' do let(:params) do { 'pin_upstream_package_source' => true, 'apt_source_pin_level' => 900, } end it { is_expected.to contain_apt__pin('docker').with_priority(900) } end context 'when given a specific tmp_dir' do let(:params) { { 'tmp_dir' => '/bigtmp' } } it { is_expected.to contain_file('/etc/default/docker').with_content(%r{TMPDIR="\/bigtmp"}) } end context 'with ip_forwaring param set to false' do let(:params) { { 'ip_forward' => false } } it { is_expected.to contain_file('/etc/default/docker').with_content(%r{ip-forward=false}) } end context 'with ip_masq param set to false' do let(:params) { { 'ip_masq' => false } } it { is_expected.to contain_file('/etc/default/docker').with_content(%r{ip-masq=false}) } end context 'with iptables param set to false' do let(:params) { { 'iptables' => false } } it { is_expected.to contain_file('/etc/default/docker').with_content(%r{iptables=false}) } end context 'with icc param set to false' do let(:params) { { 'icc' => false } } it { is_expected.to contain_file('/etc/default/docker').with_content(%r{icc=false}) } end context 'with tcp_bind array param' do let(:params) { { 'tcp_bind' => ['tcp://127.0.0.1:2375', 'tcp://10.0.0.1:2375'] } } it do is_expected.to contain_file('/etc/default/docker').with_content( %r{tcp:\/\/127.0.0.1:2375 -H tcp:\/\/10.0.0.1:2375}, ) end end context 'with tcp_bind string param' do let(:params) { { 'tcp_bind' => 'tcp://127.0.0.1:2375' } } it do is_expected.to contain_file('/etc/default/docker').with_content( %r{tcp:\/\/127.0.0.1:2375}, ) end end context 'with tls param' do let(:params) do { 'tcp_bind' => 'tcp://127.0.0.1:2375', 'tls_enable' => true, } end it do is_expected.to contain_file('/etc/default/docker').with_content( %r{tcp:\/\/127.0.0.1:2375}, ) is_expected.to contain_file('/etc/default/docker').with_content( %r{--tls --tlsverify --tlscacert=\/etc\/docker\/tls\/ca.pem --tlscert=\/etc\/docker\/tls\/cert.pem --tlskey=\/etc\/docker\/tls\/key.pem}, ) end end context 'with tls param and without tlsverify' do let(:params) do { 'tcp_bind' => 'tcp://127.0.0.1:2375', 'tls_enable' => true, 'tls_verify' => false, } end it do is_expected.to contain_file('/etc/default/docker').with_content( %r{tcp:\/\/127.0.0.1:2375}, ) is_expected.to contain_file('/etc/default/docker').with_content( %r{--tls --tlscacert=\/etc\/docker\/tls\/ca.pem --tlscert=\/etc\/docker\/tls\/cert.pem --tlskey=\/etc\/docker\/tls\/key.pem}, ) end end context 'with fixed_cidr and bridge params' do let(:params) do { 'fixed_cidr' => '10.0.0.0/24', 'bridge' => 'br0', } end it { is_expected.to contain_file('/etc/default/docker').with_content(%r{fixed-cidr 10.0.0.0\/24}) } end context 'with ipv6 params' do let(:params) do { 'ipv6' => true, 'ipv6_cidr' => '2001:db8:1::/64', 'default_gateway_ipv6' => 'fe80::2d4:12ff:fef6:67a2/16', } end it { is_expected.to contain_file('/etc/default/docker').with_content(%r{--ipv6}) } it { is_expected.to contain_file('/etc/default/docker').with_content(%r{--fixed-cidr-v6 2001:db8:1::\/64}) } it { is_expected.to contain_file('/etc/default/docker').with_content(%r{--default-gateway-v6 fe80::2d4:12ff:fef6:67a2\/16}) } end context 'with default_gateway and bridge params' do let(:params) do { 'default_gateway' => '10.0.0.1', 'bridge' => 'br0', } end it { is_expected.to contain_file('/etc/default/docker').with_content(%r{default-gateway 10.0.0.1}) } end context 'with bridge param' do let(:params) { { 'bridge' => 'br0' } } it { is_expected.to contain_file('/etc/default/docker').with_content(%r{bridge br0}) } end context 'with custom service_name' do let(:params) { { 'service_name' => 'docker.io' } } it { is_expected.to contain_file('/etc/default/docker.io') } end end if osfamily == 'RedHat' let(:facts) do { architecture: 'x86_64', osfamily: osfamily, operatingsystem: 'RedHat', operatingsystemrelease: '7.2', operatingsystemmajrelease: '7', kernelversion: '3.10.0', } end service_config_file = '/etc/sysconfig/docker' storage_config_file = '/etc/sysconfig/docker-storage' it { is_expected.to contain_file('/etc/sysconfig/docker').without_content(%r{icc=}) } context 'with proxy param' do let(:params) { { 'proxy' => 'http://127.0.0.1:3128' } } it { is_expected.to contain_file(service_config_file).with_content(%r{http_proxy='http:\/\/127.0.0.1:3128'}) } it { is_expected.to contain_file(service_config_file).with_content(%r{https_proxy='http:\/\/127.0.0.1:3128'}) } end context 'with no_proxy param' do let(:params) { { 'no_proxy' => '.github.com' } } it { is_expected.to contain_file(service_config_file).with_content(%r{no_proxy='.github.com'}) } end context 'with registry_mirror param set to mirror value' do let(:params) { { 'registry_mirror' => 'https://mirror.gcr.io' } } it { is_expected.to contain_file('/etc/sysconfig/docker').with_content(%r{registry-mirror}) } end context 'when given a specific tmp_dir' do let(:params) { { 'tmp_dir' => '/bigtmp' } } it { is_expected.to contain_file('/etc/sysconfig/docker').with_content(%r{TMPDIR="\/bigtmp"}) } end context 'with ip_forwaring param set to false' do let(:params) { { 'ip_forward' => false } } it { is_expected.to contain_file('/etc/sysconfig/docker').with_content(%r{ip-forward=false}) } end context 'with ip_masq param set to false' do let(:params) { { 'ip_masq' => false } } it { is_expected.to contain_file('/etc/sysconfig/docker').with_content(%r{ip-masq=false}) } end context 'with iptables param set to false' do let(:params) { { 'iptables' => false } } it { is_expected.to contain_file('/etc/sysconfig/docker').with_content(%r{iptables=false}) } end context 'with icc param set to false' do let(:params) { { 'icc' => false } } it { is_expected.to contain_file('/etc/sysconfig/docker').with_content(%r{icc=false}) } end context 'with tcp_bind array param' do let(:params) { { 'tcp_bind' => ['tcp://127.0.0.1:2375', 'tcp://10.0.0.1:2375'] } } it do is_expected.to contain_file('/etc/sysconfig/docker').with_content( %r{tcp:\/\/127.0.0.1:2375 -H tcp:\/\/10.0.0.1:2375}, ) end end context 'with tcp_bind string param' do let(:params) { { 'tcp_bind' => 'tcp://127.0.0.1:2375' } } it do is_expected.to contain_file('/etc/sysconfig/docker').with_content( %r{tcp:\/\/127.0.0.1:2375}, ) end end context 'with tls param' do let(:params) do { 'tcp_bind' => 'tcp://127.0.0.1:2375', 'tls_enable' => true, } end it do is_expected.to contain_file('/etc/sysconfig/docker').with_content( %r{tcp:\/\/127.0.0.1:2375}, ) is_expected.to contain_file('/etc/sysconfig/docker').with_content( %r{--tls --tlsverify --tlscacert=\/etc\/docker\/tls\/ca.pem --tlscert=\/etc\/docker\/tls\/cert.pem --tlskey=\/etc\/docker\/tls\/key.pem}, ) end end context 'with tls param and without tlsverify' do let(:params) do { 'tcp_bind' => 'tcp://127.0.0.1:2375', 'tls_enable' => true, 'tls_verify' => false, } end it do is_expected.to contain_file('/etc/sysconfig/docker').with_content( %r{tcp:\/\/127.0.0.1:2375}, ) is_expected.to contain_file('/etc/sysconfig/docker').with_content( %r{--tls --tlscacert=\/etc\/docker\/tls\/ca.pem --tlscert=\/etc\/docker\/tls\/cert.pem --tlskey=\/etc\/docker\/tls\/key.pem}, ) end end context 'with fixed_cidr and bridge params' do let(:params) do { 'fixed_cidr' => '10.0.0.0/24', 'bridge' => 'br0', } end it { is_expected.to contain_file('/etc/sysconfig/docker').with_content(%r{fixed-cidr 10.0.0.0\/24}) } end context 'with default_gateway and bridge params' do let(:params) do { 'default_gateway' => '10.0.0.1', 'bridge' => 'br0', } end it { is_expected.to contain_file('/etc/sysconfig/docker').with_content(%r{default-gateway 10.0.0.1}) } end context 'with bridge param' do let(:params) { { 'bridge' => 'br0' } } it { is_expected.to contain_file('/etc/sysconfig/docker').with_content(%r{bridge br0}) } end context 'when given specific storage options' do let(:params) do { 'storage_driver' => 'devicemapper', 'dm_basesize' => '3G', } end it { is_expected.to contain_file('/etc/sysconfig/docker-storage').with_content(%r{^(DOCKER_STORAGE_OPTIONS=" --storage-driver devicemapper --storage-opt dm.basesize=3G)}) } end context 'It should include default prerequired_packages' do it { is_expected.to contain_package('device-mapper').with_ensure('present') } end context 'It should install from rpm package' do let(:params) do { 'manage_package' => true, 'use_upstream_package_source' => false, 'docker_engine_package_name' => 'docker-engine', 'package_source' => 'https://get.docker.com/rpm/1.7.0/centos-7/RPMS/x86_64/docker-engine-1.7.0-1.el7.x86_64.rpm', } end it do is_expected.to contain_package('docker').with( 'ensure' => 'present', 'source' => 'https://get.docker.com/rpm/1.7.0/centos-7/RPMS/x86_64/docker-engine-1.7.0-1.el7.x86_64.rpm', 'name' => 'docker-engine', ) end end context 'It should install from rpm package with docker::repo_opt set' do let(:params) do { 'manage_package' => true, 'use_upstream_package_source' => false, 'docker_engine_package_name' => 'docker-engine', 'package_source' => 'https://get.docker.com/rpm/1.7.0/centos-7/RPMS/x86_64/docker-engine-1.7.0-1.el7.x86_64.rpm', 'repo_opt' => '--enablerepo=rhel7-extras', } end it do is_expected.to contain_package('docker').with( 'ensure' => 'present', 'source' => 'https://get.docker.com/rpm/1.7.0/centos-7/RPMS/x86_64/docker-engine-1.7.0-1.el7.x86_64.rpm', 'name' => 'docker-engine', 'install_options' => '--enablerepo=rhel7-extras', ) end end context 'It uses default docker::repo_opt' do let(:params) do { 'manage_package' => true, 'use_upstream_package_source' => false, 'docker_engine_package_name' => 'docker-engine', 'package_source' => 'https://get.docker.com/rpm/1.7.0/centos-7/RPMS/x86_64/docker-engine-1.7.0-1.el7.x86_64.rpm', } end it do is_expected.to contain_package('docker').with( 'ensure' => 'present', 'source' => 'https://get.docker.com/rpm/1.7.0/centos-7/RPMS/x86_64/docker-engine-1.7.0-1.el7.x86_64.rpm', 'name' => 'docker-engine', 'install_options' => '--enablerepo=rhel-7-server-extras-rpms', ) end end context 'It allows overwriting docker::repo_opt with empty string' do let(:params) do { 'manage_package' => true, 'use_upstream_package_source' => false, 'docker_engine_package_name' => 'docker-engine', 'package_source' => 'https://get.docker.com/rpm/1.7.0/centos-7/RPMS/x86_64/docker-engine-1.7.0-1.el7.x86_64.rpm', 'repo_opt' => '', } end it do is_expected.to contain_package('docker').with( 'ensure' => 'present', 'source' => 'https://get.docker.com/rpm/1.7.0/centos-7/RPMS/x86_64/docker-engine-1.7.0-1.el7.x86_64.rpm', 'name' => 'docker-engine', 'install_options' => nil, ) end end end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('docker::repos').that_comes_before('Class[docker::install]') } it { is_expected.to contain_class('docker::install').that_comes_before('Class[docker::config]') } it { is_expected.to contain_class('docker::config').that_comes_before('Class[docker::service]') } it { is_expected.to contain_file(service_config_file).without_content(%r{icc=}) } # storage_config_file = '/etc/default/docker-storage' context 'with a specific docker command' do let(:params) { { 'docker_ce_start_command' => 'docker.io' } } it { is_expected.to contain_file('/etc/systemd/system/docker.service.d/service-overrides.conf').with_content(%r{docker.io}) } end context 'with an extra After entry' do let(:params) { { 'service_after_override' => 'containerd.service' } } it { is_expected.to contain_file('/etc/systemd/system/docker.service.d/service-overrides.conf').with_content(%r{containerd.service}) } end context 'with a specific socket group and override' do let(:params) do { 'socket_group' => 'root', 'socket_override' => true, } end it { is_expected.to contain_file('/etc/systemd/system/docker.socket.d/socket-overrides.conf').with_content(%r{root}) } end context 'with a custom package name' do let(:params) { { 'docker_ce_package_name' => 'docker-custom-pkg-name' } } it { is_expected.to contain_package('docker').with_name('docker-custom-pkg-name').with_ensure('present') } end context 'with a custom package name and version' do let(:params) do { 'version' => '17.06.2~ce-0~debian', 'docker_ce_package_name' => 'docker-custom-pkg-name', } end it { is_expected.to contain_package('docker').with_name('docker-custom-pkg-name').with_ensure('17.06.2~ce-0~debian') } end context 'when not managing the package' do let(:params) { { 'manage_package' => false } } skip 'the APT module at v2.1 does not support STRICT_VARIABLES' do it { is_expected.not_to contain_package('docker') } end end context 'It should accept custom prerequired_packages' do let(:params) do { 'prerequired_packages' => ['test_package'], 'manage_package' => false } end skip 'the APT module at v2.1 does not support STRICT_VARIABLES' do it { is_expected.to contain_package('test_package').with_ensure('present') } end end context 'with proxy param' do let(:params) { { 'proxy' => 'http://127.0.0.1:3128' } } it { is_expected.to contain_file(service_config_file).with_content(%r{http_proxy='http:\/\/127.0.0.1:3128'}) } it { is_expected.to contain_file(service_config_file).with_content(%r{https_proxy='http:\/\/127.0.0.1:3128'}) } end context 'with no_proxy param' do let(:params) { { 'no_proxy' => '.github.com' } } it { is_expected.to contain_file(service_config_file).with_content(%r{no_proxy='.github.com'}) } end context 'with execdriver param lxc' do let(:params) { { 'execdriver' => 'lxc' } } it { is_expected.to contain_file(service_config_file).with_content(%r{-e lxc}) } end context 'with execdriver param native' do let(:params) { { 'execdriver' => 'native' } } it { is_expected.to contain_file(service_config_file).with_content(%r{-e native}) } end ['aufs', 'devicemapper', 'btrfs', 'overlay', 'overlay2', 'vfs', 'zfs'].each do |driver| context "with #{driver} storage driver" do let(:params) { { 'storage_driver' => driver } } it { is_expected.to contain_file(storage_config_file).with_content(%r{ --storage-driver #{driver}}) } end end context 'with thinpool device param' do let(:params) do { 'storage_driver' => 'devicemapper', 'dm_thinpooldev' => '/dev/mapper/vg_test-docker--pool' } end it { is_expected.to contain_file(storage_config_file).with_content(%r{--storage-opt dm\.thinpooldev=\/dev\/mapper\/vg_test-docker--pool}) } end context 'with use deferred removal param' do let(:params) do { 'storage_driver' => 'devicemapper', 'dm_use_deferred_removal' => true } end it { is_expected.to contain_file(storage_config_file).with_content(%r{--storage-opt dm\.use_deferred_removal=true}) } end context 'with use deferred deletion param' do let(:params) do { 'storage_driver' => 'devicemapper', 'dm_use_deferred_deletion' => true } end it { is_expected.to contain_file(storage_config_file).with_content(%r{--storage-opt dm\.use_deferred_deletion=true}) } end context 'with block discard param' do let(:params) do { 'storage_driver' => 'devicemapper', 'dm_blkdiscard' => true } end it { is_expected.to contain_file(storage_config_file).with_content(%r{--storage-opt dm\.blkdiscard=true}) } end context 'with override udev sync check param' do let(:params) do { 'storage_driver' => 'devicemapper', 'dm_override_udev_sync_check' => true } end it { is_expected.to contain_file(storage_config_file).with_content(%r{--storage-opt dm\.override_udev_sync_check=true}) } end context 'without execdriver param' do it { is_expected.not_to contain_file(service_config_file).with_content(%r{-e lxc}) } it { is_expected.not_to contain_file(service_config_file).with_content(%r{-e native}) } end context 'with multi dns param' do let(:params) { { 'dns' => ['8.8.8.8', '8.8.4.4'] } } it { is_expected.to contain_file(service_config_file).with_content(%r{--dns 8.8.8.8}).with_content(%r{--dns 8.8.4.4}) } end context 'with dns param' do let(:params) { { 'dns' => '8.8.8.8' } } it { is_expected.to contain_file(service_config_file).with_content(%r{--dns 8.8.8.8}) } end context 'with multi dns_search param' do let(:params) { { 'dns_search' => ['my.domain.local', 'other-domain.de'] } } it { is_expected.to contain_file(service_config_file).with_content(%r{--dns-search my.domain.local}).with_content(%r{--dns-search other-domain.de}) } end context 'with dns_search param' do let(:params) { { 'dns_search' => 'my.domain.local' } } it { is_expected.to contain_file(service_config_file).with_content(%r{--dns-search my.domain.local}) } end context 'with multi extra parameters' do let(:params) { { 'extra_parameters' => ['--this this', '--that that'] } } it { is_expected.to contain_file(service_config_file).with_content(%r{--this this}) } it { is_expected.to contain_file(service_config_file).with_content(%r{--that that}) } end context 'with a string extra parameters' do let(:params) { { 'extra_parameters' => '--this this' } } it { is_expected.to contain_file(service_config_file).with_content(%r{--this this}) } end context 'with multi shell values' do let(:params) { { 'shell_values' => ['--this this', '--that that'] } } it { is_expected.to contain_file(service_config_file).with_content(%r{--this this}) } it { is_expected.to contain_file(service_config_file).with_content(%r{--that that}) } end context 'with a string shell values' do let(:params) { { 'shell_values' => '--this this' } } it { is_expected.to contain_file(service_config_file).with_content(%r{--this this}) } end context 'with socket group set' do let(:params) { { 'socket_group' => 'notdocker' } } it { is_expected.to contain_file(service_config_file).with_content(%r{-G notdocker}) } end context 'with labels set' do let(:params) { { 'labels' => ['storage=ssd', 'stage=production'] } } it { is_expected.to contain_file(service_config_file).with_content(%r{--label storage=ssd}) } it { is_expected.to contain_file(service_config_file).with_content(%r{--label stage=production}) } end context 'with service_state set to stopped' do let(:params) { { 'service_state' => 'stopped' } } it { is_expected.to contain_service('docker').with_ensure('stopped') } end context 'with a custom service name' do let(:params) { { 'service_name' => 'docker.io' } } it { is_expected.to contain_service('docker').with_name('docker.io') } end context 'with service_enable set to false' do let(:params) { { 'service_enable' => false } } it { is_expected.to contain_service('docker').with_enable('false') } end context 'with service_enable set to true' do let(:params) { { 'service_enable' => true } } it { is_expected.to contain_service('docker').with_enable('true') } end context 'with service_manage set to false' do let(:params) { { 'manage_service' => false } } it { is_expected.not_to contain_service('docker') } end context 'with specific log_level' do let(:params) { { 'log_level' => 'debug' } } it { is_expected.to contain_file(service_config_file).with_content(%r{-l debug}) } end context 'with an invalid log_level' do let(:params) { { 'log_level' => 'verbose' } } it do expect { is_expected.to contain_package('docker') }.to raise_error(Puppet::Error, %r{log_level must be one of debug, info, warn, error or fatal}) end end context 'with specific log_driver' do let(:params) { { 'log_driver' => 'json-file' } } it { is_expected.to contain_file(service_config_file).with_content(%r{--log-driver json-file}) } end context 'with an invalid log_driver' do let(:params) { { 'log_driver' => 'etwlogs' } } it do expect { is_expected.to contain_package('docker') }.to raise_error(Puppet::Error, %r{log_driver must be one of none, json-file, syslog, journald, gelf, fluentd, splunk or awslogs}) end end context 'with specific log_driver and log_opt' do let(:params) do { 'log_driver' => 'json-file', 'log_opt' => ['max-size=1m', 'max-file=3'] } end it { is_expected.to contain_file(service_config_file).with_content(%r{--log-driver json-file}) } it { is_expected.to contain_file(service_config_file).with_content(%r{--log-opt max-size=1m}) } it { is_expected.to contain_file(service_config_file).with_content(%r{--log-opt max-file=3}) } end context 'without log_driver no log_opt' do let(:params) { { 'log_opt' => ['max-size=1m'] } } it { is_expected.not_to contain_file(service_config_file).with_content(%r{--log-opt max-size=1m}) } end context 'with storage_driver set to devicemapper and dm_* options set' do let(:params) do { 'storage_driver' => 'devicemapper', 'dm_datadev' => '/dev/sda', 'dm_metadatadev' => '/dev/sdb' } end it { is_expected.to contain_file(storage_config_file).with_content(%r{dm.datadev=\/dev\/sda}) } end context 'with storage_driver unset and dm_ options set' do let(:params) do { 'dm_datadev' => '/dev/sda', 'dm_metadatadev' => '/dev/sdb' } end it { is_expected.to raise_error(Puppet::Error, %r{Values for dm_ variables will be ignored unless storage_driver is set to devicemapper.}) } end context 'with storage_driver and dm_basesize set' do let(:params) do { 'storage_driver' => 'devicemapper', 'dm_basesize' => '20G' } end it { is_expected.to contain_file(storage_config_file).with_content(%r{dm.basesize=20G}) } end context 'with storage_driver unset and dm_basesize set' do let(:params) { { 'dm_basesize' => '20G' } } it { is_expected.to raise_error(Puppet::Error, %r{Values for dm_ variables will be ignored unless storage_driver is set to devicemapper.}) } end context 'with specific selinux_enabled parameter' do let(:params) { { 'selinux_enabled' => true } } it { is_expected.to contain_file(service_config_file).with_content(%r{--selinux-enabled=true}) } end context 'with an invalid selinux_enabled parameter' do let(:params) { { 'selinux_enabled' => 'yes' } } it do expect { is_expected.to contain_package('docker') }.to raise_error(Puppet::Error, %r{got String}) end end context 'with custom root dir && Docker version < 17.06' do let(:params) do { 'root_dir' => '/mnt/docker', 'version' => '17.03', } end it { is_expected.to contain_file(service_config_file).with_content(%r{-g \/mnt\/docker}) } end - context 'with custom root dir && Docker version > 17.05' do + context 'with custom root dir && Docker version > 18.09' do let(:params) do { 'root_dir' => '/mnt/docker', - 'version' => '18.03', + 'version' => '19.09', } end it { is_expected.to contain_file(service_config_file).with_content(%r{--data-root \/mnt\/docker}) } end context 'with ensure absent' do let(:params) { { 'ensure' => 'absent' } } it { is_expected.to contain_package('docker').with_ensure('absent') } end context 'with ensure absent and ' do let(:params) { { 'ensure' => 'absent' } } it { is_expected.to contain_package('docker').with_ensure('absent') } it { is_expected.to contain_package('docker-ce-cli').with_ensure('absent') } it { is_expected.to contain_package('containerd.io').with_ensure('absent') } end context 'with an invalid combination of devicemapper options' do let(:params) do { 'dm_datadev' => '/dev/mapper/vg_test-docker--pool_tdata', 'dm_metadatadev' => '/dev/mapper/vg_test-docker--pool_tmeta', 'dm_thinpooldev' => '/dev/mapper/vg_test-docker--pool' } end it do expect { is_expected.to contain_package('docker') }.to raise_error(Puppet::Error, %r{You can use the \$dm_thinpooldev parameter, or the \$dm_datadev and \$dm_metadatadev parameter pair, but you cannot use both.}) end end end end ['RedHat', 'CentOS'].each do |operatingsystem| context "on #{operatingsystem}" do let(:facts) do { architecture: 'x86_64', osfamily: 'RedHat', operatingsystem: operatingsystem, operatingsystemrelease: '7.0', operatingsystemmajrelease: '7', kernelversion: '3.10.0', os: { distro: { codename: 'wheezy' }, family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, } end storage_setup_file = '/etc/sysconfig/docker-storage-setup' context 'with storage driver' do let(:params) { { 'storage_driver' => 'devicemapper' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^STORAGE_DRIVER=devicemapper}) } end context 'with storage devices' do let(:params) { { 'storage_devs' => '/dev/sda,/dev/sdb' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^DEVS="\/dev\/sda,\/dev\/sdb"}) } end context 'with storage volume group' do let(:params) { { 'storage_vg' => 'vg_test' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^VG=vg_test}) } end context 'with storage root size' do let(:params) { { 'storage_root_size' => '10G' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^ROOT_SIZE=10G}) } end context 'with storage data size' do let(:params) { { 'storage_data_size' => '10G' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^DATA_SIZE=10G}) } end context 'with storage min data size' do let(:params) { { 'storage_min_data_size' => '2G' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^MIN_DATA_SIZE=2G}) } end context 'with storage chunk size' do let(:params) { { 'storage_chunk_size' => '10G' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^CHUNK_SIZE=10G}) } end context 'with storage grow partition' do let(:params) { { 'storage_growpart' => true } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^GROWPART=true}) } end context 'with storage auto extend pool' do let(:params) { { 'storage_auto_extend_pool' => '1' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^AUTO_EXTEND_POOL=1}) } end context 'with storage auto extend threshold' do let(:params) { { 'storage_pool_autoextend_threshold' => '1' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^POOL_AUTOEXTEND_THRESHOLD=1}) } end context 'with storage auto extend percent' do let(:params) { { 'storage_pool_autoextend_percent' => '10' } } it { is_expected.to contain_file(storage_setup_file).with_content(%r{^POOL_AUTOEXTEND_PERCENT=10}) } end context 'with custom storage_setup_file' do let(:params) { { 'storage_setup_file' => '/etc/sysconfig/docker-latest-storage-setup' } } it { is_expected.to contain_file('/etc/sysconfig/docker-latest-storage-setup').with_content(%r{managed by Puppet}) } end end end context 'specific to Ubuntu Trusty' do let(:facts) do { architecture: 'amd64', osfamily: 'Debian', lsbdistid: 'Ubuntu', operatingsystem: 'Ubuntu', lsbdistcodename: 'trusty', operatingsystemrelease: '14.04', kernelrelease: '3.8.0-29-generic', os: { distro: { codename: 'wheezy' }, family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, } end it { is_expected.to contain_service('docker').with_provider('upstart') } it { is_expected.to contain_package('docker').with_name('docker-ce').with_ensure('present') } it { is_expected.to contain_package('apparmor') } end context 'newer versions of Debian and Ubuntu' do context 'Ubuntu >= 15.04' do let(:facts) do { architecture: 'amd64', osfamily: 'Debian', lsbdistid: 'Ubuntu', operatingsystem: 'Ubuntu', lsbdistcodename: 'trusty', operatingsystemrelease: '15.04', kernelrelease: '3.8.0-29-generic', os: { distro: { codename: 'wheezy' }, family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, } end it { is_expected.to contain_service('docker').with_provider('systemd').with_hasstatus(true).with_hasrestart(true) } end context 'Debian >= 8' do let(:facts) do { architecture: 'amd64', osfamily: 'Debian', operatingsystem: 'Debian', lsbdistid: 'Debian', lsbdistcodename: 'jessie', kernelrelease: '3.2.0-4-amd64', operatingsystemmajrelease: '8', os: { distro: { codename: 'wheezy' }, family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } }, } end it { is_expected.to contain_service('docker').with_provider('systemd').with_hasstatus(true).with_hasrestart(true) } end end context 'with an invalid distro name' do let(:facts) do { architecture: 'Whatever', osfamily: 'Whatever', operatingsystem: 'Whatever', lsbdistid: 'Whatever', lsbdistcodename: 'Whatever', kernelrelease: 'Whatever', operatingsystemmajrelease: 'Whatever', os: { distro: { codename: 'Whatever' }, family: 'Whatever', name: 'Whatever', release: { major: 'Whatever', full: 'Whatever' } }, } end it do expect { is_expected.to contain_package('docker') }.to raise_error(Puppet::Error, %r{This module only works on Debian, Red Hat or Windows based systems.}) end end context 'CentOS < 7' do let(:facts) do { architecture: 'x86_64', osfamily: 'RedHat', operatingsystem: 'CentOS', kernelversion: '3.10.0', operatingsystemmajrelease: '6', os: { family: 'RedHat', name: 'CentOS', release: { major: '6', full: '6.0' } }, } end it do expect { is_expected.to contain_package('docker') }.to raise_error(Puppet::Error, %r{This module only works on CentOS version 7 and higher based systems.}) end end end