httpd-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject Re: need help to add per-user config to Apache::Test
Date Fri, 05 Sep 2003 02:14:31 GMT
Randy Kobes wrote:
> On Wed, 3 Sep 2003, Stas Bekman wrote:
> 
> 
>>Randy Kobes wrote:
>>
>>>On Tue, 2 Sep 2003, Stas Bekman wrote:
> 
> [ .. ]
> 
>>It should work during 'make test' as well, since it already runs t/TEST
>>-config. And also whenever you provide any options to t/TEST it reconfigures,
>>so I believe the normal run will do the same:
>>
>>  t/TEST -save -httpd /usr/local/httpd/bin/httpd
>>
>>I haven't tested that though.
> 
> 
> I've checked that (with the diff below), and it seems to
> work now as you say, both within Apache-Test and for a 3rd
> party package. Without the -save the new -httpd is used,
> but not saved into Apache::TestConfigData.
> [ .. ]

Great!

>>>Good idea - that's much simpler. The following assumes
>>>that an empty Apache/TestConfigData.pm is present, and
>>>then, as you say, 'make install' will pick up any changes
>>>that have been made to it.
>>
>>If I remember correctly 'make install' will complain about
>>the mismatch in sizes since 'make' has already put the
>>files into blib? Did it work for you just fine? Purhaps we
>>do need to update the two.
> 
> 
> On linux, I tried installing Apache-Test, and then changing
> the settings via
>    t/TEST -save -httpd /path/to/some/other/httpd
> This wrote a new lib/Apache/TestConfigData.pm, and
>    make install
> did recognize the change, copied it over to blib/, and
> installed the new copy.

Very good!

> The diff below also includes a change to better get the
> location of Apache::TestConfigData.
> ==============================================================
> Index: lib/Apache/TestRun.pm
> ===================================================================
> RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestRun.pm,v
> retrieving revision 1.113
> diff -u -r1.113 TestRun.pm
> --- lib/Apache/TestRun.pm	22 Jul 2003 11:21:36 -0000	1.113
> +++ lib/Apache/TestRun.pm	4 Sep 2003 21:02:44 -0000
> @@ -11,19 +11,69 @@
>  use Apache::TestHarness ();
>  use Apache::TestTrace;
> 
> +use constant WIN32 => Apache::TestConfig::WIN32;
> +require Win32 if WIN32;
> +
> +use Cwd;
> +# Are we building things within Apache-Test?
> +sub in_apache_test {
> +    my $cwd =  WIN32 ? Win32::GetLongPathName(cwd) : cwd;
> +    return ($cwd =~ m{Apache-Test}) ? 1 : 0;
> +}

In the effort to remove some of the Win32 noise, I was thinking that we can 
write a generic function which gets a path as an argument and figures out 
internally if it needs to keep the argument as passed or mangle it. So it'll 
do something like:

     my $cwd =  Apache::TestUtil::path(cwd);

probably need a more intuitive name for this function.

I suppose we can do it after this patch goes in, so that we don't mix too many 
changes at once. Unless you want to provide that function first and then 
adjust the patch to use it. It's up to you, either way is fine.

> +use constant IN_APACHE_TEST => in_apache_test();
> +
> +require File::Spec;
> +# routine to determine where the configuration file
> +# Apache::TestConfigData lives. The order searched is
> +# 1) a path within Apache-Test, if we are building things there
> +# 2) an $ENV{HOME}/.apache-test/ directory;
> +# 3) somewhere in @INC, other than a path within Apache-Test.
> +sub config_data {
> +    my $sys_config;
> +    my $file = 'TestConfigData.pm';
> +    for (@INC) {
> +	my $candidate = File::Spec->catfile($_, 'Apache', $file);
> +	if (-e $candidate) {
> +	    $sys_config = $candidate;
> +	    last;
> +	}
> +    }
> +    if ($sys_config) {
> +	eval {require $sys_config};
> +	return $sys_config if (not $@ and IN_APACHE_TEST);
> +	$sys_config = undef if $@;
> +    }
> +    # XXX $ENV{HOME} isn't propagated in mod_perl
> +    if ($ENV{HOME}) {
> +	my $priv_config = File::Spec->catfile($ENV{HOME},
> +					      '.apache-test',
> +					      $file);
> +        eval {require $priv_config};
> +	return $priv_config unless $@;
> +    }
> +    return $sys_config ? $sys_config : undef;
> +}

all the above needs proper indentation (4).

> +use constant CONFIG_DATA => config_data();
> +
>  use File::Find qw(finddepth);
> -use File::Spec::Functions qw(catfile);
> +use File::Spec::Functions qw(catfile catdir);
>  use Getopt::Long qw(GetOptions);
> +use File::Basename;
>  use Config;
> +use Symbol;
> 
>  use constant STARTUP_TIMEOUT => 300; # secs (good for extreme debug cases)
>  use subs qw(exit_shell exit_perl);
> 
> +die 'Could not find a suitable Apache::TestConfigData'
> +    unless defined CONFIG_DATA;
> +
>  my %core_files  = ();
>  my %original_t_perms = ();
> 
>  my @std_run      = qw(start-httpd run-tests stop-httpd);
> -my @others       = qw(verbose configure clean help ssl http11);
> +my @others       = qw(verbose configure clean help ssl http11 save);
>  my @flag_opts    = (@std_run, @others);
>  my @string_opts  = qw(order trace);
>  my @ostring_opts = qw(proxy ping);
> @@ -55,6 +105,7 @@
>     'ssl'             => 'run tests through ssl',
>     'proxy'           => 'proxy requests (default proxy is localhost)',
>     'trace=T'         => 'change tracing default to: warning, notice, info, debug,
...',
> +   'save'            => 'save test paramaters into Apache::TestConfigData',
>     (map { $_, "\U$_\E url" } @request_opts),
>  );
> 
> @@ -407,6 +458,8 @@
>      $test_config->cmodules_configure;
>      $test_config->generate_httpd_conf;
>      $test_config->save;
> +    $self->write_config() if
> +        (not %{$Apache::TestConfigData} or $self->{opts}->{save});
>  }
> 
>  sub try_exit_opts {
> @@ -509,6 +562,10 @@
> 
>  sub new_test_config {
>      my $self = shift;
> +    for (qw(httpd port user group apxs)) {
> +        next unless $Apache::TestConfigData->{$_};
> +        $self->{conf_opts}->{$_} ||= $Apache::TestConfigData->{$_};
> +    }

Just a sanity check, the env var overrides (.e.g. USER) come in later, right?

> +sub write_config {
> +    my $self = shift;
> +    my $fh = Symbol::gensym();
> +    my $vars = $self->{test_config}->{vars};
> +    my $conf_opts = $self->{conf_opts};
> +    my $file = IN_APACHE_TEST ?
> +	catfile($vars->{top_dir}, CONFIG_DATA) :
> +	CONFIG_DATA;
> +    die "Cannot open $file: $!" unless (open($fh, ">$file"));
> +    warn "Writing $file.\n";
> +    my $config_dump = '';
> +    if ($self->{test_config}->{vars}->{httpd}) {
> +	for (qw(group user apxs port httpd)) {
> +	    next unless my $var = $conf_opts->{$_} || $vars->{$_};
> +	    $config_dump .= qq{    '$_' => } . qq{'$var',\n};
> +	}
> +    }

more indentation...

what else do we miss in this implementation (besides $HOME)?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Mime
View raw message