From e0604d0976fcdd3c02495a3e4bd00c1fc8aeb3dd Mon Sep 17 00:00:00 2001 From: james-stocks Date: Thu, 11 Feb 2016 18:13:46 +0000 Subject: [PATCH] (PCP-294) Acceptance - on pcp-broker start-up, wait for 'running' state Due to PCP-294, the acceptance tests might message pcp-broker before it has fully started. This commit changes the pre-suite to use the master ref for pcp-broker (PCP-250 being fixed allows this); and changes the helper methods so pcp-broker is queried for its running state. [skip ci] --- acceptance/lib/pxp-agent/test_helper.rb | 28 +++++++++++++++++++++ acceptance/setup/common/010_Setup_Broker.rb | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/acceptance/lib/pxp-agent/test_helper.rb b/acceptance/lib/pxp-agent/test_helper.rb index e0ab6cbc..94d1785c 100644 --- a/acceptance/lib/pxp-agent/test_helper.rb +++ b/acceptance/lib/pxp-agent/test_helper.rb @@ -1,5 +1,8 @@ require 'pxp-agent/config_helper.rb' require 'pcp/client' +require 'net/http' +require 'openssl' +require 'json' # This file contains general test helper methods for pxp-agent acceptance tests @@ -40,6 +43,16 @@ def run_pcp_broker(host) on(host, 'cd /opt/puppet-git-repos/pcp-broker; export LEIN_ROOT=ok; lein tk /var/log/pcp-broker.log 2>&1 &') assert(port_open_within?(host, PCP_BROKER_PORT, 60), "pcp-broker port #{PCP_BROKER_PORT.to_s} not open within 1 minutes of starting the broker") + broker_state = nil + attempts = 0 + until broker_state == "running" or attempts == 100 do + broker_state = get_pcp_broker_status(host) + if broker_state != "running" + attempts += 1 + sleep 0.5 + end + end + assert_equal("running", broker_state, "Shortly after startup, pcp-broker should report its state as being 'running'") end def kill_pcp_broker(host) @@ -49,6 +62,21 @@ def kill_pcp_broker(host) end end +def get_pcp_broker_status(host) + uri = URI.parse("https://#{host}:#{PCP_BROKER_PORT}/status/v1/services/broker-service") + begin + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + res = http.get(uri.request_uri) + document = JSON.load(res.body) + return document["state"] + rescue => e + puts e.inspect + return nil + end +end + # Query pcp-broker's inventory of associated clients # Reference: https://github.com/puppetlabs/pcp-specifications/blob/master/pcp/inventory.md # @param broker hostname or beaker host object of the pcp-broker host diff --git a/acceptance/setup/common/010_Setup_Broker.rb b/acceptance/setup/common/010_Setup_Broker.rb index 441406bf..18dab9b5 100644 --- a/acceptance/setup/common/010_Setup_Broker.rb +++ b/acceptance/setup/common/010_Setup_Broker.rb @@ -17,7 +17,7 @@ step 'Clone pcp-broker to master' do clone_git_repo_on(master, GIT_CLONE_FOLDER, - extract_repo_info_from(build_git_url('pcp-broker', nil, nil, 'https')).merge(:rev => '602c003')) + extract_repo_info_from(build_git_url('pcp-broker', nil, nil, 'https'))) end step 'Download lein bootstrap' do