diff --git a/.fixtures.yml b/.fixtures.yml index 464fa884..f812b84d 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -8,7 +8,7 @@ fixtures: facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' puppet_agent: repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.12.1 + ref: v4.13.0 provision: 'https://github.com/puppetlabs/provision.git' yumrepo_core: repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70737e1f..1c4a9c44 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,11 +21,14 @@ jobs: - ubuntu-20.04 - ubuntu-latest collection: - - puppet6-nightly - puppet7-nightly + - puppet8-nightly runs-on: ${{ matrix.platform }} + env: + PUPPET_GEM_VERSION: '~> 7.24' + steps: - name: Checkout Source uses: actions/checkout@v2 @@ -90,8 +93,11 @@ jobs: provider: "provision::provision_service" image: "windows-2022" collection: - - puppet6-nightly - - puppet7-nightly + - puppet7-nightly + - puppet8-nightly + + env: + PUPPET_GEM_VERSION: '~> 7.24' steps: - name: Checkout Source diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index b29c3637..0e84f2ae 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -20,11 +20,14 @@ jobs: - ubuntu-20.04 - ubuntu-latest collection: - - puppet6-nightly - puppet7-nightly + - puppet8-nightly runs-on: ${{ matrix.platform }} + env: + PUPPET_GEM_VERSION: '~> 7.24' + steps: - name: Checkout Source uses: actions/checkout@v2 @@ -89,8 +92,11 @@ jobs: provider: "provision::provision_service" image: "windows-2022" collection: - - puppet6-nightly - - puppet7-nightly + - puppet7-nightly + - puppet8-nightly + + env: + PUPPET_GEM_VERSION: '~> 7.24' steps: - name: Checkout Source diff --git a/.rubocop.yml b/.rubocop.yml index a886d8db..67a4a804 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,15 @@ --- +inherit_from: .rubocop_todo.yml + require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.5' + ExtraDetails: true + DisplayStyleGuide: true + TargetRubyVersion: '2.6' Include: - "**/*.rb" Exclude: @@ -18,7 +23,6 @@ AllCops: - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" -inherit_from: ".rubocop_todo.yml" Layout/LineLength: Description: People have wide screens, use them. Max: 200 @@ -80,441 +84,3 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets -Performance/AncestorsInclude: - Enabled: true -Performance/BigDecimalWithNumericArgument: - Enabled: true -Performance/BlockGivenWithExplicitBlock: - Enabled: true -Performance/CaseWhenSplat: - Enabled: true -Performance/ConstantRegexp: - Enabled: true -Performance/MethodObjectAsBlock: - Enabled: true -Performance/RedundantSortBlock: - Enabled: true -Performance/RedundantStringChars: - Enabled: true -Performance/ReverseFirst: - Enabled: true -Performance/SortReverse: - Enabled: true -Performance/Squeeze: - Enabled: true -Performance/StringInclude: - Enabled: true -Performance/Sum: - Enabled: true -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Bundler/InsecureProtocolSource: - Enabled: false -Gemspec/DuplicatedAssignment: - Enabled: false -Gemspec/OrderedDependencies: - Enabled: false -Gemspec/RequiredRubyVersion: - Enabled: false -Gemspec/RubyVersionGlobalsUsage: - Enabled: false -Layout/ArgumentAlignment: - Enabled: false -Layout/BeginEndAlignment: - Enabled: false -Layout/ClosingHeredocIndentation: - Enabled: false -Layout/EmptyComment: - Enabled: false -Layout/EmptyLineAfterGuardClause: - Enabled: false -Layout/EmptyLinesAroundArguments: - Enabled: false -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false -Layout/EndOfLine: - Enabled: false -Layout/FirstArgumentIndentation: - Enabled: false -Layout/HashAlignment: - Enabled: false -Layout/HeredocIndentation: - Enabled: false -Layout/LeadingEmptyLines: - Enabled: false -Layout/SpaceAroundMethodCallOperator: - Enabled: false -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: false -Layout/SpaceInsideReferenceBrackets: - Enabled: false -Lint/BigDecimalNew: - Enabled: false -Lint/BooleanSymbol: - Enabled: false -Lint/ConstantDefinitionInBlock: - Enabled: false -Lint/DeprecatedOpenSSLConstant: - Enabled: false -Lint/DisjunctiveAssignmentInConstructor: - Enabled: false -Lint/DuplicateElsifCondition: - Enabled: false -Lint/DuplicateRequire: - Enabled: false -Lint/DuplicateRescueException: - Enabled: false -Lint/EmptyConditionalBody: - Enabled: false -Lint/EmptyFile: - Enabled: false -Lint/ErbNewArguments: - Enabled: false -Lint/FloatComparison: - Enabled: false -Lint/HashCompareByIdentity: - Enabled: false -Lint/IdentityComparison: - Enabled: false -Lint/InterpolationCheck: - Enabled: false -Lint/MissingCopEnableDirective: - Enabled: false -Lint/MixedRegexpCaptureTypes: - Enabled: false -Lint/NestedPercentLiteral: - Enabled: false -Lint/NonDeterministicRequireOrder: - Enabled: false -Lint/OrderedMagicComments: - Enabled: false -Lint/OutOfRangeRegexpRef: - Enabled: false -Lint/RaiseException: - Enabled: false -Lint/RedundantCopEnableDirective: - Enabled: false -Lint/RedundantRequireStatement: - Enabled: false -Lint/RedundantSafeNavigation: - Enabled: false -Lint/RedundantWithIndex: - Enabled: false -Lint/RedundantWithObject: - Enabled: false -Lint/RegexpAsCondition: - Enabled: false -Lint/ReturnInVoidContext: - Enabled: false -Lint/SafeNavigationConsistency: - Enabled: false -Lint/SafeNavigationWithEmpty: - Enabled: false -Lint/SelfAssignment: - Enabled: false -Lint/SendWithMixinArgument: - Enabled: false -Lint/ShadowedArgument: - Enabled: false -Lint/StructNewOverride: - Enabled: false -Lint/ToJSON: - Enabled: false -Lint/TopLevelReturnWithArgument: - Enabled: false -Lint/TrailingCommaInAttributeDeclaration: - Enabled: false -Lint/UnreachableLoop: - Enabled: false -Lint/UriEscapeUnescape: - Enabled: false -Lint/UriRegexp: - Enabled: false -Lint/UselessMethodDefinition: - Enabled: false -Lint/UselessTimes: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/BlockNesting: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Migration/DepartmentName: - Enabled: false -Naming/AccessorMethodName: - Enabled: false -Naming/BlockParameterName: - Enabled: false -Naming/HeredocDelimiterCase: - Enabled: false -Naming/HeredocDelimiterNaming: - Enabled: false -Naming/MemoizedInstanceVariableName: - Enabled: false -Naming/MethodParameterName: - Enabled: false -Naming/RescuedExceptionsVariableName: - Enabled: false -Naming/VariableNumber: - Enabled: false -Performance/BindCall: - Enabled: false -Performance/DeletePrefix: - Enabled: false -Performance/DeleteSuffix: - Enabled: false -Performance/InefficientHashSearch: - Enabled: false -Performance/UnfreezeString: - Enabled: false -Performance/UriDefaultParser: - Enabled: false -RSpec/Be: - Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false -RSpec/Capybara/FeatureMethods: - Enabled: false -RSpec/Capybara/VisibilityMatcher: - Enabled: false -RSpec/ContextMethod: - Enabled: false -RSpec/ContextWording: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/EmptyHook: - Enabled: false -RSpec/EmptyLineAfterExample: - Enabled: false -RSpec/EmptyLineAfterExampleGroup: - Enabled: false -RSpec/EmptyLineAfterHook: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/ExampleWithoutDescription: - Enabled: false -RSpec/ExpectChange: - Enabled: false -RSpec/ExpectInHook: - Enabled: false -RSpec/FactoryBot/AttributeDefinedStatically: - Enabled: false -RSpec/FactoryBot/CreateList: - Enabled: false -RSpec/FactoryBot/FactoryClassName: - Enabled: false -RSpec/HooksBeforeExamples: - Enabled: false -RSpec/ImplicitBlockExpectation: - Enabled: false -RSpec/ImplicitSubject: - Enabled: false -RSpec/LeakyConstantDeclaration: - Enabled: false -RSpec/LetBeforeExamples: - Enabled: false -RSpec/MissingExampleGroupArgument: - Enabled: false -RSpec/MultipleExpectations: - Enabled: false -RSpec/MultipleMemoizedHelpers: - Enabled: false -RSpec/MultipleSubjects: - Enabled: false -RSpec/NestedGroups: - Enabled: false -RSpec/PredicateMatcher: - Enabled: false -RSpec/ReceiveCounts: - Enabled: false -RSpec/ReceiveNever: - Enabled: false -RSpec/RepeatedExampleGroupBody: - Enabled: false -RSpec/RepeatedExampleGroupDescription: - Enabled: false -RSpec/RepeatedIncludeExample: - Enabled: false -RSpec/ReturnFromStub: - Enabled: false -RSpec/SharedExamples: - Enabled: false -RSpec/StubbedMock: - Enabled: false -RSpec/UnspecifiedException: - Enabled: false -RSpec/VariableDefinition: - Enabled: false -RSpec/VoidExpect: - Enabled: false -RSpec/Yield: - Enabled: false -Security/Open: - Enabled: false -Style/AccessModifierDeclarations: - Enabled: false -Style/AccessorGrouping: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/BisectedAttrAccessor: - Enabled: false -Style/CaseLikeIf: - Enabled: false -Style/ClassEqualityComparison: - Enabled: false -Style/ColonMethodDefinition: - Enabled: false -Style/CombinableLoops: - Enabled: false -Style/CommentedKeyword: - Enabled: false -Style/Dir: - Enabled: false -Style/DoubleCopDisableDirective: - Enabled: false -Style/EmptyBlockParameter: - Enabled: false -Style/EmptyLambdaParameter: - Enabled: false -Style/Encoding: - Enabled: false -Style/EvalWithLocation: - Enabled: false -Style/ExpandPathArguments: - Enabled: false -Style/ExplicitBlockArgument: - Enabled: false -Style/ExponentialNotation: - Enabled: false -Style/FloatDivision: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/GlobalStdStream: - Enabled: false -Style/HashAsLastArrayItem: - Enabled: false -Style/HashLikeCase: - Enabled: false -Style/HashTransformKeys: - Enabled: false -Style/HashTransformValues: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/KeywordParametersOrder: - Enabled: false -Style/MinMax: - Enabled: false -Style/MixinUsage: - Enabled: false -Style/MultilineWhenThen: - Enabled: false -Style/NegatedUnless: - Enabled: false -Style/NumericPredicate: - Enabled: false -Style/OptionalBooleanParameter: - Enabled: false -Style/OrAssignment: - Enabled: false -Style/RandomWithOffset: - Enabled: false -Style/RedundantAssignment: - Enabled: false -Style/RedundantCondition: - Enabled: false -Style/RedundantConditional: - Enabled: false -Style/RedundantFetchBlock: - Enabled: false -Style/RedundantFileExtensionInRequire: - Enabled: false -Style/RedundantRegexpCharacterClass: - Enabled: false -Style/RedundantRegexpEscape: - Enabled: false -Style/RedundantSelfAssignment: - Enabled: false -Style/RedundantSort: - Enabled: false -Style/RescueStandardError: - Enabled: false -Style/SingleArgumentDig: - Enabled: false -Style/SlicingWithRange: - Enabled: false -Style/SoleNestedConditional: - Enabled: false -Style/StderrPuts: - Enabled: false -Style/StringConcatenation: - Enabled: false -Style/Strip: - Enabled: false -Style/SymbolProc: - Enabled: false -Style/TrailingBodyOnClass: - Enabled: false -Style/TrailingBodyOnMethodDefinition: - Enabled: false -Style/TrailingBodyOnModule: - Enabled: false -Style/TrailingCommaInHashLiteral: - Enabled: false -Style/TrailingMethodEndStatement: - Enabled: false -Style/UnpackFirst: - Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/DuplicateRegexpCharacterClassElement: - Enabled: false -Lint/EmptyBlock: - Enabled: false -Lint/EmptyClass: - Enabled: false -Lint/NoReturnInBeginEndBlocks: - Enabled: false -Lint/ToEnumArguments: - Enabled: false -Lint/UnexpectedBlockArity: - Enabled: false -Lint/UnmodifiedReduceAccumulator: - Enabled: false -Performance/CollectionLiteralInLoop: - Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/CollectionCompact: - Enabled: false -Style/DocumentDynamicEvalDefinition: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/NilLambda: - Enabled: false -Style/RedundantArgument: - Enabled: false -Style/SwapValues: - Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9fb474ce..ff17c29a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,105 +1,3 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2020-12-16 17:04:12 UTC using RuboCop version 1.6.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 2 -# Configuration parameters: Include. -# Include: **/*.gemfile, **/Gemfile, **/gems.rb -Bundler/DuplicatedGem: - Exclude: - - 'Gemfile' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. -# Include: **/*.gemfile, **/Gemfile, **/gems.rb -Bundler/OrderedGems: - Exclude: - - 'Gemfile' - -# Offense count: 24 -# Cop supports --auto-correct. -Layout/ClosingHeredocIndentation: - Exclude: - - 'spec/acceptance/docker_custom_source_spec.rb' - - 'spec/acceptance/docker_full_spec.rb' - - 'spec/acceptance/docker_spec.rb' - - 'spec/acceptance/stack_spec.rb' - - 'spec/spec_helper_acceptance_local.rb' - -# Offense count: 24 -# Cop supports --auto-correct. -Layout/EmptyLineAfterGuardClause: - Enabled: false - -# Offense count: 667 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Enabled: false - -# Offense count: 10 -# Cop supports --auto-correct. -Layout/HeredocIndentation: - Exclude: - - 'Rakefile' - - 'spec/spec_helper_acceptance_local.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: normal, indented_internal_methods -Layout/IndentationConsistency: - Exclude: - - 'Guardfile' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: IndentationWidth, EnforcedStyle. -# SupportedStyles: spaces, tabs -Layout/IndentationStyle: - Exclude: - - 'Guardfile' - -# Offense count: 2 -# Cop supports --auto-correct. -Layout/SpaceAroundMethodCallOperator: - Exclude: - - 'spec/shared_examples/install.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: final_newline, final_blank_line -Layout/TrailingEmptyLines: - Exclude: - - 'Guardfile' - - 'Rakefile' - -# Offense count: 1 -# Cop supports --auto-correct. -Lint/InterpolationCheck: - Exclude: - - 'spec/acceptance/docker_full_spec.rb' - -# Offense count: 1 -# Configuration parameters: MaximumRangeSize. -Lint/MissingCopEnableDirective: - Exclude: - - 'lib/puppet/provider/docker_compose/ruby.rb' - -# Offense count: 1 -Lint/MixedRegexpCaptureTypes: - Exclude: - - 'Gemfile' - # Offense count: 22 # Configuration parameters: AllowKeywordBlockArguments. Lint/UnderscorePrefixedVariableName: @@ -126,353 +24,134 @@ Lint/UselessAssignment: - 'spec/shared_examples/image.rb' - 'spec/shared_examples/machine.rb' -# Offense count: 18 -# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. +# Offense count: 20 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 309 + Max: 291 -# Offense count: 131 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. -# IgnoredMethods: refine +# Offense count: 11 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. +# AllowedMethods: refine Metrics/BlockLength: - Max: 712 + Max: 125 # Offense count: 7 # Configuration parameters: CountBlocks. Metrics/BlockNesting: Max: 7 -# Offense count: 15 -# Configuration parameters: IgnoredMethods. +# Offense count: 17 +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: - Max: 36 + Max: 67 -# Offense count: 20 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +# Offense count: 24 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 485 + Max: 462 # Offense count: 2 # Configuration parameters: CountKeywordArgs, MaxOptionalParameters. Metrics/ParameterLists: Max: 9 -# Offense count: 12 -# Configuration parameters: IgnoredMethods. +# Offense count: 14 +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: - Max: 39 - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: lowercase, uppercase -Naming/HeredocDelimiterCase: - Exclude: - - 'spec/acceptance/compose_v3_spec.rb' - - 'spec/acceptance_swarm/swarm_spec.rb' + Max: 71 -# Offense count: 48 +# Offense count: 47 # Configuration parameters: ForbiddenDelimiters. -# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) Naming/HeredocDelimiterNaming: Exclude: - - 'Rakefile' - 'spec/acceptance/docker_custom_source_spec.rb' - 'spec/acceptance/docker_full_spec.rb' - 'spec/acceptance/machine_spec.rb' - 'spec/spec_helper_acceptance_local.rb' -# Offense count: 13 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: snake_case, camelCase -Naming/VariableName: - Exclude: - - 'Rakefile' - -# Offense count: 1 -Security/Eval: - Exclude: - - 'Gemfile' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect. -Security/JSONLoad: - Exclude: - - 'Rakefile' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, conditionals -Style/AndOr: - Exclude: - - 'Rakefile' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'lib/puppet/provider/docker_compose/ruby.rb' - - 'lib/puppet/provider/docker_stack/ruby.rb' - - 'spec/spec_helper.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -Style/CaseLikeIf: - Exclude: - - 'lib/puppet/parser/functions/docker_run_flags.rb' - - 'lib/puppet/provider/docker_network/ruby.rb' - - 'spec/shared_examples/plugin.rb' - - 'spec/shared_examples/registry.rb' - -# Offense count: 11 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: nested, compact -Style/ClassAndModuleChildren: - Exclude: - - 'lib/puppet/parser/functions/docker_exec_flags.rb' - - 'lib/puppet/parser/functions/docker_params_changed.rb' - - 'lib/puppet/parser/functions/docker_plugin_enable_flags.rb' - - 'lib/puppet/parser/functions/docker_plugin_install_flags.rb' - - 'lib/puppet/parser/functions/docker_plugin_remove_flags.rb' - - 'lib/puppet/parser/functions/docker_run_flags.rb' - - 'lib/puppet/parser/functions/docker_secrets_flags.rb' - - 'lib/puppet/parser/functions/docker_service_flags.rb' - - 'lib/puppet/parser/functions/docker_stack_flags.rb' - - 'lib/puppet/parser/functions/docker_swarm_init_flags.rb' - - 'lib/puppet/parser/functions/docker_swarm_join_flags.rb' - -# Offense count: 1 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'lib/puppet/parser/functions/docker_params_changed.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty, nil, both -Style/EmptyElse: - Exclude: - - 'lib/facter/docker.rb' - - 'spec/shared_examples/service.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: format, sprintf, percent -Style/FormatString: - Exclude: - - 'Rakefile' - - 'lib/puppet/parser/functions/docker_secrets_flags.rb' - - 'spec/helper/get_docker_secrets_flags.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: always, always_true, never -Style/FrozenStringLiteralComment: - Exclude: - - 'Gemfile' - - 'Guardfile' - -# Offense count: 12 -# Cop supports --auto-correct. -Style/GlobalStdStream: - Exclude: - - 'tasks/node_ls.rb' - - 'tasks/node_rm.rb' - - 'tasks/node_update.rb' - - 'tasks/service_create.rb' - - 'tasks/service_rm.rb' - - 'tasks/service_scale.rb' - - 'tasks/service_update.rb' - - 'tasks/swarm_init.rb' - - 'tasks/swarm_join.rb' - - 'tasks/swarm_leave.rb' - - 'tasks/swarm_token.rb' - - 'tasks/swarm_update.rb' - -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: braces, no_braces -Style/HashAsLastArrayItem: - Exclude: - - 'Gemfile' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -Style/HashSyntax: - Exclude: - - 'Guardfile' - -# Offense count: 5 -Style/IdenticalConditionalBranches: +# Offense count: 8 +# Configuration parameters: MinSize. +Performance/CollectionLiteralInLoop: Exclude: - - 'spec/helper/get_defaults.rb' - - 'spec/helper/get_values_init.rb' + - 'spec/defines/exec_spec.rb' + - 'spec/defines/image_spec.rb' + - 'spec/defines/registry_spec.rb' + - 'spec/defines/run_spec.rb' + - 'spec/defines/secrets_spec.rb' + - 'spec/defines/services_spec.rb' + - 'spec/defines/stack_spec.rb' + - 'spec/defines/swarm_spec.rb' -# Offense count: 95 -# Cop supports --auto-correct. -Style/IfUnlessModifier: +# Offense count: 41 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: line_count_dependent, lambda, literal -Style/Lambda: - Exclude: - - 'lib/puppet/parser/functions/docker_run_flags.rb' - - 'lib/puppet/parser/functions/docker_secrets_flags.rb' - - 'lib/puppet/provider/docker_network/ruby.rb' - - 'lib/puppet/provider/docker_volume/ruby.rb' - - 'spec/helper/get_docker_run_flags.rb' - - 'spec/helper/get_docker_secrets_flags.rb' - -# Offense count: 2 -Style/MixinUsage: - Exclude: - - 'spec/spec_helper.rb' - - 'spec/spec_helper_acceptance_local.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantCondition: - Exclude: - - 'spec/shared_examples/run.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantConditional: - Exclude: - - 'spec/helper/get_defaults.rb' +# Offense count: 32 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Enabled: false -# Offense count: 3 -# Cop supports --auto-correct. -Style/RedundantInterpolation: - Exclude: - - 'Rakefile' +# Offense count: 102 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 52 # Offense count: 2 -# Cop supports --auto-correct. -Style/RedundantRegexpCharacterClass: +RSpec/ExpectInHook: Exclude: - - 'spec/classes/compose_spec.rb' - -# Offense count: 53 -# Cop supports --auto-correct. -Style/RedundantRegexpEscape: - Exclude: - - 'Gemfile' - - 'Guardfile' - - 'Rakefile' - - 'spec/acceptance/docker_custom_source_spec.rb' - 'spec/acceptance/docker_full_spec.rb' - - 'spec/acceptance/docker_spec.rb' - - 'spec/classes/compose_spec.rb' - -# Offense count: 123 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: +# Offense count: 6 +# Configuration parameters: Max. +RSpec/IndexedLet: Exclude: - - 'spec/spec_helper.rb' + - 'spec/acceptance/docker_params_changed_spec.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. -# AllowedMethods: present?, blank?, presence, try, try! -Style/SafeNavigation: - Exclude: - - 'Rakefile' +# Offense count: 38 +RSpec/MultipleExpectations: + Max: 4 -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: AllowModifier. -Style/SoleNestedConditional: +# Offense count: 24 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: Exclude: - - 'lib/facter/docker.rb' - - 'lib/puppet/provider/docker_network/ruby.rb' - 'spec/classes/compose_spec.rb' + - 'spec/classes/images_spec.rb' + - 'spec/classes/init_spec.rb' - 'spec/classes/machine_spec.rb' + - 'spec/classes/networks_spec.rb' + - 'spec/classes/plugins_spec.rb' + - 'spec/defines/image_spec.rb' + - 'spec/defines/plugin_spec.rb' + - 'spec/defines/run_spec.rb' - 'spec/defines/services_spec.rb' -# Offense count: 34 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - Exclude: - - 'Gemfile' - - 'Rakefile' - -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: MinSize. -# SupportedStyles: percent, brackets -Style/SymbolArray: - EnforcedStyle: brackets +# Offense count: 5 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 4 -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowSafeAssignment. -# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex -Style/TernaryParentheses: +# Offense count: 59 +# Configuration parameters: AllowedPatterns. +# AllowedPatterns: ^expect_, ^assert_ +RSpec/NoExpectationExample: Exclude: - - 'lib/puppet/provider/docker_compose/ruby.rb' - - 'lib/puppet/provider/docker_stack/ruby.rb' - -# Offense count: 156 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArguments: - Enabled: false - -# Offense count: 44 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArrayLiteral: - Enabled: false - -# Offense count: 189 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Enabled: false - -# Offense count: 21 -# Cop supports --auto-correct. -# Configuration parameters: MinSize, WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - EnforcedStyle: brackets + - 'spec/acceptance/compose_v3_spec.rb' + - 'spec/acceptance/docker_custom_source_spec.rb' + - 'spec/acceptance/docker_full_spec.rb' + - 'spec/acceptance/docker_spec.rb' + - 'spec/acceptance/machine_spec.rb' + - 'spec/acceptance/network_spec.rb' + - 'spec/acceptance/plugin_spec.rb' + - 'spec/acceptance/stack_spec.rb' + - 'spec/acceptance/volume_spec.rb' + - 'spec/acceptance_swarm/swarm_spec.rb' -# Offense count: 85 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Layout/LineLength: - Max: 255 +# Offense count: 3 +RSpec/StubbedMock: + Exclude: + - 'spec/unit/lib/facter/docker_spec.rb' diff --git a/Gemfile b/Gemfile index 6037def2..cc04fc1c 100644 --- a/Gemfile +++ b/Gemfile @@ -30,9 +30,9 @@ group :development do gem "pry", '~> 0.10', require: false gem "simplecov-console", '~> 0.5', require: false gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.6.1', require: false - gem "rubocop-performance", '= 1.9.1', require: false - gem "rubocop-rspec", '= 2.0.1', require: false + gem "rubocop", '~> 1.48.1', require: false + gem "rubocop-performance", '~> 1.16', require: false + gem "rubocop-rspec", '~> 2.19', require: false gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "ruby-pwsh", require: false gem "github_changelog_generator", '= 1.15.2', require: false diff --git a/Rakefile b/Rakefile index 346c96ec..5ef7a479 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,6 @@ require 'bundler' require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? diff --git a/lib/facter/docker.rb b/lib/facter/docker.rb index a8d7e87e..368c12e6 100644 --- a/lib/facter/docker.rb +++ b/lib/facter/docker.rb @@ -55,10 +55,10 @@ def interfaces setcode do docker_version = Facter.value(:docker_version) if docker_version - if !docker_version['Client'].nil? - docker_version['Client']['Version'] - else + if docker_version['Client'].nil? docker_version['Version'] + else + docker_version['Client']['Version'] end end end diff --git a/lib/puppet/functions/docker_params_changed.rb b/lib/puppet/functions/docker_params_changed.rb index bcd4b12a..7412a033 100644 --- a/lib/puppet/functions/docker_params_changed.rb +++ b/lib/puppet/functions/docker_params_changed.rb @@ -89,11 +89,9 @@ def detect_changes(opts) param_changed = true if opts['volumes'].is_a?(String) && opts['volumes'].include?(':') && opts['volumes'] != inspect_hash['Mounts'].to_a[0] && opts['osfamily'] != 'windows' param_changed = true if opts['volumes'].is_a?(String) && !opts['volumes'].include?(':') && opts['volumes'] != inspect_hash['Config']['Volumes'].to_a[0] && opts['osfamily'] != 'windows' param_changed = true if opts['volumes'].is_a?(String) && opts['volumes'].scan(%r{(?=:)}).count == 2 && opts['volumes'] != inspect_hash['Mounts'].to_a[0] && opts['osfamily'] == 'windows' - param_changed = if opts['volumes'].is_a?(String) && opts['volumes'].scan(%r{(?=:)}).count == 1 && opts['volumes'] != inspect_hash['Config']['Volumes'].to_a[0] && opts['osfamily'] == 'windows' - true - else - param_changed - end + if opts['volumes'].is_a?(String) && opts['volumes'].scan(%r{(?=:)}).count == 1 && opts['volumes'] != inspect_hash['Config']['Volumes'].to_a[0] && opts['osfamily'] == 'windows' + param_changed = true + end pp_paths = opts['volumes'].reject { |item| item.include?(':') } if opts['volumes'].is_a?(Array) && opts['osfamily'] != 'windows' pp_mounts = opts['volumes'].select { |item| item.include?(':') } if opts['volumes'].is_a?(Array) && opts['osfamily'] != 'windows' diff --git a/lib/puppet/parser/functions/docker_exec_flags.rb b/lib/puppet/parser/functions/docker_exec_flags.rb index 809675b3..537140fd 100644 --- a/lib/puppet/parser/functions/docker_exec_flags.rb +++ b/lib/puppet/parser/functions/docker_exec_flags.rb @@ -10,17 +10,11 @@ module Puppet::Parser::Functions opts = args[0] || {} flags = [] - if opts['detach'] - flags << '--detach=true' - end + flags << '--detach=true' if opts['detach'] - if opts['interactive'] - flags << '--interactive=true' - end + flags << '--interactive=true' if opts['interactive'] - if opts['tty'] - flags << '--tty=true' - end + flags << '--tty=true' if opts['tty'] opts['env']&.each do |namevaluepair| flags << "--env #{namevaluepair}" diff --git a/lib/puppet/parser/functions/docker_run_flags.rb b/lib/puppet/parser/functions/docker_run_flags.rb index 84db5d92..0bab3976 100644 --- a/lib/puppet/parser/functions/docker_run_flags.rb +++ b/lib/puppet/parser/functions/docker_run_flags.rb @@ -21,17 +21,11 @@ module Puppet::Parser::Functions opts = args[0] || {} flags = [] - if opts['username'] - flags << "-u #{call_function('docker::escape', [opts['username']])}" - end + flags << "-u #{call_function('docker::escape', [opts['username']])}" if opts['username'] - if opts['hostname'] - flags << "-h #{call_function('docker::escape', [opts['hostname']])}" - end + flags << "-h #{call_function('docker::escape', [opts['hostname']])}" if opts['hostname'] - if opts['restart'] - flags << "--restart '#{opts['restart']}'" - end + flags << "--restart '#{opts['restart']}'" if opts['restart'] if opts['net'] if opts['net'].is_a? String @@ -41,9 +35,7 @@ module Puppet::Parser::Functions end end - if opts['memory_limit'] - flags << "-m #{opts['memory_limit']}" - end + flags << "-m #{opts['memory_limit']}" if opts['memory_limit'] cpusets = [opts['cpuset']].flatten.compact unless cpusets.empty? @@ -51,29 +43,17 @@ module Puppet::Parser::Functions flags << "--cpuset-cpus=#{value}" end - if opts['disable_network'] - flags << '-n false' - end + flags << '-n false' if opts['disable_network'] - if opts['privileged'] - flags << '--privileged' - end + flags << '--privileged' if opts['privileged'] - if opts['health_check_cmd'] && opts['health_check_cmd'].to_s != 'undef' - flags << "--health-cmd='#{opts['health_check_cmd']}'" - end + flags << "--health-cmd='#{opts['health_check_cmd']}'" if opts['health_check_cmd'] && opts['health_check_cmd'].to_s != 'undef' - if opts['health_check_interval'] && opts['health_check_interval'].to_s != 'undef' - flags << "--health-interval=#{opts['health_check_interval']}s" - end + flags << "--health-interval=#{opts['health_check_interval']}s" if opts['health_check_interval'] && opts['health_check_interval'].to_s != 'undef' - if opts['tty'] - flags << '-t' - end + flags << '-t' if opts['tty'] - if opts['read_only'] - flags << '--read-only=true' - end + flags << '--read-only=true' if opts['read_only'] params_join_char = if opts['osfamily'] && opts['osfamily'].to_s != 'undef' opts['osfamily'].casecmp('windows').zero? ? " `\n" : " \\\n" diff --git a/lib/puppet/parser/functions/docker_secrets_flags.rb b/lib/puppet/parser/functions/docker_secrets_flags.rb index 79a2930d..4f0caf40 100644 --- a/lib/puppet/parser/functions/docker_secrets_flags.rb +++ b/lib/puppet/parser/functions/docker_secrets_flags.rb @@ -10,21 +10,15 @@ module Puppet::Parser::Functions opts = args[0] || {} flags = [] - if opts['ensure'].to_s == 'present' - flags << 'create' - end + flags << 'create' if opts['ensure'].to_s == 'present' - if opts['secret_name'] && opts['secret_name'].to_s != 'undef' - flags << "'#{opts['secret_name']}'" - end + flags << "'#{opts['secret_name']}'" if opts['secret_name'] && opts['secret_name'].to_s != 'undef' - if opts['secret_path'] && opts['secret_path'].to_s != 'undef' - flags << "'#{opts['secret_path']}'" - end + flags << "'#{opts['secret_path']}'" if opts['secret_path'] && opts['secret_path'].to_s != 'undef' multi_flags = ->(values, format) { filtered = [values].flatten.compact - filtered.map { |val| format + " \\\n" % val } + filtered.map { |val| format + (" \\\n" % val) } } [ ['-l %s', 'label'], diff --git a/lib/puppet/parser/functions/docker_service_flags.rb b/lib/puppet/parser/functions/docker_service_flags.rb index d6333fa6..b8d3f9fd 100644 --- a/lib/puppet/parser/functions/docker_service_flags.rb +++ b/lib/puppet/parser/functions/docker_service_flags.rb @@ -10,13 +10,9 @@ module Puppet::Parser::Functions opts = args[0] || {} flags = [] - if opts['service_name'] && opts['service_name'].to_s != 'undef' - flags << "'#{opts['service_name']}'" - end + flags << "'#{opts['service_name']}'" if opts['service_name'] && opts['service_name'].to_s != 'undef' - if opts['detach'].to_s != 'false' - flags << '--detach' - end + flags << '--detach' if opts['detach'].to_s != 'false' if opts['env'].is_a? Array opts['env'].each do |env| @@ -50,21 +46,13 @@ module Puppet::Parser::Functions flags << "--publish '#{opts['publish']}'" end - if opts['replicas'] && opts['replicas'].to_s != 'undef' - flags << "--replicas '#{opts['replicas']}'" - end + flags << "--replicas '#{opts['replicas']}'" if opts['replicas'] && opts['replicas'].to_s != 'undef' - if opts['tty'].to_s != 'false' - flags << '--tty' - end + flags << '--tty' if opts['tty'].to_s != 'false' - if opts['user'] && opts['user'].to_s != 'undef' - flags << "--user '#{opts['user']}'" - end + flags << "--user '#{opts['user']}'" if opts['user'] && opts['user'].to_s != 'undef' - if opts['workdir'] && opts['workdir'].to_s != 'undef' - flags << "--workdir '#{opts['workdir']}'" - end + flags << "--workdir '#{opts['workdir']}'" if opts['workdir'] && opts['workdir'].to_s != 'undef' if opts['extra_params'].is_a? Array opts['extra_params'].each do |param| @@ -72,9 +60,7 @@ module Puppet::Parser::Functions end end - if opts['host_socket'] && opts['host_socket'].to_s != 'undef' - flags << "-H '#{opts['host_socket']}'" - end + flags << "-H '#{opts['host_socket']}'" if opts['host_socket'] && opts['host_socket'].to_s != 'undef' if opts['registry_mirror'].is_a? Array opts['registry_mirror'].each do |param| @@ -84,9 +70,7 @@ module Puppet::Parser::Functions flags << "--registry-mirror='#{opts['registry_mirror']}'" end - if opts['image'] && opts['image'].to_s != 'undef' - flags << "'#{opts['image']}'" - end + flags << "'#{opts['image']}'" if opts['image'] && opts['image'].to_s != 'undef' if opts['command'].is_a? Array flags << opts['command'].join(' ') diff --git a/lib/puppet/parser/functions/docker_stack_flags.rb b/lib/puppet/parser/functions/docker_stack_flags.rb index 735f6e31..7ed6eb8d 100644 --- a/lib/puppet/parser/functions/docker_stack_flags.rb +++ b/lib/puppet/parser/functions/docker_stack_flags.rb @@ -10,9 +10,7 @@ module Puppet::Parser::Functions opts = args[0] || {} flags = [] - if opts['bundle_file'] && opts['bundle_file'].to_s != 'undef' - flags << "--bundle-file '#{opts['bundle_file']}'" - end + flags << "--bundle-file '#{opts['bundle_file']}'" if opts['bundle_file'] && opts['bundle_file'].to_s != 'undef' if opts['compose_files'] && opts['compose_files'].to_s != 'undef' opts['compose_files'].each do |file| @@ -20,17 +18,11 @@ module Puppet::Parser::Functions end end - if opts['resolve_image'] && opts['resolve_image'].to_s != 'undef' - flags << "--resolve-image '#{opts['resolve_image']}'" - end + flags << "--resolve-image '#{opts['resolve_image']}'" if opts['resolve_image'] && opts['resolve_image'].to_s != 'undef' - if opts['prune'] && opts['prune'].to_s != 'undef' - flags << '--prune' - end + flags << '--prune' if opts['prune'] && opts['prune'].to_s != 'undef' - if opts['with_registry_auth'] && opts['with_registry_auth'].to_s != 'undef' - flags << '--with-registry-auth' - end + flags << '--with-registry-auth' if opts['with_registry_auth'] && opts['with_registry_auth'].to_s != 'undef' flags.flatten.join(' ') end diff --git a/lib/puppet/parser/functions/docker_swarm_init_flags.rb b/lib/puppet/parser/functions/docker_swarm_init_flags.rb index 1a8bc961..13bcc1e7 100644 --- a/lib/puppet/parser/functions/docker_swarm_init_flags.rb +++ b/lib/puppet/parser/functions/docker_swarm_init_flags.rb @@ -10,21 +10,13 @@ module Puppet::Parser::Functions opts = args[0] || {} flags = [] - if opts['init'].to_s != 'false' - flags << 'init' - end + flags << 'init' if opts['init'].to_s != 'false' - if opts['advertise_addr'] && opts['advertise_addr'].to_s != 'undef' - flags << "--advertise-addr '#{opts['advertise_addr']}'" - end + flags << "--advertise-addr '#{opts['advertise_addr']}'" if opts['advertise_addr'] && opts['advertise_addr'].to_s != 'undef' - if opts['autolock'].to_s != 'false' - flags << '--autolock' - end + flags << '--autolock' if opts['autolock'].to_s != 'false' - if opts['cert_expiry'] && opts['cert_expiry'].to_s != 'undef' - flags << "--cert-expiry '#{opts['cert_expiry']}'" - end + flags << "--cert-expiry '#{opts['cert_expiry']}'" if opts['cert_expiry'] && opts['cert_expiry'].to_s != 'undef' if opts['default_addr_pool'].is_a? Array opts['default_addr_pool'].each do |default_addr_pool| @@ -32,33 +24,19 @@ module Puppet::Parser::Functions end end - if opts['default_addr_pool_mask_length'] && opts['default_addr_pool_mask_length'].to_s != 'undef' - flags << "--default-addr-pool-mask-length '#{opts['default_addr_pool_mask_length']}'" - end + flags << "--default-addr-pool-mask-length '#{opts['default_addr_pool_mask_length']}'" if opts['default_addr_pool_mask_length'] && opts['default_addr_pool_mask_length'].to_s != 'undef' - if opts['dispatcher_heartbeat'] && opts['dispatcher_heartbeat'].to_s != 'undef' - flags << "--dispatcher-heartbeat '#{opts['dispatcher_heartbeat']}'" - end + flags << "--dispatcher-heartbeat '#{opts['dispatcher_heartbeat']}'" if opts['dispatcher_heartbeat'] && opts['dispatcher_heartbeat'].to_s != 'undef' - if opts['external_ca'] && opts['external_ca'].to_s != 'undef' - flags << "--external-ca '#{opts['external_ca']}'" - end + flags << "--external-ca '#{opts['external_ca']}'" if opts['external_ca'] && opts['external_ca'].to_s != 'undef' - if opts['force_new_cluster'].to_s != 'false' - flags << '--force-new-cluster' - end + flags << '--force-new-cluster' if opts['force_new_cluster'].to_s != 'false' - if opts['listen_addr'] && opts['listen_addr'].to_s != 'undef' - flags << "--listen-addr '#{opts['listen_addr']}'" - end + flags << "--listen-addr '#{opts['listen_addr']}'" if opts['listen_addr'] && opts['listen_addr'].to_s != 'undef' - if opts['max_snapshots'] && opts['max_snapshots'].to_s != 'undef' - flags << "--max-snapshots '#{opts['max_snapshots']}'" - end + flags << "--max-snapshots '#{opts['max_snapshots']}'" if opts['max_snapshots'] && opts['max_snapshots'].to_s != 'undef' - if opts['snapshot_interval'] && opts['snapshot_interval'].to_s != 'undef' - flags << "--snapshot-interval '#{opts['snapshot_interval']}'" - end + flags << "--snapshot-interval '#{opts['snapshot_interval']}'" if opts['snapshot_interval'] && opts['snapshot_interval'].to_s != 'undef' flags.flatten.join(' ') end diff --git a/lib/puppet/parser/functions/docker_swarm_join_flags.rb b/lib/puppet/parser/functions/docker_swarm_join_flags.rb index 936f29e5..ed9e4bb1 100644 --- a/lib/puppet/parser/functions/docker_swarm_join_flags.rb +++ b/lib/puppet/parser/functions/docker_swarm_join_flags.rb @@ -10,21 +10,13 @@ module Puppet::Parser::Functions opts = args[0] || {} flags = [] - if opts['join'].to_s != 'false' - flags << 'join' - end + flags << 'join' if opts['join'].to_s != 'false' - if opts['advertise_addr'] && opts['advertise_addr'].to_s != 'undef' - flags << "--advertise-addr '#{opts['advertise_addr']}'" - end + flags << "--advertise-addr '#{opts['advertise_addr']}'" if opts['advertise_addr'] && opts['advertise_addr'].to_s != 'undef' - if opts['listen_addr'] && opts['listen_addr'].to_s != 'undef' - flags << "--listen-addr \"#{opts['listen_addr']}\"" - end + flags << "--listen-addr \"#{opts['listen_addr']}\"" if opts['listen_addr'] && opts['listen_addr'].to_s != 'undef' - if opts['token'] && opts['token'].to_s != 'undef' - flags << "--token '#{opts['token']}'" - end + flags << "--token '#{opts['token']}'" if opts['token'] && opts['token'].to_s != 'undef' flags.flatten.join(' ') end diff --git a/lib/puppet/provider/docker_compose/ruby.rb b/lib/puppet/provider/docker_compose/ruby.rb index 4c9bf0c2..0d196d54 100644 --- a/lib/puppet/provider/docker_compose/ruby.rb +++ b/lib/puppet/provider/docker_compose/ruby.rb @@ -13,6 +13,7 @@ def set_tmpdir return unless resource[:tmpdir] + # Check if the the tmpdir target exists Puppet.warning("#{resource[:tmpdir]} (defined as docker_compose tmpdir) does not exist") unless Dir.exist?(resource[:tmpdir]) # Set TMPDIR environment variable only if defined among resources and exists @@ -41,12 +42,10 @@ def exists? compose_services = compose_output['services'] - if compose_services.count != compose_containers.uniq.count - return false - end + return false if compose_services.count != compose_containers.uniq.count counts = Hash[*compose_services.each.map { |key, array| - image = (array['image']) ? array['image'] : get_image(key, compose_services) + image = array['image'] || get_image(key, compose_services) Puppet.info("Checking for compose service #{key} #{image}") [key, compose_containers.count("'#{key}-#{image}'")] }.flatten] @@ -56,7 +55,7 @@ def exists? # Containers described in the compose file are not running counts.any? { |_k, v| v.zero? } || # The scaling factors in the resource do not match the number of running containers - resource[:scale] && counts.merge(resource[:scale]) != counts + (resource[:scale] && counts.merge(resource[:scale]) != counts) false else true @@ -80,6 +79,7 @@ def create args = [compose_files, '-p', name, 'up', '-d', '--remove-orphans'].insert(3, resource[:options]).insert(5, resource[:up_args]).compact dockercompose(args) return unless resource[:scale] + instructions = resource[:scale].map { |k, v| "#{k}=#{v}" } Puppet.info("Scaling compose project #{name}: #{instructions.join(' ')}") args = [compose_files, '-p', name, 'scale'].insert(3, resource[:options]).compact + instructions @@ -96,6 +96,7 @@ def destroy def restart return unless exists? + Puppet.info("Rebuilding and Restarting all containers for compose project #{name}") kill_args = [compose_files, '-p', name, 'kill'].insert(3, resource[:options]).compact dockercompose(kill_args) diff --git a/lib/puppet/provider/docker_network/ruby.rb b/lib/puppet/provider/docker_network/ruby.rb index 6b7074c0..750f8f20 100644 --- a/lib/puppet/provider/docker_network/ruby.rb +++ b/lib/puppet/provider/docker_network/ruby.rb @@ -50,17 +50,11 @@ def self.instances lines = output.split("\n") lines.shift # remove header row lines.map do |line| - _, name, driver = line.split(' ') + _, name, driver = line.split inspect = docker(['network', 'inspect', name]) obj = JSON.parse(inspect).first - ipam_driver = unless obj['IPAM']['Driver'].nil? - obj['IPAM']['Driver'] - end - subnet = unless obj['IPAM']['Config'].nil? || obj['IPAM']['Config'].empty? - if obj['IPAM']['Config'].first.key? 'Subnet' - obj['IPAM']['Config'].first['Subnet'] - end - end + ipam_driver = (obj['IPAM']['Driver'] unless obj['IPAM']['Driver'].nil?) + subnet = (obj['IPAM']['Config'].first['Subnet'] if !(obj['IPAM']['Config'].nil? || obj['IPAM']['Config'].empty?) && (obj['IPAM']['Config'].first.key? 'Subnet')) new( name: name, id: obj['Id'], diff --git a/lib/puppet/provider/docker_stack/ruby.rb b/lib/puppet/provider/docker_stack/ruby.rb index aabc4e87..2bb77d48 100644 --- a/lib/puppet/provider/docker_stack/ruby.rb +++ b/lib/puppet/provider/docker_stack/ruby.rb @@ -36,11 +36,10 @@ def exists? end end - if stack_services.count != stack_containers.count - return false - end + return false if stack_services.count != stack_containers.count + counts = Hash[*stack_services.each.map { |key, array| - image = (array['image']) ? array['image'] : get_image(key, stack_services) + image = array['image'] || get_image(key, stack_services) image = "#{image}:latest" unless image.include?(':') Puppet.info("Checking for compose service #{key} #{image}") ["#{key}-#{image}", stack_containers.count("#{key}-#{image}")] diff --git a/lib/puppet/provider/docker_volume/ruby.rb b/lib/puppet/provider/docker_volume/ruby.rb index d5ca869f..55d3ecf2 100644 --- a/lib/puppet/provider/docker_volume/ruby.rb +++ b/lib/puppet/provider/docker_volume/ruby.rb @@ -32,7 +32,7 @@ def self.instances lines = output.split("\n") lines.shift # remove header row lines.map do |line| - driver, name = line.split(' ') + driver, name = line.split inspect = docker(['volume', 'inspect', name]) obj = JSON.parse(inspect).first new( diff --git a/lib/puppet/type/docker_compose.rb b/lib/puppet/type/docker_compose.rb index c7df66c0..c5f50851 100644 --- a/lib/puppet/type/docker_compose.rb +++ b/lib/puppet/type/docker_compose.rb @@ -13,12 +13,8 @@ def refresh desc 'A hash of compose services and number of containers.' validate do |value| raise _('scale should be a Hash') unless value.is_a? Hash - unless value.all? { |k, _v| k.is_a? String } - raise _('The name of the compose service in scale should be a String') - end - unless value.all? { |_k, v| v.is_a? Integer } - raise _('The number of containers in scale should be an Integer') - end + raise _('The name of the compose service in scale should be a String') unless value.all? { |k, _v| k.is_a? String } + raise _('The number of containers in scale should be an Integer') unless value.all? { |_k, v| v.is_a? Integer } end end diff --git a/metadata.json b/metadata.json index 95918a11..3eac1d1d 100644 --- a/metadata.json +++ b/metadata.json @@ -59,10 +59,10 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 6.24.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "pdk-version": "2.7.0", "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", - "template-ref": "2.7.3-0-g8f110f1" + "template-ref": "tags/2.7.5-0-ge5b0114" } diff --git a/spec/acceptance/compose_v3_spec.rb b/spec/acceptance/compose_v3_spec.rb index aca09c1f..0a314aaa 100644 --- a/spec/acceptance/compose_v3_spec.rb +++ b/spec/acceptance/compose_v3_spec.rb @@ -23,12 +23,12 @@ describe 'docker compose' do before(:all) do retry_on_error_matching(60, 5, %r{connection failure running}) do - install_code = <<-code + install_code = <<-CODE class { 'docker': #{docker_args} } class { 'docker::compose': version => '1.23.2', } - code + CODE apply_manifest(install_code, catch_failures: true) end end @@ -139,6 +139,14 @@ class { 'docker::compose': '1.21.2' end + after(:all) do + install_pp = <<-MANIFEST + class { 'docker': #{docker_args}} + class { 'docker::compose': } + MANIFEST + apply_manifest(install_pp, catch_failures: true) + end + it 'is idempotent' do pp = <<-MANIFEST class { 'docker::compose': @@ -153,13 +161,5 @@ class { 'docker::compose': run_shell("test -e \"#{install_dir}/docker-compose#{file_extension}\"", expect_failures: true) run_shell("test -e \"#{install_dir}/docker-compose-#{version}#{file_extension}\"", expect_failures: true) end - - after(:all) do - install_pp = <<-MANIFEST - class { 'docker': #{docker_args}} - class { 'docker::compose': } - MANIFEST - apply_manifest(install_pp, catch_failures: true) - end end end diff --git a/spec/acceptance/docker_custom_source_spec.rb b/spec/acceptance/docker_custom_source_spec.rb index 4911fd70..512dbbf0 100644 --- a/spec/acceptance/docker_custom_source_spec.rb +++ b/spec/acceptance/docker_custom_source_spec.rb @@ -38,7 +38,7 @@ end else run_shell('ps aux | grep docker') do |r| - expect(r.stdout).to match %r{dockerd -H unix:\/\/\/var\/run\/docker.sock} + expect(r.stdout).to match %r{dockerd -H unix:///var/run/docker.sock} end end end @@ -61,7 +61,7 @@ class { 'docker': #{docker_args} } require => Docker::Image['#{default_image}'], #{default_docker_run_arg} } - EOS + EOS pp2 = <<-EOS class { 'docker': #{docker_args} } @@ -75,7 +75,7 @@ class { 'docker': #{docker_args} } image => '#{default_image}', require => Docker::Image['#{default_image}'], } - EOS + EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp) unless selinux == 'true' diff --git a/spec/acceptance/docker_full_spec.rb b/spec/acceptance/docker_full_spec.rb index 82b5cc1b..b4dc06f4 100644 --- a/spec/acceptance/docker_full_spec.rb +++ b/spec/acceptance/docker_full_spec.rb @@ -88,7 +88,7 @@ end else run_shell('ps aux | grep docker') do |r| - expect(r.stdout).to match(%r{dockerd -H unix:\/\/\/var\/run\/docker.sock}) + expect(r.stdout).to match(%r{dockerd -H unix:///var/run/docker.sock}) end end end @@ -111,7 +111,7 @@ class { 'docker': #{docker_args} } require => Docker::Image['#{default_image}'], #{default_docker_run_arg} } - EOS + EOS pp2 = <<-EOS class { 'docker': #{docker_args} } @@ -125,7 +125,7 @@ class { 'docker': #{docker_args} } image => '#{default_image}', require => Docker::Image['#{default_image}'], } - EOS + EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) unless selinux == 'true' @@ -194,7 +194,7 @@ class { 'docker': end else run_shell('netstat -tulpn | grep docker') do |r| - expect(r.stdout).to match(%r{tcp\s+0\s+0\s+127.0.0.1:4444\s+0.0.0.0\:\*\s+LISTEN\s+\d+\/docker}) + expect(r.stdout).to match(%r{tcp\s+0\s+0\s+127.0.0.1:4444\s+0.0.0.0:\*\s+LISTEN\s+\d+/docker}) end end end @@ -218,7 +218,7 @@ class { 'docker': it 'shows docker listening on the specified unix socket' do if os[:family] != 'windows' run_shell('ps aux | grep docker') do |r| - expect(r.stdout).to match(%r{unix:\/\/\/var\/run\/docker.sock}) + expect(r.stdout).to match(%r{unix:///var/run/docker.sock}) end end end @@ -505,7 +505,7 @@ class { 'docker': #{docker_args}} sleep 4 run_shell("#{docker_command} ps") do |r| - expect(r.stdout).to match(%r{#{default_run_command}.+5555\/tcp\, 0\.0\.0.0\:\d+\-\>4444\/tcp}) + expect(r.stdout).to match(%r{#{default_run_command}.+5555/tcp, 0\.0\.0.0:\d+->4444/tcp}) end end @@ -608,8 +608,8 @@ class { 'docker': #{docker_args} } # A sleep to give docker time to execute properly sleep 4 - run_shell('#{docker_command} inspect container_3_5_5') do |r| - expect(r.stdout).to match(%r{"CpusetCpus"\: "0"}) + run_shell("#{docker_command} inspect container_3_5_5") do |r| + expect(r.stdout).to match(%r{"CpusetCpus": "0"}) end end @@ -805,7 +805,7 @@ class { 'docker': #{docker_args} } restart_on_unhealthy => true, #{default_docker_run_arg} } - EOS + EOS pp_delete = <<-EOS class { 'docker': #{docker_args} } @@ -840,13 +840,13 @@ class { 'docker': #{docker_args} } image => '#{default_image}:#{default_image_tag}', verify_digest => '#{default_local_digest}', } - EOS + EOS pp_invalid = <<-EOS docker::run { '#{default_image}': image => '#{default_image}:#{default_image_tag}', verify_digest => 'sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc000', } - EOS + EOS apply_manifest(pp, catch_failures: true) run_shell('/usr/local/bin/docker-run-alpine-start.sh', expect_failures: false) do |r| @@ -875,7 +875,7 @@ class { 'docker': #{docker_args} } require => Docker::Image['#{default_image}'], #{default_docker_run_arg} } - EOS + EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) unless selinux == 'true' @@ -892,14 +892,14 @@ class { 'docker': #{docker_args} } command => '#{default_docker_exec_command}', tty => true, } - EOS + EOS pp_delete = <<-EOS docker::run { 'container_4_1': image => '#{default_image}', ensure => absent, } - EOS + EOS apply_manifest(pp2, catch_failures: true) @@ -937,7 +937,7 @@ class { 'docker': #{docker_args} } command => '#{default_docker_exec_command}', refreshonly => true, } - EOS + EOS apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) unless selinux == 'true' @@ -960,14 +960,14 @@ class { 'docker': #{docker_args} } ensure => 'present', notify => Docker::Exec['test_command'], } - EOS + EOS pp_delete = <<-EOS docker::run { '#{container_name}': image => '#{default_image}', ensure => absent, } - EOS + EOS pp2 = pp + pp_extra diff --git a/spec/acceptance/docker_params_changed_spec.rb b/spec/acceptance/docker_params_changed_spec.rb index 71b4bbe4..6b9b41a2 100644 --- a/spec/acceptance/docker_params_changed_spec.rb +++ b/spec/acceptance/docker_params_changed_spec.rb @@ -5,6 +5,7 @@ if os[:family] == 'windows' os_name = run_shell('systeminfo | findstr /R /C:"OS Name"') raise 'Could not retrieve systeminfo for Windows box' if os_name.exit_code != 0 + os_name = if os_name.stdout.split(%r{\s}).include?('2016') 'win-2016' elsif os_name.stdout.split(%r{\s}).include?('2019') @@ -37,6 +38,11 @@ run_shell("mkdir #{volume_location}volume_2") end + after(:all) do + run_shell("rm -r #{volume_location}volume_1") + run_shell("rm -r #{volume_location}volume_2") + end + context 'when image is changed' do image_changed = if os[:family] == 'windows' if os_name == 'win-2016' @@ -141,9 +147,4 @@ class {'docker': #{docker_args}} end end end - - after(:all) do - run_shell("rm -r #{volume_location}volume_1") - run_shell("rm -r #{volume_location}volume_2") - end end diff --git a/spec/acceptance/docker_spec.rb b/spec/acceptance/docker_spec.rb index c60e88e1..e6c3d098 100644 --- a/spec/acceptance/docker_spec.rb +++ b/spec/acceptance/docker_spec.rb @@ -9,6 +9,7 @@ if os[:family] == 'windows' result = run_shell("ipconfig | findstr /i 'ipv4'") raise 'Could not retrieve ip address for Windows box' if result.exit_code != 0 + ip = result.stdout.split("\n")[0].split(':')[1].strip @windows_ip = ip docker_args = "docker_ee => true, extra_parameters => '\"insecure-registries\": [ \"#{@windows_ip}:5000\" ]'" @@ -113,11 +114,11 @@ class { 'docker': #{docker_args} } end end - it 'works' do + it 'runs without error' do apply_manifest(pp, catch_failures: true) run_shell(shell_command) do |r| if os[:family] == 'windows' - expect(r.stdout).to match(%r{\"data-root\": \"#{root_dir}\"}) + expect(r.stdout).to match(%r{"data-root": "#{root_dir}"}) else expect(r.stdout).to match(%r{--data-root #{root_dir}}) end @@ -194,7 +195,7 @@ class { 'docker': it 'netstat -tlndp' do result = run_shell('netstat -tlndp') expect(result[:exit_code]).to eq 0 - expect(result[:stdout]).to match %r{0\.0\.0\.0\:80} + expect(result[:stdout]).to match %r{0\.0\.0\.0:80} end it 'id testuser | grep docker' do @@ -234,7 +235,7 @@ class { 'docker': it 'has a registry mirror set' do run_shell('ps -aux | grep docker') do |r| - expect(r.stdout).to match(%r{--registry-mirror=http:\/\/testmirror.io}) + expect(r.stdout).to match(%r{--registry-mirror=http://testmirror.io}) end end end @@ -254,8 +255,8 @@ class { 'docker': it 'has all registry mirrors set' do run_shell('ps -aux | grep docker') do |r| - expect(r.stdout).to match(%r{--registry-mirror=http:\/\/testmirror1.io}) - expect(r.stdout).to match(%r{--registry-mirror=http:\/\/testmirror2.io}) + expect(r.stdout).to match(%r{--registry-mirror=http://testmirror1.io}) + expect(r.stdout).to match(%r{--registry-mirror=http://testmirror2.io}) end end end @@ -279,7 +280,7 @@ class { 'docker': #{docker_args}} net => '#{docker_network}', ports => '#{registry_port}:#{registry_port}', } - MANIFEST + MANIFEST retry_on_error_matching(60, 5, %r{connection failure running}) do apply_manifest(pp, catch_failures: true) end diff --git a/spec/acceptance/stack_spec.rb b/spec/acceptance/stack_spec.rb index 7d25c1ac..6e27c4cb 100644 --- a/spec/acceptance/stack_spec.rb +++ b/spec/acceptance/stack_spec.rb @@ -24,7 +24,7 @@ class { 'docker': #{docker_args} } listen_addr => $facts['networking']['ip'], require => Class['docker'], } - MANIFEST + MANIFEST apply_manifest(install_pp, catch_failures: true) end end diff --git a/spec/acceptance/volume_spec.rb b/spec/acceptance/volume_spec.rb index cb95e540..e2ef56c2 100644 --- a/spec/acceptance/volume_spec.rb +++ b/spec/acceptance/volume_spec.rb @@ -25,6 +25,10 @@ end context 'with a local volume described in Puppet' do + after(:all) do + run_shell("#{command} volume rm #{volume_name}") + end + it 'applies idempotently' do pp = <<-MANIFEST docker_volume { '#{volume_name}': @@ -38,9 +42,5 @@ it 'has created a volume' do run_shell("#{command} volume inspect #{volume_name}", expect_failures: false) end - - after(:all) do - run_shell("#{command} volume rm #{volume_name}") - end end end diff --git a/spec/acceptance_swarm/swarm_spec.rb b/spec/acceptance_swarm/swarm_spec.rb index 9268618a..14d4d7c8 100644 --- a/spec/acceptance_swarm/swarm_spec.rb +++ b/spec/acceptance_swarm/swarm_spec.rb @@ -25,9 +25,9 @@ describe 'docker swarm', skip: skip_tests do before(:each) do retry_on_error_matching(60, 5, %r{connection failure running}) do - install_code = <<-code + install_code = <<-CODE class { 'docker': #{docker_args} } - code + CODE apply_manifest_on(swarm_manager, install_code, catch_failures: true) end retry_on_error_matching(60, 5, %r{connection failure running}) do @@ -56,11 +56,11 @@ class { 'docker': #{docker_args} } end after(:each) do - remove_worker = <<-code + remove_worker = <<-CODE docker::swarm {'cluster_worker': ensure => 'absent', } - code + CODE retry_on_error_matching(60, 5, %r{connection failure running}) do apply_manifest_on(swarm_worker, remove_worker, catch_failures: true) end diff --git a/spec/classes/compose_spec.rb b/spec/classes/compose_spec.rb index 3b0d7a90..ef07d405 100644 --- a/spec/classes/compose_spec.rb +++ b/spec/classes/compose_spec.rb @@ -3,37 +3,36 @@ require 'spec_helper' tests = { - 'with default valus' => { - }, + 'with default valus' => {}, 'with ensure => absent' => { - 'ensure' => 'absent', + 'ensure' => 'absent' }, 'with version => 1.7.0' => { - 'version' => '1.7.0', + 'version' => '1.7.0' }, 'when proxy is provided' => { 'version' => '1.7.0', - 'proxy' => 'http://proxy.example.org:3128/', + 'proxy' => 'http://proxy.example.org:3128/' }, 'when proxy is not a http proxy' => { - 'proxy' => 'this is not a URL', + 'proxy' => 'this is not a URL' }, 'when proxy contains username and password' => { 'version' => '1.7.0', - 'proxy' => 'http://user:password@proxy.example.org:3128/', + 'proxy' => 'http://user:password@proxy.example.org:3128/' }, 'when proxy IP is provided' => { 'version' => '1.7.0', - 'proxy' => 'http://10.10.10.10:3128/', + 'proxy' => 'http://10.10.10.10:3128/' }, 'when base_url is provided' => { - 'version' => '1.7.0', - 'base_url' => 'http://example.org', + 'version' => '1.7.0', + 'base_url' => 'http://example.org' }, 'when raw_url is provided' => { - 'version' => '1.7.0', - 'raw_url' => 'http://example.org', - }, + 'version' => '1.7.0', + 'raw_url' => 'http://example.org' + } } describe 'docker::compose', type: :class do @@ -41,7 +40,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -56,14 +55,14 @@ tests.each do |title, local_params| context title do params = { - 'ensure' => 'present', - 'version' => defaults['compose_version'], + 'ensure' => 'present', + 'version' => defaults['compose_version'], 'install_path' => defaults['compose_install_path'], 'symlink_name' => defaults['compose_symlink_name'], - 'proxy' => :undef, - 'base_url' => defaults['compose_base_url'], - 'raw_url' => :undef, - 'curl_ensure' => defaults['curl_ensure'], + 'proxy' => :undef, + 'base_url' => defaults['compose_base_url'], + 'raw_url' => :undef, + 'curl_ensure' => defaults['curl_ensure'] }.merge(local_params) let(:facts) do @@ -74,14 +73,12 @@ params end - if params['proxy'] != :undef - unless %r{^((http[s]?)?:\/\/)?([^:^@]+:[^:^@]+@|)([\da-z\.-]+)\.([\da-z\.]{2,6})(:[\d])?([\/\w \.-]*)*\/?$}.match?(params['proxy']) - it { - is_expected.to compile.and_raise_error(%r{does not match}) - } + if params['proxy'] != :undef && !%r{^((https?)?://)?([^:^@]+:[^:^@]+@|)([\da-z.-]+)\.([\da-z.]{2,6})(:\d)?([/\w .-]*)*/?$}.match?(params['proxy']) + it { + expect(subject).to compile.and_raise_error(%r{does not match}) + } - next - end + next end include_examples 'compose', params, facts diff --git a/spec/classes/images_spec.rb b/spec/classes/images_spec.rb index 8d5255f4..38fa0476 100644 --- a/spec/classes/images_spec.rb +++ b/spec/classes/images_spec.rb @@ -4,11 +4,11 @@ tests = { 'with ensure => present' => { - 'ensure' => 'present', + 'ensure' => 'present' }, 'with ensure => absent' => { - 'ensure' => 'absent', - }, + 'ensure' => 'absent' + } } describe 'docker::images', type: :class do @@ -16,7 +16,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -32,14 +32,14 @@ context title do params = { 'base' => { - 'ensure' => 'present', - 'image_tag' => :undef, + 'ensure' => 'present', + 'image_tag' => :undef, 'image_digest' => :undef, - 'force' => false, - 'docker_file' => :undef, - 'docker_dir' => :undef, - 'docker_tar' => :undef, - }, + 'force' => false, + 'docker_file' => :undef, + 'docker_dir' => :undef, + 'docker_tar' => :undef + } } params.each do |key, values| @@ -52,15 +52,15 @@ let(:params) do { 'images' => { - key => values, - }, + key => values + } } end include_examples 'image', values, facts, defaults it { - is_expected.to contain_docker__image(key) + expect(subject).to contain_docker__image(key) } end end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index a2d3fb5e..dc072224 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -3,33 +3,32 @@ require 'spec_helper' tests = { - 'with default values' => { - }, + 'with default values' => {}, 'with docker_users set' => { 'docker_users' => [ 'some_random_user', 'foo', 'bar', - ], + ] }, 'with package_source set to docker-engine' => { - 'package_source' => 'docker-engine', + 'package_source' => 'docker-engine' }, 'with package_source set to docker-ce' => { - 'package_source' => 'docker-ce', + 'package_source' => 'docker-ce' }, 'with ensure set to absent' => { - 'ensure' => 'absent', + 'ensure' => 'absent' }, 'with ensure set to absent and given version' => { - 'ensure' => 'absent', - 'version' => '16', + 'ensure' => 'absent', + 'version' => '16' }, 'with ms parameter set' => { - 'version' => '16', - 'docker_msft_provider_version' => '123', - 'nuget_package_provider_version' => '41', - }, + 'version' => '16', + 'docker_msft_provider_version' => '123', + 'nuget_package_provider_version' => '41' + } } describe 'docker', type: :class do @@ -37,18 +36,18 @@ ## ## set some needed facts ## - if %r{windows}.match?(os) + if os.include?('windows') facts = windows_facts.merge(os_facts) default_params = { - 'docker_ee' => true, - 'docker_users' => [], + 'docker_ee' => true, + 'docker_users' => [] } else facts = os_facts default_params = { - 'docker_users' => [], + 'docker_users' => [] } end @@ -61,125 +60,125 @@ tests.each do |title, local_params| context title do params = { - 'acknowledge_unsupported_os' => false, - 'apt_source_pin_level' => defaults['apt_source_pin_level'], - 'bip' => defaults['bip'], - 'bridge' => defaults['bridge'], - 'create_user' => true, - 'daemon_environment_files' => [], - 'default_gateway_ipv6' => defaults['default_gateway_ipv6'], - 'default_gateway' => defaults['default_gateway'], - 'dependent_packages' => defaults['dependent_packages'], - 'dm_basesize' => defaults['dm_basesize'], - 'dm_blkdiscard' => defaults['dm_blkdiscard'], - 'dm_blocksize' => defaults['dm_blocksize'], - 'dm_datadev' => defaults['dm_datadev'], - 'dm_fs' => defaults['dm_fs'], - 'dm_loopdatasize' => defaults['dm_loopdatasize'], - 'dm_loopmetadatasize' => defaults['dm_loopmetadatasize'], - 'dm_metadatadev' => defaults['dm_metadatadev'], - 'dm_mkfsarg' => defaults['dm_mkfsarg'], - 'dm_mountopt' => defaults['dm_mountopt'], - 'dm_override_udev_sync_check' => defaults['dm_override_udev_sync_check'], - 'dm_thinpooldev' => defaults['dm_thinpooldev'], - 'dm_use_deferred_deletion' => defaults['dm_use_deferred_deletion'], - 'dm_use_deferred_removal' => defaults['dm_use_deferred_removal'], - 'dns_search' => defaults['dns_search'], - 'dns' => defaults['dns'], - 'docker_ce_channel' => defaults['docker_ce_channel'], - 'docker_ce_key_id' => defaults['package_ce_key_id'], - 'docker_ce_key_source' => defaults['package_ce_key_source'], - 'docker_ce_package_name' => defaults['docker_ce_package_name'], - 'docker_ce_cli_package_name' => defaults['docker_ce_cli_package_name'], - 'docker_ce_release' => defaults['package_ce_release'], - 'docker_ce_source_location' => defaults['package_ce_source_location'], - 'docker_ce_start_command' => defaults['docker_ce_start_command'], - 'docker_ee_key_id' => defaults['package_ee_key_id'], - 'docker_ee_key_source' => defaults['package_ee_key_source'], - 'docker_ee_package_name' => defaults['package_ee_package_name'], - 'docker_ee_release' => defaults['package_ee_release'], - 'docker_ee_repos' => defaults['package_ee_repos'], - 'docker_ee_source_location' => defaults['package_ee_source_location'], - 'docker_ee' => defaults['docker_ee'], - 'docker_engine_package_name' => defaults['docker_engine_package_name'], - 'docker_engine_start_command' => defaults['docker_engine_start_command'], - 'docker_group' => defaults['docker_group'], - 'docker_msft_provider_version' => defaults['docker_msft_provider_version'], - 'docker_package_key_check_source' => defaults['package_key_check_source'], - 'docker_package_key_id' => defaults['package_key_id'], - 'docker_package_key_source' => defaults['package_key_source'], - 'docker_package_location' => defaults['package_source_location'], - 'docker_package_release' => defaults['package_release'], - 'docker_users' => [], - 'ensure' => defaults['package_ensure'], - 'execdriver' => defaults['execdriver'], - 'extra_parameters' => :undef, - 'fixed_cidr' => defaults['fixed_cidr'], - 'icc' => defaults['icc'], - 'ip_forward' => defaults['ip_forward'], - 'ip_masq' => defaults['ip_masq'], - 'iptables' => defaults['iptables'], - 'ipv6_cidr' => defaults['ipv6_cidr'], - 'ipv6' => defaults['ipv6'], - 'labels' => defaults['labels'], - 'log_driver' => defaults['log_driver'], - 'log_level' => defaults['log_level'], - 'log_opt' => defaults['log_opt'], - 'manage_package' => defaults['manage_package'], - 'manage_service' => defaults['manage_service'], - 'mtu' => defaults['mtu'], - 'no_proxy' => defaults['no_proxy'], - 'nuget_package_provider_version' => defaults['nuget_package_provider_version'], - 'os_lc' => defaults['os_lc'], - 'overlay2_override_kernel_check' => defaults['overlay2_override_kernel_check'], - 'package_release' => defaults['package_release'], - 'package_source' => defaults['package_source'], - 'pin_upstream_package_source' => defaults['pin_upstream_package_source'], - 'prerequired_packages' => defaults['prerequired_packages'], - 'proxy' => defaults['proxy'], - 'registry_mirror' => defaults['registry_mirror'], - 'repo_opt' => defaults['repo_opt'], - 'root_dir' => defaults['root_dir'], - 'selinux_enabled' => defaults['selinux_enabled'], - 'service_after_override' => defaults['service_after_override'], - 'service_config_template' => defaults['service_config_template'], - 'service_config' => defaults['service_config'], - 'service_enable' => defaults['service_enable'], - 'service_hasrestart' => defaults['service_hasrestart'], - 'service_hasstatus' => defaults['service_hasstatus'], - 'service_name' => defaults['service_name'], - 'service_overrides_template' => defaults['service_overrides_template'], - 'service_provider' => defaults['service_provider'], - 'service_state' => defaults['service_state'], - 'shell_values' => :undef, - 'socket_bind' => defaults['socket_bind'], - 'socket_group' => defaults['socket_group'], - 'socket_override' => defaults['socket_override'], - 'socket_overrides_template' => defaults['socket_overrides_template'], - 'storage_auto_extend_pool' => defaults['storage_auto_extend_pool'], - 'storage_chunk_size' => defaults['storage_chunk_size'], - 'storage_config_template' => defaults['storage_config_template'], - 'storage_config' => defaults['storage_config'], - 'storage_data_size' => defaults['storage_data_size'], - 'storage_devs' => defaults['storage_devs'], - 'storage_driver' => defaults['storage_driver'], - 'storage_growpart' => defaults['storage_growpart'], - 'storage_min_data_size' => defaults['storage_min_data_size'], - 'storage_pool_autoextend_percent' => defaults['storage_pool_autoextend_percent'], + 'acknowledge_unsupported_os' => false, + 'apt_source_pin_level' => defaults['apt_source_pin_level'], + 'bip' => defaults['bip'], + 'bridge' => defaults['bridge'], + 'create_user' => true, + 'daemon_environment_files' => [], + 'default_gateway_ipv6' => defaults['default_gateway_ipv6'], + 'default_gateway' => defaults['default_gateway'], + 'dependent_packages' => defaults['dependent_packages'], + 'dm_basesize' => defaults['dm_basesize'], + 'dm_blkdiscard' => defaults['dm_blkdiscard'], + 'dm_blocksize' => defaults['dm_blocksize'], + 'dm_datadev' => defaults['dm_datadev'], + 'dm_fs' => defaults['dm_fs'], + 'dm_loopdatasize' => defaults['dm_loopdatasize'], + 'dm_loopmetadatasize' => defaults['dm_loopmetadatasize'], + 'dm_metadatadev' => defaults['dm_metadatadev'], + 'dm_mkfsarg' => defaults['dm_mkfsarg'], + 'dm_mountopt' => defaults['dm_mountopt'], + 'dm_override_udev_sync_check' => defaults['dm_override_udev_sync_check'], + 'dm_thinpooldev' => defaults['dm_thinpooldev'], + 'dm_use_deferred_deletion' => defaults['dm_use_deferred_deletion'], + 'dm_use_deferred_removal' => defaults['dm_use_deferred_removal'], + 'dns_search' => defaults['dns_search'], + 'dns' => defaults['dns'], + 'docker_ce_channel' => defaults['docker_ce_channel'], + 'docker_ce_key_id' => defaults['package_ce_key_id'], + 'docker_ce_key_source' => defaults['package_ce_key_source'], + 'docker_ce_package_name' => defaults['docker_ce_package_name'], + 'docker_ce_cli_package_name' => defaults['docker_ce_cli_package_name'], + 'docker_ce_release' => defaults['package_ce_release'], + 'docker_ce_source_location' => defaults['package_ce_source_location'], + 'docker_ce_start_command' => defaults['docker_ce_start_command'], + 'docker_ee_key_id' => defaults['package_ee_key_id'], + 'docker_ee_key_source' => defaults['package_ee_key_source'], + 'docker_ee_package_name' => defaults['package_ee_package_name'], + 'docker_ee_release' => defaults['package_ee_release'], + 'docker_ee_repos' => defaults['package_ee_repos'], + 'docker_ee_source_location' => defaults['package_ee_source_location'], + 'docker_ee' => defaults['docker_ee'], + 'docker_engine_package_name' => defaults['docker_engine_package_name'], + 'docker_engine_start_command' => defaults['docker_engine_start_command'], + 'docker_group' => defaults['docker_group'], + 'docker_msft_provider_version' => defaults['docker_msft_provider_version'], + 'docker_package_key_check_source' => defaults['package_key_check_source'], + 'docker_package_key_id' => defaults['package_key_id'], + 'docker_package_key_source' => defaults['package_key_source'], + 'docker_package_location' => defaults['package_source_location'], + 'docker_package_release' => defaults['package_release'], + 'docker_users' => [], + 'ensure' => defaults['package_ensure'], + 'execdriver' => defaults['execdriver'], + 'extra_parameters' => :undef, + 'fixed_cidr' => defaults['fixed_cidr'], + 'icc' => defaults['icc'], + 'ip_forward' => defaults['ip_forward'], + 'ip_masq' => defaults['ip_masq'], + 'iptables' => defaults['iptables'], + 'ipv6_cidr' => defaults['ipv6_cidr'], + 'ipv6' => defaults['ipv6'], + 'labels' => defaults['labels'], + 'log_driver' => defaults['log_driver'], + 'log_level' => defaults['log_level'], + 'log_opt' => defaults['log_opt'], + 'manage_package' => defaults['manage_package'], + 'manage_service' => defaults['manage_service'], + 'mtu' => defaults['mtu'], + 'no_proxy' => defaults['no_proxy'], + 'nuget_package_provider_version' => defaults['nuget_package_provider_version'], + 'os_lc' => defaults['os_lc'], + 'overlay2_override_kernel_check' => defaults['overlay2_override_kernel_check'], + 'package_release' => defaults['package_release'], + 'package_source' => defaults['package_source'], + 'pin_upstream_package_source' => defaults['pin_upstream_package_source'], + 'prerequired_packages' => defaults['prerequired_packages'], + 'proxy' => defaults['proxy'], + 'registry_mirror' => defaults['registry_mirror'], + 'repo_opt' => defaults['repo_opt'], + 'root_dir' => defaults['root_dir'], + 'selinux_enabled' => defaults['selinux_enabled'], + 'service_after_override' => defaults['service_after_override'], + 'service_config_template' => defaults['service_config_template'], + 'service_config' => defaults['service_config'], + 'service_enable' => defaults['service_enable'], + 'service_hasrestart' => defaults['service_hasrestart'], + 'service_hasstatus' => defaults['service_hasstatus'], + 'service_name' => defaults['service_name'], + 'service_overrides_template' => defaults['service_overrides_template'], + 'service_provider' => defaults['service_provider'], + 'service_state' => defaults['service_state'], + 'shell_values' => :undef, + 'socket_bind' => defaults['socket_bind'], + 'socket_group' => defaults['socket_group'], + 'socket_override' => defaults['socket_override'], + 'socket_overrides_template' => defaults['socket_overrides_template'], + 'storage_auto_extend_pool' => defaults['storage_auto_extend_pool'], + 'storage_chunk_size' => defaults['storage_chunk_size'], + 'storage_config_template' => defaults['storage_config_template'], + 'storage_config' => defaults['storage_config'], + 'storage_data_size' => defaults['storage_data_size'], + 'storage_devs' => defaults['storage_devs'], + 'storage_driver' => defaults['storage_driver'], + 'storage_growpart' => defaults['storage_growpart'], + 'storage_min_data_size' => defaults['storage_min_data_size'], + 'storage_pool_autoextend_percent' => defaults['storage_pool_autoextend_percent'], 'storage_pool_autoextend_threshold' => defaults['storage_pool_autoextend_threshold'], - 'storage_root_size' => defaults['storage_root_size'], - 'storage_setup_file' => defaults['storage_setup_file'], - 'storage_vg' => defaults['storage_vg'], - 'tcp_bind' => defaults['tcp_bind'], - 'tls_cacert' => defaults['tls_cacert'], - 'tls_cert' => defaults['tls_cert'], - 'tls_enable' => defaults['tls_enable'], - 'tls_key' => defaults['tls_key'], - 'tls_verify' => defaults['tls_verify'], - 'tmp_dir_config' => defaults['tmp_dir_config'], - 'tmp_dir' => defaults['tmp_dir'], - 'use_upstream_package_source' => defaults['use_upstream_package_source'], - 'version' => defaults['version'], + 'storage_root_size' => defaults['storage_root_size'], + 'storage_setup_file' => defaults['storage_setup_file'], + 'storage_vg' => defaults['storage_vg'], + 'tcp_bind' => defaults['tcp_bind'], + 'tls_cacert' => defaults['tls_cacert'], + 'tls_cert' => defaults['tls_cert'], + 'tls_enable' => defaults['tls_enable'], + 'tls_key' => defaults['tls_key'], + 'tls_verify' => defaults['tls_verify'], + 'tmp_dir_config' => defaults['tmp_dir_config'], + 'tmp_dir' => defaults['tmp_dir'], + 'use_upstream_package_source' => defaults['use_upstream_package_source'], + 'version' => defaults['version'] }.merge(default_params).merge(local_params) let(:facts) do @@ -190,34 +189,32 @@ params end - if params['ensure'] != 'absent' - if params['package_source'] != :undef && facts[:os]['family'].include?('windows') - it { - is_expected.to compile.and_raise_error(%r{Custom package source is currently not implemented on windows.}) - } - else - it { - is_expected.to contain_class('docker::repos').that_comes_before('Class[docker::install]') - is_expected.to contain_class('docker::install').that_comes_before('Class[docker::config]') - is_expected.to contain_class('docker::config').that_comes_before('Class[docker::service]') - is_expected.to contain_class('docker::service') - } + if params['ensure'] == 'absent' + it { + expect(subject).to contain_class('docker::repos').that_comes_before('Class[docker::install]') + expect(subject).to contain_class('docker::install') + } - include_examples 'params', facts - include_examples 'repos', params, facts - include_examples 'install', params, facts - include_examples 'config', params, facts - include_examples 'service', params, facts - end + include_examples 'params', facts + include_examples 'repos', params, facts + include_examples 'install', params, facts + elsif params['package_source'] != :undef && facts[:os]['family'].include?('windows') + it { + expect(subject).to compile.and_raise_error(%r{Custom package source is currently not implemented on windows.}) + } else it { - is_expected.to contain_class('docker::repos').that_comes_before('Class[docker::install]') - is_expected.to contain_class('docker::install') + expect(subject).to contain_class('docker::repos').that_comes_before('Class[docker::install]') + expect(subject).to contain_class('docker::install').that_comes_before('Class[docker::config]') + expect(subject).to contain_class('docker::config').that_comes_before('Class[docker::service]') + expect(subject).to contain_class('docker::service') } include_examples 'params', facts include_examples 'repos', params, facts include_examples 'install', params, facts + include_examples 'config', params, facts + include_examples 'service', params, facts end end end diff --git a/spec/classes/machine_spec.rb b/spec/classes/machine_spec.rb index 62834733..c3aa31d6 100644 --- a/spec/classes/machine_spec.rb +++ b/spec/classes/machine_spec.rb @@ -3,8 +3,7 @@ require 'spec_helper' tests = { - 'with default value' => { - }, + 'with default value' => {} } describe 'docker::machine', type: :class do @@ -12,7 +11,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -27,12 +26,12 @@ tests.each do |title, local_params| context title do params = { - 'ensure' => 'present', - 'version' => defaults['machine_version'], + 'ensure' => 'present', + 'version' => defaults['machine_version'], 'install_path' => defaults['machine_install_path'], - 'proxy' => :undef, - 'url' => :undef, - 'curl_ensure' => defaults['curl_ensure'], + 'proxy' => :undef, + 'url' => :undef, + 'curl_ensure' => defaults['curl_ensure'] }.merge(local_params) let(:facts) do @@ -43,14 +42,12 @@ params end - if params['proxy'] != :undef - unless '^((http[s]?)?:\/\/)?([^:^@]+:[^:^@]+@|)([\da-z\.-]+)\.([\da-z\.]{2,6})(:[\d])?([\/\w \.-]*)*\/?$'.match?(params['proxy']) - it { - is_expected.to compile.and_raise_error(%r{}) - } + if params['proxy'] != :undef && !'^((http[s]?)?:\/\/)?([^:^@]+:[^:^@]+@|)([\da-z\.-]+)\.([\da-z\.]{2,6})(:[\d])?([\/\w \.-]*)*\/?$'.match?(params['proxy']) + it { + expect(subject).to compile.and_raise_error(%r{}) + } - next - end + next end include_examples 'machine', params, facts, defaults diff --git a/spec/classes/networks_spec.rb b/spec/classes/networks_spec.rb index 2eba6019..1be3469c 100644 --- a/spec/classes/networks_spec.rb +++ b/spec/classes/networks_spec.rb @@ -4,19 +4,19 @@ tests = { 'network-present' => { - 'ensure' => 'present', - 'driver' => 'overlay', - 'subnet' => '192.168.1.0/24', - 'gateway' => '192.168.1.1', - 'ip_range' => '192.168.1.4/32', + 'ensure' => 'present', + 'driver' => 'overlay', + 'subnet' => '192.168.1.0/24', + 'gateway' => '192.168.1.1', + 'ip_range' => '192.168.1.4/32' }, 'network-absent' => { - 'ensure' => 'absent', - 'driver' => 'overlay', - 'subnet' => '192.168.1.0/24', - 'gateway' => '192.168.1.1', - 'ip_range' => '192.168.1.4/32', - }, + 'ensure' => 'absent', + 'driver' => 'overlay', + 'subnet' => '192.168.1.0/24', + 'gateway' => '192.168.1.1', + 'ip_range' => '192.168.1.4/32' + } } describe 'docker::networks', type: :class do @@ -24,7 +24,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -47,17 +47,17 @@ let(:params) do { 'networks' => { - title => local_params, - }, + title => local_params + } } end it { - is_expected.to contain_docker_network(title).with( - 'ensure' => params['ensure'], - 'driver' => params['driver'], - 'subnet' => params['subnet'], - 'gateway' => params['gateway'], + expect(subject).to contain_docker_network(title).with( + 'ensure' => params['ensure'], + 'driver' => params['driver'], + 'subnet' => params['subnet'], + 'gateway' => params['gateway'], 'ip_range' => params['ip_range'], ) } diff --git a/spec/classes/plugins_spec.rb b/spec/classes/plugins_spec.rb index 012fda09..91c3d3bd 100644 --- a/spec/classes/plugins_spec.rb +++ b/spec/classes/plugins_spec.rb @@ -4,11 +4,11 @@ tests = { 'foo/enabled:latest' => { - 'enabled' => true, + 'enabled' => true }, 'foo/disabled:latest' => { - 'enabled' => false, - }, + 'enabled' => false + } } describe 'docker::plugins', type: :class do @@ -16,7 +16,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -32,16 +32,16 @@ context title do params = { 'base' => { - 'ensure' => 'present', - 'enabled' => true, - 'timeout' => :undef, - 'plugin_alias' => :undef, - 'disable_on_install' => false, + 'ensure' => 'present', + 'enabled' => true, + 'timeout' => :undef, + 'plugin_alias' => :undef, + 'disable_on_install' => false, 'disable_content_trust' => true, 'grant_all_permissions' => true, - 'force_remove' => true, - 'settings' => [], - }, + 'force_remove' => true, + 'settings' => [] + } } params.each do |key, values| @@ -54,14 +54,14 @@ let(:params) do { 'plugins' => { - key => values, - }, + key => values + } } end if facts[:os]['family'] == 'windows' it { - is_expected.to compile.and_raise_error(%r{Feature not implemented on windows.}) + expect(subject).to compile.and_raise_error(%r{Feature not implemented on windows.}) } next @@ -70,7 +70,7 @@ include_examples 'plugin', values, facts, defaults it { - is_expected.to contain_docker__plugin(key) + expect(subject).to contain_docker__plugin(key) } end end diff --git a/spec/defines/exec_spec.rb b/spec/defines/exec_spec.rb index b33051c2..b3b6f5de 100644 --- a/spec/defines/exec_spec.rb +++ b/spec/defines/exec_spec.rb @@ -3,45 +3,44 @@ require 'spec_helper' tests = { - 'with default values' => { - }, + 'with default values' => {}, 'when running detached' => { - 'detach' => true, + 'detach' => true }, 'when running with tty' => { - 'tty' => true, + 'tty' => true }, 'when running with interactive' => { - 'interactive' => true, + 'interactive' => true }, 'when running with onlyif "running"' => { 'interactive' => true, - 'onlyif' => 'running', + 'onlyif' => 'running' }, 'when running without onlyif custom command' => { 'interactive' => true, - 'onlyif' => 'custom', + 'onlyif' => 'custom' }, 'when running without onlyif' => { - 'interactive' => true, + 'interactive' => true }, 'when running with unless' => { 'interactive' => true, - 'unless' => 'some_command arg1', + 'unless' => 'some_command arg1' }, 'when running without unless' => { - 'interactive' => true, + 'interactive' => true }, 'with title that need sanitisation' => { - 'detach' => true, - 'sanitise_name' => true, + 'detach' => true, + 'sanitise_name' => true }, 'with environment variables passed to exec' => { 'env' => [ 'FOO=BAR', 'FOO2=BAR2', - ], - }, + ] + } } describe 'docker::exec', type: :define do @@ -49,7 +48,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -64,16 +63,16 @@ tests.each do |title, local_params| context title do params = { - 'command' => '/bin/echo foo', - 'container' => 'some_conainer_name', - 'detach' => false, - 'env' => [], - 'interactive' => false, - 'onlyif' => :undef, - 'refreshonly' => false, + 'command' => '/bin/echo foo', + 'container' => 'some_conainer_name', + 'detach' => false, + 'env' => [], + 'interactive' => false, + 'onlyif' => :undef, + 'refreshonly' => false, 'sanitise_name' => true, - 'tty' => false, - 'unless' => :undef, + 'tty' => false, + 'unless' => :undef }.merge(local_params) let(:facts) do diff --git a/spec/defines/image_spec.rb b/spec/defines/image_spec.rb index 08cd7d3a..6c63f40d 100644 --- a/spec/defines/image_spec.rb +++ b/spec/defines/image_spec.rb @@ -3,93 +3,92 @@ require 'spec_helper' tests = { - 'with default value' => { - }, + 'with default value' => {}, 'with ensure => absent' => { - 'ensure' => 'absent', + 'ensure' => 'absent' }, 'with ensure => absent and force => true' => { 'ensure' => 'absent', - 'force' => true, + 'force' => true }, 'with ensure => absent and image_tag => precise' => { - 'ensure' => 'absent', - 'image_tag' => 'precise', + 'ensure' => 'absent', + 'image_tag' => 'precise' }, 'with docker_file => Dockerfile' => { - 'docker_file' => 'Dockerfile', + 'docker_file' => 'Dockerfile' }, 'with ensure => present and docker_file => Dockerfile' => { - 'ensure' => 'present', - 'docker_file' => 'Dockerfile', + 'ensure' => 'present', + 'docker_file' => 'Dockerfile' }, 'with docker_dir => /tmp/docker_images/test1 and docker_file => /tmp/docker_images/test1/Dockerfile_altbuild' => { - 'docker_dir' => '/tmp/docker_images/test1', - 'docker_file' => '/tmp/docker_images/test1/Dockerfile_altbuild', + 'docker_dir' => '/tmp/docker_images/test1', + 'docker_file' => '/tmp/docker_images/test1/Dockerfile_altbuild' }, 'with docker_dir => /tmp/docker_images/test1' => { - 'docker_dir' => '/tmp/docker_images/test1', + 'docker_dir' => '/tmp/docker_images/test1' }, 'with ensure => present and docker_dir => /tmp/docker_images/test1' => { - 'ensure' => 'present', - 'docker_dir' => '/tmp/docker_images/test1', + 'ensure' => 'present', + 'docker_dir' => '/tmp/docker_images/test1' }, 'with ensure => present and image_tag => precise' => { - 'ensure' => 'present', - 'image_tag' => 'precise', + 'ensure' => 'present', + 'image_tag' => 'precise' }, 'with ensure => present and image_digest => sha256:deadbeef' => { - 'ensure' => 'present', - 'image_digest' => 'sha256:deadbeef', + 'ensure' => 'present', + 'image_digest' => 'sha256:deadbeef' }, 'with ensure => present and image_tag => precise and docker_file => Dockerfile' => { - 'ensure' => 'present', - 'image_tag' => 'precise', - 'docker_file' => 'Dockerfile', + 'ensure' => 'present', + 'image_tag' => 'precise', + 'docker_file' => 'Dockerfile' }, 'with ensure => present and image_tag => precise and docker_dir => /tmp/docker_images/test1' => { - 'ensure' => 'present', - 'image_tag' => 'precise', - 'docker_dir' => '/tmp/docker_images/test1', + 'ensure' => 'present', + 'image_tag' => 'precise', + 'docker_dir' => '/tmp/docker_images/test1' }, 'with docker_tar => /tmp/docker_tars/test1.tar' => { - 'docker_tar' => '/tmp/docker_tars/test1.tar', + 'docker_tar' => '/tmp/docker_tars/test1.tar' }, 'with ensure => present and docker_tar => /tmp/docker_tars/test1.tar' => { - 'ensure' => 'present', - 'docker_tar' => '/tmp/docker_tars/test1.tar', + 'ensure' => 'present', + 'docker_tar' => '/tmp/docker_tars/test1.tar' }, 'with docker_file => Dockerfile and docker_tar => /tmp/docker_tars/test1.tar' => { 'docker_file' => 'Dockerfile', - 'docker_tar' => '/tmp/docker_tars/test1.tar', + 'docker_tar' => '/tmp/docker_tars/test1.tar' }, 'with docker_tar => /tmp/docker_tars/test1.tar and docker_dir => /tmp/docker_images/test1' => { 'docker_tar' => '/tmp/docker_tars/test1.tar', - 'docker_dir' => '/tmp/docker_images/test1', + 'docker_dir' => '/tmp/docker_images/test1' }, 'with image_digest => sha256:deadbeef and docker_file => Dockerfile' => { 'image_digest' => 'sha256:deadbeef', - 'docker_file' => 'Dockerfile', + 'docker_file' => 'Dockerfile' }, 'with image_digest => sha256:deadbeef and docker_dir => /tmp/docker_images/test1' => { 'image_digest' => 'sha256:deadbeef', - 'docker_dir' => '/tmp/docker_images/test1', + 'docker_dir' => '/tmp/docker_images/test1' }, 'with image_digest => sha256:deadbeef and docker_tar => /tmp/docker_tars/test1.tar' => { 'image_digest' => 'sha256:deadbeef', - 'docker_tar' => '/tmp/docker_tars/test1.tar', + 'docker_tar' => '/tmp/docker_tars/test1.tar' }, 'with ensure => latest' => { - 'ensure' => 'latest', + 'ensure' => 'latest' }, 'with ensure => latest and image_tag => precise' => { - 'ensure' => 'latest', - 'image_tag' => 'precise', + 'ensure' => 'latest', + 'image_tag' => 'precise' }, 'with ensure => latest and image_digest => sha256:deadbeef' => { - 'ensure' => 'latest', - 'image_digest' => 'sha256:deadbeef', - }, + 'ensure' => 'latest', + 'image_digest' => 'sha256:deadbeef' + } } describe 'docker::image', type: :define do @@ -97,7 +96,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -112,14 +111,14 @@ tests.each do |title, local_params| context title do params = { - 'ensure' => 'present', - 'image' => 'base', - 'image_tag' => :undef, + 'ensure' => 'present', + 'image' => 'base', + 'image_tag' => :undef, 'image_digest' => :undef, - 'force' => false, - 'docker_file' => :undef, - 'docker_dir' => :undef, - 'docker_tar' => :undef, + 'force' => false, + 'docker_file' => :undef, + 'docker_dir' => :undef, + 'docker_tar' => :undef }.merge(local_params) let(:facts) do @@ -136,7 +135,7 @@ if params['docker_file'] != :undef && params['docker_tar'] != :undef it { - is_expected.to compile.and_raise_error(%r{docker::image must not have both \$docker_file and \$docker_tar set}) + expect(subject).to compile.and_raise_error(%r{docker::image must not have both \$docker_file and \$docker_tar set}) } next @@ -144,7 +143,7 @@ if params['docker_dir'] != :undef && params['docker_tar'] != :undef it { - is_expected.to compile.and_raise_error(%r{docker::image must not have both \$docker_dir and \$docker_tar set}) + expect(subject).to compile.and_raise_error(%r{docker::image must not have both \$docker_dir and \$docker_tar set}) } next @@ -152,7 +151,7 @@ if params['image_digest'] != :undef && params['docker_file'] != :undef it { - is_expected.to compile.and_raise_error(%r{docker::image must not have both \$image_digest and \$docker_file set}) + expect(subject).to compile.and_raise_error(%r{docker::image must not have both \$image_digest and \$docker_file set}) } next @@ -160,7 +159,7 @@ if params['image_digest'] != :undef && params['docker_dir'] != :undef it { - is_expected.to compile.and_raise_error(%r{docker::image must not have both \$image_digest and \$docker_dir set}) + expect(subject).to compile.and_raise_error(%r{docker::image must not have both \$image_digest and \$docker_dir set}) } next @@ -168,7 +167,7 @@ if params['image_digest'] != :undef && params['docker_tar'] != :undef it { - is_expected.to compile.and_raise_error(%r{docker::image must not have both \$image_digest and \$docker_tar set}) + expect(subject).to compile.and_raise_error(%r{docker::image must not have both \$image_digest and \$docker_tar set}) } next diff --git a/spec/defines/plugin_spec.rb b/spec/defines/plugin_spec.rb index 1d4fc1b0..6ada809b 100644 --- a/spec/defines/plugin_spec.rb +++ b/spec/defines/plugin_spec.rb @@ -7,15 +7,15 @@ 'settings' => [ 'VAR1=test', 'VAR2=value', - ], + ] }, 'foo/disabled:latest' => { - 'enabled' => false, + 'enabled' => false }, 'foo/force_remove:latest' => { - 'ensure' => 'absent', - 'force_remove' => true, - }, + 'ensure' => 'absent', + 'force_remove' => true + } } describe 'docker::plugin', type: :define do @@ -23,7 +23,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -38,16 +38,16 @@ tests.each do |title, local_params| context title do params = { - 'ensure' => 'present', - 'plugin_name' => title, - 'enabled' => true, - 'timeout' => :undef, - 'plugin_alias' => :undef, - 'disable_on_install' => false, + 'ensure' => 'present', + 'plugin_name' => title, + 'enabled' => true, + 'timeout' => :undef, + 'plugin_alias' => :undef, + 'disable_on_install' => false, 'disable_content_trust' => true, 'grant_all_permissions' => true, - 'force_remove' => true, - 'settings' => [], + 'force_remove' => true, + 'settings' => [] }.merge(local_params) let(:facts) do @@ -64,7 +64,7 @@ if facts[:os]['family'] == 'windows' it { - is_expected.to compile.and_raise_error(%r{Feature not implemented on windows.}) + expect(subject).to compile.and_raise_error(%r{Feature not implemented on windows.}) } next diff --git a/spec/defines/registry_spec.rb b/spec/defines/registry_spec.rb index bae0e0d8..e30688c0 100644 --- a/spec/defines/registry_spec.rb +++ b/spec/defines/registry_spec.rb @@ -7,27 +7,27 @@ 'ensure' => 'absent', 'version' => '17.06', 'pass_hash' => 'test1234', - 'receipt' => false, + 'receipt' => false }, 'with ensure => present' => { 'ensure' => 'present', 'version' => '17.06', 'pass_hash' => 'test1234', - 'receipt' => false, + 'receipt' => false }, 'with ensure => present and username => user1' => { 'ensure' => 'present', 'username' => 'user1', 'version' => '17.06', 'pass_hash' => 'test1234', - 'receipt' => false, + 'receipt' => false }, 'with ensure => present and password => secret' => { 'ensure' => 'present', 'password' => 'secret', 'version' => '17.06', 'pass_hash' => 'test1234', - 'receipt' => false, + 'receipt' => false }, 'with ensure => present and email => user1@example.io' => { @@ -35,7 +35,7 @@ 'email' => 'user1@example.io', 'version' => '17.06', 'pass_hash' => 'test1234', - 'receipt' => false, + 'receipt' => false }, 'with ensure => present and username => user1, and password => secret and email => user1@example.io' => { 'ensure' => 'present', @@ -44,7 +44,7 @@ 'email' => 'user1@example.io', 'version' => '17.06', 'pass_hash' => 'test1234', - 'receipt' => false, + 'receipt' => false }, 'with ensure => present and username => user1, and password => secret and email => user1@example.io and version < 1.11.0' => { 'ensure' => 'present', @@ -53,14 +53,14 @@ 'email' => 'user1@example.io', 'version' => '1.9.0', 'pass_hash' => 'test1234', - 'receipt' => false, + 'receipt' => false }, 'with username => user1, and password => secret' => { 'username' => 'user1', 'password' => 'secret', 'version' => '17.06', 'pass_hash' => 'test1234', - 'receipt' => false, + 'receipt' => false }, 'with username => user1, and password => secret and local_user => testuser' => { 'username' => 'user1', @@ -68,8 +68,8 @@ 'local_user' => 'testuser', 'version' => '17.06', 'pass_hash' => 'test1234', - 'receipt' => false, - }, + 'receipt' => false + } } describe 'docker::registry', type: :define do @@ -77,23 +77,23 @@ ## ## set some needed facts ## - if %r{windows}.match?(os) + if os.include?('windows') facts = windows_facts.merge( 'docker_home_dirs' => { 'user' => '/home/user', - 'root' => '/root', + 'root' => '/root' }, ).merge(os_facts) docker_params = { - 'docker_ee' => true, + 'docker_ee' => true } else facts = { docker_home_dirs: { 'user' => '/home/user', - 'root' => '/root', - }, + 'root' => '/root' + } }.merge(os_facts) docker_params = {} @@ -108,15 +108,15 @@ tests.each do |title, local_params| context title do params = { - 'server' => title, - 'ensure' => 'present', - 'username' => :undef, - 'password' => :undef, - 'pass_hash' => :undef, - 'email' => :undef, + 'server' => title, + 'ensure' => 'present', + 'username' => :undef, + 'password' => :undef, + 'pass_hash' => :undef, + 'email' => :undef, 'local_user' => 'root', - 'version' => defaults['version'], - 'receipt' => true, + 'version' => defaults['version'], + 'receipt' => true }.merge(local_params) let(:facts) do diff --git a/spec/defines/run_spec.rb b/spec/defines/run_spec.rb index 9651ccd2..4d27df89 100644 --- a/spec/defines/run_spec.rb +++ b/spec/defines/run_spec.rb @@ -9,217 +9,217 @@ 'foo', 'bar', 'foo_bar/baz', - ], + ] }, 'when passing after containers' => { 'after' => [ 'foo', 'bar', 'foo_bar/baz', - ], + ] }, 'when use_name is true' => { - 'use_name' => true, + 'use_name' => true }, 'when stopping the service' => { - 'running' => false, + 'running' => false }, 'when passing a cpuset' => { - 'cpuset' => '3', + 'cpuset' => '3' }, 'when passing a multiple cpu cpuset' => { 'cpuset' => [ '0', '3', - ], + ] }, 'when passing a links option' => { 'links' => [ 'example:one', 'example:two', - ], + ] }, 'when passing a hostname' => { - 'hostname' => 'example.com', + 'hostname' => 'example.com' }, 'when passing a username' => { - 'username' => 'bob', + 'username' => 'bob' }, 'when passing a port number' => { - 'ports' => '4444', + 'ports' => '4444' }, 'when passing a port to expose' => { - 'expose' => '4666', + 'expose' => '4666' }, 'when passing a label' => { - 'labels' => 'key=value', + 'labels' => 'key=value' }, 'when passing a hostentry' => { - 'hostentries' => 'dummyhost:127.0.0.2', + 'hostentries' => 'dummyhost:127.0.0.2' }, 'when connecting to shared data volumes' => { - 'volumes_from' => '6446ea52fbc9', + 'volumes_from' => '6446ea52fbc9' }, 'when connecting to several shared data volumes' => { 'volumes_from' => [ 'sample-linked-container-1', 'sample-linked-container-2', - ], + ] }, 'when passing several port numbers' => { 'ports' => [ '4444', '4555', - ], + ] }, 'when passing several labels' => { 'labels' => [ 'key1=value1', 'key2=value2', - ], + ] }, 'when passing several ports to expose' => { 'expose' => [ '4666', '4777', - ], + ] }, 'when passing serveral environment variables' => { 'env' => [ 'FOO=BAR', 'FOO2=BAR2', - ], + ] }, 'when passing an environment variable' => { - 'env' => 'FOO=BAR', + 'env' => 'FOO=BAR' }, 'when passing serveral environment files' => { 'env_file' => [ '/etc/foo.env', '/etc/bar.env', - ], + ] }, 'when passing an environment file' => { - 'env_file' => '/etc/foo.env', + 'env_file' => '/etc/foo.env' }, 'when passing serveral dns addresses' => { 'dns' => [ '8.8.8.8', '8.8.4.4', - ], + ] }, 'when passing a dns address' => { - 'dns' => '8.8.8.8', + 'dns' => '8.8.8.8' }, 'when passing serveral sockets to connect to' => { 'socket_connect' => [ 'tcp://127.0.0.1:4567', 'tcp://127.0.0.2:4567', - ], + ] }, 'when passing a socket to connect to' => { - 'socket_connect' => 'tcp://127.0.0.1:4567', + 'socket_connect' => 'tcp://127.0.0.1:4567' }, 'when passing serveral dns search domains' => { 'dns_search' => [ 'my.domain.local', 'other-domain.de', - ], + ] }, 'when passing a dns search domain' => { - 'dns_search' => 'my.domain.local', + 'dns_search' => 'my.domain.local' }, 'when disabling network' => { - 'disable_network' => true, + 'disable_network' => true }, 'when running privileged' => { - 'privileged' => true, + 'privileged' => true }, 'when passing serveral extra parameters' => { - 'extra_parameters' => ['--rm', '-w /tmp'], + 'extra_parameters' => ['--rm', '-w /tmp'] }, 'when passing an extra parameter' => { - 'extra_parameters' => '-c 4', + 'extra_parameters' => '-c 4' }, 'when passing a data volume' => { - 'volumes' => '/var/log', + 'volumes' => '/var/log' }, 'when passing serveral data volume' => { 'volumes' => [ '/var/lib/couchdb', '/var/log', - ], + ] }, 'when pull_on_start is true' => { - 'pull_on_start' => true, + 'pull_on_start' => true }, 'when pull_on_start is false' => { - 'pull_on_start' => false, + 'pull_on_start' => false }, 'when before_start is set' => { - 'before_start' => 'echo before_start', + 'before_start' => 'echo before_start' }, 'when before_start is not set' => { - 'before_start' => false, + 'before_start' => false }, 'when before_stop is set' => { - 'before_stop' => 'echo before_stop', + 'before_stop' => 'echo before_stop' }, 'when before_stop is not set' => { - 'before_stop' => false, + 'before_stop' => false }, 'when after_start is set' => { - 'after_start' => 'echo after_start', + 'after_start' => 'echo after_start' }, 'when after_start is not set' => { - 'after_start' => false, + 'after_start' => false }, 'when after_stop is set' => { - 'after_stop' => 'echo after_stop', + 'after_stop' => 'echo after_stop' }, 'when after_stop is not set' => { - 'after_stop' => false, + 'after_stop' => false }, 'when docker_service is false' => { - 'docker_service' => false, + 'docker_service' => false }, 'when docker_service is true' => { - 'docker_service' => true, + 'docker_service' => true }, 'when docker_service is true and restart_service_on_docker_refresh is false' => { 'docker_service' => true, - 'restart_service_on_docker_refresh' => false, + 'restart_service_on_docker_refresh' => false }, 'when docker_service is my-docker' => { - 'docker_service' => 'my-docker', + 'docker_service' => 'my-docker' }, 'when docker_service is my-docker and restart_service_on_docker_refresh is false' => { 'docker_service' => 'my-docker', - 'restart_service_on_docker_refresh' => false, + 'restart_service_on_docker_refresh' => false }, 'when passing syslog_facility' => { - 'syslog_facility' => 'user', + 'syslog_facility' => 'user' }, 'when passing serveral extra systemd parameters' => { 'extra_systemd_parameters' => { 'Service' => { - 'TimeoutStopSec' => '120', + 'TimeoutStopSec' => '120' }, 'Unit' => { 'Documentation' => 'https://example.com/' }, 'Install' => { - 'Alias' => 'example2', - }, + 'Alias' => 'example2' + } } }, 'when passing an extra systemd parameter' => { 'extra_systemd_parameters' => { 'Service' => { - 'TimeoutStopSec' => '120', + 'TimeoutStopSec' => '120' } } - }, + } } describe 'docker::run', type: :define do @@ -227,17 +227,17 @@ ## ## set some needed facts ## - if %r{windows}.match?(os) + if os.include?('windows') facts = windows_facts.merge(os_facts) facts = facts.merge({ puppetversion: Puppet.version }) os_params = { 'restart' => 'no', - 'extra_parameters' => '-c 4', + 'extra_parameters' => '-c 4' } docker_params = { - 'docker_ee' => true, + 'docker_ee' => true } else facts = { puppetversion: Puppet.version }.merge(os_facts) @@ -256,70 +256,68 @@ tests.each do |title, local_params| context title do params = { - 'after_create' => :undef, - 'after_service' => [], - 'after_start' => false, - 'after_stop' => false, - 'after' => [], - 'before_start' => false, - 'before_stop' => false, - 'command' => 'command', - 'cpuset' => [], - 'custom_unless' => [], - 'depend_services' => ['docker.service'], - 'depends' => [], - 'detach' => :undef, - 'disable_network' => false, - 'dns_search' => [], - 'dns' => [], - 'docker_service' => false, - 'ensure' => 'present', - 'env_file' => [], - 'env' => [], - 'expose' => [], - 'extra_parameters' => :undef, - 'extra_systemd_parameters' => {}, - 'health_check_cmd' => :undef, - 'health_check_interval' => :undef, - 'hostentries' => [], - 'hostname' => false, - 'image' => 'base', - 'labels' => [], - 'links' => [], - 'lxc_conf' => [], - 'manage_service' => true, - 'memory_limit' => '0b', - 'net' => 'bridge', - 'ports' => [], - 'privileged' => false, - 'pull_on_start' => false, - 'read_only' => false, - 'remain_after_exit' => :undef, - 'remove_container_on_start' => true, - 'remove_container_on_stop' => true, - 'remove_volume_on_start' => false, - 'remove_volume_on_stop' => false, - 'restart_on_unhealthy' => false, + 'after_create' => :undef, + 'after_service' => [], + 'after_start' => false, + 'after_stop' => false, + 'after' => [], + 'before_start' => false, + 'before_stop' => false, + 'command' => 'command', + 'cpuset' => [], + 'custom_unless' => [], + 'depend_services' => ['docker.service'], + 'depends' => [], + 'detach' => :undef, + 'disable_network' => false, + 'dns_search' => [], + 'dns' => [], + 'docker_service' => false, + 'ensure' => 'present', + 'env_file' => [], + 'env' => [], + 'expose' => [], + 'extra_parameters' => :undef, + 'extra_systemd_parameters' => {}, + 'health_check_cmd' => :undef, + 'health_check_interval' => :undef, + 'hostentries' => [], + 'hostname' => false, + 'image' => 'base', + 'labels' => [], + 'links' => [], + 'lxc_conf' => [], + 'manage_service' => true, + 'memory_limit' => '0b', + 'net' => 'bridge', + 'ports' => [], + 'privileged' => false, + 'pull_on_start' => false, + 'read_only' => false, + 'remain_after_exit' => :undef, + 'remove_container_on_start' => true, + 'remove_container_on_stop' => true, + 'remove_volume_on_start' => false, + 'remove_volume_on_stop' => false, + 'restart_on_unhealthy' => false, 'restart_service_on_docker_refresh' => true, - 'restart_service' => true, - 'restart' => :undef, - 'running' => true, - 'service_prefix' => 'docker-', - 'service_provider' => :undef, - 'socket_connect' => [], - 'stop_wait_time' => 10, - 'syslog_identifier' => :undef, - 'systemd_restart' => 'on-failure', - 'tty' => false, - 'use_name' => false, - 'username' => false, - 'volumes_from' => [], - 'volumes' => [], + 'restart_service' => true, + 'restart' => :undef, + 'running' => true, + 'service_prefix' => 'docker-', + 'service_provider' => :undef, + 'socket_connect' => [], + 'stop_wait_time' => 10, + 'syslog_identifier' => :undef, + 'systemd_restart' => 'on-failure', + 'tty' => false, + 'use_name' => false, + 'username' => false, + 'volumes_from' => [], + 'volumes' => [] }.merge(os_params).merge(local_params) - if params['docker_service'] && params['docker_service'].to_s != 'true' - docker_params['service_name'] = params['docker_service'] - end + docker_params['service_name'] = params['docker_service'] if params['docker_service'] && params['docker_service'].to_s != 'true' let(:facts) do facts @@ -344,7 +342,7 @@ class { 'docker': if params['remove_volume_on_start'] && !params['remove_container_on_start'] it { - is_expected.to compile.and_raise_error("In order to remove the volume on start for #{_title} you need to also remove the container") + expect(subject).to compile.and_raise_error("In order to remove the volume on start for #{_title} you need to also remove the container") } next @@ -352,7 +350,7 @@ class { 'docker': if params['remove_volume_on_stop'] && !params['remove_container_on_stop'] it { - is_expected.to compile.and_raise_error("In order to remove the volume on stop for #{_title} you need to also remove the container") + expect(subject).to compile.and_raise_error("In order to remove the volume on stop for #{_title} you need to also remove the container") } next @@ -368,13 +366,13 @@ class { 'docker': if !params['service_provider_real'] == 'systemd' && !params['service_provider_real'] == 'upstart' if facts[:os]['family'] != 'windows' it { - is_expected.to compile.and_raise_error('Docker needs a Debian or RedHat based system.') + expect(subject).to compile.and_raise_error('Docker needs a Debian or RedHat based system.') } next elsif params['ensure'] == 'present' it { - is_expected.to compile.and_raise_error('Restart parameter is required for Windows') + expect(subject).to compile.and_raise_error('Restart parameter is required for Windows') } next diff --git a/spec/defines/secrets_spec.rb b/spec/defines/secrets_spec.rb index e0a23d55..e47c4c4c 100644 --- a/spec/defines/secrets_spec.rb +++ b/spec/defines/secrets_spec.rb @@ -6,12 +6,12 @@ 'with ensure present' => { 'secret_name' => 'test_secret', 'secret_path' => '/root/secret.txt', - 'label' => ['test'], + 'label' => ['test'] }, 'with ensure absent' => { - 'ensure' => 'absent', - 'secret_name' => 'test_secret', - }, + 'ensure' => 'absent', + 'secret_name' => 'test_secret' + } } describe 'docker::secrets', type: :define do @@ -19,7 +19,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -34,10 +34,10 @@ tests.each do |title, local_params| context title do params = { - 'ensure' => 'present', - 'label' => [], + 'ensure' => 'present', + 'label' => [], 'secret_name' => :undef, - 'secret_path' => :undef, + 'secret_path' => :undef }.merge(local_params) let(:facts) do diff --git a/spec/defines/services_spec.rb b/spec/defines/services_spec.rb index 0f5603e3..fd8df5e1 100644 --- a/spec/defines/services_spec.rb +++ b/spec/defines/services_spec.rb @@ -4,48 +4,48 @@ tests = { 'with ensure => present and service create' => { - 'create' => true, + 'create' => true, 'service_name' => 'foo', - 'image' => 'foo:bar', - 'publish' => '80:80', - 'replicas' => '5', + 'image' => 'foo:bar', + 'publish' => '80:80', + 'replicas' => '5', 'extra_params' => ['--update-delay 1m', '--restart-window 30s'], - 'env' => ['MY_ENV=1', 'MY_ENV2=2'], - 'label' => ['com.example.foo="bar"', 'bar=baz'], - 'mounts' => ['type=bind,src=/tmp/a,dst=/tmp/a', 'type=bind,src=/tmp/b,dst=/tmp/b,readonly'], - 'networks' => ['overlay'], - 'command' => 'echo hello world', + 'env' => ['MY_ENV=1', 'MY_ENV2=2'], + 'label' => ['com.example.foo="bar"', 'bar=baz'], + 'mounts' => ['type=bind,src=/tmp/a,dst=/tmp/a', 'type=bind,src=/tmp/b,dst=/tmp/b,readonly'], + 'networks' => ['overlay'], + 'command' => 'echo hello world' }, 'multiple services declaration' => { 'service_name' => 'foo_2', - 'image' => 'foo:bar', - 'command' => ['echo', 'hello', 'world'], + 'image' => 'foo:bar', + 'command' => ['echo', 'hello', 'world'] }, 'multiple publish ports and multiple networks' => { 'service_name' => 'foo_3', - 'image' => 'foo:bar', - 'publish' => ['80:8080', '9000:9000'], - 'networks' => ['foo_1', 'foo_2'], + 'image' => 'foo:bar', + 'publish' => ['80:8080', '9000:9000'], + 'networks' => ['foo_1', 'foo_2'] }, 'with ensure => present and service update' => { - 'create' => false, - 'update' => true, + 'create' => false, + 'update' => true, 'service_name' => 'foo', - 'image' => 'bar:latest', + 'image' => 'bar:latest' }, 'with ensure => present and service scale' => { - 'create' => false, - 'scale' => true, + 'create' => false, + 'scale' => true, 'service_name' => 'bar', - 'replicas' => '5', + 'replicas' => '5' }, 'with ensure => absent' => { - 'ensure' => 'absent', - 'service_name' => 'foo', + 'ensure' => 'absent', + 'service_name' => 'foo' }, 'when adding a system user' => { - 'user' => ['user1'], - }, + 'user' => ['user1'] + } } describe 'docker::services', type: :define do @@ -53,7 +53,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -68,26 +68,26 @@ tests.each do |title, local_params| context title do params = { - 'ensure' => 'present', - 'create' => true, - 'update' => false, - 'scale' => false, - 'detach' => true, - 'tty' => false, - 'env' => [], - 'label' => [], - 'extra_params' => [], - 'image' => :undef, - 'service_name' => :undef, - 'publish' => :undef, - 'replicas' => :undef, - 'user' => :undef, - 'workdir' => :undef, - 'host_socket' => :undef, + 'ensure' => 'present', + 'create' => true, + 'update' => false, + 'scale' => false, + 'detach' => true, + 'tty' => false, + 'env' => [], + 'label' => [], + 'extra_params' => [], + 'image' => :undef, + 'service_name' => :undef, + 'publish' => :undef, + 'replicas' => :undef, + 'user' => :undef, + 'workdir' => :undef, + 'host_socket' => :undef, 'registry_mirror' => :undef, - 'mounts' => :undef, - 'networks' => :undef, - 'command' => :undef, + 'mounts' => :undef, + 'networks' => :undef, + 'command' => :undef }.merge(local_params) let(:facts) do @@ -102,14 +102,12 @@ 'rspec_services' end - if params['ensure'] == 'absent' - if params['update'] || params['scale'] - it { - is_expected.to compile.and_raise_error('When removing a service you can not update it.') - } + if params['ensure'] == 'absent' && (params['update'] || params['scale']) + it { + expect(subject).to compile.and_raise_error('When removing a service you can not update it.') + } - next - end + next end include_examples 'services', 'rspec_services', params, facts, defaults diff --git a/spec/defines/stack_spec.rb b/spec/defines/stack_spec.rb index 5504d8c5..8d6f3a98 100644 --- a/spec/defines/stack_spec.rb +++ b/spec/defines/stack_spec.rb @@ -4,24 +4,24 @@ tests = { 'create stack with compose file' => { - 'stack_name' => 'foo', + 'stack_name' => 'foo', 'compose_files' => ['/tmp/docker-compose.yaml'], - 'resolve_image' => 'always', + 'resolve_image' => 'always' }, 'create stack with multiple compose files' => { - 'stack_name' => 'foo', + 'stack_name' => 'foo', 'compose_files' => ['/tmp/docker-compose.yaml', '/tmp/docker-compose-2.yaml'], - 'resolve_image' => 'always', + 'resolve_image' => 'always' }, 'with prune' => { - 'stack_name' => 'foo', + 'stack_name' => 'foo', 'compose_files' => ['/tmp/docker-compose.yaml'], - 'prune' => true, + 'prune' => true }, 'with ensure => absent' => { - 'ensure' => 'absent', - 'stack_name' => 'foo', - }, + 'ensure' => 'absent', + 'stack_name' => 'foo' + } } describe 'docker::stack', type: :define do @@ -29,7 +29,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -44,13 +44,13 @@ tests.each do |title, local_params| context title do params = { - 'ensure' => 'present', - 'stack_name' => :undef, - 'bundle_file' => :undef, - 'compose_files' => :undef, - 'prune' => false, + 'ensure' => 'present', + 'stack_name' => :undef, + 'bundle_file' => :undef, + 'compose_files' => :undef, + 'prune' => false, 'with_registry_auth' => false, - 'resolve_image' => :undef, + 'resolve_image' => :undef }.merge(local_params) let(:facts) do diff --git a/spec/defines/swarm_spec.rb b/spec/defines/swarm_spec.rb index 4338922c..c6cb3565 100644 --- a/spec/defines/swarm_spec.rb +++ b/spec/defines/swarm_spec.rb @@ -4,32 +4,32 @@ tests = { 'with ensure => present and swarm init' => { - 'init' => true, + 'init' => true, 'advertise_addr' => '192.168.1.1', - 'listen_addr' => '192.168.1.1', + 'listen_addr' => '192.168.1.1' }, 'with ensure => present and swarm init and default-addr-pool and default_addr_pool_mask_length' => { - 'init' => true, - 'advertise_addr' => '192.168.1.1', - 'listen_addr' => '192.168.1.1', - 'default_addr_pool' => ['30.30.0.0/16', '40.40.0.0/16'], - 'default_addr_pool_mask_length' => '24', + 'init' => true, + 'advertise_addr' => '192.168.1.1', + 'listen_addr' => '192.168.1.1', + 'default_addr_pool' => ['30.30.0.0/16', '40.40.0.0/16'], + 'default_addr_pool_mask_length' => '24' }, 'with ensure => present and swarm join' => { - 'join' => true, + 'join' => true, 'advertise_addr' => '192.168.1.1', - 'listen_addr' => '192.168.1.1', - 'token' => 'foo', - 'manager_ip' => '192.168.1.2', + 'listen_addr' => '192.168.1.1', + 'token' => 'foo', + 'manager_ip' => '192.168.1.2' }, 'with ensure => absent' => { - 'ensure' => 'absent', - 'join' => true, + 'ensure' => 'absent', + 'join' => true, 'advertise_addr' => '192.168.1.1', - 'listen_addr' => '192.168.1.1', - 'token' => 'foo', - 'manager_ip' => '192.168.1.2', - }, + 'listen_addr' => '192.168.1.1', + 'token' => 'foo', + 'manager_ip' => '192.168.1.2' + } } describe 'docker::swarm', type: :define do @@ -37,7 +37,7 @@ ## ## set some needed facts ## - facts = if %r{windows}.match?(os) + facts = if os.include?('windows') windows_facts.merge(os_facts) else os_facts @@ -52,22 +52,22 @@ tests.each do |title, local_params| context title do params = { - 'ensure' => 'present', - 'init' => false, - 'join' => false, - 'advertise_addr' => :undef, - 'autolock' => false, - 'cert_expiry' => :undef, - 'default_addr_pool' => :undef, + 'ensure' => 'present', + 'init' => false, + 'join' => false, + 'advertise_addr' => :undef, + 'autolock' => false, + 'cert_expiry' => :undef, + 'default_addr_pool' => :undef, 'default_addr_pool_mask_length' => :undef, - 'dispatcher_heartbeat' => :undef, - 'external_ca' => :undef, - 'force_new_cluster' => false, - 'listen_addr' => :undef, - 'max_snapshots' => :undef, - 'snapshot_interval' => :undef, - 'token' => :undef, - 'manager_ip' => :undef, + 'dispatcher_heartbeat' => :undef, + 'external_ca' => :undef, + 'force_new_cluster' => false, + 'listen_addr' => :undef, + 'max_snapshots' => :undef, + 'snapshot_interval' => :undef, + 'token' => :undef, + 'manager_ip' => :undef }.merge(local_params) let(:facts) do diff --git a/spec/helper/get_defaults.rb b/spec/helper/get_defaults.rb index a7d883e2..d22e00b8 100644 --- a/spec/helper/get_defaults.rb +++ b/spec/helper/get_defaults.rb @@ -109,30 +109,21 @@ def get_defaults(_facts) case _facts[:os]['family'] when 'Debian' - case _facts[:os]['name'] - when 'Ubuntu' - package_release = "ubuntu-#{_facts[:os]['distro']['codename']}" - service_after_override = :undef - service_config_template = 'docker/etc/sysconfig/docker.systemd.erb' - service_hasrestart = true - service_hasstatus = true - service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb' - service_provider = 'systemd' - socket_override = false - socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.erb' - storage_config = '/etc/default/docker-storage' - else - package_release = "debian-#{_facts[:os]['distro']['codename']}" - service_after_override = :undef - service_config_template = 'docker/etc/sysconfig/docker.systemd.erb' - service_hasrestart = true - service_hasstatus = true - service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb' - service_provider = 'systemd' - socket_override = false - socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.erb' - storage_config = '/etc/default/docker-storage' - end + package_release = case _facts[:os]['name'] + when 'Ubuntu' + "ubuntu-#{_facts[:os]['distro']['codename']}" + else + "debian-#{_facts[:os]['distro']['codename']}" + end + service_after_override = :undef + service_config_template = 'docker/etc/sysconfig/docker.systemd.erb' + service_hasrestart = true + service_hasstatus = true + service_overrides_template = 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb' + service_provider = 'systemd' + socket_override = false + socket_overrides_template = 'docker/etc/systemd/system/docker.socket.d/socket-overrides.conf.erb' + storage_config = '/etc/default/docker-storage' apt_source_pin_level = 500 docker_group = docker_group_default @@ -159,11 +150,7 @@ def get_defaults(_facts) package_key_source = 'https://apt.dockerproject.org/gpg' package_source_location = 'http://apt.dockerproject.org/repo' - detach_service_in_init = if service_provider == 'systemd' - false - else - true - end + detach_service_in_init = service_provider != 'systemd' when 'RedHat' service_after_override = :undef service_config = '/etc/sysconfig/docker' @@ -486,6 +473,6 @@ def get_defaults(_facts) 'tmp_dir' => tmp_dir, 'tmp_dir_config' => tmp_dir_config, 'use_upstream_package_source' => use_upstream_package_source, - 'version' => version, + 'version' => version } end diff --git a/spec/helper/get_docker_exec_flags.rb b/spec/helper/get_docker_exec_flags.rb index 6fe692a7..fe5a474c 100644 --- a/spec/helper/get_docker_exec_flags.rb +++ b/spec/helper/get_docker_exec_flags.rb @@ -3,17 +3,11 @@ def get_docker_exec_flags(args) flags = [] - if args['detach'] - flags << '--detach=true' - end + flags << '--detach=true' if args['detach'] - if args['interactive'] - flags << '--interactive=true' - end + flags << '--interactive=true' if args['interactive'] - if args['tty'] - flags << '--tty=true' - end + flags << '--tty=true' if args['tty'] unless args['env'].empty? args['env'].each do |namevaluepair| diff --git a/spec/helper/get_docker_params_changed.rb b/spec/helper/get_docker_params_changed.rb index 980ec272..07eeab37 100644 --- a/spec/helper/get_docker_params_changed.rb +++ b/spec/helper/get_docker_params_changed.rb @@ -18,11 +18,9 @@ def get_docker_params_changed(opts) param_changed = true if opts['volumes'].is_a?(String) && opts['volumes'].include?(':') && opts['volumes'] != inspect_hash['Mounts'].to_a[0] && opts['osfamily'] != 'windows' param_changed = true if opts['volumes'].is_a?(String) && !opts['volumes'].include?(':') && opts['volumes'] != inspect_hash['Config']['Volumes'].to_a[0] && opts['osfamily'] != 'windows' param_changed = true if opts['volumes'].is_a?(String) && opts['volumes'].scan(%r{(?=:)}).count == 2 && opts['volumes'] != inspect_hash['Mounts'].to_a[0] && opts['osfamily'] == 'windows' - param_changed = if opts['volumes'].is_a?(String) && opts['volumes'].scan(%r{(?=:)}).count == 1 && opts['volumes'] != inspect_hash['Config']['Volumes'].to_a[0] && opts['osfamily'] == 'windows' - true - else - param_changed - end + if opts['volumes'].is_a?(String) && opts['volumes'].scan(%r{(?=:)}).count == 1 && opts['volumes'] != inspect_hash['Config']['Volumes'].to_a[0] && opts['osfamily'] == 'windows' + param_changed = true + end pp_paths = opts['volumes'].reject { |item| item.include?(':') } if opts['volumes'].is_a?(Array) && opts['osfamily'] != 'windows' pp_mounts = opts['volumes'].select { |item| item.include?(':') } if opts['volumes'].is_a?(Array) && opts['osfamily'] != 'windows' diff --git a/spec/helper/get_docker_run_flags.rb b/spec/helper/get_docker_run_flags.rb index eaa45197..3823f703 100644 --- a/spec/helper/get_docker_run_flags.rb +++ b/spec/helper/get_docker_run_flags.rb @@ -5,25 +5,15 @@ def get_docker_run_flags(args) flags = [] - if args['username'] - flags << "-u '#{args['username'].shellescape}'" - end + flags << "-u '#{args['username'].shellescape}'" if args['username'] - if args['hostname'] - flags << "-h '#{args['hostname'].shellescape}'" - end + flags << "-h '#{args['hostname'].shellescape}'" if args['hostname'] - if args['restart'] - flags << "--restart '#{args['restart']}'" - end + flags << "--restart '#{args['restart']}'" if args['restart'] - if args['net'].is_a? String - flags << "--net #{args['net']}" - end + flags << "--net #{args['net']}" if args['net'].is_a? String - if args['memory_limit'] - flags << "-m #{args['memory_limit']}" - end + flags << "-m #{args['memory_limit']}" if args['memory_limit'] cpusets = [args['cpuset']].flatten.compact @@ -32,29 +22,17 @@ def get_docker_run_flags(args) flags << "--cpuset-cpus=#{value}" end - if args['disable_network'] - flags << '-n false' - end + flags << '-n false' if args['disable_network'] - if args['privileged'] - flags << '--privileged' - end + flags << '--privileged' if args['privileged'] - if args['health_check_cmd'] && args['health_check_cmd'].to_s != 'undef' - flags << "--health-cmd='#{args['health_check_cmd']}'" - end + flags << "--health-cmd='#{args['health_check_cmd']}'" if args['health_check_cmd'] && args['health_check_cmd'].to_s != 'undef' - if args['health_check_interval'] && args['health_check_interval'].to_s != 'undef' - flags << "--health-interval=#{args['health_check_interval']}s" - end + flags << "--health-interval=#{args['health_check_interval']}s" if args['health_check_interval'] && args['health_check_interval'].to_s != 'undef' - if args['tty'] - flags << '-t' - end + flags << '-t' if args['tty'] - if args['read_only'] - flags << '--read-only=true' - end + flags << '--read-only=true' if args['read_only'] params_join_char = if args['osfamily'] && args['osfamily'].to_s != 'undef' args['osfamily'].casecmp('windows').zero? ? " `\n" : " \\\n" diff --git a/spec/helper/get_docker_secrets_flags.rb b/spec/helper/get_docker_secrets_flags.rb index a6173627..70460948 100644 --- a/spec/helper/get_docker_secrets_flags.rb +++ b/spec/helper/get_docker_secrets_flags.rb @@ -5,21 +5,15 @@ def get_docker_secrets_flags(args) flags = [] - if args['ensure'].to_s == 'present' - flags << 'create' - end + flags << 'create' if args['ensure'].to_s == 'present' - if args['secret_name'] && args['secret_name'].to_s != 'undef' - flags << "'#{args['secret_name']}'" - end + flags << "'#{args['secret_name']}'" if args['secret_name'] && args['secret_name'].to_s != 'undef' - if args['secret_path'] && args['secret_path'].to_s != 'undef' - flags << "'#{args['secret_path']}'" - end + flags << "'#{args['secret_path']}'" if args['secret_path'] && args['secret_path'].to_s != 'undef' multi_flags = ->(values, format) { filtered = [values].flatten.compact - filtered.map { |val| format + " \\\n" % val } + filtered.map { |val| format + (" \\\n" % val) } } [ ['-l %s', 'label'], diff --git a/spec/helper/get_docker_service_flags.rb b/spec/helper/get_docker_service_flags.rb index c33daece..bfd01ba3 100644 --- a/spec/helper/get_docker_service_flags.rb +++ b/spec/helper/get_docker_service_flags.rb @@ -5,13 +5,9 @@ def get_docker_service_flags(args) flags = [] - if args['service_name'] && args['service_name'].to_s != 'undef' - flags << "'#{args['service_name']}'" - end + flags << "'#{args['service_name']}'" if args['service_name'] && args['service_name'].to_s != 'undef' - if args['detach'].to_s != 'false' - flags << '--detach' - end + flags << '--detach' if args['detach'].to_s != 'false' if args['env'].is_a? Array args['env'].each do |env| @@ -45,21 +41,13 @@ def get_docker_service_flags(args) flags << "--publish '#{args['publish']}'" end - if args['replicas'] && args['replicas'].to_s != 'undef' - flags << "--replicas '#{args['replicas']}'" - end + flags << "--replicas '#{args['replicas']}'" if args['replicas'] && args['replicas'].to_s != 'undef' - if args['tty'].to_s != 'false' - flags << '--tty' - end + flags << '--tty' if args['tty'].to_s != 'false' - if args['user'] && args['user'].to_s != 'undef' - flags << "--user '#{args['user']}'" - end + flags << "--user '#{args['user']}'" if args['user'] && args['user'].to_s != 'undef' - if args['workdir'] && args['workdir'].to_s != 'undef' - flags << "--workdir '#{args['workdir']}'" - end + flags << "--workdir '#{args['workdir']}'" if args['workdir'] && args['workdir'].to_s != 'undef' if args['extra_params'].is_a? Array args['extra_params'].each do |param| @@ -67,9 +55,7 @@ def get_docker_service_flags(args) end end - if args['host_socket'] && args['host_socket'].to_s != 'undef' - flags << "-H '#{args['host_socket']}'" - end + flags << "-H '#{args['host_socket']}'" if args['host_socket'] && args['host_socket'].to_s != 'undef' if args['registry_mirror'].is_a? Array args['registry_mirror'].each do |param| @@ -79,9 +65,7 @@ def get_docker_service_flags(args) flags << "--registry-mirror='#{args['registry_mirror']}'" end - if args['image'] && args['image'].to_s != 'undef' - flags << "'#{args['image']}'" - end + flags << "'#{args['image']}'" if args['image'] && args['image'].to_s != 'undef' if args['command'].is_a? Array flags << args['command'].join(' ') diff --git a/spec/helper/get_docker_stack_flags.rb b/spec/helper/get_docker_stack_flags.rb index 2aa873e8..2785b5d3 100644 --- a/spec/helper/get_docker_stack_flags.rb +++ b/spec/helper/get_docker_stack_flags.rb @@ -3,9 +3,7 @@ def get_docker_stack_flags(args) flags = [] - if args['bundle_file'] && args['bundle_file'].to_s != 'undef' - flags << "--bundle-file '#{args['bundle_file']}'" - end + flags << "--bundle-file '#{args['bundle_file']}'" if args['bundle_file'] && args['bundle_file'].to_s != 'undef' if args['compose_files'] && args['compose_files'].to_s != 'undef' args['compose_files'].each do |file| @@ -13,17 +11,11 @@ def get_docker_stack_flags(args) end end - if args['resolve_image'] && args['resolve_image'].to_s != 'undef' - flags << "--resolve-image '#{args['resolve_image']}'" - end + flags << "--resolve-image '#{args['resolve_image']}'" if args['resolve_image'] && args['resolve_image'].to_s != 'undef' - if args['prune'] && args['prune'].to_s != 'undef' - flags << '--prune' - end + flags << '--prune' if args['prune'] && args['prune'].to_s != 'undef' - if args['with_registry_auth'] && args['with_registry_auth'].to_s != 'undef' - flags << '--with-registry-auth' - end + flags << '--with-registry-auth' if args['with_registry_auth'] && args['with_registry_auth'].to_s != 'undef' flags.flatten.join(' ') end diff --git a/spec/helper/get_docker_swarm_init_flags.rb b/spec/helper/get_docker_swarm_init_flags.rb index f496e5b9..97a73e77 100644 --- a/spec/helper/get_docker_swarm_init_flags.rb +++ b/spec/helper/get_docker_swarm_init_flags.rb @@ -3,21 +3,13 @@ def get_docker_swarm_init_flags(args) flags = [] - if args['init'].to_s != 'false' - flags << 'init' - end + flags << 'init' if args['init'].to_s != 'false' - if args['advertise_addr'] && args['advertise_addr'].to_s != 'undef' - flags << "--advertise-addr '#{args['advertise_addr']}'" - end + flags << "--advertise-addr '#{args['advertise_addr']}'" if args['advertise_addr'] && args['advertise_addr'].to_s != 'undef' - if args['autolock'].to_s != 'false' - flags << '--autolock' - end + flags << '--autolock' if args['autolock'].to_s != 'false' - if args['cert_expiry'] && args['cert_expiry'].to_s != 'undef' - flags << "--cert-expiry '#{args['cert_expiry']}'" - end + flags << "--cert-expiry '#{args['cert_expiry']}'" if args['cert_expiry'] && args['cert_expiry'].to_s != 'undef' if args['default_addr_pool'].is_a? Array args['default_addr_pool'].each do |default_addr_pool| @@ -25,33 +17,19 @@ def get_docker_swarm_init_flags(args) end end - if args['default_addr_pool_mask_length'] && args['default_addr_pool_mask_length'].to_s != 'undef' - flags << "--default-addr-pool-mask-length '#{args['default_addr_pool_mask_length']}'" - end + flags << "--default-addr-pool-mask-length '#{args['default_addr_pool_mask_length']}'" if args['default_addr_pool_mask_length'] && args['default_addr_pool_mask_length'].to_s != 'undef' - if args['dispatcher_heartbeat'] && args['dispatcher_heartbeat'].to_s != 'undef' - flags << "--dispatcher-heartbeat '#{args['dispatcher_heartbeat']}'" - end + flags << "--dispatcher-heartbeat '#{args['dispatcher_heartbeat']}'" if args['dispatcher_heartbeat'] && args['dispatcher_heartbeat'].to_s != 'undef' - if args['external_ca'] && args['external_ca'].to_s != 'undef' - flags << "--external-ca '#{args['external_ca']}'" - end + flags << "--external-ca '#{args['external_ca']}'" if args['external_ca'] && args['external_ca'].to_s != 'undef' - if args['force_new_cluster'].to_s != 'false' - flags << '--force-new-cluster' - end + flags << '--force-new-cluster' if args['force_new_cluster'].to_s != 'false' - if args['listen_addr'] && args['listen_addr'].to_s != 'undef' - flags << "--listen-addr '#{args['listen_addr']}'" - end + flags << "--listen-addr '#{args['listen_addr']}'" if args['listen_addr'] && args['listen_addr'].to_s != 'undef' - if args['max_snapshots'] && args['max_snapshots'].to_s != 'undef' - flags << "--max-snapshots '#{args['max_snapshots']}'" - end + flags << "--max-snapshots '#{args['max_snapshots']}'" if args['max_snapshots'] && args['max_snapshots'].to_s != 'undef' - if args['snapshot_interval'] && args['snapshot_interval'].to_s != 'undef' - flags << "--snapshot-interval '#{args['snapshot_interval']}'" - end + flags << "--snapshot-interval '#{args['snapshot_interval']}'" if args['snapshot_interval'] && args['snapshot_interval'].to_s != 'undef' flags.flatten.join(' ') end diff --git a/spec/helper/get_docker_swarm_join_flags.rb b/spec/helper/get_docker_swarm_join_flags.rb index 4794eaab..f6d2dc8f 100644 --- a/spec/helper/get_docker_swarm_join_flags.rb +++ b/spec/helper/get_docker_swarm_join_flags.rb @@ -3,21 +3,13 @@ def get_docker_swarm_join_flags(args) flags = [] - if args['join'].to_s != 'false' - flags << 'join' - end + flags << 'join' if args['join'].to_s != 'false' - if args['advertise_addr'] && args['advertise_addr'].to_s != 'undef' - flags << "--advertise-addr '#{args['advertise_addr']}'" - end + flags << "--advertise-addr '#{args['advertise_addr']}'" if args['advertise_addr'] && args['advertise_addr'].to_s != 'undef' - if args['listen_addr'] && args['listen_addr'].to_s != 'undef' - flags << "--listen-addr \"#{args['listen_addr']}\"" - end + flags << "--listen-addr \"#{args['listen_addr']}\"" if args['listen_addr'] && args['listen_addr'].to_s != 'undef' - if args['token'] && args['token'].to_s != 'undef' - flags << "--token '#{args['token']}'" - end + flags << "--token '#{args['token']}'" if args['token'] && args['token'].to_s != 'undef' flags.flatten.join(' ') end diff --git a/spec/helper/get_values_init.rb b/spec/helper/get_values_init.rb index 2b6422c9..c35b21f9 100644 --- a/spec/helper/get_values_init.rb +++ b/spec/helper/get_values_init.rb @@ -35,22 +35,14 @@ def get_values_init(_params, _facts) docker_package_name = _params['docker_ce_package_name'] end else + package_location = _params['docker_package_location'] + package_key_source = _params['docker_package_key_source'] + package_key_check_source = _params['docker_package_key_check_source'] case _facts[:os]['family'] when 'Debian' - package_location = _params['docker_package_location'] - package_key_source = _params['docker_package_key_source'] - package_key_check_source = _params['docker_package_key_check_source'] - package_key = _params['docker_package_key_id'] + package_key = _params['docker_package_key_id'] package_repos = 'main' release = _params['docker_package_release'] - when 'RedHat' - package_location = _params['docker_package_location'] - package_key_source = _params['docker_package_key_source'] - package_key_check_source = _params['docker_package_key_check_source'] - else - package_location = _params['docker_package_location'] - package_key_source = _params['docker_package_key_source'] - package_key_check_source = _params['docker_package_key_check_source'] end docker_start_command = _params['docker_engine_start_command'] @@ -64,14 +56,14 @@ def get_values_init(_params, _facts) end { - 'docker_package_name' => docker_package_name, - 'docker_start_command' => docker_start_command, - 'package_key' => package_key, + 'docker_package_name' => docker_package_name, + 'docker_start_command' => docker_start_command, + 'package_key' => package_key, 'package_key_check_source' => package_key_check_source, - 'package_key_source' => package_key_source, - 'package_location' => package_location, - 'package_repos' => package_repos, - 'release' => release, - 'root_dir_flag' => root_dir_flag, + 'package_key_source' => package_key_source, + 'package_location' => package_location, + 'package_repos' => package_repos, + 'release' => release, + 'root_dir_flag' => root_dir_flag } end diff --git a/spec/helper/windows_facts.rb b/spec/helper/windows_facts.rb index b32359b1..f5516855 100644 --- a/spec/helper/windows_facts.rb +++ b/spec/helper/windows_facts.rb @@ -2,9 +2,9 @@ def windows_facts { - 'docker_program_data_path' => 'C:/ProgramData', + 'docker_program_data_path' => 'C:/ProgramData', 'docker_program_files_path' => 'C:/Program Files', - 'docker_systemroot' => 'C:/Windows', - 'docker_user_temp_path' => 'C:/Users/Administrator/AppData/Local/Temp', + 'docker_systemroot' => 'C:/Windows', + 'docker_user_temp_path' => 'C:/Users/Administrator/AppData/Local/Temp' } end diff --git a/spec/shared_examples/compose.rb b/spec/shared_examples/compose.rb index bd4c3952..d9ff9f57 100644 --- a/spec/shared_examples/compose.rb +++ b/spec/shared_examples/compose.rb @@ -22,29 +22,29 @@ docker_compose_location_versioned = "#{install_path}/docker-compose-#{version}#{file_extension}" if ensure_value == 'present' - docker_compose_url = if raw_url != :undef - raw_url - else + docker_compose_url = if raw_url == :undef "#{base_url}/#{version}/docker-compose-#{_facts[:kernel]}-x86_64#{file_extension}" + else + raw_url end - proxy_opt = if proxy != :undef - "--proxy #{proxy}" - else + proxy_opt = if proxy == :undef '' + else + "--proxy #{proxy}" end if _facts[:os]['family'] == 'windows' docker_download_command = "if (Invoke-WebRequest #{docker_compose_url} #{proxy_opt} -UseBasicParsing -OutFile \"#{docker_compose_location_versioned}\") { exit 0 } else { exit 1 }" it { - is_expected.to contain_exec("Install Docker Compose #{version}").with( + expect(subject).to contain_exec("Install Docker Compose #{version}").with( # 'command' => template('docker/windows/download_docker_compose.ps1.erb'), 'provider' => 'powershell', - 'creates' => docker_compose_location_versioned, + 'creates' => docker_compose_location_versioned, ) - is_expected.to contain_file(docker_compose_location).with( + expect(subject).to contain_file(docker_compose_location).with( 'ensure' => 'link', 'target' => docker_compose_location_versioned, ).that_requires( @@ -54,28 +54,28 @@ else if curl_ensure it { - is_expected.to contain_package('curl') + expect(subject).to contain_package('curl') } end it { - is_expected.to contain_exec("Install Docker Compose #{version}").with( - 'path' => '/usr/bin/', - 'cwd' => '/tmp', + expect(subject).to contain_exec("Install Docker Compose #{version}").with( + 'path' => '/usr/bin/', + 'cwd' => '/tmp', 'command' => "curl -s -S -L #{proxy_opt} #{docker_compose_url} -o #{docker_compose_location_versioned}", 'creates' => docker_compose_location_versioned, ).that_requires( 'Package[curl]', ) - is_expected.to contain_file(docker_compose_location_versioned).with( + expect(subject).to contain_file(docker_compose_location_versioned).with( 'owner' => file_owner, - 'mode' => '0755', + 'mode' => '0755', ).that_requires( "Exec[Install Docker Compose #{version}]", ) - is_expected.to contain_file(docker_compose_location).with( + expect(subject).to contain_file(docker_compose_location).with( 'ensure' => 'link', 'target' => docker_compose_location_versioned, ).that_requires( @@ -86,11 +86,11 @@ else it { - is_expected.to contain_file(docker_compose_location_versioned).with( + expect(subject).to contain_file(docker_compose_location_versioned).with( 'ensure' => 'absent', ) - is_expected.to contain_file(docker_compose_location).with( + expect(subject).to contain_file(docker_compose_location).with( 'ensure' => 'absent', ) } diff --git a/spec/shared_examples/config.rb b/spec/shared_examples/config.rb index 7501b1ec..6d97da3a 100644 --- a/spec/shared_examples/config.rb +++ b/spec/shared_examples/config.rb @@ -4,18 +4,18 @@ docker_users = _params['docker_users'] it { - is_expected.to contain_class('docker::config') + expect(subject).to contain_class('docker::config') } unless docker_users.empty? docker_users.each do |user| - if %r{windows}.match?(_facts[:os]['family']) + if _facts[:os]['family'].include?('windows') it { - is_expected.to contain_docker__windows_account(user) + expect(subject).to contain_docker__windows_account(user) } else it { - is_expected.to contain_docker__system_user(user) + expect(subject).to contain_docker__system_user(user) } include_examples 'system_user', user, _params['docker_group'] diff --git a/spec/shared_examples/exec.rb b/spec/shared_examples/exec.rb index 2889d003..b71a7abd 100644 --- a/spec/shared_examples/exec.rb +++ b/spec/shared_examples/exec.rb @@ -28,8 +28,8 @@ docker_exec_flags = get_docker_exec_flags( 'detach' => detach, 'interactive' => interactive, - 'tty' => tty, - 'env' => env, + 'tty' => tty, + 'env' => env, ) sanitised_container = if sanitise_name @@ -41,18 +41,14 @@ exec = "#{docker_command} exec #{docker_exec_flags} #{sanitised_container} #{command}" unless_command = case unless_value - when :undef - nil - when '' + when :undef, '' nil else "#{docker_command} exec #{docker_exec_flags} #{sanitised_container} #{unless_value}" end onlyif_command = case onlyif - when :undef - nil - when '' + when :undef, '' nil when 'running' "#{docker_command} ps --no-trunc --format='table {{.Names}}' | grep '^#{sanitised_container}$'" @@ -61,14 +57,14 @@ end it { - is_expected.to contain_exec(exec).with( + expect(subject).to contain_exec(exec).with( 'environment' => exec_environment, - 'onlyif' => onlyif_command, - 'path' => exec_path, + 'onlyif' => onlyif_command, + 'path' => exec_path, 'refreshonly' => refreshonly, - 'timeout' => exec_timeout, - 'provider' => exec_provider, - 'unless' => unless_command, + 'timeout' => exec_timeout, + 'provider' => exec_provider, + 'unless' => unless_command, ) } end diff --git a/spec/shared_examples/image.rb b/spec/shared_examples/image.rb index 95cc4cb4..6a4492fa 100644 --- a/spec/shared_examples/image.rb +++ b/spec/shared_examples/image.rb @@ -30,11 +30,11 @@ end it { - is_expected.to contain_file(update_docker_image_path).with( - 'ensure' => 'present', - 'owner' => update_docker_image_owner, - 'group' => update_docker_image_owner, - 'mode' => '0555', + expect(subject).to contain_file(update_docker_image_path).with( + 'ensure' => 'present', + 'owner' => update_docker_image_owner, + 'group' => update_docker_image_owner, + 'mode' => '0555', # 'content' => template($update_docker_image_template), ) } @@ -85,44 +85,44 @@ if ensure_value == 'absent' it { - is_expected.to contain_exec(image_remove).with( - 'path' => exec_path, + expect(subject).to contain_exec(image_remove).with( + 'path' => exec_path, 'environment' => exec_environment, - 'onlyif' => _image_find, - 'provider' => exec_provider, - 'timeout' => exec_timeout, - 'logoutput' => true, + 'onlyif' => _image_find, + 'provider' => exec_provider, + 'timeout' => exec_timeout, + 'logoutput' => true, ) } elsif ensure_value == 'latest' || image_tag == 'latest' it { - is_expected.to contain_notify("Check if image #{image_arg} is in-sync").with( + expect(subject).to contain_notify("Check if image #{image_arg} is in-sync").with( 'noop' => false, ).that_notifies( "Exec[#{image_install}]", ) - is_expected.to contain_exec(image_install).with( + expect(subject).to contain_exec(image_install).with( 'environment' => exec_environment, - 'path' => exec_path, - 'timeout' => exec_timeout, - 'returns' => ['0', '2'], + 'path' => exec_path, + 'timeout' => exec_timeout, + 'returns' => ['0', '2'], - 'provider' => exec_provider, - 'logoutput' => true, + 'provider' => exec_provider, + 'logoutput' => true, ).that_requires( "File[#{update_docker_image_path}]", ).that_notifies( "Exec[echo 'Update of #{image_arg} complete']", ) - is_expected.to contain_exec("echo 'Update of #{image_arg} complete'").with( + expect(subject).to contain_exec("echo 'Update of #{image_arg} complete'").with( 'environment' => exec_environment, - 'path' => exec_path, - 'timeout' => exec_timeout, + 'path' => exec_path, + 'timeout' => exec_timeout, - 'provider' => exec_provider, - 'logoutput' => true, + 'provider' => exec_provider, + 'logoutput' => true, 'refreshonly' => true, ).that_requires( "File[#{update_docker_image_path}]", @@ -130,14 +130,14 @@ } elsif ensure_value == 'present' it { - is_expected.to contain_exec(image_install).with( - 'unless' => _image_find, + expect(subject).to contain_exec(image_install).with( + 'unless' => _image_find, 'environment' => exec_environment, - 'path' => exec_path, - 'timeout' => exec_timeout, - 'returns' => ['0', '2'], - 'provider' => exec_provider, - 'logoutput' => true, + 'path' => exec_path, + 'timeout' => exec_timeout, + 'returns' => ['0', '2'], + 'provider' => exec_provider, + 'logoutput' => true, ).that_requires( "File[#{update_docker_image_path}]", ) diff --git a/spec/shared_examples/install.rb b/spec/shared_examples/install.rb index c6e08138..00e0bd62 100644 --- a/spec/shared_examples/install.rb +++ b/spec/shared_examples/install.rb @@ -18,52 +18,53 @@ if _params['package_source'] != :undef it { - is_expected.to contain_class('docker::install') + expect(subject).to contain_class('docker::install') } case _params['package_source'] when 'docker-engine' it { - is_expected.to contain_package('docker').with( + expect(subject).to contain_package('docker').with( { - 'ensure' => ensure_value, - 'source' => _params['package_source'], - 'name' => _params['docker_engine_package_name'], + 'ensure' => ensure_value, + 'source' => _params['package_source'], + 'name' => _params['docker_engine_package_name'] }.merge(docker_hash), ) } when 'docker-ce' it { - is_expected.to contain_package('docker').with( + expect(subject).to contain_package('docker').with( { - 'ensure' => ensure_value, - 'source' => _params['package_source'], - 'name' => _params['docker_ce_package_name'], + 'ensure' => ensure_value, + 'source' => _params['package_source'], + 'name' => _params['docker_ce_package_name'] }.merge(docker_hash), ) } + it { - is_expected.to contain_package('docker-ce-cli').with( + expect(subject).to contain_package('docker-ce-cli').with( { - 'ensure' => ensure_value, - 'source' => _params['package_source'], - 'name' => _params['docker_ce_cli_package_name'], + 'ensure' => ensure_value, + 'source' => _params['package_source'], + 'name' => _params['docker_ce_cli_package_name'] }.merge(docker_hash), ) } end elsif _facts[:os]['family'] != 'windows' it { - is_expected.to contain_package('docker').with( + expect(subject).to contain_package('docker').with( 'ensure' => ensure_value, - 'name' => values['docker_package_name'], + 'name' => values['docker_package_name'], ) } if ensure_value == 'absent' _params['dependent_packages'].each do |dependent_package| it { - is_expected.to contain_package(dependent_package).with( + expect(subject).to contain_package(dependent_package).with( 'ensure' => ensure_value, ) } @@ -72,25 +73,25 @@ elsif ensure_value == 'absent' it { if _params['version'] != :undef - is_expected.to contain_exec('remove-docker-package').with( + expect(subject).to contain_exec('remove-docker-package').with( 'command' => %r{-RequiredVersion #{_params['version']}}, ) end - is_expected.to contain_exec('remove-docker-package').with( - 'command' => %r{\$package=Uninstall-Package #{_params['docker_ee_package_name']} -ProviderName \$dockerProviderName -Force}, - 'provider' => 'powershell', - 'unless' => %r{\$package=Get-Package #{_params['docker_ee_package_name']} -ProviderName \$dockerProviderName -ErrorAction Ignore}, + expect(subject).to contain_exec('remove-docker-package').with( + 'command' => %r{\$package=Uninstall-Package #{_params['docker_ee_package_name']} -ProviderName \$dockerProviderName -Force}, + 'provider' => 'powershell', + 'unless' => %r{\$package=Get-Package #{_params['docker_ee_package_name']} -ProviderName \$dockerProviderName -ErrorAction Ignore}, 'logoutput' => true, ) } else if _params['package_location'] it { - is_expected.to contain_exec('install-docker-package').with( - 'command' => %r{Invoke-webrequest -UseBasicparsing -Outfile \$dockerLocation "#{_params['docker_download_url']}"}, - 'provider' => 'powershell', - 'unless' => %r{\$webRequest = \[System.Net.HttpWebRequest\]::Create("#{_params['docker_download_url']}");}, + expect(subject).to contain_exec('install-docker-package').with( + 'command' => %r{Invoke-webrequest -UseBasicparsing -Outfile \$dockerLocation "#{_params['docker_download_url']}"}, + 'provider' => 'powershell', + 'unless' => %r{\$webRequest = \[System.Net.HttpWebRequest\]::Create("#{_params['docker_download_url']}");}, 'logoutput' => true, ).that_notifies( 'Exec[service-restart-on-failure]', @@ -99,7 +100,7 @@ else it { if _params['nuget_package_provider_version'] != :undef - is_expected. to contain_exec( + expect(subject).to contain_exec( 'install-docker-package', ).with_command( %r{-RequiredVersion #{_params['nuget_package_provider_version']}}, @@ -109,7 +110,7 @@ end if _params['docker_msft_provider_version'] != :undef - is_expected. to contain_exec( + expect(subject).to contain_exec( 'install-docker-package', ).with_command( %r{-RequiredVersion #{_params['docker_msft_provider_version']}}, @@ -119,7 +120,7 @@ end if _params['version'] != :undef - is_expected.to contain_exec( + expect(subject).to contain_exec( 'install-docker-package', ).with_command( %r{-RequiredVersion #{_params['version']}}, @@ -128,10 +129,10 @@ ) end - is_expected.to contain_exec('install-docker-package').with( - 'command' => %r{\$package=Install-Package #{_params['docker_ee_package_name']} -ProviderName \$dockerProviderName -Force}, - 'provider' => 'powershell', - 'unless' => %r{\$package=Get-Package #{_params['docker_ee_package_name']} -ProviderName \$dockerProviderName}, + expect(subject).to contain_exec('install-docker-package').with( + 'command' => %r{\$package=Install-Package #{_params['docker_ee_package_name']} -ProviderName \$dockerProviderName -Force}, + 'provider' => 'powershell', + 'unless' => %r{\$package=Get-Package #{_params['docker_ee_package_name']} -ProviderName \$dockerProviderName}, 'logoutput' => true, ).that_notifies( 'Exec[service-restart-on-failure]', @@ -140,11 +141,11 @@ end it { - is_expected.to contain_exec('service-restart-on-failure').with( - 'command' => 'SC.exe failure Docker reset= 432000 actions= restart/30000/restart/60000/restart/60000', + expect(subject).to contain_exec('service-restart-on-failure').with( + 'command' => 'SC.exe failure Docker reset= 432000 actions= restart/30000/restart/60000/restart/60000', 'refreshonly' => true, - 'logoutput' => true, - 'provider' => 'powershell', + 'logoutput' => true, + 'provider' => 'powershell', ) } end diff --git a/spec/shared_examples/machine.rb b/spec/shared_examples/machine.rb index 3541d5d6..9661a837 100644 --- a/spec/shared_examples/machine.rb +++ b/spec/shared_examples/machine.rb @@ -38,15 +38,15 @@ docker_download_command = "if (Invoke-WebRequest #{docker_machine_url} #{proxy_opt} -UseBasicParsing -OutFile \"#{docker_machine_location_versioned}\") { exit 0 } else { exit 1 }" it { - is_expected.to contain_exec("Install Docker Machine #{version}").with( + expect(subject).to contain_exec("Install Docker Machine #{version}").with( # 'command' => template('docker/windows/download_docker_machine.ps1.erb'), 'provider' => 'powershell', - 'creates' => docker_machine_location_versioned, + 'creates' => docker_machine_location_versioned, ) - is_expected.to contain_file(docker_machine_location).with( - 'ensure' => 'link', - 'target' => docker_machine_location_versioned, + expect(subject).to contain_file(docker_machine_location).with( + 'ensure' => 'link', + 'target' => docker_machine_location_versioned, ).that_requires( "Exec[Install Docker Machine #{version}]", ) @@ -54,41 +54,41 @@ else if curl_ensure it { - is_expected.to contain_package('curl') + expect(subject).to contain_package('curl') } end it { - is_expected.to contain_exec("Install Docker Machine #{version}").with( - 'path' => '/usr/bin/', - 'cwd' => '/tmp', + expect(subject).to contain_exec("Install Docker Machine #{version}").with( + 'path' => '/usr/bin/', + 'cwd' => '/tmp', 'command' => "curl -s -S -L #{proxy_opt} #{docker_machine_url} -o #{docker_machine_location_versioned}", 'creates' => docker_machine_location_versioned, ).that_requires( 'Package[curl]', ) - is_expected.to contain_file(docker_machine_location_versioned).with( + expect(subject).to contain_file(docker_machine_location_versioned).with( 'owner' => file_owner, - 'mode' => '0755', + 'mode' => '0755', ).that_requires( "Exec[Install Docker Machine #{version}]", ) - is_expected.to contain_file(docker_machine_location).with( - 'ensure' => 'link', - 'target' => docker_machine_location_versioned, + expect(subject).to contain_file(docker_machine_location).with( + 'ensure' => 'link', + 'target' => docker_machine_location_versioned, ).that_requires( "File[#{docker_machine_location_versioned}]", ) } end else - is_expected.to contain_file(docker_machine_location_versioned).with( + expect(subject).to contain_file(docker_machine_location_versioned).with( 'ensure' => 'absent', ) - is_expected.to contain_file(docker_machine_location).with( + expect(subject).to contain_file(docker_machine_location).with( 'ensure' => 'absent', ) end diff --git a/spec/shared_examples/params.rb b/spec/shared_examples/params.rb index 48290543..9856dffb 100644 --- a/spec/shared_examples/params.rb +++ b/spec/shared_examples/params.rb @@ -4,16 +4,16 @@ case _facts[:os]['family'] when 'Debian' it { - is_expected.to contain_class('docker::params') - is_expected.to contain_class('docker::systemd_reload') - is_expected.to contain_exec('docker-systemd-reload').with( + expect(subject).to contain_class('docker::params') + expect(subject).to contain_class('docker::systemd_reload') + expect(subject).to contain_exec('docker-systemd-reload').with( 'path' => [ '/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/', ], - 'command' => 'systemctl daemon-reload', + 'command' => 'systemctl daemon-reload', 'refreshonly' => 'true', ) } diff --git a/spec/shared_examples/plugin.rb b/spec/shared_examples/plugin.rb index 793cd3ac..fb09c0d5 100644 --- a/spec/shared_examples/plugin.rb +++ b/spec/shared_examples/plugin.rb @@ -17,29 +17,29 @@ if ensure_value == 'present' docker_plugin_install_flags = get_docker_plugin_install_flags( 'plugin_name' => plugin_name, - 'plugin_alias' => plugin_alias, - 'disable_on_install' => disable_on_install, + 'plugin_alias' => plugin_alias, + 'disable_on_install' => disable_on_install, 'disable_content_trust' => disable_content_trust, 'grant_all_permissions' => grant_all_permissions, - 'settings' => settings, + 'settings' => settings, ) exec_install = "#{docker_command} install #{docker_plugin_install_flags}" unless_install = "#{docker_command} ls --format='{{.PluginReference}}' | grep -w #{plugin_name}" it { - is_expected.to contain_exec("plugin install #{plugin_name}").with( - 'command' => exec_install, + expect(subject).to contain_exec("plugin install #{plugin_name}").with( + 'command' => exec_install, 'environment' => 'HOME=/root', - 'path' => ['/bin', '/usr/bin'], - 'timeout' => 0, - 'unless' => unless_install, + 'path' => ['/bin', '/usr/bin'], + 'timeout' => 0, + 'unless' => unless_install, ) } elsif ensure_value == 'absent' docker_plugin_remove_flags = get_docker_plugin_remove_flags( - 'plugin_name' => plugin_name, + 'plugin_name' => plugin_name, 'force_remove' => force_remove, ) @@ -47,43 +47,43 @@ onlyif_rm = "#{docker_command} ls --format='{{.PluginReference}}' | grep -w #{plugin_name}" it { - is_expected.to contain_exec("plugin remove #{plugin_name}").with( - 'command' => exec_rm, + expect(subject).to contain_exec("plugin remove #{plugin_name}").with( + 'command' => exec_rm, 'environment' => 'HOME=/root', - 'path' => ['/bin', '/usr/bin'], - 'timeout' => 0, - 'onlyif' => onlyif_rm, + 'path' => ['/bin', '/usr/bin'], + 'timeout' => 0, + 'onlyif' => onlyif_rm, ) } end if enabled docker_plugin_enable_flags = get_docker_plugin_enable_flags( - 'plugin_name' => plugin_name, + 'plugin_name' => plugin_name, 'plugin_alias' => plugin_alias, - 'timeout' => timeout, + 'timeout' => timeout, ) exec_enable = "#{docker_command} enable #{docker_plugin_enable_flags}" onlyif_enable = "#{docker_command} ls -f enabled=false --format='{{.PluginReference}}' | grep -w #{plugin_name}" it { - is_expected.to contain_exec("plugin enable #{plugin_name}").with( - 'command' => exec_enable, + expect(subject).to contain_exec("plugin enable #{plugin_name}").with( + 'command' => exec_enable, 'environment' => 'HOME=/root', - 'path' => ['/bin', '/usr/bin'], - 'timeout' => 0, - 'onlyif' => onlyif_enable, + 'path' => ['/bin', '/usr/bin'], + 'timeout' => 0, + 'onlyif' => onlyif_enable, ) } else it { - is_expected.to contain_exec("disable #{plugin_name}").with( - 'command' => "#{docker_command} disable #{plugin_name}", + expect(subject).to contain_exec("disable #{plugin_name}").with( + 'command' => "#{docker_command} disable #{plugin_name}", 'environment' => 'HOME=/root', - 'path' => ['/bin', '/usr/bin'], - 'timeout' => 0, - 'unless' => "#{docker_command} ls -f enabled=false --format='{{.PluginReference}}' | grep -w #{plugin_name}", + 'path' => ['/bin', '/usr/bin'], + 'timeout' => 0, + 'unless' => "#{docker_command} ls -f enabled=false --format='{{.PluginReference}}' | grep -w #{plugin_name}", ) } end diff --git a/spec/shared_examples/registry.rb b/spec/shared_examples/registry.rb index 6efc1701..df966185 100644 --- a/spec/shared_examples/registry.rb +++ b/spec/shared_examples/registry.rb @@ -25,7 +25,7 @@ exec_path = ['/bin', '/usr/bin'] exec_timeout = 0 exec_provider = nil - password_env = "\${password}" + password_env = '${password}' exec_user = local_user local_user_home = facts[:docker_home_dirs][local_user] end @@ -48,44 +48,21 @@ docker_auth = "#{title}#{auth_environment}#{auth_cmd}#{local_user}" - exec_env = if auth_environment != '' - exec_environment << auth_environment << "docker_auth=#{docker_auth}" - else + exec_env = if auth_environment == '' exec_environment << "docker_auth=#{docker_auth}" + else + exec_environment << auth_environment << "docker_auth=#{docker_auth}" end if receipt - if facts[:os]['family'] != 'windows' - server_strip = server.tr('/', '_') - local_user_strip = local_user.gsub('[-_]', '') - - _pass_hash = case pass_hash - when :undef - pw_hash(docker_auth, 'SHA-512', local_user_strip) - else - pass_hash - end - - auth_command = "#{auth_cmd} || rm -f \"/#{local_user_home}/registry-auth-puppet_receipt_#{server_strip}_#{local_user}\"" - - it { - is_expected.to contain_file('/${local_user_home}/registry-auth-puppet_receipt_${server_strip}_${local_user}').with( - 'ensure' => ensure_value, - 'content' => _pass_hash, - 'owner' => local_user, - 'group' => local_user, - ).that_notifies( - "Exec[#{title} auth]", - ) - } - else + if facts[:os]['family'] == 'windows' server_strip = server.gsub('[/:]', '_') passfile = "#{facts['docker_user_temp_path']}/registry-auth-puppet_receipt_#{server_strip}_#{local_user}" auth_command = "if (-not (#{auth_cmd})) { Remove-Item -Path #{passfile} -Force -Recurse -EA SilentlyContinue; exit 0 } else { exit 0 }" if ensure_value == 'absent' it { - is_expected.to contain_file(passfile).with( + expect(subject).to contain_file(passfile).with( 'ensure' => ensure_value, ).that_notifies( "Exec[#{title} auth]", @@ -93,30 +70,53 @@ } elsif ensure_value == 'present' it { - is_expected.to contain_exec(compute - hash).with( + expect(subject).to contain_exec(compute - hash).with( # 'command' => template('docker/windows/compute_hash.ps1.erb'), 'environment' => exec_env, - 'provider' => exec_provider, - 'logoutput' => true, + 'provider' => exec_provider, + 'logoutput' => true, # 'unless' => template('docker/windows/check_hash.ps1.erb'), ).that_notifies( "Exec[#{title} auth]", ) } end + else + server_strip = server.tr('/', '_') + local_user_strip = local_user.gsub('[-_]', '') + + _pass_hash = case pass_hash + when :undef + pw_hash(docker_auth, 'SHA-512', local_user_strip) + else + pass_hash + end + + auth_command = "#{auth_cmd} || rm -f \"/#{local_user_home}/registry-auth-puppet_receipt_#{server_strip}_#{local_user}\"" + + it { + expect(subject).to contain_file('/${local_user_home}/registry-auth-puppet_receipt_${server_strip}_${local_user}').with( + 'ensure' => ensure_value, + 'content' => _pass_hash, + 'owner' => local_user, + 'group' => local_user, + ).that_notifies( + "Exec[#{title} auth]", + ) + } end else auth_command = auth_cmd end it { - is_expected.to contain_exec("#{title} auth").with( + expect(subject).to contain_exec("#{title} auth").with( 'environment' => exec_env, - 'command' => auth_command, - 'user' => exec_user, - 'path' => exec_path, - 'timeout' => exec_timeout, - 'provider' => exec_provider, + 'command' => auth_command, + 'user' => exec_user, + 'path' => exec_path, + 'timeout' => exec_timeout, + 'provider' => exec_provider, 'refreshonly' => receipt, ) } diff --git a/spec/shared_examples/repos.rb b/spec/shared_examples/repos.rb index 9e3c0b46..8330f8ee 100644 --- a/spec/shared_examples/repos.rb +++ b/spec/shared_examples/repos.rb @@ -2,7 +2,7 @@ shared_examples 'repos' do |params, facts| it { - is_expected.to contain_class('docker::repos') + expect(subject).to contain_class('docker::repos') } values = get_values_init(params, facts) @@ -15,7 +15,7 @@ unless params['prerequired_packages'].empty? params['prerequired_packages'].each do |package| it { - is_expected.to contain_package(package) + expect(subject).to contain_package(package) } end end @@ -28,17 +28,17 @@ if params['use_upstream_package_source'] it { - is_expected.to contain_apt__source('docker').with( - 'location' => location, + expect(subject).to contain_apt__source('docker').with( + 'location' => location, 'architecture' => architecture, - 'release' => release, - 'repos' => package_repos, - 'key' => { - 'id' => package_key, - 'source' => key_source, + 'release' => release, + 'repos' => package_repos, + 'key' => { + 'id' => package_key, + 'source' => key_source }, 'include' => { - 'src' => false, + 'src' => false }, ) } @@ -53,30 +53,30 @@ end it { - is_expected.to contain_apt__pin('docker').with( - 'ensure' => pin_ensure, - 'origin' => repo_host, + expect(subject).to contain_apt__pin('docker').with( + 'ensure' => pin_ensure, + 'origin' => repo_host, 'priority' => params['apt_source_pin_level'], ) } if params['manage_package'] it { - is_expected.to contain_class('apt') + expect(subject).to contain_class('apt') } if facts[:os]['name'] == 'Debian' && facts[:os]['distro']['codename'] == 'wheezy' it { - is_expected.to contain_class('apt::backports') + expect(subject).to contain_class('apt::backports') } end it { params['prerequired_packages'].each do |package| - is_expected.to contain_exec('apt_update').that_comes_before("package[#{package}]") + expect(subject).to contain_exec('apt_update').that_comes_before("package[#{package}]") end - is_expected.to contain_apt__source('docker').that_comes_before('package[docker]') + expect(subject).to contain_apt__source('docker').that_comes_before('package[docker]') } end end @@ -98,10 +98,10 @@ if params['use_upstream_package_source'] it { - is_expected.to contain_yumrepo('docker').with( - 'descr' => 'Docker', - 'baseurl' => baseurl, - 'gpgkey' => gpgkey, + expect(subject).to contain_yumrepo('docker').with( + 'descr' => 'Docker', + 'baseurl' => baseurl, + 'gpgkey' => gpgkey, 'gpgcheck' => gpgkey_check, ).that_comes_before('package[docker]') } diff --git a/spec/shared_examples/run.rb b/spec/shared_examples/run.rb index 112e5a5c..75faecdb 100644 --- a/spec/shared_examples/run.rb +++ b/spec/shared_examples/run.rb @@ -62,17 +62,17 @@ volumes_from = params['volumes_from'] docker_group = defaults['docker_group'] - if socket_connect != [] + if socket_connect == [] + docker_command = defaults['docker_command'] + else sockopts = [socket_connect].join(',') docker_command = "#{defaults['docker_command']} -H #{sockopts}" - else - docker_command = defaults['docker_command'] end if use_name it { - is_expected.to contain_notify("docker use_name warning: #{title}").with( - 'message' => 'The use_name parameter is no-longer required and will be removed in a future release', + expect(subject).to contain_notify("docker use_name warning: #{title}").with( + 'message' => 'The use_name parameter is no-longer required and will be removed in a future release', 'withpath' => true, ) } @@ -87,32 +87,32 @@ docker_run_flags = get_docker_run_flags( 'cpuset' => [cpuset], - 'disable_network' => disable_network, - 'dns_search' => [dns_search], - 'dns' => [dns], - 'env_file' => [env_file], - 'env' => [env], - 'expose' => [expose], + 'disable_network' => disable_network, + 'dns_search' => [dns_search], + 'dns' => [dns], + 'env_file' => [env_file], + 'env' => [env], + 'expose' => [expose], 'extra_params' => [extra_parameters], - 'health_check_cmd' => health_check_cmd, + 'health_check_cmd' => health_check_cmd, 'health_check_interval' => health_check_interval, - 'hostentries' => [hostentries], - 'hostname' => hostname, - 'labels' => [labels], - 'links' => [links], - 'lxc_conf' => [lxc_conf], - 'memory_limit' => memory_limit, - 'net' => net, - 'osfamily' => facts[:os]['family'], - 'ports' => [ports], - 'privileged' => privileged, - 'read_only' => read_only, - 'restart_on_unhealthy' => restart_on_unhealthy, - 'socket_connect' => [socket_connect], - 'tty' => tty, - 'username' => username, - 'volumes_from' => [volumes_from], - 'volumes' => [volumes], + 'hostentries' => [hostentries], + 'hostname' => hostname, + 'labels' => [labels], + 'links' => [links], + 'lxc_conf' => [lxc_conf], + 'memory_limit' => memory_limit, + 'net' => net, + 'osfamily' => facts[:os]['family'], + 'ports' => [ports], + 'privileged' => privileged, + 'read_only' => read_only, + 'restart_on_unhealthy' => restart_on_unhealthy, + 'socket_connect' => [socket_connect], + 'tty' => tty, + 'username' => username, + 'volumes_from' => [volumes_from], + 'volumes' => [volumes], ) sanitised_title = title.gsub('[^0-9A-Za-z.\-_]', '-') @@ -124,7 +124,7 @@ exec_provider = 'powershell' cidfile = "#{facts['docker_user_temp_path']}/#{service_prefix}#{sanitised_title}.cid" restart_check = "#{docker_command} inspect #{sanitised_title} -f '{{ if eq \\\"unhealthy\\\" .State.Health.Status }} {{ .Name }}{{ end }}' | findstr #{sanitised_title}" - container_running_check = "\$state = #{docker_command} inspect #{sanitised_title} -f \"{{ .State.Running }}\"; if (\$state -ieq \"true\") { Exit 0 } else { Exit 1 }" + container_running_check = "$state = #{docker_command} inspect #{sanitised_title} -f \"{{ .State.Running }}\"; if ($state -ieq \"true\") { Exit 0 } else { Exit 1 }" else exec_environment = 'HOME=/root' exec_path = ['/bin', '/usr/bin'] @@ -137,122 +137,18 @@ if restart_on_unhealthy it { - is_expected.to contain_exec("Restart unhealthy container #{title} with docker").with( - 'command' => "#{docker_command} restart #{sanitised_title}", - 'onlyif' => restart_check, + expect(subject).to contain_exec("Restart unhealthy container #{title} with docker").with( + 'command' => "#{docker_command} restart #{sanitised_title}", + 'onlyif' => restart_check, 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, ) } end - if restart.to_s != 'undef' - if ensure_value == 'absent' - it { - is_expected.to contain_exec("stop #{title} with docker").with( - 'command' => "#{docker_command} stop --time=#{stop_wait_time} #{sanitised_title}", - 'onlyif' => "#{docker_command} inspect #{sanitised_title}", - 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, - ) - - is_expected.to contain_exec("remove #{title} with docker").with( - 'command' => "#{docker_command} rm -v #{sanitised_title}", - 'onlyif' => "#{docker_command} inspect #{sanitised_title}", - 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, - ) - - is_expected.to contain_file(cidfile).with( - 'ensure' => 'absent', - ) - } - else - run_with_docker_command = [ - "#{docker_command} run -d #{docker_run_flags}", - "--name #{sanitised_title} --cidfile=#{cidfile}", - "--restart=\"#{restart}\" #{image} #{command}", - ] - - # inspect = [ - # "#{docker_command} inspect #{sanitised_title}", - # ] - - # exec_unless = if custom_unless - # custom_unless << inspect - # else - # inspect - # end - - if facts[:puppetversion].to_i < 6 - it { - is_expected.to contain_exec("run #{title} with docker").with( - 'command' => run_with_docker_command.join(' '), - ## todo: - ## fix the following strange behavior: - ## expected that the catalogue would contain Exec[run command with docker] with unless set to [["docker inspect command"]] - ## but it is set to [["docker inspect command"], "docker inspect command"] - # 'unless' => exec_unless, - 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, - ) - } - - if !running - it { - is_expected.to contain_exec("stop #{title} with docker").with( - 'command' => "#{docker_command} stop --time=#{stop_wait_time} #{sanitised_title}", - 'onlyif' => container_running_check, - 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, - ) - } - else - it { - is_expected.to contain_exec("start #{title} with docker").with( - 'command' => "#{docker_command} start #{sanitised_title}", - 'unless' => container_running_check, - 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, - ) - } - end - else - docker_params_changed_args = { - 'sanitised_title' => sanitised_title, - 'osfamily' => facts[:os]['family'], - 'command' => run_with_docker_command.join(' '), - 'cidfile' => cidfile, - 'image' => image, - 'volumes' => volumes, - 'ports' => ports, - 'stop_wait_time' => stop_wait_time, - 'container_running' => running, - 'logfile_path' => facts[:os]['family'] == 'windows' ? facts['docker_user_temp_path'] : '/tmp', - } - - detect_changes = get_docker_params_changed(docker_params_changed_args) - - it { - is_expected.to contain_notify("#{title}_docker_params_changed").with( - 'message' => detect_changes, - ) - } - end - end - else + if restart.to_s == 'undef' case service_provider_real when 'systemd' hasstatus = true @@ -270,59 +166,61 @@ hasstatus = defaults['service_hasstatus'] end - _syslog_identifier = if syslog_identifier - syslog_identifier - else - "#{service_prefix}#{sanitised_title}" - end + _syslog_identifier = syslog_identifier || "#{service_prefix}#{sanitised_title}" if ensure_value == 'absent' if facts[:os]['family'] == 'windows' it { - is_expected.to contain_exec("stop container #{service_prefix}#{sanitised_title}").with( - 'command' => "#{docker_command} stop --time=#{stop_wait_time} #{sanitised_title}", - 'onlyif' => "#{docker_command} inspect #{sanitised_title}", + expect(subject).to contain_exec("stop container #{service_prefix}#{sanitised_title}").with( + 'command' => "#{docker_command} stop --time=#{stop_wait_time} #{sanitised_title}", + 'onlyif' => "#{docker_command} inspect #{sanitised_title}", 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, ).that_notifies( "Exec[remove container #{service_prefix}#{sanitised_title}]", ) } else it { - is_expected.to contain_service("#{service_prefix}#{sanitised_title}").with( - 'ensure' => false, - 'enable' => false, + expect(subject).to contain_service("#{service_prefix}#{sanitised_title}").with( + 'ensure' => false, + 'enable' => false, 'hasstatus' => hasstatus, - 'provider' => service_provider_real, + 'provider' => service_provider_real, ) } end it { - is_expected.to contain_exec("remove container #{service_prefix}#{sanitised_title}").with( - 'command' => "#{docker_command} rm -v #{sanitised_title}", - 'onlyif' => "#{docker_command} inspect #{sanitised_title}", + expect(subject).to contain_exec("remove container #{service_prefix}#{sanitised_title}").with( + 'command' => "#{docker_command} rm -v #{sanitised_title}", + 'onlyif' => "#{docker_command} inspect #{sanitised_title}", 'environment' => exec_environment, - 'path' => exec_path, + 'path' => exec_path, 'refreshonly' => true, - 'provider' => exec_provider, - 'timeout' => exec_timeout, + 'provider' => exec_provider, + 'timeout' => exec_timeout, ) } - if facts[:os]['family'] != 'windows' + if facts[:os]['family'] == 'windows' + it { + expect(subject).to contain_file(cidfile).with( + 'ensure' => 'absent', + ) + } + else it { - is_expected.to contain_file("/etc/systemd/system/#{service_prefix}#{sanitised_title}.service").with( + expect(subject).to contain_file("/etc/systemd/system/#{service_prefix}#{sanitised_title}.service").with( 'ensure' => 'absent', ) } if startscript it { - is_expected.to contain_file(startscript).with( + expect(subject).to contain_file(startscript).with( 'ensure' => 'absent', ) } @@ -330,62 +228,46 @@ if stopscript it { - is_expected.to contain_file(stopscript).with( + expect(subject).to contain_file(stopscript).with( 'ensure' => 'absent', ) } end - else - it { - is_expected.to contain_file(cidfile).with( - 'ensure' => 'absent', - ) - } end else if startscript it { - is_expected.to contain_file(startscript).with( - 'ensure' => 'file', - 'owner' => 'root', - 'group' => docker_group, - 'mode' => '0770', + expect(subject).to contain_file(startscript).with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => docker_group, + 'mode' => '0770', ) } end if stopscript it { - is_expected.to contain_file(stopscript).with( - 'ensure' => 'file', - 'owner' => 'root', - 'group' => docker_group, - 'mode' => '0770', + expect(subject).to contain_file(stopscript).with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => docker_group, + 'mode' => '0770', ) } end it { - is_expected.to contain_file(initscript).with( - 'ensure' => 'file', - 'owner' => 'root', - 'group' => docker_group, - 'mode' => mode, + expect(subject).to contain_file(initscript).with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => docker_group, + 'mode' => mode, ) } if manage_service - if !running - it { - is_expected.to contain_service("#{service_prefix}#{sanitised_title}").with( - 'ensure' => running, - 'enable' => false, - 'hasstatus' => hasstatus, - ).that_requires( - "File[#{initscript}]", - ) - } - else + if running if initscript == "/etc/init.d/#{service_prefix}#{sanitised_title}" transition_onlyif = [ "/usr/bin/test -f /var/run/docker-#{sanitised_title}.cid &&", @@ -393,13 +275,13 @@ ] it { - is_expected.to contain_exec("/bin/sh /etc/init.d/#{service_prefix}#{sanitised_title} stop").with( + expect(subject).to contain_exec("/bin/sh /etc/init.d/#{service_prefix}#{sanitised_title} stop").with( 'onlyif' => transition_onlyif.join(' '), ).that_comes_before( "File[/var/run/#{service_prefix}#{sanitised_title}.cid]", ) - is_expected.to contain_file("/var/run/#{service_prefix}#{sanitised_title}.cid").with( + expect(subject).to contain_file("/var/run/#{service_prefix}#{sanitised_title}.cid").with( 'ensure' => 'absent', ).that_comes_before( "File[#{initscript}]", @@ -408,10 +290,10 @@ end it { - is_expected.to contain_service("#{service_prefix}#{sanitised_title}").with( - 'ensure' => running, - 'enable' => true, - 'provider' => service_provider_real, + expect(subject).to contain_service("#{service_prefix}#{sanitised_title}").with( + 'ensure' => running, + 'enable' => true, + 'provider' => service_provider_real, 'hasstatus' => hasstatus, ).that_requires( "File[#{initscript}]", @@ -421,34 +303,44 @@ if docker_service if docker_service.to_s == 'true' it { - is_expected.to contain_service('docker').that_comes_before("Service[#{service_prefix}#{sanitised_title}]") + expect(subject).to contain_service('docker').that_comes_before("Service[#{service_prefix}#{sanitised_title}]") } if restart_service_on_docker_refresh.to_s == 'true' it { - is_expected.to contain_service('docker').that_notifies("Service[#{service_prefix}#{sanitised_title}]") + expect(subject).to contain_service('docker').that_notifies("Service[#{service_prefix}#{sanitised_title}]") } end else it { - is_expected.to contain_service('docker').with('name' => docker_service).that_comes_before("Service[#{service_prefix}#{sanitised_title}]") + expect(subject).to contain_service('docker').with('name' => docker_service).that_comes_before("Service[#{service_prefix}#{sanitised_title}]") } if restart_service_on_docker_refresh.to_s == 'true' it { - is_expected.to contain_service('docker').with('name' => docker_service).that_notifies("Service[#{service_prefix}#{sanitised_title}]") + expect(subject).to contain_service('docker').with('name' => docker_service).that_notifies("Service[#{service_prefix}#{sanitised_title}]") } end end end + else + it { + expect(subject).to contain_service("#{service_prefix}#{sanitised_title}").with( + 'ensure' => running, + 'enable' => false, + 'hasstatus' => hasstatus, + ).that_requires( + "File[#{initscript}]", + ) + } end end if service_provider_real == 'systemd' it { - is_expected.to contain_exec("docker-#{sanitised_title}-systemd-reload").with( - 'path' => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'], - 'command' => 'systemctl daemon-reload', + expect(subject).to contain_exec("docker-#{sanitised_title}-systemd-reload").with( + 'path' => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'], + 'command' => 'systemctl daemon-reload', 'refreshonly' => true, ).that_requires( [ @@ -468,5 +360,107 @@ } end end + elsif ensure_value == 'absent' + it { + expect(subject).to contain_exec("stop #{title} with docker").with( + 'command' => "#{docker_command} stop --time=#{stop_wait_time} #{sanitised_title}", + 'onlyif' => "#{docker_command} inspect #{sanitised_title}", + 'environment' => exec_environment, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, + ) + + expect(subject).to contain_exec("remove #{title} with docker").with( + 'command' => "#{docker_command} rm -v #{sanitised_title}", + 'onlyif' => "#{docker_command} inspect #{sanitised_title}", + 'environment' => exec_environment, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, + ) + + expect(subject).to contain_file(cidfile).with( + 'ensure' => 'absent', + ) + } + else + run_with_docker_command = [ + "#{docker_command} run -d #{docker_run_flags}", + "--name #{sanitised_title} --cidfile=#{cidfile}", + "--restart=\"#{restart}\" #{image} #{command}", + ] + + # inspect = [ + # "#{docker_command} inspect #{sanitised_title}", + # ] + + # exec_unless = if custom_unless + # custom_unless << inspect + # else + # inspect + # end + + if facts[:puppetversion].to_i < 6 + it { + expect(subject).to contain_exec("run #{title} with docker").with( + 'command' => run_with_docker_command.join(' '), + ## todo: + ## fix the following strange behavior: + ## expected that the catalogue would contain Exec[run command with docker] with unless set to [["docker inspect command"]] + ## but it is set to [["docker inspect command"], "docker inspect command"] + # 'unless' => exec_unless, + 'environment' => exec_environment, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, + ) + } + + if running + it { + expect(subject).to contain_exec("start #{title} with docker").with( + 'command' => "#{docker_command} start #{sanitised_title}", + 'unless' => container_running_check, + 'environment' => exec_environment, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, + ) + } + else + it { + expect(subject).to contain_exec("stop #{title} with docker").with( + 'command' => "#{docker_command} stop --time=#{stop_wait_time} #{sanitised_title}", + 'onlyif' => container_running_check, + 'environment' => exec_environment, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, + ) + } + end + else + docker_params_changed_args = { + 'sanitised_title' => sanitised_title, + 'osfamily' => facts[:os]['family'], + 'command' => run_with_docker_command.join(' '), + 'cidfile' => cidfile, + 'image' => image, + 'volumes' => volumes, + 'ports' => ports, + 'stop_wait_time' => stop_wait_time, + 'container_running' => running, + 'logfile_path' => (facts[:os]['family'] == 'windows') ? facts['docker_user_temp_path'] : '/tmp' + } + + detect_changes = get_docker_params_changed(docker_params_changed_args) + + it { + expect(subject).to contain_notify("#{title}_docker_params_changed").with( + 'message' => detect_changes, + ) + } + end end end diff --git a/spec/shared_examples/secrets.rb b/spec/shared_examples/secrets.rb index e3e5c00b..2e57812d 100644 --- a/spec/shared_examples/secrets.rb +++ b/spec/shared_examples/secrets.rb @@ -11,7 +11,7 @@ if ensure_value == 'present' docker_secrets_flags = get_docker_secrets_flags( 'ensure' => ensure_value, - 'label' => label, + 'label' => label, 'secret_name' => secret_name, 'secret_path' => secret_path, ) @@ -20,20 +20,20 @@ unless_secret = "#{docker_command} inspect #{secret_name}" it { - is_expected.to contain_exec("#{title} docker secret create").with( + expect(subject).to contain_exec("#{title} docker secret create").with( 'command' => exec_secret, - 'unless' => unless_secret, - 'path' => ['/bin', '/usr/bin'], + 'unless' => unless_secret, + 'path' => ['/bin', '/usr/bin'], ) } end if ensure_value == 'absent' it { - is_expected.to contain_exec("#{title} docker secret rm").with( + expect(subject).to contain_exec("#{title} docker secret rm").with( 'command' => "#{docker_command} rm #{secret_name}", - 'onlyif' => "#{docker_command} inspect #{secret_name}", - 'path' => ['/bin', '/usr/bin'], + 'onlyif' => "#{docker_command} inspect #{secret_name}", + 'path' => ['/bin', '/usr/bin'], ) } end diff --git a/spec/shared_examples/service.rb b/spec/shared_examples/service.rb index f3d7ef8c..36b50b64 100644 --- a/spec/shared_examples/service.rb +++ b/spec/shared_examples/service.rb @@ -25,11 +25,11 @@ if facts[:os]['family'] == 'RedHat' it { - is_expected.to contain_file(params['storage_setup_file']).with( - 'ensure' => 'file', - 'force' => true, - 'before' => manage_service, - 'notify' => manage_service, + expect(subject).to contain_file(params['storage_setup_file']).with( + 'ensure' => 'file', + 'force' => true, + 'before' => manage_service, + 'notify' => manage_service, ) } end @@ -40,7 +40,7 @@ "#{facts['docker_program_data_path']}/docker/config/", ].each do |dir| it { - is_expected.to contain_file(dir).with_ensure('directory') + expect(subject).to contain_file(dir).with_ensure('directory') } end end @@ -48,15 +48,15 @@ case params['service_provider'] when 'systemd' it { - is_expected.to contain_file('/etc/systemd/system/docker.service.d').with_ensure('directory') + expect(subject).to contain_file('/etc/systemd/system/docker.service.d').with_ensure('directory') } if params['service_overrides_template'] it { - is_expected.to contain_file('/etc/systemd/system/docker.service.d/service-overrides.conf').with( - 'ensure' => 'file', + expect(subject).to contain_file('/etc/systemd/system/docker.service.d/service-overrides.conf').with( + 'ensure' => 'file', # 'content' => template($service_overrides_template), - 'before' => manage_service, + 'before' => manage_service, ).that_notifies( 'Exec[docker-systemd-reload-before-service]', ) @@ -65,11 +65,11 @@ if params['socket_override'] it { - is_expected.to contain_file('/etc/systemd/system/docker.socket.d').with_ensure('directory') + expect(subject).to contain_file('/etc/systemd/system/docker.socket.d').with_ensure('directory') } it { - is_expected.to contain_file('/etc/systemd/system/docker.socket.d/socket-overrides.conf').with( + expect(subject).to contain_file('/etc/systemd/system/docker.socket.d/socket-overrides.conf').with( 'ensure' => 'file', # 'content' => template($socket_overrides_template), ).that_comes_before( @@ -81,9 +81,9 @@ end it { - is_expected.to contain_exec('docker-systemd-reload-before-service').with( - 'path' => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'], - 'command' => 'systemctl daemon-reload > /dev/null', + expect(subject).to contain_exec('docker-systemd-reload-before-service').with( + 'path' => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'], + 'command' => 'systemctl daemon-reload > /dev/null', 'refreshonly' => true, ).that_notifies( manage_service, @@ -91,10 +91,10 @@ } when 'upstart' it { - is_expected.to contain_file('/etc/init.d/docker').with( + expect(subject).to contain_file('/etc/init.d/docker').with( 'ensure' => 'link', 'target' => '/lib/init/upstart-job', - 'force' => true, + 'force' => true, ).that_notifies( manage_service, ) @@ -103,9 +103,9 @@ if params['storage_config'] != :undef it { - is_expected.to contain_file(params['storage_config']).with( - 'ensure' => 'file', - 'force' => true, + expect(subject).to contain_file(params['storage_config']).with( + 'ensure' => 'file', + 'force' => true, ).that_notifies( manage_service, ) @@ -114,9 +114,9 @@ if service_config it { - is_expected.to contain_file(service_config).with( - 'ensure' => 'file', - 'force' => true, + expect(subject).to contain_file(service_config).with( + 'ensure' => 'file', + 'force' => true, ).that_notifies( manage_service, ) @@ -126,9 +126,9 @@ if params['manage_service'] if facts[:os]['family'] == 'windows' it { - is_expected.to contain_reboot('pending_reboot').with( - 'when' => 'pending', - 'onlyif' => 'component_based_servicing', + expect(subject).to contain_reboot('pending_reboot').with( + 'when' => 'pending', + 'onlyif' => 'component_based_servicing', 'timeout' => 1, ) } @@ -153,13 +153,13 @@ params['service_provider'] end - is_expected.to contain_service('docker').with( - 'ensure' => params['service_state'], - 'name' => params['service_name'], - 'enable' => params['service_enable'], - 'hasstatus' => hasstatus, + expect(subject).to contain_service('docker').with( + 'ensure' => params['service_state'], + 'name' => params['service_name'], + 'enable' => params['service_enable'], + 'hasstatus' => hasstatus, 'hasrestart' => hasrestart, - 'provider' => provider, + 'provider' => provider, ) } end diff --git a/spec/shared_examples/services.rb b/spec/shared_examples/services.rb index 3ccf20f3..92eb84aa 100644 --- a/spec/shared_examples/services.rb +++ b/spec/shared_examples/services.rb @@ -38,65 +38,65 @@ if create docker_service_create_flags = get_docker_service_flags( - 'detach' => detach, - 'env' => Array(env), - 'service_name' => service_name, - 'label' => Array(label), - 'publish' => publish, - 'replicas' => replicas, - 'tty' => tty, - 'user' => user, - 'workdir' => workdir, - 'extra_params' => Array(extra_params), - 'image' => image, - 'host_socket' => host_socket, + 'detach' => detach, + 'env' => Array(env), + 'service_name' => service_name, + 'label' => Array(label), + 'publish' => publish, + 'replicas' => replicas, + 'tty' => tty, + 'user' => user, + 'workdir' => workdir, + 'extra_params' => Array(extra_params), + 'image' => image, + 'host_socket' => host_socket, 'registry_mirror' => registry_mirror, - 'mounts' => mounts, - 'networks' => networks, - 'command' => command, + 'mounts' => mounts, + 'networks' => networks, + 'command' => command, ) exec_create = "#{docker_command} create --name #{docker_service_create_flags}" - unless_create = "docker service ps #{service_name == :undef ? '' : service_name}" + unless_create = "docker service ps #{(service_name == :undef) ? '' : service_name}" it { - is_expected.to contain_exec("#{title} docker service create").with( - 'command' => exec_create, + expect(subject).to contain_exec("#{title} docker service create").with( + 'command' => exec_create, 'environment' => exec_environment, - 'path' => exec_path, - 'timeout' => exec_timeout, - 'provider' => exec_provider, - 'unless' => unless_create, + 'path' => exec_path, + 'timeout' => exec_timeout, + 'provider' => exec_provider, + 'unless' => unless_create, ) } end if update docker_service_flags = get_docker_service_flags( - 'detach' => detach, - 'env' => Array(env), - 'service_name' => service_name, - 'label' => Array(label), - 'publish' => publish, - 'replicas' => replicas, - 'tty' => tty, - 'user' => user, - 'workdir' => workdir, - 'extra_params' => Array(extra_params), - 'image' => image, - 'host_socket' => host_socket, + 'detach' => detach, + 'env' => Array(env), + 'service_name' => service_name, + 'label' => Array(label), + 'publish' => publish, + 'replicas' => replicas, + 'tty' => tty, + 'user' => user, + 'workdir' => workdir, + 'extra_params' => Array(extra_params), + 'image' => image, + 'host_socket' => host_socket, 'registry_mirror' => registry_mirror, ) exec_update = "#{docker_command} update #{docker_service_flags}" it { - is_expected.to contain_exec("#{title} docker service update").with( - 'command' => exec_update, + expect(subject).to contain_exec("#{title} docker service update").with( + 'command' => exec_update, 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, ) } end @@ -111,24 +111,24 @@ exec_scale = "#{docker_command} scale #{service_name}=#{replicas}" it { - is_expected.to contain_exec("#{title} docker service scale").with( - 'command' => exec_scale, + expect(subject).to contain_exec("#{title} docker service scale").with( + 'command' => exec_scale, 'environment' => exec_environment, - 'path' => exec_path, - 'timeout' => exec_timeout, - 'provider' => exec_provider, + 'path' => exec_path, + 'timeout' => exec_timeout, + 'provider' => exec_provider, ) } end if ensure_value == 'absent' it { - is_expected.to contain_exec("#{title} docker service remove").with( - 'command' => "docker service rm #{service_name}", - 'onlyif' => "docker service ps #{service_name}", - 'path' => exec_path, + expect(subject).to contain_exec("#{title} docker service remove").with( + 'command' => "docker service rm #{service_name}", + 'onlyif' => "docker service ps #{service_name}", + 'path' => exec_path, 'provider' => exec_provider, - 'timeout' => exec_timeout, + 'timeout' => exec_timeout, ) } end diff --git a/spec/shared_examples/stack.rb b/spec/shared_examples/stack.rb index 0ded5444..f72c2c38 100644 --- a/spec/shared_examples/stack.rb +++ b/spec/shared_examples/stack.rb @@ -27,20 +27,20 @@ if ensure_value == 'present' docker_stack_flags = get_docker_stack_flags( 'stack_name' => stack_name, - 'bundle_file' => bundle_file, - 'compose_files' => compose_files, - 'prune' => prune, + 'bundle_file' => bundle_file, + 'compose_files' => compose_files, + 'prune' => prune, 'with_registry_auth' => with_registry_auth, - 'resolve_image' => resolve_image, + 'resolve_image' => resolve_image, ) exec_stack = "#{docker_command} deploy #{docker_stack_flags} #{stack_name}" it { - is_expected.to contain_exec("docker stack create #{stack_name}").with( - 'command' => exec_stack, - 'unless' => check_stack, - 'path' => exec_path, + expect(subject).to contain_exec("docker stack create #{stack_name}").with( + 'command' => exec_stack, + 'unless' => check_stack, + 'path' => exec_path, 'provider' => provider, ) } @@ -48,10 +48,10 @@ if ensure_value == 'absent' it { - is_expected.to contain_exec("docker stack destroy #{stack_name}").with( - 'command' => "#{docker_command} rm #{stack_name}", - 'onlyif' => check_stack, - 'path' => exec_path, + expect(subject).to contain_exec("docker stack destroy #{stack_name}").with( + 'command' => "#{docker_command} rm #{stack_name}", + 'onlyif' => check_stack, + 'path' => exec_path, 'provider' => provider, ) } diff --git a/spec/shared_examples/swarm.rb b/spec/shared_examples/swarm.rb index 5a7357d4..eb5041fc 100644 --- a/spec/shared_examples/swarm.rb +++ b/spec/shared_examples/swarm.rb @@ -44,29 +44,29 @@ if init docker_swarm_init_flags = get_docker_swarm_init_flags( 'init' => init, - 'advertise_addr' => advertise_addr, - 'autolock' => autolock, - 'cert_expiry' => cert_expiry, - 'dispatcher_heartbeat' => dispatcher_heartbeat, - 'default_addr_pool' => default_addr_pool, + 'advertise_addr' => advertise_addr, + 'autolock' => autolock, + 'cert_expiry' => cert_expiry, + 'dispatcher_heartbeat' => dispatcher_heartbeat, + 'default_addr_pool' => default_addr_pool, 'default_addr_pool_mask_length' => default_addr_pool_mask_length, - 'external_ca' => external_ca, - 'force_new_cluster' => force_new_cluster, - 'listen_addr' => listen_addr, - 'max_snapshots' => max_snapshots, - 'snapshot_interval' => snapshot_interval, + 'external_ca' => external_ca, + 'force_new_cluster' => force_new_cluster, + 'listen_addr' => listen_addr, + 'max_snapshots' => max_snapshots, + 'snapshot_interval' => snapshot_interval, ) exec_init = "#{docker_command} #{docker_swarm_init_flags}" it { - is_expected.to contain_exec('Swarm init').with( - 'command' => exec_init, + expect(subject).to contain_exec('Swarm init').with( + 'command' => exec_init, 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, - 'unless' => unless_init, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, + 'unless' => unless_init, ) } end @@ -75,30 +75,30 @@ docker_swarm_join_flags = get_docker_swarm_join_flags( 'join' => join, 'advertise_addr' => advertise_addr, - 'listen_addr' => listen_addr, - 'token' => token, + 'listen_addr' => listen_addr, + 'token' => token, ) exec_join = "#{docker_command} #{docker_swarm_join_flags} #{manager_ip}" it { - is_expected.to contain_exec('Swarm join').with( - 'command' => exec_join, + expect(subject).to contain_exec('Swarm join').with( + 'command' => exec_join, 'environment' => exec_environment, - 'path' => exec_path, - 'provider' => exec_provider, - 'timeout' => exec_timeout, - 'unless' => unless_join, + 'path' => exec_path, + 'provider' => exec_provider, + 'timeout' => exec_timeout, + 'unless' => unless_join, ) } end if ensure_value == 'absent' it { - is_expected.to contain_exec('Leave swarm').with( - 'command' => 'docker swarm leave --force', - 'onlyif' => onlyif_leave, - 'path' => exec_path, + expect(subject).to contain_exec('Leave swarm').with( + 'command' => 'docker swarm leave --force', + 'onlyif' => onlyif_leave, + 'path' => exec_path, 'provider' => exec_provider, ) } diff --git a/spec/shared_examples/system_user.rb b/spec/shared_examples/system_user.rb index 4f16b1fe..1c4950ed 100644 --- a/spec/shared_examples/system_user.rb +++ b/spec/shared_examples/system_user.rb @@ -4,15 +4,15 @@ docker_group = group it { - is_expected.to contain_user(user).with( + expect(subject).to contain_user(user).with( 'ensure' => 'present', ).that_comes_before("Exec[docker-system-user-#{user}]") } it { - is_expected.to contain_exec("docker-system-user-#{user}").with( + expect(subject).to contain_exec("docker-system-user-#{user}").with( 'command' => "/usr/sbin/usermod -aG #{docker_group} #{user}", - 'unless' => "/bin/cat /etc/group | grep '^#{docker_group}:' | grep -qw #{user}", + 'unless' => "/bin/cat /etc/group | grep '^#{docker_group}:' | grep -qw #{user}", ) } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 65d59b84..8f1d7fbc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,11 +7,11 @@ require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) -include RspecPuppetFacts +include RspecPuppetFacts # rubocop:disable Style/MixinUsage default_facts = { puppetversion: Puppet.version, - facterversion: Facter.version, + facterversion: Facter.version } default_fact_files = [ @@ -24,7 +24,7 @@ begin default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end @@ -38,8 +38,6 @@ Puppet.settings[:strict] = :warning end c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] - c.after(:suite) do - end end # Ensures that a module is defined diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index fd360836..b0ef8bd5 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -4,7 +4,7 @@ require 'rspec/retry' require 'tempfile' -include PuppetLitmus +include PuppetLitmus # rubocop:disable Style/MixinUsage # This method allows a block to be passed in and if an exception is raised # that matches the 'error_matcher' matcher, the block will wait a set number @@ -24,6 +24,7 @@ def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, e yield rescue StandardError => e raise unless try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher) + sleep retry_wait_interval_secs retry end @@ -75,6 +76,8 @@ def fetch_puppet_version run_shell('apt-get install -y net-tools') end + run_shell('apt-get purge -y container-tools') unless os[:family] == 'windows' || !ENV['CI'] + run_shell('puppet module install puppetlabs-stdlib --version 4.24.0', expect_failures: true) run_shell('puppet module install puppetlabs-apt --version 4.4.1', expect_failures: true) run_shell('puppet module install puppetlabs-translate --version 1.0.0', expect_failures: true) @@ -89,88 +92,88 @@ def fetch_puppet_version run_shell('yum-config-manager --enable docker\*') end - docker_compose_content_v3 = <<-EOS -version: "3.4" -x-images: - &default-image - alpine:3.8 -services: - compose_test: - image: *default-image - command: /bin/sh -c "while true; do echo hello world; sleep 1; done" - EOS - docker_compose_override_v3 = <<-EOS -version: "3.4" -x-images: - &default-image - debian:stable-slim -services: - compose_test: - image: *default-image - command: /bin/sh -c "while true; do echo hello world; sleep 1; done" - EOS - docker_stack_override_v3 = <<-EOS -version: "3.4" -x-images: - &default-image - debian:stable-slim -services: - compose_test: - image: *default-image - command: /bin/sh -c "while true; do echo hello world; sleep 1; done" - EOS - docker_compose_content_v3_windows = <<-EOS -version: "3" -services: - compose_test: - image: winamd64/hello-seattle - command: cmd.exe /C "ping 8.8.8.8 -t" -networks: - default: - external: - name: nat - EOS - docker_compose_override_v3_windows = <<-EOS -version: "3" -services: - compose_test: - image: winamd64/hello-seattle:nanoserver - command: cmd.exe /C "ping 8.8.8.8 -t" -networks: - default: - external: - name: nat - EOS - docker_compose_override_v3_windows2016 = <<-EOS -version: "3" -services: - compose_test: - image: winamd64/hello-seattle:nanoserver-sac2016 - command: cmd.exe /C "ping 8.8.8.8 -t" -networks: - default: - external: - name: nat - EOS - docker_stack_content_windows = <<-EOS -version: "3" -services: - compose_test: - image: winamd64/hello-seattle - command: cmd.exe /C "ping 8.8.8.8 -t" - EOS - docker_stack_override_windows = <<-EOS -version: "3" -services: - compose_test: - image: winamd64/hello-seattle:nanoserver - EOS - docker_stack_override_windows2016 = <<-EOS -version: "3" -services: - compose_test: - image: winamd64/hello-seattle:nanoserver-sac2016 - EOS + docker_compose_content_v3 = <<~EOS + version: "3.4" + x-images: + &default-image + alpine:3.8 + services: + compose_test: + image: *default-image + command: /bin/sh -c "while true; do echo hello world; sleep 1; done" + EOS + docker_compose_override_v3 = <<~EOS + version: "3.4" + x-images: + &default-image + debian:stable-slim + services: + compose_test: + image: *default-image + command: /bin/sh -c "while true; do echo hello world; sleep 1; done" + EOS + docker_stack_override_v3 = <<~EOS + version: "3.4" + x-images: + &default-image + debian:stable-slim + services: + compose_test: + image: *default-image + command: /bin/sh -c "while true; do echo hello world; sleep 1; done" + EOS + docker_compose_content_v3_windows = <<~EOS + version: "3" + services: + compose_test: + image: winamd64/hello-seattle + command: cmd.exe /C "ping 8.8.8.8 -t" + networks: + default: + external: + name: nat + EOS + docker_compose_override_v3_windows = <<~EOS + version: "3" + services: + compose_test: + image: winamd64/hello-seattle:nanoserver + command: cmd.exe /C "ping 8.8.8.8 -t" + networks: + default: + external: + name: nat + EOS + docker_compose_override_v3_windows2016 = <<~EOS + version: "3" + services: + compose_test: + image: winamd64/hello-seattle:nanoserver-sac2016 + command: cmd.exe /C "ping 8.8.8.8 -t" + networks: + default: + external: + name: nat + EOS + docker_stack_content_windows = <<~EOS + version: "3" + services: + compose_test: + image: winamd64/hello-seattle + command: cmd.exe /C "ping 8.8.8.8 -t" + EOS + docker_stack_override_windows = <<~EOS + version: "3" + services: + compose_test: + image: winamd64/hello-seattle:nanoserver + EOS + docker_stack_override_windows2016 = <<~EOS + version: "3" + services: + compose_test: + image: winamd64/hello-seattle:nanoserver-sac2016 + EOS if os[:family] == 'windows' create_remote_file(host, '/tmp/docker-compose-v3.yml', docker_compose_content_v3_windows) create_remote_file(host, '/tmp/docker-stack.yml', docker_stack_content_windows) @@ -189,8 +192,10 @@ def fetch_puppet_version end next unless os[:family] == 'windows' + result = run_shell("ipconfig | findstr /i 'ipv4'") raise 'Could not retrieve ip address for Windows box' if result.exit_code != 0 + ip = result.stdout.split("\n")[0].split(':')[1].strip retry_on_error_matching(60, 5, %r{connection failure running}) do @windows_ip = ip diff --git a/spec/unit/lib/facter/docker_spec.rb b/spec/unit/lib/facter/docker_spec.rb index 022d061d..e908add5 100644 --- a/spec/unit/lib/facter/docker_spec.rb +++ b/spec/unit/lib/facter/docker_spec.rb @@ -45,12 +45,14 @@ docker_manager_token = File.read(fixtures('facts', 'docker_swarm_manager_token')) allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token manager -q", timeout: 90).and_return(docker_manager_token.chomp) end + after(:each) { Facter.clear } describe 'docker fact with composer network' do before :each do allow(Facter.fact(:interfaces)).to receive(:value).and_return('br-c5810f1e3113,docker0,eth0,lo') end + it do fact = File.read(fixtures('facts', 'facts_with_compose')) fact = JSON.parse(fact.to_json, quirks_mode: true) @@ -65,6 +67,7 @@ before :each do allow(Facter.fact(:interfaces)).to receive(:value).and_return('br-19a6ebf6f5a5,docker0,eth0,lo') end + it do fact = File.read(fixtures('facts', 'facts_without_compose')).chomp fact_json = fact.to_json @@ -83,6 +86,7 @@ allow(Facter.fact(:docker_version)).to receive(:value).and_return(JSON.parse(docker_version)) allow(Facter.fact(:interfaces)).to receive(:value).and_return('br-19a6ebf6f5a5,docker0,eth0,lo') end + it do expect(Facter.fact(:docker_client_version).value).to eq( '17.03.1-ce-client', @@ -127,6 +131,7 @@ allow(Facter.fact(:docker_version)).to receive(:value).and_return(JSON.parse(docker_version)) allow(Facter.fact(:interfaces)).to receive(:value).and_return('br-19a6ebf6f5a5,docker0,eth0,lo') end + it do expect(Facter.fact(:docker_server_version).value).to eq( '17.03.1-ce-server', @@ -138,6 +143,7 @@ before :each do allow(Facter.fact(:interfaces)).to receive(:value).and_return('br-19a6ebf6f5a5,docker0,eth0,lo') end + it 'has valid entries' do expect(Facter.fact(:docker).value).to include( 'Architecture' => 'x86_64', @@ -149,6 +155,7 @@ before :each do allow(Facter.fact(:interfaces)).to receive(:value).and_return('br-19a6ebf6f5a5,docker0,eth0,lo') end + it do expect(Facter.fact(:docker_worker_join_token).value).to eq( 'SWMTKN-1-2m7ekt7511j5kgrc6seyrewpdxv47ksz1sdg7iybzhuug6nmws-0jh0syqeoj3tlr81p165ydfkm', @@ -160,6 +167,7 @@ before :each do allow(Facter.fact(:interfaces)).to receive(:value).and_return('br-19a6ebf6f5a5,docker0,eth0,lo') end + it do expect(Facter.fact(:docker_manager_join_token).value).to eq( 'SWMTKN-1-2m7ekt7511j5kgrc6seyrewpdxv47ksz1sdg7iybzhuug6nmws-8gh1ns1lcavgau8k9p6ou7xj3', @@ -172,6 +180,7 @@ docker_info = File.read(fixtures('facts', 'docker_info_swarm_inactive')) allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} info --format '{{json .}}'", timeout: 90).and_return(docker_info) end + it do expect(Facter.fact(:docker_worker_join_token).value).to be_nil end diff --git a/spec/unit/lib/puppet/parser/functions/docker_run_flags_spec.rb b/spec/unit/lib/puppet/parser/functions/docker_run_flags_spec.rb index 157a98ba..0e46ebd4 100644 --- a/spec/unit/lib/puppet/parser/functions/docker_run_flags_spec.rb +++ b/spec/unit/lib/puppet/parser/functions/docker_run_flags_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'the "docker_run_flags" parser function' do diff --git a/tasks/node_ls.rb b/tasks/node_ls.rb index 54294a28..fdff4209 100755 --- a/tasks/node_ls.rb +++ b/tasks/node_ls.rb @@ -12,10 +12,11 @@ def node_ls(filter, quiet) stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) filter = params['filter'] quiet = params['quiet'] diff --git a/tasks/node_rm.rb b/tasks/node_rm.rb index 9b92a576..dd148592 100755 --- a/tasks/node_rm.rb +++ b/tasks/node_rm.rb @@ -12,10 +12,11 @@ def node_rm(force, node) stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) force = params['force'] node = params['node'] diff --git a/tasks/node_update.rb b/tasks/node_update.rb index 9bc22c6a..38989db2 100755 --- a/tasks/node_update.rb +++ b/tasks/node_update.rb @@ -26,10 +26,11 @@ def node_update(availability, role, label_add, label_rm, node) stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) availability = params['availability'] role = params['role'] label_add = params['label_add'] diff --git a/tasks/service_create.rb b/tasks/service_create.rb index 6e2872de..4d92d8d1 100755 --- a/tasks/service_create.rb +++ b/tasks/service_create.rb @@ -32,10 +32,11 @@ def service_create(image, replicas, expose, env, command, extra_params, service, stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) image = params['image'] replicas = params['replicas'] expose = params['expose'] diff --git a/tasks/service_rm.rb b/tasks/service_rm.rb index 01f59f19..d49547a8 100755 --- a/tasks/service_rm.rb +++ b/tasks/service_rm.rb @@ -11,10 +11,11 @@ def service_rm(service) stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) service = params['service'] begin diff --git a/tasks/service_scale.rb b/tasks/service_scale.rb index f954316a..901d2d7b 100755 --- a/tasks/service_scale.rb +++ b/tasks/service_scale.rb @@ -13,10 +13,11 @@ def service_scale(service, scale, detach) stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) service = params['service'] scale = params['scale'] detach = params['detach'] diff --git a/tasks/service_update.rb b/tasks/service_update.rb index 52eeb4d1..7f557a24 100755 --- a/tasks/service_update.rb +++ b/tasks/service_update.rb @@ -25,10 +25,11 @@ def service_update(image, service, constraint_add, constraint_rm) stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) image = params['image'] service = params['service'] constraint_add = params['constraint_add'] diff --git a/tasks/swarm_init.rb b/tasks/swarm_init.rb index 78c49af0..649a465f 100755 --- a/tasks/swarm_init.rb +++ b/tasks/swarm_init.rb @@ -19,10 +19,11 @@ def swarm_init(advertise_addr, autolock, cert_expiry, dispatcher_heartbeat, exte stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) advertise_addr = params['advertise_addr'] autolock = params['autolock'] cert_expiry = params['cert_expiry'] diff --git a/tasks/swarm_join.rb b/tasks/swarm_join.rb index c98471d5..32bf99c4 100755 --- a/tasks/swarm_join.rb +++ b/tasks/swarm_join.rb @@ -14,10 +14,11 @@ def swarm_join(advertise_addr, listen_addr, token, manager_ip) stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) advertise_addr = params['advertise_addr'] listen_addr = params['listen_addr'] token = params['token'] diff --git a/tasks/swarm_leave.rb b/tasks/swarm_leave.rb index d6bc6bbb..652fde03 100755 --- a/tasks/swarm_leave.rb +++ b/tasks/swarm_leave.rb @@ -10,10 +10,11 @@ def swarm_leave(force) cmd_string += ' -f' if force == 'true' stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) force = params['force'] begin result = swarm_leave(force) diff --git a/tasks/swarm_token.rb b/tasks/swarm_token.rb index 35eae179..f951bbd2 100755 --- a/tasks/swarm_token.rb +++ b/tasks/swarm_token.rb @@ -11,10 +11,11 @@ def swarm_token(node_role) stdout, stderr, status = Open3.capture3(cmd_string) raise Puppet::Error, "stderr: '#{stderr}'" if status != 0 + stdout.strip end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) node_role = params['node_role'] begin diff --git a/tasks/swarm_update.rb b/tasks/swarm_update.rb index 208a5d21..cbbfcd12 100755 --- a/tasks/swarm_update.rb +++ b/tasks/swarm_update.rb @@ -5,7 +5,7 @@ require 'open3' require 'puppet' -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) image = params['image'] service = params['service']