Sha256: e5f16e58cc24b574dbf7e1b1597ed92a640cd188e0c153227d60483348fc0f71

Contents?: true

Size: 1.48 KB

Versions: 16

Compression:

Stored size: 1.48 KB

Contents

require 'time'

module HybridPlatformsConductor

  module HpcPlugins

    module Test

      # Test that the last deployment was done recently
      class DeployFreshness < HybridPlatformsConductor::Test

        MAX_ACCEPTABLE_REFRESH_PERIOD_SECS = 3 * 31 * 24 * 60 * 60 # 3 months

        # Check my_test_plugin.rb.sample documentation for signature details.
        def test_on_node
          now = Time.now
          {
            "#{@nodes_handler.sudo_on(@node)} ls -t /var/log/deployments" => proc do |stdout|
              if stdout.empty?
                error 'Node has never been deployed using deploy (/var/log/deployments is empty)'
              elsif stdout.first =~ /No such file or directory/
                error 'Node has never been deployed using deploy (/var/log/deployments does not exist)'
              else
                # Expecting following file names
                # 2017-12-01_093418_a_usernme
                file_match = stdout.first.match(/^#{Regexp.escape(@node)}_(\d{4}-\d{2}-\d{2})_.+$/)
                if file_match.nil?
                  error "Invalid chef deployment log file found: #{stdout.first}"
                else
                  last_deploy_time = Time.parse(file_match[1])
                  error "Last deployment has been done on #{last_deploy_time.strftime('%F')}. Should refresh it." if now - last_deploy_time > MAX_ACCEPTABLE_REFRESH_PERIOD_SECS
                end
              end
            end
          }
        end

      end

    end

  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hybrid_platforms_conductor-32.12.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.11.2 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.11.1 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.11.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.10.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.9.1 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.9.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.8.2 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.8.1 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.8.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.7.3 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.7.2 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.7.1 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.7.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.6.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.5.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb