[pve-devel] [PATCH ha-manager v4 1/4] Env, HW: add HW fencing related functions
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Mar 16 13:01:27 CET 2016
This adds three methods to hardware fencing related functions:
* read_fence_config
* fencing_mode
* exec_fence_agent
'read_fence_config' allows to create a common code base between the
real world and the test/sim world regarding fencing a bit easier.
In PVE2 it parses the config from /etc/pve/ha/fence.cfg and in
the Sim method it parses the config from testdir/status/fence.cfg.
The 'fencing_mode' method checks respective to the callee's
environment if hardware fencing is enabled and returns the wanted
mode:
* PVE2: if the datacenter.cfg key 'fencing' is set then it will be
used, else we use 'watchdog' as default.
* Sim: if the cfg exist and at least one device is configured we use
'hardware' fencing, else we default to 'watchdog'.
For the simulator we should make also a option to turn HW fencing
off and on independent if devices are configured when we implement
HW fencing for it, but that is not really needed for now.
'exec_fence_agent' executes, as the name suggests, environment
specific a fence agent.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
changes since v3:
* updated commit message to match code
* do not use exec_fence_agent for Test/Sim watchdog
I kept the method name 'exec_fence_agents' as it's parameter
signature matches this name better than 'exec' only, the unused
node param in the PVE2 exec_fence_agent method is not ideal but
as we needed for the sim I let it as it is for now.
Also naming it exec matches the semantic it does in PVE2 but not the
one from the Sim Hardware, while exec_fence_agent matches both envs.
src/PVE/HA/Env.pm | 18 ++++++++++++++++++
src/PVE/HA/Env/PVE2.pm | 29 +++++++++++++++++++++++++++++
src/PVE/HA/Sim/Env.pm | 22 ++++++++++++++++++++++
src/PVE/HA/Sim/Hardware.pm | 30 ++++++++++++++++++++++++++++--
4 files changed, 97 insertions(+), 2 deletions(-)
diff --git a/src/PVE/HA/Env.pm b/src/PVE/HA/Env.pm
index f6be7b2..c7537b1 100644
--- a/src/PVE/HA/Env.pm
+++ b/src/PVE/HA/Env.pm
@@ -87,6 +87,24 @@ sub read_service_config {
return $self->{plug}->read_service_config();
}
+sub read_fence_config {
+ my ($self) = @_;
+
+ return $self->{plug}->read_fence_config();
+}
+
+sub fencing_mode {
+ my ($self) = @_;
+
+ return $self->{plug}->fencing_mode();
+}
+
+sub exec_fence_agent {
+ my ($self, $agent, $node, @param) = @_;
+
+ return $self->{plug}->exec_fence_agent($agent, $node, @param);
+}
+
# this is normally only allowed by the master to recover a _fenced_ service
sub steal_service {
my ($self, $sid, $current_node, $new_node) = @_;
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index 8638786..37823ee 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -15,6 +15,7 @@ use PVE::RPCEnvironment;
use PVE::HA::Tools ':exit_codes';
use PVE::HA::Env;
use PVE::HA::Config;
+use PVE::HA::FenceConfig;
use PVE::HA::Resources;
use PVE::HA::Resources::PVEVM;
use PVE::HA::Resources::PVECT;
@@ -144,6 +145,34 @@ sub read_service_config {
return $conf;
}
+sub read_fence_config {
+ my ($self) = @_;
+
+ return PVE::HA::Config::read_fence_config();
+}
+
+sub fencing_mode {
+ my ($self) = @_;
+
+ my $datacenterconfig = cfs_read_file('datacenter.cfg');
+
+ return 'watchdog' if !$datacenterconfig->{fencing};
+
+ return $datacenterconfig->{fencing};
+}
+
+sub exec_fence_agent {
+ my ($self, $agent, $node, @param) = @_;
+
+ # setup execution environment
+ $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
+
+ my $cmd = "$agent " . PVE::HA::FenceConfig::gen_arg_str(@param);
+
+ exec($cmd);
+ exit -1;
+}
+
# this is only allowed by the master to recover a _fenced_ service
sub steal_service {
my ($self, $sid, $current_node, $new_node) = @_;
diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm
index 5ce174a..3715eff 100644
--- a/src/PVE/HA/Sim/Env.pm
+++ b/src/PVE/HA/Sim/Env.pm
@@ -167,6 +167,28 @@ sub read_service_config {
return $self->{hardware}->read_service_config();
}
+sub read_fence_config {
+ my ($self) = @_;
+
+ return $self->{hardware}->read_fence_config();
+}
+
+# the test/sim framework has hardware enabled fencing if
+# it has devices configured
+sub fencing_mode {
+ my ($self) = @_;
+
+ my $cfg = $self->read_fence_config();
+
+ return (defined($cfg) && keys %{$cfg}) ? 'hardware' : 'watchdog';
+}
+
+sub exec_fence_agent {
+ my ($self, $agent, $node, @param) = @_;
+
+ return $self->{hardware}->exec_fence_agent($agent, $node, @param);
+}
+
sub read_group_config {
my ($self) = @_;
diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index 652f11d..a212671 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -15,7 +15,8 @@ use IO::File;
use Fcntl qw(:DEFAULT :flock);
use File::Copy;
use File::Path qw(make_path remove_tree);
-use PVE::HA::Config 'testenv';
+use PVE::HA::Config;
+use PVE::HA::FenceConfig;
my $watchdog_timeout = 60;
@@ -114,7 +115,29 @@ sub write_service_config {
my $filename = "$self->{statusdir}/service_config";
return PVE::HA::Tools::write_json_to_file($filename, $conf);
-}
+}
+
+sub read_fence_config {
+ my ($self) = @_;
+
+ my $raw = undef;
+
+ my $filename = "$self->{statusdir}/fence.cfg";
+ if (-e $filename) {
+ $raw = PVE::Tools::file_get_contents($filename);
+ }
+
+ return PVE::HA::FenceConfig::parse_config($filename, $raw);
+}
+
+sub exec_fence_agent {
+ my ($self, $agent, $node, @param) = @_;
+
+ # let all agent succeed and behave the same for now
+ $self->sim_hardware_cmd("power $node off", $agent);
+
+ return 0; # EXIT_SUCCESS
+}
sub set_service_state {
my ($self, $sid, $state) = @_;
@@ -306,6 +329,9 @@ sub new {
$self->write_hardware_status_nolock($cstatus);
}
+ if (-f "$testdir/fence.cfg") {
+ copy("$testdir/fence.cfg", "$statusdir/fence.cfg");
+ }
my $cstatus = $self->read_hardware_status_nolock();
--
2.1.4
More information about the pve-devel
mailing list