Sha256: a299b2de373a2d95e5b9dcf2d0daff653fe5164d6dc3c8a5d2fca5b4f546aa2f

Contents?: true

Size: 1.49 KB

Versions: 14

Compression:

Stored size: 1.49 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
                # node-name_2017-12-01_093418_user-name
                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

14 entries across 14 versions & 1 rubygems

Version Path
hybrid_platforms_conductor-32.17.1 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.17.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.16.4 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.16.3 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.16.2 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.16.1 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.16.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.15.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.14.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.13.4 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.13.3 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.13.2 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.13.1 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb
hybrid_platforms_conductor-32.13.0 lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb