diff options
author | Michael Larson <slioch@slioch.vyatta.com> | 2010-05-21 10:19:01 -0700 |
---|---|---|
committer | Michael Larson <slioch@slioch.vyatta.com> | 2010-05-21 10:19:01 -0700 |
commit | 755f0d7a791c7d80ebd4017aa1e853ee0614cd29 (patch) | |
tree | cb881d491a2e0adcba19edb0b08123215b6d27f3 /scripts | |
parent | e11c320caa96d58396eddd91052a0c58a67bb69e (diff) | |
download | vyatta-cfg-755f0d7a791c7d80ebd4017aa1e853ee0614cd29.tar.gz vyatta-cfg-755f0d7a791c7d80ebd4017aa1e853ee0614cd29.zip |
fix for disable nodes loading (bug 5610). Additional checks added on configuration of disable nodes. requires vyatta-config-migrate package as well.
Additional fix required for loading configuration with deactivated nodes that are activated through the loading process.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/vyatta-activate-config.pl | 78 | ||||
-rwxr-xr-x | scripts/vyatta-config-gen-sets.pl | 3 | ||||
-rwxr-xr-x | scripts/vyatta-config-loader.pl | 18 | ||||
-rwxr-xr-x | scripts/vyatta-load-config.pl | 7 |
4 files changed, 68 insertions, 38 deletions
diff --git a/scripts/vyatta-activate-config.pl b/scripts/vyatta-activate-config.pl index 31165a4..3eca90f 100644 --- a/scripts/vyatta-activate-config.pl +++ b/scripts/vyatta-activate-config.pl @@ -27,15 +27,40 @@ use lib "/opt/vyatta/share/perl5"; sub wanted { return unless ( $_ eq '.disable' ); - print("Cannot set nested deactivated nodes\n"); + print("Cannot deactivate nested elements\n"); exit 1; } +sub check_parents { + my @p = @_; + my $l_dir = "$ENV{VYATTA_TEMP_CONFIG_DIR}/"; + my $a_dir = "$ENV{VYATTA_ACTIVE_CONFIGURATION_DIR}/"; + foreach my $sw (@p) { + $l_dir .= "/$sw"; + $a_dir .= "/$sw"; + + if (-e "$l_dir/.disable") { + return 1; + } + if (-e "$a_dir/.disable") { + return 1; + } + } + return 0; +} + sub usage() { print "Usage: $0 <path>\n"; exit 0; } +my $action = $ARGV[0]; + +if (!defined $ARGV[1] || $ARGV[1] eq '') { + print("Cannot activate/deactivate configuration root\n"); + exit 1; +} + #adjust for leaf node my $i = 0; my @path = @ARGV[1..$#ARGV]; @@ -53,7 +78,6 @@ if (! -e $full_path) { my $leaf = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path/node.val"; if (-e $leaf) { #prevent setting on leaf or multi, check for node.val -# $full_path = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path"; printf("Cannot activate/deactivate end node\n"); exit 1; } @@ -63,49 +87,53 @@ if (! -e $full_path) { } } +####################################################### +#now check for nesting of the activate/deactivate nodes +####################################################### +if ($action eq 'deactivate') { + my $active_dir = "$ENV{VYATTA_ACTIVE_CONFIGURATION_DIR}/$path"; + my $local_dir = $full_path; + if (-e $active_dir) { #checks active children + find( \&wanted, $active_dir ); + } + if (-e $local_dir) { #checks locally commit children + find( \&wanted, $local_dir ); + } + #final check that walks up tree and checks + if (check_parents(@path)) { #checks active and locally committed parents + print("Cannot deactivate nested elements\n"); + exit 1; + } +} -if ($ARGV[0] eq 'activate') { +####################################################### +#now apply the magic +####################################################### +if ($action eq 'activate') { $full_path .= "/.disable"; if (-e $full_path) { `rm -f $full_path`; } else { - printf("This element is not deactivated\n"); + printf("This element has not been deactivated\n"); exit 1; } } -elsif ($ARGV[0] eq 'deactivate') { +elsif ($action eq 'deactivate') { #first let's check and ensure that there is not another child .disable node... #also needs to be enforced when committing my $active_dir = "$ENV{VYATTA_ACTIVE_CONFIGURATION_DIR}/$path"; my $local_dir = $full_path; - if (-e "$active_dir/.disable") { - printf("This node is already deactivated\n"); + if (-e "$active_dir/.disable" || -e "$local_dir/.disable") { + printf("This element has already been deactivated\n"); exit 1; } - elsif (-e $active_dir) { - find( \&wanted, $active_dir ); - } - if (-e $local_dir) { - find( \&wanted, $local_dir ); - } `touch $full_path/.disable`; } -elsif ($ARGV[0] eq 'complete') { - #provide match... - printf("complete\n"); -} else { - printf("incoming arg: " . $ARGV[0] . "\n"); + printf("bad argument: " . $action . "\n"); usage(); } -#if this is activate -# make sure no activate subnodes -# create .disable file in node -#else -# ensure .disable file exists -# remove node - print "Done\n"; exit 0; diff --git a/scripts/vyatta-config-gen-sets.pl b/scripts/vyatta-config-gen-sets.pl index e364dfa..7cf4feb 100755 --- a/scripts/vyatta-config-gen-sets.pl +++ b/scripts/vyatta-config-gen-sets.pl @@ -32,7 +32,8 @@ my $conf_file = '/opt/vyatta/etc/config/config.boot'; $conf_file = $ARGV[0] if defined $ARGV[0]; # get a list of all config statement in the startup config file -my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($conf_file); +my %cfg_hier = Vyatta::ConfigLoad::getStartupConfigStatements($conf_file); +my @all_nodes = @{ $cfg_hier{'set'} }; if (scalar(@all_nodes) == 0) { # no config statements exit 1; diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl index b8e594e..0aae55b 100755 --- a/scripts/vyatta-config-loader.pl +++ b/scripts/vyatta-config-loader.pl @@ -46,7 +46,9 @@ sub restore_fds { } # get a list of all config statement in the startup config file -my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0],'true'); +my %cfg_hier = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0],'true'); +my @all_nodes = @{ $cfg_hier{'set'} }; +my @deactivate_nodes = @{ $cfg_hier{'deactivate'} }; if (scalar(@all_nodes) == 0) { # no config statements restore_fds(); @@ -98,13 +100,6 @@ foreach (@all_nodes) { next; } - if (@pr[0] eq '!') { - @pr = @pr[1..$#pr]; - my $deactivate_cmd = "$CWRAPPER deactivate " . (join ' ', @pr) . " 1>/dev/null"; - system("$deactivate_cmd"); - #ignore these errors due to nesting warnings. - } - my $cmd = "$CWRAPPER set " . (join ' ', @pr); # this debug file should be deleted before release system("echo [$cmd] >> /tmp/foo"); @@ -116,6 +111,13 @@ foreach (@all_nodes) { # continue after set failure (or should we abort?) } } + +# Now deactivate these nodes +for (@deactivate_nodes) { + my $cmd = "$CWRAPPER deactivate " . $_ . " 1>/dev/null"; + system("$cmd"); +} + $ret = system("$commit_cmd"); if ($ret >> 8) { print OLDOUT "Commit failed at boot\n"; diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index 62d6e8b..296dc0d 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -220,10 +220,9 @@ foreach (@set_list) { } foreach (@deactivate_list) { - my ( $cmd_ref, $rank ) = @{$_}; - my @cmd = ( "$sbindir/vyatta-activate-config.pl deactivate", @{$cmd_ref} ); - my $cmd_str = join ' ', @cmd; - system("$cmd_str 1>/dev/null"); + #need to remove .disable nodes recursively in tree through activate command + my $cmd = "$sbindir/vyatta-activate-config.pl deactivate $_"; + system("$cmd 1>/dev/null"); #ignore error on complaint re: nested nodes } |