-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1451 from stdweird/metaconfig_arbitrary_code_fc_s…
…tyke ncm-metaconfig: support running arbitrary commands in various steps
- Loading branch information
Showing
11 changed files
with
261 additions
and
22 deletions.
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
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,82 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Test::Quattor qw(commands commands_fail_pre); | ||
use NCM::Component::metaconfig; | ||
use Test::MockModule; | ||
|
||
=pod | ||
=head1 DESCRIPTION | ||
Test the configure() method. | ||
=cut | ||
|
||
my $orig = 'X'; | ||
|
||
sub clean | ||
{ | ||
set_file_contents("/foo/bar", "$orig"); | ||
command_history_reset(); | ||
} | ||
|
||
my $cmp = NCM::Component::metaconfig->new('metaconfig'); | ||
my $cfg = get_config_for_profile('commands'); | ||
my $cfg_fail = get_config_for_profile('commands_fail_pre'); | ||
|
||
clean(); | ||
|
||
is($cmp->Configure($cfg), 1, "Configure succeeds"); | ||
my $fh = get_file("/foo/bar"); | ||
ok($orig ne "$fh", "orig content is not same as current $fh"); | ||
|
||
ok($fh, "A file was actually created"); | ||
isa_ok($fh, "CAF::FileWriter"); | ||
|
||
# if default sysv init service changes, also modify the aii_command negative test | ||
ok(command_history_ok(['/cmd pre', '/cmd test', '/cmd changed', '/cmd post', 'service foo restart']), | ||
"commands run and serivce foo restarted"); | ||
|
||
clean(); | ||
|
||
# changed failed, post does not run, daemons does run | ||
set_command_status('/cmd changed', 1); | ||
$cmp->Configure($cfg); | ||
ok(command_history_ok(['/cmd pre', '/cmd test', '/cmd changed', 'service foo restart'], ['/cmd post']), | ||
"commands except post run and serivce foo restarted"); | ||
my $fcnt = get_file_contents("/foo/bar"); | ||
ok($orig ne "$fcnt", "orig content is not same as current $fcnt"); | ||
|
||
clean(); | ||
|
||
# test failed, changed, post and daemons do not run, content unmodified | ||
set_command_status('/cmd test', 1); | ||
$cmp->Configure($cfg); | ||
ok(command_history_ok(['/cmd pre', '/cmd test'], ['/cmd changed', 'service foo restart', '/cmd post']), | ||
"commands run except changed, post and no serivce foo restarted"); | ||
$fcnt = get_file_contents("/foo/bar"); | ||
# unmodified | ||
is($orig, "$fcnt", "orig content is same as current $fcnt on test failed"); | ||
|
||
clean(); | ||
# pre failed, test, changed, post and daemons do not run, content unmodified | ||
set_command_status('/cmd pre', 1); | ||
$cmp->Configure($cfg); | ||
ok(command_history_ok(['/cmd pre'], ['/cmd test', '/cmd changed', 'service foo restart', '/cmd post']), | ||
"commands run except test, changed, post and no serivce foo restarted"); | ||
$fcnt = get_file_contents("/foo/bar"); | ||
# unmodified | ||
is($orig, "$fcnt", "orig content is same as current $fcnt on pre failed"); | ||
|
||
clean(); | ||
# Rerun with cmd_pre that can fail. Test still fails as usual | ||
$cmp->Configure($cfg_fail); | ||
ok(command_history_ok(['/cmd pre', '/cmd test'], ['/cmd changed', 'service foo restart', '/cmd post']), | ||
"commands pre fails, but is ok so still runs test, and no changed, post and no serivce foo restarted"); | ||
$fcnt = get_file_contents("/foo/bar"); | ||
# unmodified | ||
is($orig, "$fcnt", "orig content is same as current $fcnt on pre failed but ok to fail and test fails"); | ||
|
||
|
||
done_testing(); |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
object template aii; | ||
|
||
include 'simple'; | ||
include 'simple_commands'; |
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,3 @@ | ||
object template commands; | ||
|
||
include 'simple_commands'; |
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,8 @@ | ||
object template commands_fail_pre; | ||
|
||
include 'simple_commands'; | ||
|
||
"/software/components/metaconfig/commands/cmd_pre_fail" = | ||
"-" + value("/software/components/metaconfig/commands/cmd_pre"); | ||
|
||
"/software/components/metaconfig/services/{/foo/bar}/actions/pre" = "cmd_pre_fail"; |
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,15 @@ | ||
unique template simple_commands; | ||
|
||
include 'simple'; | ||
|
||
prefix "/software/components/metaconfig/commands"; | ||
"cmd_pre" = "/cmd pre"; | ||
"cmd_test" = "/cmd test"; | ||
"cmd_changed" = "/cmd changed"; | ||
"cmd_post" = "/cmd post"; | ||
|
||
prefix "/software/components/metaconfig/services/{/foo/bar}/actions"; | ||
"pre" = "cmd_pre"; | ||
"test" = "cmd_test"; | ||
"changed" = "cmd_changed"; | ||
"post" = "cmd_post"; |