[pve-devel] [RFC v3 pve-ha-manager 1/8] TestHardware: add 'reboot' and 'shutdown' command
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Dec 16 09:36:10 CET 2015
On 12/16/2015 09:04 AM, Dietmar Maurer wrote:
> Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
> ---
> src/PVE/HA/Sim/TestHardware.pm | 43 +++++++++++++++++++++++++++++++----
> src/test/test-reboot1/cmdlist | 4 ++++
> src/test/test-reboot1/hardware_status | 5 ++++
> src/test/test-reboot1/log.expect | 35 ++++++++++++++++++++++++++++
> src/test/test-reboot1/manager_status | 1 +
> src/test/test-reboot1/service_config | 3 +++
> 6 files changed, 86 insertions(+), 5 deletions(-)
> create mode 100644 src/test/test-reboot1/cmdlist
> create mode 100644 src/test/test-reboot1/hardware_status
> create mode 100644 src/test/test-reboot1/log.expect
> create mode 100644 src/test/test-reboot1/manager_status
> create mode 100644 src/test/test-reboot1/service_config
>
> diff --git a/src/PVE/HA/Sim/TestHardware.pm b/src/PVE/HA/Sim/TestHardware.pm
> index d49d9c0..06a3208 100644
> --- a/src/PVE/HA/Sim/TestHardware.pm
> +++ b/src/PVE/HA/Sim/TestHardware.pm
> @@ -84,6 +84,8 @@ sub log {
> # simulate hardware commands
> # power <node> <on|off>
> # network <node> <on|off>
> +# reboot <node>
> +# shutdown <node>
>
> sub sim_hardware_cmd {
> my ($self, $cmdstr, $logid) = @_;
> @@ -95,7 +97,6 @@ sub sim_hardware_cmd {
> my ($cmd, $node, $action) = split(/\s+/, $cmdstr);
>
> die "sim_hardware_cmd: no node specified" if !$node;
> - die "sim_hardware_cmd: unknown action '$action'" if $action !~ m/^(on|off)$/;
>
> my $d = $self->{nodes}->{$node};
> die "sim_hardware_cmd: no such node '$node'\n" if !$d;
> @@ -103,6 +104,7 @@ sub sim_hardware_cmd {
> $self->log('info', "execute $cmdstr", $logid);
>
> if ($cmd eq 'power') {
> + die "sim_hardware_cmd: unknown action '$action'" if $action !~ m/^(on|off)$/;
> if ($cstatus->{$node}->{power} ne $action) {
> if ($action eq 'on') {
> $d->{crm} = PVE::HA::CRM->new($d->{crm_env}) if !$d->{crm};
> @@ -121,14 +123,29 @@ sub sim_hardware_cmd {
>
> $cstatus->{$node}->{power} = $action;
> $cstatus->{$node}->{network} = $action;
> + $cstatus->{$node}->{shutdown} = undef;
> +
> + $self->write_hardware_status_nolock($cstatus);
>
> } elsif ($cmd eq 'network') {
> - $cstatus->{$node}->{network} = $action;
> + die "sim_hardware_cmd: unknown action '$action'" if $action !~ m/^(on|off)$/;
> + $cstatus->{$node}->{network} = $action;
> +
> + $self->write_hardware_status_nolock($cstatus);
> +
> + } elsif ($cmd eq 'reboot' || $cmd eq 'shutdown') {
> + $cstatus->{$node}->{shutdown} = $cmd;
> +
> + $self->write_hardware_status_nolock($cstatus);
> +
> + if ($d->{lrm}) {
> + $d->{lrm_env}->log('info', "got shutdown request");
> + $d->{lrm}->shutdown_request();
> + }
> } else {
> - die "sim_hardware_cmd: unknown command '$cmd'\n";
> + die "sim_hardware_cmd: unknown command '$cmdstr'\n";
> }
>
> - $self->write_hardware_status_nolock($cstatus);
> };
>
> return $self->global_lock($code);
> @@ -174,12 +191,28 @@ sub run {
>
> $d->{lrm_env}->loop_start_hook($self->get_time());
>
> - die "implement me (LRM exit)" if !$lrm->do_one_iteration();
> + my $exit_lrm = !$lrm->do_one_iteration();
>
> $d->{lrm_env}->loop_end_hook();
>
> my $nodetime = $d->{lrm_env}->get_time();
> $self->{cur_time} = $nodetime if $nodetime > $self->{cur_time};
> +
> + if ($exit_lrm) {
> + $d->{lrm_env}->log('info', "exit (loop end)");
> + $d->{lrm} = undef;
> + my $cstatus = $self->read_hardware_status_nolock();
> + my $nstatus = $cstatus->{$node} || die "no node status for node '$node'";
> + my $shutdown = $nstatus->{shutdown};
maybe better:
my $shutdown = $nstatus->{shutdown} || '';
to avoid undef warnings, else everything is OK (and quite a lot simpler)
in my opinion.
> + if ($shutdown eq 'reboot') {
> + $self->sim_hardware_cmd("power $node off", 'reboot');
> + $self->sim_hardware_cmd("power $node on", 'reboot');
> + } elsif ($shutdown eq 'shutdown') {
> + $self->sim_hardware_cmd("power $node off", 'shutdown');
> + } else {
> + die "unexpected LRM exit - not implemented"
> + }
> + }
> }
>
> foreach my $n (@nodes) {
> diff --git a/src/test/test-reboot1/cmdlist b/src/test/test-reboot1/cmdlist
> new file mode 100644
> index 0000000..8558351
> --- /dev/null
> +++ b/src/test/test-reboot1/cmdlist
> @@ -0,0 +1,4 @@
> +[
> + [ "power node1 on", "power node2 on", "power node3 on"],
> + [ "reboot node3" ]
> +]
> diff --git a/src/test/test-reboot1/hardware_status b/src/test/test-reboot1/hardware_status
> new file mode 100644
> index 0000000..119b81c
> --- /dev/null
> +++ b/src/test/test-reboot1/hardware_status
> @@ -0,0 +1,5 @@
> +{
> + "node1": { "power": "off", "network": "off" },
> + "node2": { "power": "off", "network": "off" },
> + "node3": { "power": "off", "network": "off" }
> +}
> \ No newline at end of file
> diff --git a/src/test/test-reboot1/log.expect b/src/test/test-reboot1/log.expect
> new file mode 100644
> index 0000000..d9d8771
> --- /dev/null
> +++ b/src/test/test-reboot1/log.expect
> @@ -0,0 +1,35 @@
> +info 0 hardware: starting simulation
> +info 20 cmdlist: execute power node1 on
> +info 20 node1/crm: status change startup => wait_for_quorum
> +info 20 node1/lrm: status change startup => wait_for_agent_lock
> +info 20 cmdlist: execute power node2 on
> +info 20 node2/crm: status change startup => wait_for_quorum
> +info 20 node2/lrm: status change startup => wait_for_agent_lock
> +info 20 cmdlist: execute power node3 on
> +info 20 node3/crm: status change startup => wait_for_quorum
> +info 20 node3/lrm: status change startup => wait_for_agent_lock
> +info 20 node1/crm: got lock 'ha_manager_lock'
> +info 20 node1/crm: status change wait_for_quorum => master
> +info 20 node1/crm: node 'node1': state changed from 'unknown' => 'online'
> +info 20 node1/crm: node 'node2': state changed from 'unknown' => 'online'
> +info 20 node1/crm: node 'node3': state changed from 'unknown' => 'online'
> +info 20 node1/crm: adding new service 'vm:103' on node 'node3'
> +info 22 node2/crm: status change wait_for_quorum => slave
> +info 24 node3/crm: status change wait_for_quorum => slave
> +info 25 node3/lrm: got lock 'ha_agent_node3_lock'
> +info 25 node3/lrm: status change wait_for_agent_lock => active
> +info 25 node3/lrm: starting service vm:103
> +info 25 node3/lrm: service status vm:103 started
> +info 120 cmdlist: execute reboot node3
> +info 120 node3/lrm: got shutdown request
> +info 120 node1/crm: service 'vm:103': state changed from 'started' to 'freeze'
> +info 126 node3/lrm: exit (loop end)
> +info 126 reboot: execute power node3 off
> +info 125 node3/crm: killed by poweroff
> +info 126 reboot: execute power node3 on
> +info 125 node3/crm: status change startup => wait_for_quorum
> +info 126 node3/lrm: status change startup => wait_for_agent_lock
> +info 144 node3/crm: status change wait_for_quorum => slave
> +info 160 node1/crm: service 'vm:103': state changed from 'freeze' to 'started'
> +info 165 node3/lrm: status change wait_for_agent_lock => active
> +info 720 hardware: exit simulation - done
> diff --git a/src/test/test-reboot1/manager_status b/src/test/test-reboot1/manager_status
> new file mode 100644
> index 0000000..9e26dfe
> --- /dev/null
> +++ b/src/test/test-reboot1/manager_status
> @@ -0,0 +1 @@
> +{}
> \ No newline at end of file
> diff --git a/src/test/test-reboot1/service_config b/src/test/test-reboot1/service_config
> new file mode 100644
> index 0000000..c3b22c8
> --- /dev/null
> +++ b/src/test/test-reboot1/service_config
> @@ -0,0 +1,3 @@
> +{
> + "vm:103": { "node": "node3", "state": "enabled" }
> +}
> \ No newline at end of file
More information about the pve-devel
mailing list