예제 #1
0
  def InstallGroup(self, groupname, sysroot_user_db, gid=None):
    """Install a group in |sysroot_user_db|.

    Args:
      groupname: name of group to install.
      sysroot_user_db: user_db.UserDB instance representing the installed
          groups.
      gid: ebuild specified gid.
    """
    if not groupname in self.groups:
      raise ValueError('Cannot add unknown group "%s"' % groupname)
    group = self.groups[groupname]

    if group.is_defunct:
      raise ValueError('Refusing to install defunct group: "%s"' % groupname)

    if gid and gid != group.gid:
      raise ValueError('Refusing to install group %s with gid=%d while account '
                       'database indicates gid=%d' %
                       (groupname, gid, group.gid))

    installable_group = user_db.Group(
        group=group.name, password=group.password,
        gid=group.gid, users=group.users)
    sysroot_user_db.AddGroup(installable_group)
예제 #2
0
  def testCanAddGroup(self):
    """Test that we can correctly add a group to a database."""
    new_group = user_db.Group(group='foo', password='******', gid=1000, users=[])
    self.assertFalse(self._user_db.GroupExists(new_group.group))
    self._user_db.AddGroup(new_group)
    self.assertTrue(self._user_db.GroupExists(new_group.group))

    # New instances should just see the new group.
    new_db = user_db.UserDB(self.tempdir)
    self.assertTrue(new_db.GroupExists(new_group.group))
 def testInstallGroup(self):
   """Test that we can install a group correctly."""
   db = self._ParseSpec(MINIMAL_ACCOUNTS_DB)
   mock_user_db = mock.MagicMock()
   db.InstallGroup(MINIMAL_DB_GROUP.name, mock_user_db)
   installed_group = user_db.Group(
       group=MINIMAL_DB_GROUP.name, password=MINIMAL_DB_GROUP.password,
       gid=MINIMAL_DB_GROUP.gid, users=MINIMAL_DB_GROUP.users)
   self.assertEqual([mock.call.AddGroup(installed_group)],
                    mock_user_db.mock_calls)