[vhffs-dev] [2128] Fixed, or rather workarounded a glitch bug when usergroup. pl robot is ran before group.pl

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 2128
Author:   gradator
Date:     2012-03-07 23:10:11 +0100 (Wed, 07 Mar 2012)
Log Message:
-----------
Fixed, or rather workarounded a glitch bug when usergroup.pl robot is ran before group.pl

Step to reproduce:
0. create a group
1. run usergroup.pl, which sets UserGroup object of the primary group user to ACTIVATED state
2. run group.pl, which fail because it can't create the UserGroup on the filesystem (this is already done)

Workaround:
- Do not create UserGroup on the filesystem if the group is not in ACTIVATED state
- user.pl, group.pl, usergroup.pl are all using the same lockfile, to prevent all possible short-time glitchs
- Run Robots::UserGroup::create after group is set to ACTIVATED, without checking whether it succeded
  (we can't, because we need to keep an history coherency and group is already ACTIVATED)
  (we do need to do that because Robots::UserGroup::create is not going to create if the group is not ACTIVED,
   as said in the first entry).

Yes this means that we do need to do a 4.4.1 release soon, this is somewhat blocking.

Modified Paths:
--------------
    branches/vhffs-4.4/vhffs-api/src/Vhffs/Panel/Group.pm
    branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm
    branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/UserGroup.pm
    branches/vhffs-4.4/vhffs-robots/src/group.pl
    branches/vhffs-4.4/vhffs-robots/src/user.pl
    branches/vhffs-4.4/vhffs-robots/src/usergroup.pl
    trunk/vhffs-api/src/Vhffs/Panel/Group.pm
    trunk/vhffs-api/src/Vhffs/Robots/Group.pm
    trunk/vhffs-api/src/Vhffs/Robots/UserGroup.pm
    trunk/vhffs-robots/src/group.pl
    trunk/vhffs-robots/src/user.pl
    trunk/vhffs-robots/src/usergroup.pl

Modified: branches/vhffs-4.4/vhffs-api/src/Vhffs/Panel/Group.pm
===================================================================
--- branches/vhffs-4.4/vhffs-api/src/Vhffs/Panel/Group.pm	2012-03-07 20:52:17 UTC (rev 2127)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/Panel/Group.pm	2012-03-07 22:10:11 UTC (rev 2128)
@@ -199,12 +199,11 @@
 	my( $groupname , $realname, $user , $vhffs, $description ) = @_;
 
 	my $group = Vhffs::Group::create($vhffs, $groupname, $realname, $user->get_uid, undef, $description);
+	return undef unless defined $group;
 
-	return undef unless( defined $group );
+	# TODO: rework that, this is ridiculous that the panel add the primary user to the recently created group
+	return undef unless $group->add_user( $user->get_uid );
 
-	return undef if ($group->add_user( $user->get_uid ) < 0 );
-
-
 	return $group;
 }
 

Modified: branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm
===================================================================
--- branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-07 20:52:17 UTC (rev 2127)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-07 22:10:11 UTC (rev 2128)
@@ -71,16 +71,13 @@
 	chown $group->get_owner->get_uid, $group->get_gid, $dir;
 	chmod 02770, $dir;
 
-	my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $group->get_owner, $group );
-	unless( Vhffs::Robots::UserGroup::create( $usergroup ) ) {
-		$group->set_status( Vhffs::Constants::CREATION_ERROR );
-		$group->commit;
-		return undef;
-	}
-
 	Vhffs::Robots::vhffs_log( $vhffs, 'Created group '.$group->get_groupname );
 	$group->set_status( Vhffs::Constants::ACTIVATED );
 	$group->commit;
+
+	my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $group->get_owner, $group );
+	Vhffs::Robots::UserGroup::create( $usergroup );
+
 	quota($group);
 
 	return 1;

Modified: branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/UserGroup.pm
===================================================================
--- branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/UserGroup.pm	2012-03-07 20:52:17 UTC (rev 2127)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/UserGroup.pm	2012-03-07 22:10:11 UTC (rev 2128)
@@ -49,6 +49,7 @@
 	my $user = $usergroup->get_user;
 	my $group = $usergroup->get_group;
 	my $vhffs = $usergroup->get_vhffs;
+	return undef unless $group->get_status == Vhffs::Constants::ACTIVATED;
 
 	unless( $vhffs->get_config->use_vhffsfs )  {
 		my $groupdir = $group->get_dir;

Modified: branches/vhffs-4.4/vhffs-robots/src/group.pl
===================================================================
--- branches/vhffs-4.4/vhffs-robots/src/group.pl	2012-03-07 20:52:17 UTC (rev 2127)
+++ branches/vhffs-4.4/vhffs-robots/src/group.pl	2012-03-07 22:10:11 UTC (rev 2128)
@@ -39,7 +39,7 @@
 my $vhffs = new Vhffs;
 exit 1 unless defined $vhffs;
 
-Vhffs::Robots::lock( $vhffs, 'group' );
+Vhffs::Robots::lock( $vhffs, 'usergroup' );
 
 my $repos = Vhffs::Group::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
 foreach ( @{$repos} ) {
@@ -56,5 +56,5 @@
 	Vhffs::Robots::Group::modify( $_ );
 }
 
-Vhffs::Robots::unlock( $vhffs, 'group' );
+Vhffs::Robots::unlock( $vhffs, 'usergroup' );
 exit 0;

Modified: branches/vhffs-4.4/vhffs-robots/src/user.pl
===================================================================
--- branches/vhffs-4.4/vhffs-robots/src/user.pl	2012-03-07 20:52:17 UTC (rev 2127)
+++ branches/vhffs-4.4/vhffs-robots/src/user.pl	2012-03-07 22:10:11 UTC (rev 2128)
@@ -38,7 +38,7 @@
 my $vhffs = new Vhffs;
 exit 1 unless defined $vhffs;
 
-Vhffs::Robots::lock( $vhffs, 'user' );
+Vhffs::Robots::lock( $vhffs, 'usergroup' );
 
 my $users = Vhffs::User::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
 foreach ( @{$users} ) {
@@ -55,5 +55,5 @@
 	Vhffs::Robots::User::modify( $_ );
 }
 
-Vhffs::Robots::unlock( $vhffs, 'user' );
+Vhffs::Robots::unlock( $vhffs, 'usergroup' );
 exit 0;

Modified: branches/vhffs-4.4/vhffs-robots/src/usergroup.pl
===================================================================
--- branches/vhffs-4.4/vhffs-robots/src/usergroup.pl	2012-03-07 20:52:17 UTC (rev 2127)
+++ branches/vhffs-4.4/vhffs-robots/src/usergroup.pl	2012-03-07 22:10:11 UTC (rev 2128)
@@ -38,7 +38,7 @@
 my $vhffs = new Vhffs;
 exit 1 unless defined $vhffs;
 
-Vhffs::Robots::lock( $vhffs , 'usergroup' );
+Vhffs::Robots::lock( $vhffs, 'usergroup' );
 
 my $usergroups = Vhffs::UserGroup::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
 foreach ( @{$usergroups} ) {
@@ -55,6 +55,5 @@
 	Vhffs::Robots::UserGroup::modify( $_ );
 }
 
-Vhffs::Robots::unlock( $vhffs , 'usergroup' );
-
+Vhffs::Robots::unlock( $vhffs, 'usergroup' );
 exit 0;

Modified: trunk/vhffs-api/src/Vhffs/Panel/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Group.pm	2012-03-07 20:52:17 UTC (rev 2127)
+++ trunk/vhffs-api/src/Vhffs/Panel/Group.pm	2012-03-07 22:10:11 UTC (rev 2128)
@@ -199,12 +199,11 @@
 	my( $groupname , $realname, $user , $vhffs, $description ) = @_;
 
 	my $group = Vhffs::Group::create($vhffs, $groupname, $realname, $user->get_uid, undef, $description);
+	return undef unless defined $group;
 
-	return undef unless( defined $group );
+	# TODO: rework that, this is ridiculous that the panel add the primary user to the recently created group
+	return undef unless $group->add_user( $user->get_uid );
 
-	return undef if ($group->add_user( $user->get_uid ) < 0 );
-
-
 	return $group;
 }
 

Modified: trunk/vhffs-api/src/Vhffs/Robots/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-07 20:52:17 UTC (rev 2127)
+++ trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-07 22:10:11 UTC (rev 2128)
@@ -71,16 +71,13 @@
 	chown $group->get_owner->get_uid, $group->get_gid, $dir;
 	chmod 02770, $dir;
 
-	my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $group->get_owner, $group );
-	unless( Vhffs::Robots::UserGroup::create( $usergroup ) ) {
-		$group->set_status( Vhffs::Constants::CREATION_ERROR );
-		$group->commit;
-		return undef;
-	}
-
 	Vhffs::Robots::vhffs_log( $vhffs, 'Created group '.$group->get_groupname );
 	$group->set_status( Vhffs::Constants::ACTIVATED );
 	$group->commit;
+
+	my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $group->get_owner, $group );
+	Vhffs::Robots::UserGroup::create( $usergroup );
+
 	quota($group);
 
 	return 1;

Modified: trunk/vhffs-api/src/Vhffs/Robots/UserGroup.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/UserGroup.pm	2012-03-07 20:52:17 UTC (rev 2127)
+++ trunk/vhffs-api/src/Vhffs/Robots/UserGroup.pm	2012-03-07 22:10:11 UTC (rev 2128)
@@ -49,6 +49,7 @@
 	my $user = $usergroup->get_user;
 	my $group = $usergroup->get_group;
 	my $vhffs = $usergroup->get_vhffs;
+	return undef unless $group->get_status == Vhffs::Constants::ACTIVATED;
 
 	unless( $vhffs->get_config->use_vhffsfs )  {
 		my $groupdir = $group->get_dir;

Modified: trunk/vhffs-robots/src/group.pl
===================================================================
--- trunk/vhffs-robots/src/group.pl	2012-03-07 20:52:17 UTC (rev 2127)
+++ trunk/vhffs-robots/src/group.pl	2012-03-07 22:10:11 UTC (rev 2128)
@@ -39,7 +39,7 @@
 my $vhffs = new Vhffs;
 exit 1 unless defined $vhffs;
 
-Vhffs::Robots::lock( $vhffs, 'group' );
+Vhffs::Robots::lock( $vhffs, 'usergroup' );
 
 my $repos = Vhffs::Group::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
 foreach ( @{$repos} ) {
@@ -56,5 +56,5 @@
 	Vhffs::Robots::Group::modify( $_ );
 }
 
-Vhffs::Robots::unlock( $vhffs, 'group' );
+Vhffs::Robots::unlock( $vhffs, 'usergroup' );
 exit 0;

Modified: trunk/vhffs-robots/src/user.pl
===================================================================
--- trunk/vhffs-robots/src/user.pl	2012-03-07 20:52:17 UTC (rev 2127)
+++ trunk/vhffs-robots/src/user.pl	2012-03-07 22:10:11 UTC (rev 2128)
@@ -38,7 +38,7 @@
 my $vhffs = new Vhffs;
 exit 1 unless defined $vhffs;
 
-Vhffs::Robots::lock( $vhffs, 'user' );
+Vhffs::Robots::lock( $vhffs, 'usergroup' );
 
 my $users = Vhffs::User::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
 foreach ( @{$users} ) {
@@ -55,5 +55,5 @@
 	Vhffs::Robots::User::modify( $_ );
 }
 
-Vhffs::Robots::unlock( $vhffs, 'user' );
+Vhffs::Robots::unlock( $vhffs, 'usergroup' );
 exit 0;

Modified: trunk/vhffs-robots/src/usergroup.pl
===================================================================
--- trunk/vhffs-robots/src/usergroup.pl	2012-03-07 20:52:17 UTC (rev 2127)
+++ trunk/vhffs-robots/src/usergroup.pl	2012-03-07 22:10:11 UTC (rev 2128)
@@ -38,7 +38,7 @@
 my $vhffs = new Vhffs;
 exit 1 unless defined $vhffs;
 
-Vhffs::Robots::lock( $vhffs , 'usergroup' );
+Vhffs::Robots::lock( $vhffs, 'usergroup' );
 
 my $usergroups = Vhffs::UserGroup::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
 foreach ( @{$usergroups} ) {
@@ -55,6 +55,5 @@
 	Vhffs::Robots::UserGroup::modify( $_ );
 }
 
-Vhffs::Robots::unlock( $vhffs , 'usergroup' );
-
+Vhffs::Robots::unlock( $vhffs, 'usergroup' );
 exit 0;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/