# This is a prototype. It still needs to be documented. # This object represents various usually-global state in a test # script. NACL::Realm->realm() gets/sets the test-process-global # realm. One can imagine creating more local versions to override # usually-global things in less-global contexts, but we haven't yet # made that very compelling (resource records are currently dependent # on test-global input). See the NACL Arch Spec for the idea. # Instances of NACL::Cleanup(.*) may wish to be added here. # NATE::ParamSet may wish to be added here, to the extent that it can # be a test tree thing rather than a Tharn.pm and Subtest.pm thing. # # Copyright (c) 2001-2014 NetApp, Inc., All Rights Reserved # Any use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @summary Represents the test environment of tests ## @author lincoln, dl-nacl-dev@netapp.com ## @status shared ## @pod here package NACL::Realm; use strict; use warnings; use NATE::Log qw(log_global); my $Log = log_global(); my $may_enter = $Log->may_enter(); my $may_exit = $Log->may_exit(); use NATE::Events qw(call_on_fork_add); use NACL::ResourceRecords; use Params::Validate qw(validate :types); use NACL::Realm::HelpXmlStore; use Class::MethodMaker [ new => [ '-hash', 'new' ], scalar => [ { '-default_ctor' => sub { require NACL::Cleanup; NACL::Cleanup->new(); }, }, 'cleanup' ], scalar => [ { '-default_ctor' => sub { NACL::ResourceRecords->new(); }, }, 'resource_records' ], scalar => [ '-static', { '-default_ctor' => sub { NACL::Realm->new(); } }, 'realm' ], hash => '_help_xml_store', ]; # Every subtest had better reformulate its own ideas of what # resource records are associated with the subtest based on the # parameters passed to that subtest, rather than allow itself to # inherit the full resource list from the parent. # So, whenever a fork-without-exec happens (ugh) we clear out the # old resource record object. Once the child is alive enough to # call $realm->resource_records(), that method will build a new # resource record object and thus a new list of resource records. call_on_fork_add( { callback => sub { NACL::Realm->realm()->resource_records_reset(); }, keep_on_fork => 1, }, { callback => sub { NACL::Realm->realm()->cleanup_reset(); }, keep_on_fork => 1, }, ); sub get_help_xml_obj { $Log->enter() if $may_enter; my ( $self, @args ) = @_; my %opts = validate( @args, { command_interface => { type => OBJECT, isa => 'NACL::C::CommandInterface::ONTAP', optional => 1 }, }, ); my $version_mgr = $opts{command_interface}->version_manager(); my $build_root = $version_mgr->get_version_attribute( attribute => 'build_path' ); if ( $self->_help_xml_store_exists($build_root) ) { $Log->exit() if $may_exit; return $self->_help_xml_store_index($build_root); } else { my $obj = NACL::Realm::HelpXmlStore->new( build_root => $build_root, version_manager => $version_mgr, ); $self->_help_xml_store_set( $build_root => $obj ); $Log->exit() if $may_exit; return $obj; } } 1;