-
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.
ncm-metaconfig: support running arbitrary commands in various steps
- Loading branch information
Showing
5 changed files
with
151 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Test::Quattor qw(commands); | ||
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'); | ||
|
||
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"); | ||
|
||
|
||
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
object template commands; | ||
|
||
include 'simple'; | ||
|
||
prefix "/software/components/metaconfig/services/{/foo/bar}/commands"; | ||
"pre" = "cmd pre"; | ||
"test" = "cmd test"; | ||
"changed" = "cmd changed"; | ||
"post" = "cmd post"; |