Example #1
0
    def test_reimport_repo_negative(self, test_data):
        """@test: Import and enable all Repositories from the default data set
        (predefined source), then try to Import Repositories from the same CSV
        again.

        @feature: Repetitive Import Enable Repositories
        @assert: 3 Repositories imported and enabled, second run should trigger
        no action.

        """
        # randomize the values for orgs and repos
        files = dict(self.default_dataset[1])
        for file_ in zip(
            ['users', 'repositories'],
            [u'organization_id', u'org_id'],
        ):
            files[file_[0]] = update_csv_values(
                files[file_[0]],
                file_[1],
                test_data[file_[0]],
                self.default_dataset[0]
            )
        # import the prerequisities
        import_org = Import.organization_with_tr_data(
            {'csv-file': files['users']}
        )
        # now proceed with importing the repositories
        import_repo = Import.repository_with_tr_data({
            'csv-file': files['repositories'],
            'synchronize': True,
            'wait': True,
        })
        for result in (import_org, import_repo):
            self.assertEqual(result[0].return_code, 0)

        # get the sat6 mapping of the imported organizations
        imp_orgs = get_sat6_id(csv_to_dataset([files['users']]), import_org[1])
        repos_before = [
            Repository.list({'organization-id': imp_org['sat6']}).stdout
            for imp_org in imp_orgs
        ]
        # Reimport the same repos and check for changes in sat6
        self.assertEqual(
            Import.repository({
                'csv-file': files['repositories'],
                'synchronize': True,
                'wait': True,
                }).return_code, 0
        )
        self.assertEqual(
            repos_before,
            [
                Repository.list({'organization-id': imp_org['sat6']}).stdout
                for imp_org in imp_orgs
            ]
        )
Example #2
0
    def test_import_repo_recovery(self, test_data):
        """@test: Try to Import Repos with the same name to invoke
        usage of a recovery strategy (rename, map, none)

        @feature: Import Repository Recover

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

        """
        # prepare the data
        files = dict(self.default_dataset[1])
        # randomize the values for orgs and repos
        files = dict(self.default_dataset[1])
        for file_ in zip(
            ['users', 'repositories'],
            [u'organization_id', u'org_id'],
        ):
            files[file_[0]] = update_csv_values(
                files[file_[0]],
                file_[1],
                test_data[file_[0]],
                self.default_dataset[0]
            )
        # import the prerequisities
        import_org = Import.organization_with_tr_data(
            {'csv-file': files['users']}
        )
        for result in (
            import_org,
            Import.repository_with_tr_data(
                {'csv-file': files['repositories']}
            ),
        ):
            self.assertEqual(result[0].return_code, 0)
        # clear the .transition_data to clear the transition mapping
        ssh.command('rm -rf "${HOME}"/.transition_data/repositories*')
        ssh.command('rm -rf "${HOME}"/.transition_data/products*')

        # use the default (rename) strategy
        import_repo_rename = Import.repository_with_tr_data(
            {'csv-file': files['repositories'], 'verbose': True}
        )
        self.assertEqual(import_repo_rename[0].return_code, 0)
        for record in import_repo_rename[1][1]:
            self.assertEqual(
                Repository.info({'id': record['sat6']}).return_code, 0
            )
        Import.repository(
            {'csv-file': files['repositories'], 'delete': True}
        )

        # use the 'none' strategy
        repos_before = [
            Repository.list({'organization-id': tr['sat6']}).stdout
            for tr in import_org[1]
        ]
        Import.repository(
            {'csv-file': files['repositories'], 'recover': 'none'}
        )
        self.assertEqual(
            repos_before,
            [Repository.list({'organization-id': tr['sat6']}).stdout
                for tr in import_org[1]],
        )

        # use the 'map' strategy
        import_repo_map = Import.repository_with_tr_data({
            'csv-file': files['repositories'],
            'recover': 'map',
            'verbose': True,
        })
        self.assertEqual(import_repo_map[0].return_code, 0)
        for record in import_repo_map[1][1]:
            self.assertEqual(
                Repository.info({'id': record['sat6']}).return_code, 0
            )