Class: HybridPlatformsConductor::HpcPlugins::Test::DeployFreshness

Inherits:
Test
  • Object
show all
Defined in:
lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb

Overview

Test that the last deployment was done recently

Constant Summary collapse

MAX_ACCEPTABLE_REFRESH_PERIOD_SECS =

3 months

3 * 31 * 24 * 60 * 60

Constants included from LoggerHelpers

LoggerHelpers::LEVELS_MODIFIERS, LoggerHelpers::LEVELS_TO_STDERR

Instance Attribute Summary

Attributes inherited from Test

#errors, #expected_failure, #name, #node, #platform

Instance Method Summary collapse

Methods inherited from Test

#assert_equal, #assert_match, #error, #executed, #executed?, #initialize, only_on_nodes, only_on_platforms, #to_s

Methods inherited from Plugin

extend_config_dsl_with, #initialize, valid?

Methods included from LoggerHelpers

#err, #init_loggers, #log_component=, #log_debug?, #log_level=, #out, #section, #set_loggers_format, #stderr_device, #stderr_device=, #stderr_displayed?, #stdout_device, #stdout_device=, #stdout_displayed?, #stdouts_to_s, #with_progress_bar

Constructor Details

This class inherits a constructor from HybridPlatformsConductor::Test

Instance Method Details

#test_on_nodeObject

Check my_test_plugin.rb.sample documentation for signature details.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hybrid_platforms_conductor/hpc_plugins/test/deploy_freshness.rb', line 15

def test_on_node
  now = Time.now
  {
    'sudo 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