Changeset 1321 for branches


Ignore:
Timestamp:
04/07/15 16:47:26 (9 years ago)
Author:
nanardon
Message:

Fix exchange IP function, use new function to clarify code

Location:
branches/4.0
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0

  • branches/4.0/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r1312 r1321  
    356356    { 
    357357        my $obj = $self->get_object('nethost', $nethostname); 
    358         my @cname = grep { $_ && $_ ne $to} 
    359         $obj->get_attributes('cname'); 
    360         $obj->set_c_fields(cname => [ @cname ]) or return; 
     358        $obj->_delAttributeValue(cname => $to); 
    361359    } 
    362360    $self->rename_object('nethost', $nethostname, $to) or return; 
    363361    if ($config{'addcname'}) { 
    364362        my $obj = $self->get_object('nethost', $to); 
    365         my @cname = grep { $_ } $obj->get_attributes('cname'); 
    366         $obj->set_c_fields(cname => [ @cname, $nethostname ]); 
     363        $obj->_addAttributeValue(cname => $nethostname); 
    367364    } 
    368365    return 1; 
     
    381378        $obj1 = $self->get_object('nethost', $host1); 
    382379    } else { 
    383         $self->la_log(LA_ERR, "Cannot find host having $ip1"); 
     380        $self->log(LA_ERR, "Cannot find host having $ip1"); 
    384381        return; 
    385382    } 
     
    387384        $obj2 = $self->get_object('nethost', $host2); 
    388385    } else { 
    389         $self->la_log(LA_ERR, "Cannot find host having $ip2"); 
     386        $self->log(LA_ERR, "Cannot find host having $ip2"); 
    390387        return; 
    391388    } 
    392389    if ($obj1->id eq $obj2->id) { 
    393         $self->la_log(LA_ERR, "Both ip belong to same host (%s)", $obj1->id); 
     390        $self->log(LA_ERR, "Both ip belong to same host (%s)", $obj1->id); 
    394391        return; 
    395392    } 
    396393 
    397     my @ip1 = grep { $_ && $_ ne $ip1 } $obj1->get_attributes('ip'); 
    398     $obj1->set_c_fields(ip => [ @ip1 ]); 
    399     my @ip2 = grep { $_ && $_ ne $ip2 } $obj2->get_attributes('ip'); 
    400     $obj2->set_c_fields(ip => [ @ip2, $ip1 ]) or return; 
    401     $obj1->set_c_fields(ip => [ @ip1, $ip2 ]) or return; 
     394    $self->log(LA_NOTICE, "Exchanging IP between %s and %s", $obj1->id, $obj2->id); 
     395    $obj1->delAttributeValue('ip', $ip1) or return; 
     396    $obj2->delAttributeValue('ip', $ip2) or return; 
     397    $obj1->addAttributeValue('ip', $ip2) or return; 
     398    $obj2->addAttributeValue('ip', $ip1) or return; 
    402399    return 1; 
    403400} 
  • branches/4.0/LATMOS-Accounts/t/11_bases_unix.t

    r1071 r1321  
    11use strict; 
    22use warnings; 
    3 use Test::More tests => 29; 
     3use Test::More tests => 33; 
    44use File::Temp; 
    55 
     
    5151ok(eq_set($group->get_c_field('memberUID'), [ 'admin' ]), 'can get group\'s member after change'); 
    5252 
     53ok($group->addAttributeValue('memberUID', 'root'), 'can use addAttributeValue'); 
     54ok(eq_set($group->get_c_field('memberUID'), [ 'admin', 'root' ]), 'can get group\'s member after addAttributeValue'); 
     55ok($group->delAttributeValue('memberUID', 'root'), 'can use addAttributeValue'); 
     56ok(eq_set($group->get_c_field('memberUID'), [ 'admin' ]), 'can get group\'s member after addAttributeValue'); 
    5357 
    5458ok(my $unixbmod = LATMOS::Accounts::Bases->new( 
Note: See TracChangeset for help on using the changeset viewer.