IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 27, 2019, 12:04:14 PM (7 years ago)
Author:
eugene
Message:

merging updates to Nebulous from EAM dev branch ipp-20191011

Location:
trunk/Nebulous-Server
Files:
16 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/Build.PL

    r39926 r41172  
    4343    },
    4444    script_files        => [qw(
    45         bin/neb-admin
    46         bin/neb-fsck
    4745        bin/neb-cabadd
    4846        bin/neb-voladd
     
    5452    )],
    5553)->create_build_script;
     54
     55# these scripts are no longer installed (2019.10.31)
     56#       bin/neb-admin
     57#       bin/neb-fsck
  • trunk/Nebulous-Server/MANIFEST

    r32383 r41172  
    44MANIFEST
    55README
    6 bin/neb-admin
    7 bin/neb-fsck
    8 bin/neb-initdb
    96bin/neb-voladd
    107bin/neb-cabadd
  • trunk/Nebulous-Server/bin/neb-voladd

    r28492 r41172  
    4343
    4444my $dbh = DBI->connect(
     45    # if you want to work with the localhost database but get socket path errors,
     46    # you should set the server host as 127.0.0.1 (not localhost)
     47
     48    # the following tells DBI to read the mysql/my.cnf files
     49    #  "DBI:mysql:database=$db:host=$dbhost:mysql_read_default_group=dbd_mysql",
     50
    4551    "DBI:mysql:database=$db:host=$dbhost",
    4652    $dbuser,
  • trunk/Nebulous-Server/docs/apache2-mod_perl-startup.pl

    r23687 r41172  
    2828use Nebulous::Server;
    2929
    30 my $dsn         = 'DBI:mysql:database=nebulous:host=ipp019.ifa.hawaii.edu';
     30my $dsn         = 'DBI:mysql:database=nebulous:host=nebulous.ipp.ifa.hawaii.edu';
    3131my $dbuser      = 'nebulous';
    32 my $dbpasswd    = '@neb@';
     32my $dbpasswd    = 'XXXX';
    3333
    3434#$Apache::DBI::DEBUG = 1;
    3535#Apache::DBI->connect_on_init( $dsn, $dbuser, $dbpasswd );
    3636Apache::DBI->setPingTimeOut($dsn, 10);
    37 Nebulous::Server::SOAP->new_on_init(
     37
     38my $config = Nebulous::Server::Config->new(
     39    trace       => 'warn',
     40                                           );
     41$config->add_db(
     42    dbindex     => 0,
    3843    dsn         => $dsn,
    3944    dbuser      => $dbuser,
    4045    dbpasswd    => $dbpasswd,
    41     log_level   => 'all',
    42 );
     46                );
     47
     48Nebulous::Server::SOAP->new_on_init($config);
     49
    4350
    44511;
  • trunk/Nebulous-Server/docs/install.txt

    r23687 r41172  
    5555    export NEB_PASS=@neb@
    5656
     57    *** this is very dangerous and should only be run in test examples:
    5758    neb-initdb
    5859
    59     neb-voladd --vhost ipp000 --vname ipp000.0 --uri file:///data/ipp000.0/nebulous
    60     neb-voladd --vhost ipp001 --vname ipp000.1 --uri file:///data/ipp000.1/nebulous
    61     neb-voladd --vhost ipp002 --vname ipp002.0 --uri file:///data/ipp002.0/nebulous
    62     neb-voladd --vhost ipp003 --vname ipp003.0 --uri file:///data/ipp003.0/nebulous
    63     neb-voladd --vhost ipp022 --vname ipp022.0 --uri file:///data/ipp022.0/nebulous
     60    neb-voladd --vhost ipp000 --vname ipp000.0 --uri file:///data/ipp000.0/nebulous --mountpoint /data/ipp000.0/nebulous
     61    neb-voladd --vhost ipp001 --vname ipp000.1 --uri file:///data/ipp000.1/nebulous --mountpoint /data/ipp000.1/nebulous
     62    neb-voladd --vhost ipp002 --vname ipp002.0 --uri file:///data/ipp002.0/nebulous --mountpoint /data/ipp002.0/nebulous
     63    neb-voladd --vhost ipp003 --vname ipp003.0 --uri file:///data/ipp003.0/nebulous --mountpoint /data/ipp003.0/nebulous
     64    neb-voladd --vhost ipp022 --vname ipp022.0 --uri file:///data/ipp022.0/nebulous --mountpoint /data/ipp022.0/nebulous
    6465
    6566    # or in bulk:
  • trunk/Nebulous-Server/lib/Nebulous/Server.pm

    r39926 r41172  
    1313use base qw( Class::Accessor::Fast );
    1414
     15use Carp;
     16
    1517use Cache::Memcached;
    1618use DBI;
     19
     20## for gentoo:
    1721use Digest::SHA1 qw( sha1_hex );
     22
     23## for ubuntu:
     24# use Digest::SHA qw( sha1_hex );
     25
    1826use Fcntl ':mode';
    1927use File::Basename qw( basename dirname fileparse );
     
    7785        Cache::Memcached->new({
    7886            servers => $config->memcached_servers,
    79        })
    80     );
     87                              })
     88        );
    8189#    $self->cache->set("foo", "bar") or die "set failed";
    8290#    $self->cache->get("foo") or die "get failed";
     
    215223}
    216224
     225my $get_storage_volume_calls = 0;
     226
    217227sub create_object
    218228{
     
    252262    # the key's volume can't be validiated on input for this method so we have
    253263    # to check it after parsing the key
    254     if (defined $vol_name
    255         and not $self->_is_valid_volume_name($key, $key->volume)) {
     264    if (defined $vol_name and not $self->_is_valid_volume_name($key, $key->volume)) {
    256265        unless ($key->hard_volume) {
    257266            $log->warn( "$vol_name is not a known volume name" );
     
    262271    }
    263272       
     273    $get_storage_volume_calls = 0;
     274
    264275    my ($vol_id, $vol_host, $vol_path, $vol_xattr)
    265276        = $self->_get_storage_volume($key, $vol_name, $key->hard_volume);
     
    273284                # create storage_object
    274285                my $query = $db->prepare_cached( $sql->new_object );
    275                 $query->execute('NULL', $key->path, basename($key->path), $parent_id);
     286# bad syntax    $query->execute('NULL', $key->path, basename($key->path), $parent_id);
     287                $query->execute(0, $key->path, basename($key->path), $parent_id);
     288                $query->finish;
    276289            }
    277290
     
    292305                my $query = $db->prepare_cached( $sql->new_object_attr );
    293306                $query->execute($so_id);
     307                $query->finish;
    294308            }
    295309
     
    300314                my $query = $db->prepare_cached( $sql->new_object_instance );
    301315                $query->execute($vol_id);
     316                $query->finish;
    302317            }
    303318
     
    327342                # vol_id, uri, ins_id
    328343                $query->execute($vol_id, "$uri", $ins_id);
     344                $query->finish;
    329345            }
    330346
     
    421437                    }
    422438                    $query->finish;
     439                    $db->commit;
    423440                }
    424441
     
    441458                    my $query = $db->prepare_cached($sql->new_directory);
    442459                    $query->execute($dir, $parent_id);
     460                    $query->finish;
     461                    $db->commit;
    443462                }
    444463
     
    452471                    ($parent_id) = $query->fetchrow_array;
    453472                    $query->finish;
     473                    $db->commit;
    454474                }
    455475                die("failed to get LAST_INSERT_ID()")
    456476                    unless $parent_id;
    457 
    458                 $db->commit;
    459477            }
    460478        };
     
    712730        {
    713731            type        => SCALAR|UNDEF,
    714 #            callbacks   => {
    715 #                # check that the volume name requested is valid
    716 #                'is valid volume name' => sub {
    717 #                    return 1 if not defined $_[0];
    718 #                    $self->_is_valid_volume_name($_[0])
    719 #                },
    720 #            },
    721732            optional    => 1,
    722733        },
     
    726737
    727738    # if a volume name is explicity specified then we should make the
    728     # replication onto that volume (even if there is alread an instance on that
     739    # replication onto that volume (even if there is already an instance on that
    729740    # volume) if at all possible and throw an error if we can not.
     741
    730742    # if a volume name IS NOT specified then we should make the replication
    731743    # onto any (hopefully the best) volume that DOES NOT already have an
    732     # instance on it.  If all avilable volume already have an instance on them
     744    # instance on it.  If all available volumes already have an instance on them
    733745    # then we should throw an error
     746
    734747    # volume names implied as part of the key are *IGNORED* as the source and
    735748    # *SHOULD NOT* be used as the destination either
    736749
    737750    eval {
    738         $key = parse_neb_key($key);
     751        # EAM 2019.10.31 : if I supply dest_vol_name here, then
     752        # $key->volume will point at that volume and the section below
     753        # will correctly be testing the validity of dest_vol_name
     754        $key = parse_neb_key($key, $dest_vol_name);
    739755    };
    740756    $log->logdie("$@") if $@;
     
    742758    my $db  = $self->db($key);
    743759
     760    ## Old comment:
    744761    # puke if the source volume is bogus, we may want to actually use this as
    745762    # the instance to be copied later
    746     if (defined $key->volume
    747         and not $self->_is_valid_volume_name($key, $key->volume)) {
     763
     764    # EAM 2019.10.31 : in the past, the key-implied volume was
     765    # supplied here, which was inconsistent since above it says the
     766    # key-implied volume is ignored. By supplying $dest_vol_name to
     767    # parse_neb_key above, the key->volume now refers to the
     768    # dest_volume
     769    if (defined $key->volume and not $self->_is_valid_volume_name($key, $key->volume)) {
    748770        unless ($key->hard_volume) {
    749771            $log->warn($key->volume . " not a known volume name");
     
    752774        }
    753775    }
    754     # puke if the source volume is bogus, we may want to actually use this as
    755     # the instance to be copied later
    756     if (defined $dest_vol_name
    757         and not $self->_is_valid_volume_name($key, $dest_vol_name)) {
    758            $log->logdie($key->volume . " is not a valid volume name");
    759     }
    760        
     776
     777    # puke if the destination volume is bogus
     778    ## XXX if I supply dest_vol_name to parse_neb_key above, this section below is redundant with the above
     779    ## if (defined $dest_vol_name
     780    ##     and not $self->_is_valid_volume_name($key, $dest_vol_name)) {
     781    ##        $log->logdie($key->volume . " is not a valid volume name");
     782    ## }
     783
     784    $get_storage_volume_calls = 0;
     785
    761786    my ($vol_id, $vol_host, $vol_path, $vol_xattr);
    762787    if (defined $dest_vol_name) {
     788        # if we supplied dest_vol_name, then the call to parse_neb_key above
     789        # will have set $key->volume to that value and hard_volume to match
    763790        ($vol_id, $vol_host, $vol_path, $vol_xattr)
    764             = $self->_get_storage_volume($key, $dest_vol_name);
     791            = $self->_get_storage_volume($key, $key->volume, $key->hard_volume);
    765792    } else {
    766793        ($vol_id, $vol_host, $vol_path, $vol_xattr)
    767794            = $self->_get_replication_volume($key);
    768795    }
     796
     797    # print "selected target: $vol_id, $vol_host\n";
    769798
    770799    my $uri;
     
    784813                $so_id = $query->fetchrow_hashref->{ 'so_id' };
    785814                $query->finish;
     815                $db->commit;
    786816            }
    787817
     
    800830                # time LAST_INSERT_ID() is invoked
    801831                $query->finish;
     832                $db->commit;
    802833            }
    803834
     
    841872    eval {
    842873        my $mode = $self->getxattr_object("$key", 'user.mode');
    843         if (defined $mode) {
    844             $self->chmod_object("$key", $mode);
     874        if (defined $mode && $mode ne "") {
     875            $self->chmod_object("$key", $mode);
    845876        }
    846877    };
     
    852883
    853884    $log->debug("leaving");
    854 
    855885    return "$uri";
    856886}
     
    13231353            die( "xattr $key:$name does not exist" );
    13241354        }
     1355
    13251356        # if we go more then one row bad something very bad has happened.
    13261357        unless ($rows == 1) {
     
    13351366        $value = $row->{ 'value' };
    13361367    };
     1368    $db->commit;
     1369
    13371370    if ($@) {
    13381371        if ($@ =~ /user\..*? does not exist/) {
    13391372            # do not log xattr does not exist messages
     1373            # NOTE: the client is using the reported message to interpret the errors
    13401374            die $@;
    13411375        }
     
    13861420    };
    13871421    $log->logdie("database error: $@") if $@;
     1422    $db->commit;
    13881423
    13891424    $log->debug("leaving");
     
    14421477                die( "affected row count is $rows instead of 1" );
    14431478            }
    1444 
    14451479            $db->commit;
    14461480            $log->debug("commit");
     
    15451579        $work_dir = $pattern;
    15461580        $file_pattern = '%';
    1547     }
    1548     else {
     1581    } else {
    15491582        my $dir_plain = dirname($pattern);
    15501583        if ($dir_plain eq 'neb:') {
     
    15751608        my $query = $db->prepare_cached( $sql->find_dir_by_parent_id . " AND dirname LIKE ? ");
    15761609        $query->execute( $dir_id, $file_pattern );
     1610        $db->commit;
    15771611
    15781612        while ( my $row = $query->fetchrow_hashref ) {
     
    15951629        my $query = $db->prepare_cached( $sql->find_object_by_dir_id . " AND ext_id_basename LIKE ? ");
    15961630        $query->execute( $dir_id , $file_pattern);
     1631        $db->commit;
    15971632
    15981633        while ( my $row = $query->fetchrow_hashref ) {
     
    16241659    my $sql = $self->sql;
    16251660    my $db  = $self->_db_for_index($index);
    1626 
    16271661
    16281662    # first check to see if the key is an exact match
     
    16451679        $log->logdie("database error: $@");
    16461680    }
     1681    $db->commit;
    16471682
    16481683    if (scalar @keys) {
     
    16781713    };
    16791714    $log->logdie("database error: $@") if $@;
     1715    $db->commit;
    16801716
    16811717    # find files under dir
     
    16921728    };
    16931729    $log->logdie("database error: $@") if $@;
     1730    $db->commit;
    16941731
    16951732    $log->debug( "leaving" );
     
    17531790}
    17541791
     1792# sub find_instances
    17551793sub find_instances_old
    17561794{
     
    17691807        {
    17701808            type        => SCALAR|UNDEF,
    1771 #            callbacks   => {
    1772 #                # check that the volume name requested is valid
    1773 #                'is valid volume name' => sub {
    1774 #                    return 1 if not defined $_[0];
    1775 #                    $self->_is_valid_volume_name($_[0])
    1776 #                },
    1777 #            },
    17781809            optional    => 1,
    17791810        },
     
    17871818    my $sql = $self->sql;
    17881819
    1789 #    unless ($key) {
    1790 #        $log->warn("key was undefined after validate_pos(), trying again...");
    1791 #        return $self->find_instances(@_);
    1792 #    }
     1820    # default value for find_invalid is false
     1821    if (not defined $find_invalid) { $find_invalid = 0; }
    17931822
    17941823    # vol_name overrides the key implied volume
     
    18281857            my $rows;
    18291858            # ext_id, available
    1830             if (defined($find_invalid)) {
     1859            if (defined($find_invalid) and $find_invalid) {
     1860                # XXX returns instances which are NOT available
    18311861                $rows = $query->execute($key->path, 0);
    18321862            }
     
    18651895}
    18661896
    1867 #sub find_instances_by_proximity
     1897# sub find_instances_by_proximity
    18681898sub find_instances
    18691899{
     
    18821912        {
    18831913            type        => SCALAR|UNDEF,
    1884 #            callbacks   => {
    1885 #                # check that the volume name requested is valid
    1886 #                'is valid volume name' => sub {
    1887 #                    return 1 if not defined $_[0];
    1888 #                    $self->_is_valid_volume_name($_[0])
    1889 #                },
    1890 #            },
    18911914            optional    => 1,
    18921915        },
     
    18971920        },
    18981921    );
    1899 
    19001922    my $sql = $self->sql;
    19011923
    1902 #    unless ($key) {
    1903 #        $log->warn("key was undefined after validate_pos(), trying again...");
    1904 #        return $self->find_instances(@_);
    1905 #    }
     1924    if (not defined $find_invalid) { $find_invalid = 0; }
     1925
     1926    if ($find_invalid eq "find them all") {
     1927        $log->logdie("old neb-cull --one_only, neb-rm --invalid both disabled by new Server.pm");
     1928    }
    19061929
    19071930    # vol_name overrides the key implied volume
     
    19321955            }
    19331956        }
    1934 
    1935 
    19361957    }
    19371958
     
    19721993            # ext_id, name, available
    19731994            # host_vol_id host_cab_id host_site_id ext_id available
    1974             my $rows = $query->execute($h_vol_id, $h_cab_id, $h_site_id, $key->path, 1);
     1995
     1996            my $rows;
     1997            if (defined($find_invalid) and $find_invalid) {
     1998                # returns instances which are NOT available (volume not available)
     1999                $rows = $query->execute($h_vol_id, $h_cab_id, $h_site_id, $key->path, 0);
     2000            } else {
     2001                $rows = $query->execute($h_vol_id, $h_cab_id, $h_site_id, $key->path, 1);
     2002            }           
    19752003            unless ($rows > 0) {
    19762004                $query->finish;
    1977                 die("no instances on storage volume or volume is not avaiable for key: $key volume: $vol_name");
     2005                die("no instances on storage volume or volume is not available for key: $key volume: $vol_name");
    19782006            }
    19792007        } else {
    19802008            $query = $db->prepare_cached( $sql->get_object_instances );
     2009            # ext_id, available
     2010
    19812011            my $rows;
    1982             # ext_id, available
    1983             if (defined($find_invalid)) {
     2012            if (defined($find_invalid) and $find_invalid) {
     2013                # returns instances which are NOT available (volume not available)
    19842014                $rows = $query->execute($key->path, 0);
    1985             }
    1986             else {
     2015            } else {
    19872016                $rows = $query->execute($key->path, 1);
    19882017            }
     
    19922021            }
    19932022        }
     2023        $db->commit;
     2024        ## if we do not call commit here, the transaction stays
     2025        ## open blocking some operations below.
    19942026
    19952027        while (my $row = $query->fetchrow_hashref) {
    19962028            my $instance = $row->{ 'uri' };
    19972029            push @locations, $instance if $instance;
     2030
     2031            # Carp::carp ("instance 2: $row->{ 'uri' }, $row->{ 'vol_id' }, $row->{ 'cab_id' }, $row->{ 'vol_idx' }\n");
    19982032        }
    19992033    };
     
    20032037        if (defined $vol_name and not defined $key->hard_volume) {
    20042038            $log->debug("retrying with 'any' volume");
    2005             return $self->find_instances($key->path, 'any');
     2039            return $self->find_instances($key->path, 'any', $find_invalid);
    20062040        }
    20072041        $log->logdie("database error: $@");
     
    20182052}
    20192053
     2054# this method returns instances on the specified volume
     2055# or a list of all available instances
     2056# it does NOT choose instances based on proximity
     2057# and it does NOT return invalid instances
    20202058sub find_instances_for_cull
    20212059{
     
    20612099    my $db  = $self->db($key);
    20622100
     2101    ## XXX this method is missing the alias deference section (see find_instances)
     2102    ## if aliases are intended to be compute nodes in the same cabinet / site as
     2103    ## the storage nodes, then this is not needed.
     2104
    20632105    # the key's volume can't be validiated on input for this method so we have
    20642106    # to check it after parsing the key
     
    20822124            unless ($rows > 0) {
    20832125                $query->finish;
    2084                 die("no instances on storage volume or volume is not avaiable for key: $key volume: $vol_name");
     2126                die("no instances on storage volume or volume is not available for key: $key volume: $vol_name");
    20852127            }
    20862128        } else {
     
    21052147        $db->rollback;
    21062148        # handle soft volumes
    2107         if (defined $vol_name and not defined $key->hard_volume) {
     2149        # we need to call find_intances_for_cull here so the returned structure
     2150        # is the same (find_instances just returns an array of strings)
     2151        if (defined $vol_name and not defined $key->hard_volume and ($vol_name ne "any")) {
    21082152            $log->debug("retrying with 'any' volume");
    2109             return $self->find_instances($key->path, 'any');
     2153            return $self->find_instances_for_cull($key->path, 'any');
    21102154        }
    21112155        $log->logdie("database error: $@");
    21122156    }
     2157    $db->commit;
    21132158
    21142159    # XXX remove this?
     
    22222267                }
    22232268            }
    2224 
    22252269            $db->commit;
    22262270            $log->debug("commit");
     
    22822326        $stat = $query->fetchrow_arrayref;
    22832327        $query->finish;
     2328        $db->commit;
    22842329    };
    22852330    $log->logdie("database error: $@") if $@;
     
    23182363    };
    23192364    $log->logdie("database error: $@") if $@;
     2365    $db->commit;
    23202366
    23212367    $log->logdie("no mounted volumes found") unless (scalar @$stats);
     
    24152461    my ($key, $name, $hard_volume) = @_;
    24162462   
    2417 #    $log->warn("_g_s_v: key:>$key< name:>$name< hard_vol:>$hard_volume<");
     2463    # track the number of calls to this function and
     2464    # give up after 10 attempts
     2465    $get_storage_volume_calls ++;
     2466
     2467#   $log->warn("_g_s_v: key:>$key< name:>$name< hard_vol:>$hard_volume<");
    24182468    my $sql = $self->sql;
    24192469    my $db  = $self->db($key);
     
    24272477            # %free, name, avaiable, allocate
    24282478            $rows = $query->execute($max_used_space, $name, 1, 1);
    2429             # XXX destinguish between non-existant and unavailable
     2479            # XXX distinguish between non-existant and unavailable
    24302480            unless ($rows > 0) {
    24312481                $query->finish;
     2482                $db->commit;
    24322483
    24332484                # if a volume name was specified, and is soft, and we failed to
     
    24422493            if ($rows > 1) {
    24432494                $query->finish;
     2495                $db->commit;
    24442496                die("affected row count is $rows instead of 1");
    24452497            }
     
    24492501            $rows = $query->execute($max_used_space, 1, 1, $topfew_count);
    24502502#           $log->warn("Storage_volume: $rows $topfew_count");
    2451             # there has to be atleast one storage volume
     2503            # there has to be at least one storage volume
    24522504            unless ($rows > 0) {
    24532505                $query->finish;
    2454                 die("no storage volume is available for key: $key volume: $name hard_volume: $hard_volume");
     2506                $db->commit;
     2507                # prevent failure in the die due to undefined variables
     2508                my $hard_volume_str = defined $hard_volume ? $hard_volume : "undefined";
     2509                my $name_str = defined $name ? $name : "undefined";
     2510                die("no storage volume is available for key: $key volume: $name_str hard_volume: $hard_volume_str");
    24552511            }
    24562512        }
     
    24652521            $log->error($@);
    24662522            $log->debug("retrying...");
    2467             return $self->_get_storage_volume(@_);
     2523            if ($get_storage_volume_calls < 10) {
     2524                return $self->_get_storage_volume(@_);
     2525            }
     2526            # else
     2527            $log->logdie("no available storage volume: $@");
    24682528        }
    24692529        # else
     
    25022562        unless ($rows > 0) {
    25032563            $query->finish;
    2504             die("Requested key $key does not exist");
     2564            die("Requested key $key does not exist (or cabinet is undefined)");
    25052565        }
    25062566        if ($rows == 1) {
     
    25132573            }
    25142574            $query->finish;
    2515         }
    2516         else {
     2575        } else {
     2576            # if instances are spread across multiple cabinets, allow the next instance to go anywhere
     2577            # NOTE: this does not prevent the new instance from going to the same volume as one of the existing instances
    25172578            $forbidden_cabinet = 0;
    25182579            $forbidden_site    = 0;
    25192580            $query->finish;
    25202581        }
    2521            
     2582        $db->commit;
    25222583
    25232584        $query = $db->prepare_cached( $sql->get_replication_volume_for_ext_id );
    2524         # ext_id, %free, avaiable, allocate
     2585        # ext_id, %free, available, allocate
     2586
    25252587        $rows = $query->execute($key->path, $max_used_space, 1, 1, $forbidden_cabinet, $forbidden_site, $topfew_count);
    2526         # XXX destinguish between non-existant and unaviable
     2588        # XXX distinguish between non-existant and unavailable
    25272589        unless ($rows > 0) {
    25282590            $query->finish;
     
    25442606        ($vol_id, $vol_host, $vol_path, $xattr, $free) = $query->fetchrow_array;
    25452607        $query->finish;
     2608        $db->commit;
    25462609    };
    25472610    $log->logdie("database error: $@") if $@;
     
    25902653        ($ext_id) = $query->fetchrow_array;
    25912654        $query->finish;
     2655        $db->commit;
     2656        ## if we do not call commit here, the transaction stays open blocking some operations below
    25922657    };
    25932658    if ($@) {
     
    26122677}
    26132678
    2614 
     2679# in the past, _is_valid_volume_name returned 'undef'. 
     2680# now it either returns 1 (success) or 0 (failure)
    26152681sub _is_valid_volume_name
    26162682{
     
    26502716        ($vol_id, $vol_path, $free) = $query->fetchrow_array;
    26512717        $query->finish;
     2718        $db->commit;
    26522719    };
    26532720    $log->logdie("database error: $@") if $@;
  • trunk/Nebulous-Server/lib/Nebulous/Server/SQL.pm

    r39926 r41172  
    574574DROP TABLE IF EXISTS directory;
    575575DROP TABLE IF EXISTS deleted;
     576DROP TABLE IF EXISTS cabinet;
     577DROP TABLE IF EXISTS aliasvol;
     578DROP TABLE IF EXISTS lost_instances;
    576579SET FOREIGN_KEY_CHECKS=1
    577580END
  • trunk/Nebulous-Server/lib/Test/Nebulous.pm

    r24540 r41172  
    1919our @EXPORT = qw( $NEB_DB $NEB_USER $NEB_PASS $NEB_MEMCACHED_SERVERS);
    2020
    21 our $NEB_DB     = $ENV{'NEB_DB'}   || "DBI:mysql:database=test:host=localhost";
    22 our $NEB_USER   = $ENV{'NEB_USER'} || "test";
    23 our $NEB_PASS   = $ENV{'NEB_PASS'} || '';
     21# require use of the test database server:
     22
     23our $NEB_DB     = "DBI:mysql:database=test:host=localhost:mysql_socket=/var/run/mysqld/mysqld.sock";
     24our $NEB_USER   = "test";
     25our $NEB_PASS   = '';
    2426our $NEB_MEMCACHED_SERVERS = ['127.0.0.1:11211'];
    2527
     
    3537my $dir6 = "";
    3638my $dir7 = "";
     39my $dir8 = "";
     40
     41sub show_setup {
     42    my $self = shift;
     43
     44    print "DB: $NEB_DB, USER: $NEB_USER, PASS: $NEB_PASS\n";
     45}
     46
    3747
    3848sub setup {
     
    4959    $dir6 = tempdir( CLEANUP => 0 );
    5060    $dir7 = tempdir( CLEANUP => 0 );
     61    $dir8 = tempdir( CLEANUP => 0 );
    5162
    5263    foreach my $statement (@{ $sql->get_db_schema }) {
     
    5465    }
    5566
    56     # node01/node02: allocate = TRUE
    57     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (1, 'node01', 'node01', ?, '/', TRUE, TRUE) }, undef, $dir1);
    58     $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 1);
    59 #    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir1);
     67    # generate 2 cabinets so we can replicate to a valid location
     68    $dbh->do(qq{ INSERT INTO cabinet (name, site_id, location) values ("cab01", 1, "main") });
     69    $dbh->do(qq{ INSERT INTO cabinet (name, site_id, location) values ("cab02", 1, "main") });
     70    $dbh->do(qq{ INSERT INTO cabinet (name, site_id, location) values ("cab03", 2, "back") });
     71    $dbh->do(qq{ INSERT INTO cabinet (name, site_id, location) values ("cab04", 2, "back") });
    6072
    61     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (2, 'node02', 'node02', ?, '/', TRUE, TRUE) }, undef, $dir2);
    62     $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e8 FROM volume WHERE vol_id = ? }, undef, 2);
    63 #    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir2);
     73    # node01 : allocate = TRUE (cab01, site 1)
     74    $dbh->do(qq{ INSERT INTO volume (vol_id, cab_id, name, host, path, mountpoint, allocate, available) VALUES (1, 1, 'node01', 'node01', ?, '/', TRUE, TRUE) }, undef, $dir1);
     75    $dbh->do(qq{ INSERT INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, 10e10, 10e7, note FROM volume WHERE vol_id = ? }, undef, 1);
    6476
    65     # node03: allocate = TRUE
    66     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (3, 'node03', 'node03', ?, '/', TRUE, TRUE) }, undef, $dir3);
    67     $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e8 FROM volume WHERE vol_id = ? }, undef, 3);
    68 #    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e8) }, undef, $dir3);
     77    # node02 : allocate = TRUE (cab02, site 1)
     78    $dbh->do(qq{ INSERT INTO volume (vol_id, cab_id, name, host, path, mountpoint, allocate, available) VALUES (2, 2, 'node02', 'node02', ?, '/', TRUE, TRUE) }, undef, $dir2);
     79    $dbh->do(qq{ INSERT INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, 10e10, 10e8, note FROM volume WHERE vol_id = ? }, undef, 2);
     80
     81    # node03: allocate = TRUE (cab03, site 2)
     82    $dbh->do(qq{ INSERT INTO volume (vol_id, cab_id, name, host, path, mountpoint, allocate, available) VALUES (3, 3, 'node03', 'node03', ?, '/', TRUE, TRUE) }, undef, $dir3);
     83    $dbh->do(qq{ INSERT INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, 10e10, 10e8, note FROM volume WHERE vol_id = ? }, undef, 3);
    6984
    7085    # node04: allocate = FALSE, available = FALSE
    71     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (4, 'node04', 'node04', ?, '/', FALSE, FALSE) }, undef, $dir4);
    72     $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 4);
    73 #    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir4);
     86    $dbh->do(qq{ INSERT INTO volume (vol_id, cab_id, name, host, path, mountpoint, allocate, available) VALUES (4, 1, 'node04', 'node04', ?, '/', FALSE, FALSE) }, undef, $dir4);
     87    $dbh->do(qq{ INSERT INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, 10e10, 10e8, note FROM volume WHERE vol_id = ? }, undef, 4);
    7488
    7589    # node05: allocate = FALSE, available = TRUE
    76     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (5, 'node05', 'node05', ?, '/', FALSE, TRUE) }, undef, $dir5);
    77     $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 5);
    78 #    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir5);
     90    $dbh->do(qq{ INSERT INTO volume (vol_id, cab_id, name, host, path, mountpoint, allocate, available) VALUES (5, 1, 'node05', 'node05', ?, '/', FALSE, TRUE) }, undef, $dir5);
     91    $dbh->do(qq{ INSERT INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, 10e10, 10e8, note FROM volume WHERE vol_id = ? }, undef, 5);
    7992
    8093    # node06: allocate = TRUE, available = FALSE
    81     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (6, 'node06', 'node06', ?, '/', TRUE, FALSE) }, undef, $dir6);
    82     $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e7 FROM volume WHERE vol_id = ? }, undef, 6);
    83 #    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e7) }, undef, $dir6);
     94    $dbh->do(qq{ INSERT INTO volume (vol_id, cab_id, name, host, path, mountpoint, allocate, available) VALUES (6, 1, 'node06', 'node06', ?, '/', TRUE, FALSE) }, undef, $dir6);
     95    $dbh->do(qq{ INSERT INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, 10e10, 10e8, note FROM volume WHERE vol_id = ? }, undef, 6);
    8496
    8597    # node07: full
    86     $dbh->do(qq{ INSERT INTO volume (vol_id, name, host, path, mountpoint, allocate, available) VALUES (7, 'node07', 'node07', ?, '/', TRUE, TRUE) }, undef, $dir7);
    87     $dbh->do(qq{ INSERT INTO mountedvol SELECT *, 10e10, 10e10 FROM volume WHERE vol_id = ? }, undef, 7);
    88 #    $dbh->do(qq{ INSERT INTO mount VALUES (?, 10e10, 10e10) }, undef, $dir7);
     98    $dbh->do(qq{ INSERT INTO volume (vol_id, cab_id, name, host, path, mountpoint, allocate, available) VALUES (7, 1, 'node07', 'node07', ?, '/', TRUE, TRUE) }, undef, $dir7);
     99    $dbh->do(qq{ INSERT INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, 10e10, 10e10, note FROM volume WHERE vol_id = ? }, undef, 7);
     100   
     101    # node08: allocate = TRUE, (cab04, site 2)
     102    $dbh->do(qq{ INSERT INTO volume (vol_id, cab_id, name, host, path, mountpoint, allocate, available) VALUES (8, 4, 'node08', 'node08', ?, '/', TRUE, TRUE) }, undef, $dir8);
     103    $dbh->do(qq{ INSERT INTO mountedvol SELECT vol_id,name,host,path,allocate,available,xattr,mountpoint, 10e10, 10e8, note FROM volume WHERE vol_id = ? }, undef, 8);
    89104
    90 #    $dbh->do(qq{ call getmountedvol() });
     105#   $dbh->do(qq{ call getmountedvol() });
    91106}
    92107
    93108sub cleanup {
    94109    # memcached needs to be emptied between test runs
    95         Cache::Memcached->new(servers => $NEB_MEMCACHED_SERVERS)->flush_all;
     110    Cache::Memcached->new(servers => $NEB_MEMCACHED_SERVERS)->flush_all;
    96111    # if flush_all() turns out to be useless as feared
    97112#   my $memd = Cache::Memcached->new(servers => $NEB_MEMCACHED_SERVERS);
     
    106121#   $query->finish;
    107122
     123   
    108124    foreach my $statement (@{ $sql->get_db_clear }) {
    109125        $dbh->do( $statement );
     
    118134    rmtree([$dir6], 0, 1) if -e $dir6;
    119135    rmtree([$dir7], 0, 1) if -e $dir7;
     136    rmtree([$dir8], 0, 1) if -e $dir8;
     137}
     138
     139# function to change state of one node for tests:
     140sub switch_node_state {
     141    my $self = shift;
     142
     143    $dbh->do(qq{ UPDATE volume set available = FALSE where name = 'node02'});
     144    $dbh->do(qq{ UPDATE mountedvol set available = FALSE where name = 'node02'});
     145}
     146
     147sub get_node_dirs {
     148    my $self = shift;
     149
     150    return ($dir1, $dir2, $dir3, $dir4, $dir5, $dir6, $dir7, $dir8);
    120151}
    121152
  • trunk/Nebulous-Server/t/03_server_setup.t

    r24546 r41172  
    1414use Nebulous::Server;
    1515use Test::Nebulous;
     16
     17Test::Nebulous->show_setup;
     18die "test";
    1619
    1720Test::Nebulous->setup;
  • trunk/Nebulous-Server/t/04_server_create_object.t

    r24356 r41172  
    3030
    3131Test::Nebulous->setup;
    32 
    3332{
    3433    # key
     
    4039    uri_scheme_ok($uri, 'file');
    4140
    42 SKIP: {
    43     skip "requires xattr support", 1 unless $test_xattr;
    44     is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
    45 }
    46 }
    47 
    48 Test::Nebulous->setup;
    49 
     41  SKIP: {
     42      skip "requires xattr support", 1 unless $test_xattr;
     43      is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     44    }
     45}
     46
     47Test::Nebulous->setup;
    5048{
    5149    # key
     
    5755    uri_scheme_ok($uri, 'file');
    5856
    59 SKIP: {
    60     skip "requires xattr support", 1 unless $test_xattr;
    61     is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
    62 }
     57  SKIP: {
     58      skip "requires xattr support", 1 unless $test_xattr;
     59      is(getfattr($path, 'user.nebulous_key'), 'foo', 'user.nebulous_key xattr');
     60    }
    6361}
    6462
     
    528526    $neb->create_object("foo", '~node07');
    529527};
    530 like($@, qr/node07 is not available/, "request volume this is full");
     528like($@, qr/node07 is not available/, "request volume which is full");
    531529
    532530Test::Nebulous->setup;
     
    535533    $neb->create_object("neb://~node07/foo");
    536534};
    537 like($@, qr/node07 is not available/, "request volume this is full");
     535like($@, qr/node07 is not available/, "request volume which is full");
    538536
    539537Test::Nebulous->setup;
  • trunk/Nebulous-Server/t/05_server_replicate_object.t

    r24995 r41172  
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 25;
     10use Test::More tests => 43;
    1111
    1212use lib qw( ./t ./lib );
     
    2828
    2929Test::Nebulous->setup;
    30 
    3130{
    3231    # key
     
    4544
    4645Test::Nebulous->setup;
    47 
    4846{
    4947    # key, $volume
     
    6260
    6361Test::Nebulous->setup;
    64 
    6562{
    6663    # key, $volume is undef
     
    7976
    8077Test::Nebulous->setup;
    81 
    8278{
    8379    # key, $volume
     
    147143}
    148144
     145# hard_volume tests:
     146
     147# replication with hard_volume:
     148Test::Nebulous->setup;
     149{
     150    my @nodedirs = Test::Nebulous->get_node_dirs();
     151
     152    # checking on replicate_object: hard_volume as node target
     153    my $uri1 = $neb->create_object("foo", "~node01");
     154    my $uri2 = $neb->replicate_object("foo", "~node02");
     155
     156    my $locations = $neb->find_instances("foo");
     157    my $Nloc = @$locations;
     158
     159    is($Nloc, 2, "found 2 instances");
     160   
     161    my $loc1 = $locations->[0];
     162    my $loc2 = $locations->[1];
     163
     164    like($loc1, qr/$nodedirs[0]/, "instance matches expected node");
     165    like($loc2, qr/$nodedirs[1]/, "instance matches expected node");
     166}
     167
     168# replication to unknown volume: should succeed
     169Test::Nebulous->setup;
     170{
     171    my @nodedirs = Test::Nebulous->get_node_dirs();
     172
     173    # checking on replicate_object, does this logic make sense?
     174    my $uri1 = $neb->create_object("foo", "~node01");
     175    my $uri2 = $neb->replicate_object("foo", "dummy");
     176
     177    my $locations = $neb->find_instances("foo");
     178    my $Nloc = @$locations;
     179
     180    is($Nloc, 2, "found 2 instances");
     181   
     182    my $loc1 = $locations->[0];
     183    my $loc2 = $locations->[1];
     184
     185    like($loc1, qr/$nodedirs[0]/, "instance matches expected node");
     186    uri_scheme_ok($loc2, 'file');
     187}
     188
     189# replication to unknown volume with hard_volume: should fail
     190Test::Nebulous->setup;
     191eval {
     192    my @nodedirs = Test::Nebulous->get_node_dirs();
     193
     194    # checking on replicate_object, does this logic make sense?
     195    my $uri1 = $neb->create_object("foo", "~node01");
     196    my $uri2 = $neb->replicate_object("foo", "~dummy");
     197
     198    my $locations = $neb->find_instances("foo");
     199};
     200like($@, qr/is not a valid volume name/, "replicate to unknown node with hard_volume should fail");
     201
     202# replication to unavailable volume: should succeed
     203Test::Nebulous->setup;
     204{
     205    my @nodedirs = Test::Nebulous->get_node_dirs();
     206
     207    # checking on replicate_object, does this logic make sense?
     208    my $uri1 = $neb->create_object("foo", "~node01");
     209    my $uri2 = $neb->replicate_object("foo", "node04");
     210
     211    my $locations = $neb->find_instances("foo");
     212    my $Nloc = @$locations;
     213
     214    is($Nloc, 2, "found 2 instances");
     215   
     216    my $loc1 = $locations->[0];
     217    my $loc2 = $locations->[1];
     218
     219    like($loc1, qr/$nodedirs[0]/, "instance matches expected node");
     220    uri_scheme_ok($loc2, 'file');
     221}
     222
     223# replication to unavailable volume with hard_volume: should fail
     224Test::Nebulous->setup;
     225eval {
     226    my @nodedirs = Test::Nebulous->get_node_dirs();
     227
     228    # checking on replicate_object, does this logic make sense?
     229    my $uri1 = $neb->create_object("foo", "~node01");
     230    my $uri2 = $neb->replicate_object("foo", "~node04");
     231
     232    my $locations = $neb->find_instances("foo");
     233};
     234like($@, qr/is not available/, "replicate to unknown node with hard_volume should fail");
     235
     236### END hard_volume tests
     237
     238### location-aware tests (do we respect the cab_id / vol_id exclusions?)
     239
     240# here are the volume definitions (Test/Nebulous.pm):
     241# name   : vol_id : cab_id : site_id : xattr
     242# node01 :      1 :      1 :       1 :     0
     243# node02 :      2 :      2 :       1 :     0
     244# node03 :      3 :      3 :       2 :     0
     245# node04 :      4 :      1 :       1 :     0
     246# node05 :      5 :      1 :       1 :     0
     247# node06 :      6 :      1 :       1 :     0
     248# node07 :      7 :      1 :       1 :     0
     249# node08 :      8 :      4 :       2 :     0
     250
     251# replication without volume
     252Test::Nebulous->setup;
     253{
     254    my @nodedirs = Test::Nebulous->get_node_dirs();
     255
     256    # checking on replicate_object: hard_volume as node target
     257    my $uri1 = $neb->create_object("foo", "~node01");
     258    my $uri2 = $neb->replicate_object("foo");
     259
     260    my $locations = $neb->find_instances("foo");
     261    my $Nloc = @$locations;
     262
     263    is($Nloc, 2, "found 2 instances");
     264   
     265    my $loc1 = $locations->[0];
     266    my $loc2 = $locations->[1];
     267
     268    # if the volume is not explicitly specified, then the first copy
     269    # should go to a different volume, cabinet, and site
     270    # if first is one node01, replication should go to node03 or node08
     271    # since those both have different site_id values
     272    like($loc1, qr/$nodedirs[0]/, "instance matches expected node");
     273
     274    my $isnode03 = $loc2 =~ m/$nodedirs[2]/;
     275    my $isnode08 = $loc2 =~ m/$nodedirs[7]/;
     276    ok($isnode03 || $isnode08, "instance matches expected node");
     277}
     278
     279# replication without volume
     280Test::Nebulous->setup;
     281{
     282    my @nodedirs = Test::Nebulous->get_node_dirs();
     283
     284    # checking on replicate_object, does this logic make sense?
     285    my $uri1 = $neb->create_object("foo", "~node03");
     286    my $uri2 = $neb->replicate_object("foo");
     287
     288    my $locations = $neb->find_instances("foo");
     289    my $Nloc = @$locations;
     290
     291    is($Nloc, 2, "found 2 instances");
     292   
     293    my $loc1 = $locations->[0];
     294    my $loc2 = $locations->[1];
     295
     296    # if the volume is not explicitly specified, then the first copy
     297    # should go to a different volume, cabinet, and site
     298    # if first is one node03, replication should go to node01 or node02
     299    # since those both have different site_id values
     300    like($loc1, qr/$nodedirs[2]/, "instance matches expected node");
     301
     302    my $isnode01 = $loc2 =~ m/$nodedirs[0]/;
     303    my $isnode02 = $loc2 =~ m/$nodedirs[1]/;
     304    ok($isnode01 || $isnode02, "instance matches expected node");
     305}
     306
    149307Test::Nebulous->setup;
    150308
  • trunk/Nebulous-Server/t/08_server_find_instances.t

    r24362 r41172  
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 19;
     10use Test::More tests => 44;
    1111
    1212use lib qw( ./t ./lib );
     
    2222);
    2323
    24 Test::Nebulous->setup;
    25 
     24# XXX previously, the logic was: if we request a hard volume location
     25# using ~node, then we would give an error if no data is available except on that node.
     26
     27# the code has been modified so that the requested storage object is provided if possible,
     28# even if the apparently "hard" target did not exist.
     29
     30Test::Nebulous->setup;
     31Test::Nebulous->cleanup; # make sure the database is reset before running any tests
     32
     33# for (my $i = 0; $i < $Nloc; $i++) {
     34#       my $loc = $locations->[$i];
     35#       print "location: $loc\n";
     36#}
     37
     38Test::Nebulous->setup;
    2639{
    2740    # key
     
    3548
    3649Test::Nebulous->setup;
    37 
    3850{
    3951    # key
     
    4961
    5062Test::Nebulous->setup;
    51 
    5263{
    5364    # key, volume
     
    6172
    6273Test::Nebulous->setup;
    63 
    6474{
    6575    # key, volume
     
    7383
    7484Test::Nebulous->setup;
    75 
    7685{
    7786    # key, volume
     
    8594
    8695Test::Nebulous->setup;
    87 
    8896{
    8997    # key
     
    98106}
    99107
    100 # object exists but instance is on a different volume
    101 Test::Nebulous->setup;
    102 
     108# request from a hard_volume returns an instance which is not on the hard volume if available
     109Test::Nebulous->setup;
    103110eval {
    104111    # key, volume
    105112    my $uri = $neb->create_object('foo', '~node01');
    106 
    107113    my $locations = $neb->find_instances('foo', '~node02');
    108 };
    109 like($@, qr/no instances on storage volume/, 'instances on a different volume');
     114
     115    uri_scheme_ok($locations->[0], 'file');
     116    is($uri, $locations->[0], "URIs match");
     117};
     118is($@, "", "instance on different node (as hard_volume) returned");
     119
     120# request from a hard_volume returns an instance which is not on the hard volume if available
     121Test::Nebulous->setup;
     122eval {
     123    # key, volume
     124    my $uri = $neb->create_object('foo', '~node01');
     125    my $locations = $neb->find_instances('foo', '~node02');
     126
     127    uri_scheme_ok($locations->[0], 'file');
     128    is($uri, $locations->[0], "URIs match");
     129};
     130is($@, "", "instance on different node (as hard_volume) returned");
     131
     132### TESTS FOR INSTANCE ON INVALID NODE
     133diag ("TESTS FOR INSTANCE ON INVALID NODE");
     134
     135# request from a soft_volume for an instance which is on an invalid node (find_invalid = 1) [SOFT, 1]
     136Test::Nebulous->setup;
     137eval {
     138    # key, volume
     139    my $uri = $neb->create_object('foo', '~node02');
     140    Test::Nebulous->switch_node_state;
     141
     142    my $locations = $neb->find_instances('foo', 'node02', 1);
     143    uri_scheme_ok($locations->[0], 'file');
     144    is($uri, $locations->[0], "URIs match");
     145};
     146is($@, "", "instance on invalid node (as soft_volume) returned with find_invalid = 1");
     147
     148# request from a soft_volume for an instance which is on an invalid node (find_invalid = 0) [SOFT, 0]
     149Test::Nebulous->setup;
     150eval {
     151    # key, volume
     152    my $uri = $neb->create_object('foo', '~node02');
     153    Test::Nebulous->switch_node_state;
     154
     155    my $locations = $neb->find_instances('foo', 'node02', 0);
     156};
     157like($@, qr/database error/, "instance on invalid node (as soft_volume) not returned (find_invalid = 0)");
     158
     159# request from a hard_volume for an instance which is on an invalid node (find_instance not supplied) [SOFT, X]
     160Test::Nebulous->setup;
     161eval {
     162    # key, volume
     163    my $uri = $neb->create_object('foo', '~node02');
     164    Test::Nebulous->switch_node_state;
     165
     166    my $locations = $neb->find_instances('foo', 'node02');
     167};
     168like($@, qr/no instances available for key/, "instance on invalid node (as soft_volume) not returned (find_invalid not set)");
     169
     170# request from a hard_volume for an instance which is on an invalid node (find_invalid = 1) [HARD, 1]
     171Test::Nebulous->setup;
     172eval {
     173    # key, volume
     174    my $uri = $neb->create_object('foo', '~node02');
     175    Test::Nebulous->switch_node_state;
     176
     177    my $locations = $neb->find_instances('foo', '~node02', 1);
     178    uri_scheme_ok($locations->[0], 'file');
     179    is($uri, $locations->[0], "URIs match");
     180};
     181is($@, "", "instance on invalid node (as hard_volume) returned with find_invalid = 1");
     182
     183# request from a hard_volume for an instance which is on an invalid node (find_invalid = 0) [HARD, 0]
     184Test::Nebulous->setup;
     185eval {
     186    # key, volume
     187    my $uri = $neb->create_object('foo', '~node02');
     188    Test::Nebulous->switch_node_state;
     189
     190    my $locations = $neb->find_instances('foo', '~node02', 0);
     191};
     192like($@, qr/no instances on storage volume/, "instance on invalid node (as hard_volume) not returned (find_invalid = 0)");
     193
     194# request from a hard_volume for an instance which is on an invalid node [HARD, X]
     195Test::Nebulous->setup;
     196eval {
     197    # key, volume
     198    my $uri = $neb->create_object('foo', '~node02');
     199    Test::Nebulous->switch_node_state;
     200
     201    my $locations = $neb->find_instances('foo', '~node02');
     202};
     203like($@, qr/no instances on storage volume/, "instance on invalid node (as hard_volume) not returned (find_invalid not set)");
     204
     205#### TESTING the instance proximity analysis
     206Test::Nebulous->setup;
     207{
     208    my @nodedirs = Test::Nebulous->get_node_dirs();
     209
     210    # place 4 instances on specific nodes (hard targets works):
     211    my $uri1 = $neb->create_object("foo", "~node01");
     212    my $uri2 = $neb->replicate_object("foo", "~node02");
     213    my $uri3 = $neb->replicate_object("foo", "~node03");
     214    my $uri4 = $neb->replicate_object("foo", "~node08");
     215
     216    my $locations = $neb->find_instances("foo", "node01");
     217    my $Nloc = @$locations;
     218
     219    is($Nloc, 4, "found 4 instances");
     220   
     221    my $loc1 = $locations->[0];
     222    my $loc2 = $locations->[1];
     223    my $loc3 = $locations->[2];
     224    my $loc4 = $locations->[3];
     225
     226    # choosing instance relative to node01 yields:
     227    like($loc1, qr/$nodedirs[0]/, "node01 is closest to node01");   
     228    like($loc2, qr/$nodedirs[1]/, "node02 is 2nd closest to node01");
     229    like($loc3, qr/$nodedirs[2]/, "node03 is 3rd closest to node01");
     230    like($loc4, qr/$nodedirs[7]/, "node08 is 4th closest to node01");
     231}
     232
     233#### TESTING the instance proximity analysis
     234Test::Nebulous->setup;
     235{
     236    my @nodedirs = Test::Nebulous->get_node_dirs();
     237
     238    # place 4 instances on specific nodes (hard targets works):
     239    my $uri1 = $neb->create_object("foo", "~node01");
     240    my $uri2 = $neb->replicate_object("foo", "~node02");
     241    my $uri3 = $neb->replicate_object("foo", "~node03");
     242    my $uri4 = $neb->replicate_object("foo", "~node08");
     243
     244    my $locations = $neb->find_instances("foo", "node03");
     245    my $Nloc = @$locations;
     246
     247    is($Nloc, 4, "found 4 instances");
     248   
     249    my $loc1 = $locations->[0]; #
     250    my $loc2 = $locations->[1]; #
     251    my $loc3 = $locations->[2]; #
     252    my $loc4 = $locations->[3]; #
     253
     254    # choosing instance relative to node01 yields:
     255    like($loc1, qr/$nodedirs[2]/, "node03 is closest to node03");
     256    like($loc2, qr/$nodedirs[7]/, "node08 is 2nd closest to node03");
     257    like($loc3, qr/$nodedirs[1]/, "node02 is 3rd closest to node03");
     258    like($loc4, qr/$nodedirs[0]/, "node08 is 4th closest to node03");
     259}
     260
     261########
    110262
    111263Test::Nebulous->setup;
     
    125277
    126278Test::Nebulous->setup;
    127 
    128 eval {
    129     $neb->find_instances();
    130 };
    131 like($@, qr/1 - 2 were expected/, "no params");
     279eval {
     280    my $locations = $neb->find_instances();
     281};
     282like($@, qr/1 - 3 were expected/, "no params");
     283# note the new API expects 1-3 parameters
    132284
    133285Test::Nebulous->setup;
     
    135287eval {
    136288    $neb->create_object('foo');
    137     $neb->find_instances('foo', 'node01', 3);
    138 };
    139 like($@, qr/1 - 2 were expected/, "too many params");
     289    $neb->find_instances('foo', 'node01', 3, 5);
     290};
     291like($@, qr/1 - 3 were expected/, "too many params");
     292# note the new API expects 1-3 parameters
    140293
    141294Test::Nebulous->cleanup;
  • trunk/Nebulous-Server/t/11_server_is_valid_volume_name.t

    r24356 r41172  
    88use warnings FATAL => qw( all );
    99
    10 use Test::More tests => 3;
     10use Test::More tests => 5;
    1111
    1212use lib qw( ./t ./lib );
     
    3131Test::Nebulous->setup;
    3232
    33 is($neb->_is_valid_volume_name('foo', 'node99'), undef, "invalid volume name");
     33is($neb->_is_valid_volume_name('foo', 'node99'), 0, "invalid volume name");
     34
     35Test::Nebulous->setup;
     36
     37# key does not need to exist (is hashed to select db server)
     38ok($neb->_is_valid_volume_name('bax', 'node01'), "valid volume name");
     39
     40Test::Nebulous->setup;
     41
     42# 'any' should always be a valid name
     43ok($neb->_is_valid_volume_name('foo', 'any'), "valid volume name");
    3444
    3545Test::Nebulous->cleanup;
  • trunk/Nebulous-Server/t/15_server_xattr.t

    r24356 r41172  
    184184    $neb->getxattr_object('foo', 'user.bar');
    185185};
    186 like($@, qr|xattr neb:///foo:user.bar does not exist|,
    187     "get xattr from non-existant xattr key");
     186like($@, qr|xattr neb:///foo:user.bar does not exist|, "get xattr from non-existant xattr key");
    188187
    189188Test::Nebulous->setup;
  • trunk/Nebulous-Server/t/16_mounts.t

    r24356 r41172  
    2828    my $mounts = $neb->mounts();
    2929
    30     is(scalar @$mounts, 7, "number of rows");
     30    is(scalar @$mounts, 8, "number of rows");
    3131
    3232    my %row;
     
    3535        = @{$mounts->[0]};
    3636   
    37     is($row{total},     100000000000);
    38     is($row{used},      100000000);
    39     is($row{vol_id},    1);
    40     is($row{name},      "node01");
    41     is($row{host},      "node01");
    42     is($row{allocate},  1);
    43     is($row{available}, 1);
    44     is($row{xattr},     0);
     37    is($row{total},     100000000000, "total bytes");
     38    is($row{used},      100000000, "used bytes");
     39    is($row{vol_id},    1, "vol id");
     40    is($row{name},      "node01", "name");
     41    is($row{host},      "node01", "host");
     42    is($row{allocate},  1, "is allocated");
     43    is($row{available}, 1, "is available");
     44    is($row{xattr},     0, "has no xattr");
    4545
    4646    # 2nd row
     
    4848        = @{$mounts->[1]};
    4949
    50     is($row{total},     100000000000);
    51     is($row{used},      1000000000);
    52     is($row{vol_id},    2);
    53     is($row{name},      "node02");
    54     is($row{host},      "node02");
    55     is($row{allocate},  1);
    56     is($row{available}, 1);
    57     is($row{xattr},     0);
     50    is($row{total},     100000000000, "total bytes");
     51    is($row{used},      1000000000, "used bytes");
     52    is($row{vol_id},    2, "vol id");
     53    is($row{name},      "node02", "name");
     54    is($row{host},      "node02", "host");
     55    is($row{allocate},  1, "is allocated");
     56    is($row{available}, 1, "is available");
     57    is($row{xattr},     0, "has no xattr");
    5858}
    5959
  • trunk/Nebulous-Server/t/18_server_chmod_object.t

    r24356 r41172  
    3838    is($mode, 0440, "returned mode");
    3939    is($neb->getxattr_object($key, 'user.mode'), 0440, "xattr user.mode");
     40
     41    # reset to 600 so the user can delete the file and /tmp entry
     42    chmod(0600, $path);
    4043}
    4144
     
    5053    my $mode = $neb->chmod_object($key, 0440);
    5154
    52     my $st1 = stat(URI->new($uri1)->path);
    53     my $st2 = stat(URI->new($uri2)->path);
     55    my $path1 = URI->new($uri1)->path;
     56    my $path2 = URI->new($uri2)->path;
     57
     58    my $st1 = stat($path1);
     59    my $st2 = stat($path2);
    5460
    5561    is($st1->mode &07777, 0440, "chmod() first instance");
     
    5763    is($mode, 0440, "returned mode");
    5864    is($neb->getxattr_object($key, 'user.mode'), 0440, "xattr user.mode");
     65
     66    # reset to 600 so the user can delete the file and /tmp entry
     67    chmod (0600, $path1);
     68    chmod (0600, $path2);
    5969}
    6070
Note: See TracChangeset for help on using the changeset viewer.