Skip to content

Commit

Permalink
Merge pull request #633 from MikaelSmith/revert-PCP-769
Browse files Browse the repository at this point in the history
Revert PCP-769
  • Loading branch information
MikaelSmith authored Aug 24, 2017
2 parents 527962e + e8c9627 commit b3d0cb5
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 516 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if ("${INSTALL_IS_SYSTEM_DIR}" STREQUAL "-1")
endif()

# Find libraries
set(LEATHERMAN_COMPONENTS locale nowide catch logging rapidjson json_container util file_util execution curl)
set(LEATHERMAN_COMPONENTS locale nowide catch logging rapidjson json_container util file_util execution)

if (WIN32)
list(APPEND LEATHERMAN_COMPONENTS windows)
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ Build
cmake -DCMAKE_BUILD_TYPE=Debug -DDEV_LOG_COLOR=ON ..
make

NOTE: If the versions of OpenSSL and libcurl conflict with each other, curl may fail
to load SSL files. On macOS this is common when using Homebrew. Invoke cmake with the
following commands to use the Homebrew versions of OpenSSL and libcurl:
cmake -DCMAKE_PREFIX_PATH="/usr/local/opt/openssl;/usr/local/opt/curl" ..

Usage
-----

Expand Down
14 changes: 5 additions & 9 deletions acceptance/lib/pxp-agent/task_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'pxp-agent/test_helper.rb'
require 'json'
require 'Digest'

# Runs a task on targets, and passes the output to the block for validation
# Block should expect a map parsed from the JSON output
def run_task(broker, targets, task, filename, sha256, input = {}, max_retries = 30, query_interval = 1, &block)
def run_task(broker, targets, task, filename, input = {}, max_retries = 30, query_interval = 1, &block)
target_identities = targets.map {|agent| "pcp://#{agent}/agent"}

provisional_responses =
Expand All @@ -15,7 +14,7 @@ def run_task(broker, targets, task, filename, sha256, input = {}, max_retries =
:input => input,
:files => [{:uri => {:path => "/#{task}/tasks/#{filename}", :params => {}},
:filename => filename,
:sha256 => sha256}]})
:sha256 => 'tbd'}]})
rescue => exception
fail("Exception occurred when trying to run task '#{task}' on all agents: #{exception.message}")
end
Expand All @@ -34,13 +33,12 @@ def run_task(broker, targets, task, filename, sha256, input = {}, max_retries =

def create_task_on(agent, mod, task, body)
if agent['platform'] =~ /win/
tasks_path = 'C:/ProgramData/PuppetLabs/pxp-agent/tasks-cache'
tasks_path = 'C:/ProgramData/PuppetLabs/pxp-agent/tasks'
else
tasks_path = '/opt/puppetlabs/pxp-agent/tasks-cache'
tasks_path = '/opt/puppetlabs/pxp-agent/tasks'
end

sha256 = Digest::SHA256.hexdigest(body+"\n")
task_path = "#{tasks_path}/#{sha256}"
task_path = "#{tasks_path}/#{mod}/tasks"
on agent, "mkdir -p #{task_path}"

create_remote_file(agent, "#{task_path}/#{task}", body)
Expand All @@ -49,6 +47,4 @@ def create_task_on(agent, mod, task, body)
teardown do
on agent, "rm -rf #{task_path}"
end

sha256
end
4 changes: 2 additions & 2 deletions acceptance/tests/tasks/run_echo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
task_body = "#!/bin/sh\necho $PT_message"
end

@sha256 = create_task_on(agent, 'echo', 'init.bat', task_body)
create_task_on(agent, 'echo', 'init.bat', task_body)
end
end

step 'Run echo task on agent hosts' do
run_task(master, agents, 'echo', 'init.bat', @sha256, {:message => 'hello'}) do |stdout|
run_task(master, agents, 'echo', 'init.bat', {:message => 'hello'}) do |stdout|
assert_equal('hello', stdout.strip, "Output did not contain 'hello'")
end
end # test step
Expand Down
8 changes: 5 additions & 3 deletions acceptance/tests/tasks/run_ps1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

step 'Create powershell task on agent hosts' do
windows_hosts.each do |agent|
task_body = "foreach ($i in $input) { Write-Output $i }\nWrite-Output $env:PT_data";
@sha256 = create_task_on(agent, 'echo', 'init.ps1', task_body)
create_task_on(agent, 'echo', 'init.ps1', <<-EOF)
foreach ($i in $input) { Write-Output $i }
Write-Output $env:PT_data
EOF
end
end

step 'Run powershell task on Windows agent hosts' do
run_task(master, windows_hosts, 'echo', 'init.ps1', @sha256, {:data => [1, 2, 3]}) do |stdout|
run_task(master, windows_hosts, 'echo', 'init.ps1', {:data => [1, 2, 3]}) do |stdout|
json, data = stdout.delete("\r").split("\n")
assert_equal('{"data":[1,2,3]}', json, "Output did not contain 'data'")
assert_equal('[1,2,3]', data, "Output did not contain 'data'")
Expand Down
9 changes: 5 additions & 4 deletions acceptance/tests/tasks/run_puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
shebang = '#!/opt/puppetlabs/bin/puppet apply'
end

task_body = "#{shebang}\nnotify { 'hello': }"

@sha256 = create_task_on(agent, 'hello', 'init.pp', task_body)
create_task_on(agent, 'hello', 'init.pp', <<-EOF)
#{shebang}
notify { 'hello': }
EOF
end
end

step 'Run puppet task on agent hosts' do
run_task(master, agents, 'hello', 'init.pp', @sha256, {:data => [1, 2, 3]}) do |stdout|
run_task(master, agents, 'hello', 'init.pp', {:data => [1, 2, 3]}) do |stdout|
assert_match(/Notify\[hello\]\/message: defined 'message' as 'hello'/, stdout, "Output did not contain 'hello'")
end
end # test step
Expand Down
9 changes: 6 additions & 3 deletions acceptance/tests/tasks/run_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

step 'Create ruby task on agent hosts' do
agents.each do |agent|
task_body = "#!/opt/puppetlabs/puppet/bin/ruby\nputs STDIN.gets\nputs ENV['PT_data']"
@sha256 = create_task_on(agent, 'echo', 'init.rb', task_body)
create_task_on(agent, 'echo', 'init.rb', <<-EOF)
#!/opt/puppetlabs/puppet/bin/ruby
puts STDIN.gets
puts ENV['PT_data']
EOF
end
end

step 'Run ruby task on agent hosts' do
run_task(master, agents, 'echo', 'init.rb', @sha256, {:data => [1, 2, 3]}) do |stdout|
run_task(master, agents, 'echo', 'init.rb', {:data => [1, 2, 3]}) do |stdout|
json, data = stdout.delete("\r").split("\n")
assert_equal('{"data":[1,2,3]}', json, "Output did not contain 'data'")
assert_equal('[1,2,3]', data, "Output did not contain 'data'")
Expand Down
1 change: 0 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ include_directories(
${HORSEWHISPERER_INCLUDE_DIRS}
${INIH_INCLUDE_DIRS}
${cpp-pcp-client_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
)

set(LIBRARY_COMMON_SOURCES
Expand Down
10 changes: 0 additions & 10 deletions lib/inc/pxp-agent/modules/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <pxp-agent/action_response.hpp>
#include <pxp-agent/results_storage.hpp>

#include <leatherman/curl/client.hpp>

namespace PXPAgent {
namespace Modules {

Expand All @@ -19,10 +17,6 @@ class Task : public PXPAgent::Module {
public:
Task(const boost::filesystem::path& exec_prefix,
const std::string& task_cache_dir,
const std::vector<std::string>& master_uris,
const std::string& ca,
const std::string& crt,
const std::string& key,
const std::string& spool_dir);

/// Whether or not the module supports non-blocking / asynchronous requests.
Expand All @@ -44,10 +38,6 @@ class Task : public PXPAgent::Module {

std::string task_cache_dir_, wrapper_executable_;

std::vector<std::string> master_uris_;

leatherman::curl::client client_;

void callBlockingAction(
const ActionRequest& request,
const TaskCommand &command,
Expand Down
41 changes: 5 additions & 36 deletions lib/src/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ namespace lth_util = leatherman::util;
}
}();

static const std::string DEFAULT_TASK_CACHE_DIR { (DATA_DIR / "tasks-cache").string() };
// TODO(task) switch back to tasks-cache when downloading is implemented.
static const std::string DEFAULT_TASK_CACHE_DIR { (DATA_DIR / "tasks").string() };
#else
static const fs::path DEFAULT_CONF_DIR { "/etc/puppetlabs/pxp-agent" };
const std::string DEFAULT_SPOOL_DIR { "/opt/puppetlabs/pxp-agent/spool" };
static const std::string DEFAULT_PID_FILE { "/var/run/puppetlabs/pxp-agent.pid" };
static const std::string DEFAULT_LOG_FILE { "/var/log/puppetlabs/pxp-agent/pxp-agent.log" };
static const std::string DEFAULT_PCP_ACCESS_FILE { "/var/log/puppetlabs/pxp-agent/pcp-access.log" };
static const std::string DEFAULT_MODULES_DIR { "/opt/puppetlabs/pxp-agent/modules" };
static const std::string DEFAULT_TASK_CACHE_DIR { "/opt/puppetlabs/pxp-agent/tasks-cache" };
// TODO(task) switch back to tasks-cache when downloading is implemented.
static const std::string DEFAULT_TASK_CACHE_DIR { "/opt/puppetlabs/pxp-agent/tasks" };
#endif

static const std::string DEFAULT_MODULES_CONF_DIR {
Expand Down Expand Up @@ -328,7 +330,7 @@ const Configuration::Agent& Configuration::getAgentConfiguration() const
HW::GetFlag<std::string>("spool-dir"),
HW::GetFlag<std::string>("spool-dir-purge-ttl"),
HW::GetFlag<std::string>("modules-config-dir"),
HW::GetFlag<std::string>("task-cache-dir"),
DEFAULT_TASK_CACHE_DIR,
AGENT_CLIENT_TYPE,
HW::GetFlag<int>("connection-timeout") * 1000,
static_cast<uint32_t >(HW::GetFlag<int>("association-timeout")),
Expand Down Expand Up @@ -580,16 +582,6 @@ void Configuration::defineDefaultValues()
Types::String,
DEFAULT_MODULES_CONF_DIR) } });

defaults_.insert(
Option { "task-cache-dir",
Base_ptr { new Entry<std::string>(
"task-cache-dir",
"",
lth_loc::format("Tasks cache directory, default: {1}",
DEFAULT_TASK_CACHE_DIR),
Types::String,
DEFAULT_TASK_CACHE_DIR) } });

defaults_.insert(
Option { "spool-dir",
Base_ptr { new Entry<std::string>(
Expand Down Expand Up @@ -925,29 +917,6 @@ void Configuration::validateAndNormalizeOtherSettings()
HW::SetFlag<std::string>(option, val_path.string());
}

// Create the task-cache-dir if needed and ensure that we
// have the required user rwx, and group rx permissions.
const auto task_cache_dir = HW::GetFlag<std::string>("task-cache-dir");

if (task_cache_dir.empty()) {
throw Configuration::Error {
lth_loc::translate("task-cache-dir must be defined") };
}

fs::path task_cache_dir_path { lth_file::tilde_expand(task_cache_dir) };
check_and_create_dir(task_cache_dir_path, "task-cache-dir", true);
#ifndef _WIN32
try {
fs::permissions(task_cache_dir_path, NIX_DIR_PERMS);
} catch (const fs::filesystem_error& e) {
throw Configuration::Error {
lth_loc::format("Failed to make the task-cache-dir '{1}' user/group readable and executable, and user writable during configuration validation: {2}",
task_cache_dir_path.string(), e.what()) };
}
#endif

HW::SetFlag<std::string>("task-cache-dir", task_cache_dir_path.string());

// Create the spool-dir if needed and ensure we can write in it
const auto spool_dir = HW::GetFlag<std::string>("spool-dir");

Expand Down
Loading

0 comments on commit b3d0cb5

Please sign in to comment.