Exemplo n.º 1
0
    def test_import_users_merge(self, test_data):
        """@test: Try to Merge users with the same name using 'merge-users'
        option.

        @feature: Import Users Map-users

        @assert: Users imported in 2nd import are being mapped to the existing
        ones with the same name

        """
        # prepare the data
        tmp_dir = self.default_dataset[0]
        files = dict(self.default_dataset[1])
        pwdfiles = [
            os.path.join(tmp_dir, gen_string('alpha', 6)) for _ in range(2)
        ]
        files['users'] = update_csv_values(
            files['users'],
            u'organization_id',
            test_data,
            self.default_dataset[0]
        )
        # initial import
        for result in (
            Import.organization({'csv-file': files['users']}),
            Import.user({
                'csv-file': files['users'], 'new-passwords': pwdfiles[0],
            }),
        ):
            self.assertEqual(result.return_code, 0)
        # clear the .transition_data to clear the transition mapping
        ssh.command('rm -rf "${HOME}"/.transition_data/users*')
        # import users using merge-users option
        import_merge = Import.user_with_tr_data({
            'csv-file': files['users'],
            'new-passwords': pwdfiles[1],
            'merge-users': True,
        })
        for record in import_merge[1]:
            self.assertNotEqual(User.info({'id': record['sat6']}).stdout, '')
Exemplo n.º 2
0
    def test_import_users_recovery(self, test_data):
        """@test: Try to Import users with the same name to invoke
        usage of a recovery strategy (rename, map, none)

        @feature: Import Users Recover

        @assert: 2nd Import will rename new users, 3rd one will result
        in No Action Taken and 4th import will map them

        """
        # prepare the data
        tmp_dir = self.default_dataset[0]
        files = dict(self.default_dataset[1])
        pwdfiles = [
            os.path.join(tmp_dir, gen_string('alpha', 6)) for _ in range(4)
        ]
        files['users'] = update_csv_values(
            files['users'],
            u'organization_id',
            test_data,
            self.default_dataset[0]
        )
        # initial import
        for result in (
            Import.organization({'csv-file': files['users']}),
            Import.user({
                'csv-file': files['users'],
                'new-passwords': pwdfiles[0],
            }),
        ):
            self.assertEqual(result.return_code, 0)
        # clear the .transition_data to clear the transition mapping
        ssh.command('rm -rf "${HOME}"/.transition_data/users*')

        # use the default (rename) strategy
        import_rename = Import.user_with_tr_data({
            'csv-file': files['users'],
            'new-passwords': pwdfiles[1],
        })
        for record in import_rename[1]:
            self.assertEqual(User.info({'id': record['sat6']}).return_code, 0)
        Import.user({'csv-file': files['users'], 'delete': True})

        # use the 'none' strategy
        users_before = set(user['login'] for user in User.list().stdout)
        Import.user({
            'csv-file': files['users'],
            'new-passwords': pwdfiles[2],
            'recover': 'none',
        })
        users_after = set(user['login'] for user in User.list().stdout)
        self.assertEqual(users_before, users_after)

        # use the 'map' strategy
        import_map = Import.user_with_tr_data({
            'csv-file': files['users'],
            'recover': 'map',
            'new-passwords': pwdfiles[3],
        })
        for record in import_map[1]:
            self.assertEqual(
                User.info({'id': record['sat6']}).return_code, 0
            )

        # do the cleanup
        ssh.command(u'rm -rf {}'.format(' '.join(pwdfiles)))