Ejemplo n.º 1
0
    def test_load_update_user_w_account(self, m_account_update, m_user_update):
        """UserImporterLdap.update() update user found in LDAP and in HPCStatsDB
           with an unclosed account on the cluster.
        """

        users = [ 'login4' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        creation_user4 = datetime(2015, 3, 2, 16, 0, 1)
        user4_id = 4
        MockPg2.PG_REQS['find_user'].set_assoc(
          params=( 'login4', ),
          result=[ [ user4_id ] ]
          )
        MockPg2.PG_REQS['existing_account'].set_assoc(
          params=( user4_id, self.cluster.cluster_id, ),
          result=[ [ 0 ] ]
          )
        MockPg2.PG_REQS['load_account'].set_assoc(
          params=( user4_id, self.cluster.cluster_id, ),
          result=[ [ 0, 0, creation_user4, None ] ]
        )

        self.importer.load()
        self.importer.update()
        m_user_update.assert_called_with(self.db)
        # ensure Account.update() is not called
        self.assertRaises(AssertionError,
                          m_account_update.assert_called_with,
                          self.db,
                          None)
Ejemplo n.º 2
0
    def test_load_update_user_closed_account(self, m_account_update, m_user_update):
        """UserImporterLdap.update() update user found in LDAP and in HPCStatsDB
           with a closed account on the cluster.
        """
        users = [ 'login5' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        user5_creation = datetime(2015, 3, 2, 16, 0, 1)
        user5_deletion = datetime(2015, 3, 2, 16, 0, 1)
        user5_id = 5
        MockPg2.PG_REQS['find_user'].set_assoc(
          params=( 'login5', ),
          result=[ [ user5_id ] ]
          )
        MockPg2.PG_REQS['existing_account'].set_assoc(
          params=( user5_id, self.cluster.cluster_id, ),
          result=[ [ 0 ] ]
          )
        MockPg2.PG_REQS['load_account'].set_assoc(
          params=( user5_id, self.cluster.cluster_id, ),
          result=[ [ 0, 0, user5_creation, user5_deletion ] ]
        )

        self.importer.load()
        self.importer.update()
        self.assertEquals(self.importer.accounts[0].deletion_date, None)
        m_user_update.assert_called_with(self.db)
        m_account_update.assert_called_with(self.db)
Ejemplo n.º 3
0
    def test_update_new_user(self, m_account_save, m_user_save):
        """UserImporterLdapSlurm.slurm() should save the user and the account if
           not existing in DB
        """

        users = [ ]
        users_no_group = [ 'login1' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users, users_no_group)

        MockMySQLdb.MY_REQS['get_users']['res'] = \
        [ [ 'login1' ] ]

        user1_id = 1

        MockPg2.PG_REQS['find_user'].set_assoc(
          params=( 'login1', ),
          result=[ ]
          )
        MockPg2.PG_REQS['existing_account'].set_assoc(
          params=( user1_id, self.cluster.cluster_id, ),
          result=[ ]
          )

        self.importer.load()
        self.importer.update()
        self.assertEquals(self.importer.accounts[0].creation_date,
                          date(1970, 1, 1))
        self.assertEquals(self.importer.accounts[0].deletion_date,
                          date(1970, 1, 1))
        m_user_save.assert_called_with(self.db)
        m_account_save.assert_called_with(self.db)
Ejemplo n.º 4
0
    def test_load_update_user_closed_account(self, m_account_update, m_user_update):
        """UserImporterLdap.update() update user found in LDAP and in HPCStatsDB
           with a closed account on the cluster.
        """
        users = [ 'login5' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        user5_creation = datetime(2015, 3, 2, 16, 0, 1)
        user5_deletion = datetime(2015, 3, 2, 16, 0, 1)
        user5_id = 5
        MockPg2.PG_REQS['find_user'].set_assoc(
          params=( 'login5', ),
          result=[ [ user5_id ] ]
          )
        MockPg2.PG_REQS['existing_account'].set_assoc(
          params=( user5_id, self.cluster.cluster_id, ),
          result=[ [ 0 ] ]
          )
        MockPg2.PG_REQS['load_account'].set_assoc(
          params=( user5_id, self.cluster.cluster_id, ),
          result=[ [ 0, 0, user5_creation, user5_deletion ] ]
        )

        self.importer.load()
        self.importer.update()
        self.assertEquals(self.importer.accounts[0].deletion_date, None)
        m_user_update.assert_called_with(self.db)
        m_account_update.assert_called_with(self.db)
Ejemplo n.º 5
0
    def test_load_update_user_w_account(self, m_account_update, m_user_update):
        """UserImporterLdap.update() update user found in LDAP and in HPCStatsDB
           with an unclosed account on the cluster.
        """

        users = [ 'login4' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        creation_user4 = datetime(2015, 3, 2, 16, 0, 1)
        user4_id = 4
        MockPg2.PG_REQS['find_user'].set_assoc(
          params=( 'login4', ),
          result=[ [ user4_id ] ]
          )
        MockPg2.PG_REQS['existing_account'].set_assoc(
          params=( user4_id, self.cluster.cluster_id, ),
          result=[ [ 0 ] ]
          )
        MockPg2.PG_REQS['load_account'].set_assoc(
          params=( user4_id, self.cluster.cluster_id, ),
          result=[ [ 0, 0, creation_user4, None ] ]
        )

        self.importer.load()
        self.importer.update()
        m_user_update.assert_called_with(self.db)
        # ensure Account.update() is not called
        self.assertRaises(AssertionError,
                          m_account_update.assert_called_with,
                          self.db,
                          None)
Ejemplo n.º 6
0
    def test_update_user_account_exist(self, m_account_update, m_user_update):
        """UserImporterLdapSlurm.slurm() should update the user and do not
           touch the account if they already exist in DB
        """

        users = [ ]
        users_no_group = [ 'login1' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users, users_no_group)

        MockMySQLdb.MY_REQS['get_users']['res'] = \
        [ [ 'login1' ] ]

        user1_id = 1

        MockPg2.PG_REQS['find_user'].set_assoc(
          params=( 'login1', ),
          result=[ [ user1_id ] ]
          )
        MockPg2.PG_REQS['existing_account'].set_assoc(
          params=( user1_id, self.cluster.cluster_id, ),
          result=[ [ 0 ] ]
          )

        self.importer.load()
        self.importer.update()
        m_user_update.assert_called_with(self.db)
        # ensure Account.update() is not called
        self.assertRaises(AssertionError,
                          m_account_update.assert_called_with,
                          self.db,
                          None)
Ejemplo n.º 7
0
    def test_load_user_no_dp_group(self):
        """UserImporterLdap.load() should work with user having no secondary group.
        """

        user = '******'
        fill_ldap_users(CONFIG['testcluster/ldap'], [user])
        # remove secondary group result for login1
        MockLdap.LDAP_REQS['secondary_groups_login1']['res'] = []

        # set the cn result of the prim_group LDAP query
        primary_group = 'primgrouptest'
        MockLdap.LDAP_REQS['prim_group_0']['res'][0][1]['cn'][0] = primary_group

        MockPg2.PG_REQS['get_unclosed_accounts'].set_assoc (
          params=( 0, ),
          result=[ ]
        )

        # test the user department has been computed based on its primary group
        self.importer.load()
        self.assertEquals(self.importer.users[0].department,
                          primary_group+'-unknown')

        # test with alternative default subdir
        subdir = 'testA'
        self.importer.default_subdir = subdir
        self.importer.load()
        self.assertEquals(self.importer.users[0].department,
                          primary_group+'-'+subdir)

        # test with alias
        primary_group_complicated = 'primgrouptestcomplicated'
        MockLdap.LDAP_REQS['prim_group_0']['res'][0][1]['cn'][0] = \
            primary_group_complicated
        self.importer.groups_alias = \
            { primary_group_complicated: primary_group }
        self.importer.load()
        self.assertEquals(self.importer.users[0].department,
                          primary_group+'-'+subdir)

        # test without primary group -> department must be None
        MockLdap.LDAP_REQS['prim_group_0']['res'] = {}
        self.importer.load()
        self.assertEquals(self.importer.users[0].department, None)

        # test with multiple primary groups -> must raise HPCStatsSourceError
        primary_group_complicated = 'primgrouptestcomplicated'
        MockLdap.LDAP_REQS['prim_group_0']['res'] = [ 'result1', 'result2' ]
        self.assertRaisesRegexp(
            HPCStatsSourceError,
            "too much results .%d. found for user %s primary group %d in " \
            "base %s" % (2, user, 0, self.importer.ldap_dn_groups),
            self.importer.load)
Ejemplo n.º 8
0
    def test_load_no_redundancy(self):
        """UserImporterLdapSlurm.load() should manage redundancy with LDAP.
        """

        users = [ 'login1', 'login2', 'login3' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        MockMySQLdb.MY_REQS['get_users']['res'] = \
        [ [ 'login1' ], [ 'login2' ], [ 'login4' ] ]

        self.importer.load()
        self.assertEquals(len(self.importer.users), 3)
        self.assertEquals(len(self.importer.accounts), 3)
Ejemplo n.º 9
0
    def test_load_update_new_user_no_account(self, m_account_save, m_user_save):
        """UserImporterLdap.update() save new user/account found in LDAP
           and not found in HPCStatsDB with a creation date equals to epoch
           because there is none existing accounts
        """

        users = [ 'login1' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        self.importer.load()
        self.importer.update()
        self.assertEquals(self.importer.accounts[0].creation_date, date(1970, 1, 1))
        m_user_save.assert_called_with(self.db)
        m_account_save.assert_called_with(self.db)
Ejemplo n.º 10
0
    def test_load_update_new_user_no_account(self, m_account_save, m_user_save):
        """UserImporterLdap.update() save new user/account found in LDAP
           and not found in HPCStatsDB with a creation date equals to epoch
           because there is none existing accounts
        """

        users = [ 'login1' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        self.importer.load()
        self.importer.update()
        self.assertEquals(self.importer.accounts[0].creation_date, date(1970, 1, 1))
        m_user_save.assert_called_with(self.db)
        m_account_save.assert_called_with(self.db)
Ejemplo n.º 11
0
    def test_load_user_no_ldap(self):
        """UserImporterLdapSlurm.load() should not user from Slurm if not found
           in LDAP.
        """

        users = [ ]
        users_no_group = [ ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users, users_no_group)

        MockMySQLdb.MY_REQS['get_users']['res'] = \
        [ [ 'login1' ] ]

        self.importer.load()
        self.assertEquals(len(self.importer.users), 0)
Ejemplo n.º 12
0
    def test_load_simple(self):
        """UserImporterLdap.load() should work with simple data from LDAP.
        """

        users = [ 'login1', 'login2', 'login3' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        MockPg2.PG_REQS['get_unclosed_accounts'].set_assoc (
          params=( 0, ),
          result=[ ]
        )

        self.importer.load()
        self.assertEquals(len(self.importer.users), 3)
        self.assertEquals(len(self.importer.accounts), 3)
Ejemplo n.º 13
0
    def test_load_simple(self):
        """UserImporterLdap.load() should work with simple data from LDAP.
        """

        users = [ 'login1', 'login2', 'login3' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        MockPg2.PG_REQS['get_unclosed_accounts'].set_assoc (
          params=( 0, ),
          result=[ ]
        )

        self.importer.load()
        self.assertEquals(len(self.importer.users), 3)
        self.assertEquals(len(self.importer.accounts), 3)
Ejemplo n.º 14
0
    def test_load_user_in_group(self):
        """UserImporterLdapSlurm.load() should not load user from Slurm if
           already loaded because it is member of cluster group.
        """

        users = [ 'login1' ]
        users_no_group = [ ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users, users_no_group)

        MockMySQLdb.MY_REQS['get_users']['res'] = \
        [ [ 'login1' ] ]

        self.importer.load()
        self.assertEquals(len(self.importer.users), 1)
        self.assertEquals(len(self.importer.users_acct_ldap), 1)
        self.assertEquals(len(self.importer.users_acct_slurm), 0)
Ejemplo n.º 15
0
    def test_load_simple2(self):
        """UserImporterLdap.load() should work with simple data from LDAP and
           HPCStatsDB.
        """

        users = [ 'login1', 'login2', 'login3' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        creation_user4 = datetime(2015, 3, 2, 16, 0, 1)
        MockPg2.PG_REQS['get_unclosed_accounts'].set_assoc(
          params=( 0, ),
          result=[ [ 0, 'login4', 'name_user4', 'firstname_user4',
                     'department_user4', 0, 0, creation_user4 ] ]
          )

        self.importer.load()
        self.assertEquals(len(self.importer.users), 4)
        self.assertEquals(len(self.importer.accounts), 4)
Ejemplo n.º 16
0
    def test_load_simple2(self):
        """UserImporterLdap.load() should work with simple data from LDAP and
           HPCStatsDB.
        """

        users = [ 'login1', 'login2', 'login3' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        creation_user4 = datetime(2015, 3, 2, 16, 0, 1)
        MockPg2.PG_REQS['get_unclosed_accounts'].set_assoc(
          params=( 0, ),
          result=[ [ 0, 'login4', 'name_user4', 'firstname_user4',
                     'department_user4', 0, 0, creation_user4 ] ]
          )

        self.importer.load()
        self.assertEquals(len(self.importer.users), 4)
        self.assertEquals(len(self.importer.accounts), 4)
Ejemplo n.º 17
0
    def test_load_update_close_account(self, m_account_update):
        """UserImporterLdap.update() close account found as unclosed in
           HPCStatsDB and not found in LDAP.
        """

        users = [ ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        creation_user2 = datetime(2015, 3, 2, 16, 0, 1)

        MockPg2.PG_REQS['get_unclosed_accounts'].set_assoc(
          params=( self.cluster.cluster_id, ),
          result=[ [ 2, 'login2', 'name_user2', 'firstname_user2',
                     'department_user2', 0, 0, creation_user2 ] ]
          )

        self.importer.load()
        self.importer.update()
        self.assertEquals(self.importer.accounts[0].deletion_date, date.today())
        m_account_update.assert_called_with(self.db)
Ejemplo n.º 18
0
    def test_load_update_close_account(self, m_account_update):
        """UserImporterLdap.update() close account found as unclosed in
           HPCStatsDB and not found in LDAP.
        """

        users = [ ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        creation_user2 = datetime(2015, 3, 2, 16, 0, 1)

        MockPg2.PG_REQS['get_unclosed_accounts'].set_assoc(
          params=( self.cluster.cluster_id, ),
          result=[ [ 2, 'login2', 'name_user2', 'firstname_user2',
                     'department_user2', 0, 0, creation_user2 ] ]
          )

        self.importer.load()
        self.importer.update()
        self.assertEquals(self.importer.accounts[0].deletion_date, date.today())
        m_account_update.assert_called_with(self.db)
Ejemplo n.º 19
0
    def test_load_update_new_user_other_accounts(self, m_account_save, m_user_save):
        """UserImporterLdap.update() create new user/account found in LDAP
           and not found in HPCStatsDB with a creation date equals to today
           because there are already existing accounts.
        """

        users = [ 'login1' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        MockPg2.PG_REQS['get_unclosed_accounts'].set_assoc(
          params=( self.cluster.cluster_id, ),
          result=[ ]
          )
        MockPg2.PG_REQS['nb_existing_accounts'].set_assoc(
          params=( self.cluster.cluster_id, ),
          result=[ [ 0 ], [ 1 ] ]
          )

        self.importer.load()
        self.importer.update()
        self.assertEquals(self.importer.accounts[0].creation_date, date.today())
        m_user_save.assert_called_with(self.db)
        m_account_save.assert_called_with(self.db)
Ejemplo n.º 20
0
    def test_load_update_user_wo_account(self, m_account_save, m_user_update):
        """UserImporterLdap.update() create account and update user found in
           LDAP and in HPCStatsDB but w/o account on the cluster.
        """

        users = [ 'login3' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        user3_id = 3

        MockPg2.PG_REQS['find_user'].set_assoc(
          params=( 'login3', ),
          result=[ [ user3_id ] ]
          )
        MockPg2.PG_REQS['existing_account'].set_assoc(
          params=( user3_id, self.cluster.cluster_id, ),
          result=[ ]
          )

        self.importer.load()
        self.importer.update()
        m_user_update.assert_called_with(self.db)
        m_account_save.assert_called_with(self.db)
Ejemplo n.º 21
0
    def test_load_update_user_wo_account(self, m_account_save, m_user_update):
        """UserImporterLdap.update() create account and update user found in
           LDAP and in HPCStatsDB but w/o account on the cluster.
        """

        users = [ 'login3' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        user3_id = 3

        MockPg2.PG_REQS['find_user'].set_assoc(
          params=( 'login3', ),
          result=[ [ user3_id ] ]
          )
        MockPg2.PG_REQS['existing_account'].set_assoc(
          params=( user3_id, self.cluster.cluster_id, ),
          result=[ ]
          )

        self.importer.load()
        self.importer.update()
        m_user_update.assert_called_with(self.db)
        m_account_save.assert_called_with(self.db)
Ejemplo n.º 22
0
    def test_load_update_new_user_other_accounts(self, m_account_save, m_user_save):
        """UserImporterLdap.update() create new user/account found in LDAP
           and not found in HPCStatsDB with a creation date equals to today
           because there are already existing accounts.
        """

        users = [ 'login1' ]
        fill_ldap_users(CONFIG['testcluster/ldap'], users)

        MockPg2.PG_REQS['get_unclosed_accounts'].set_assoc(
          params=( self.cluster.cluster_id, ),
          result=[ ]
          )
        MockPg2.PG_REQS['nb_existing_accounts'].set_assoc(
          params=( self.cluster.cluster_id, ),
          result=[ [ 0 ], [ 1 ] ]
          )

        self.importer.load()
        self.importer.update()
        self.assertEquals(self.importer.accounts[0].creation_date, date.today())
        m_user_save.assert_called_with(self.db)
        m_account_save.assert_called_with(self.db)