Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tphoney
committed
Oct 10, 2017
1 parent
0765497
commit 426bbc6
Showing
7 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# run a test task | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'mysql tasks' do | ||
describe 'execute some sql', if: pe_install? && puppet_version =~ %r{(5\.\d\.\d)} do | ||
pp = <<-EOS | ||
class { 'mysql::server': root_password => 'password' } | ||
mysql::db { 'spec1': | ||
user => 'root1', | ||
password => 'password', | ||
} | ||
EOS | ||
|
||
it "sets up a mysql instance" do | ||
apply_manifest(pp, catch_failures: true) | ||
end | ||
|
||
it 'execute arbitary sql' do | ||
result = run_task(task_name: 'mysql::sql', params: 'sql="show databases;" password=password') | ||
expect_multiple_regexes(result: result, regexes: [%r{information_schema}, %r{performance_schema}, %r{Job completed. 1/1 nodes succeeded}]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"description": "Allows you to execute arbitary SQL", | ||
"input_method": "stdin", | ||
"parameters": { | ||
"database": { | ||
"description": "Database to connect to", | ||
"type": "Optional[String[1]]" | ||
}, | ||
"user": { | ||
"description": "The user", | ||
"type": "Optional[String[1]]" | ||
}, | ||
"password": { | ||
"description": "The password", | ||
"type": "Optional[String[1]]" | ||
}, | ||
"sql": { | ||
"description": "The SQL you want to execute", | ||
"type": "String[1]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/opt/puppetlabs/puppet/bin/ruby | ||
require 'json' | ||
require 'open3' | ||
require 'puppet' | ||
|
||
def get(sql, database, user, password) | ||
cmd_string = "mysql -e \"#{sql}\"" | ||
cmd_string << " --database=#{database}" unless database.nil? | ||
cmd_string << " --user=#{user}" unless user.nil? | ||
cmd_string << " --password=#{password}" unless password.nil? | ||
stdout, stderr, status = Open3.capture3(cmd_string) | ||
raise Puppet::Error, _("stderr: '#{stderr}'") if status != 0 | ||
{ status: stdout.strip } | ||
end | ||
|
||
params = JSON.parse(STDIN.read) | ||
database = params['database'] | ||
user = params['user'] | ||
password = params['password'] | ||
sql = params['sql'] | ||
|
||
begin | ||
result = get(sql, database, user, password) | ||
puts result.to_json | ||
exit 0 | ||
rescue Puppet::Error => e | ||
puts({ status: 'failure', error: e.message }.to_json) | ||
exit 1 | ||
end |