def test_update_overrides_cache(self):
        with patch('rhsm.connection.UEPConnection') as mock_uep:
            self.stub_cp_provider.consumer_auth_cp = mock_uep
            mock_uep.supports_resource = Mock(return_value=True)
            mock_uep.setContentOverrides = Mock()

            repo_settings = {
                'enabled': '0',
            }
            self.invoker.return_value.get_repos.return_value = [
                Repo('hello', list(repo_settings.items())),
            ]
            self.repo_file.items.return_value = list(repo_settings.items())

            self._inject_mock_valid_consumer("123")

            # The API methods try to bootstrap injection themselves so we want
            # to avoid that here.
            with patch('subscription_manager.api.injected') as injected:
                injected.return_value = True

                result = api.enable_yum_repositories('hello')

                expected_overrides = [{
                    'contentLabel': 'hello',
                    'name': 'enabled',
                    'value': '1',
                }]
                self.assertTrue(call("123", expected_overrides) in mock_uep.setContentOverrides.mock_calls)

                self.invoker.return_value.update.assert_called_with()
                self.assertEqual(1, result)
Exemple #2
0
    def test_update_overrides_cache(self):
        with patch("rhsm.connection.UEPConnection") as mock_uep:
            self.stub_cp_provider.consumer_auth_cp = mock_uep
            mock_uep.supports_resource = Mock(return_value=True)
            mock_uep.setContentOverrides = Mock()

            repo_settings = {
                "enabled": "0",
            }
            self.invoker.return_value.get_repos.return_value = [
                Repo("hello", list(repo_settings.items())),
            ]
            self.repo_file.items.return_value = list(repo_settings.items())

            self._inject_mock_valid_consumer("123")

            # The API methods try to bootstrap injection themselves so we want
            # to avoid that here.
            with patch("subscription_manager.api.injected") as injected:
                injected.return_value = True

                result = api.enable_yum_repositories("hello")

                expected_overrides = [{
                    "contentLabel": "hello",
                    "name": "enabled",
                    "value": "1",
                }]
                self.assertTrue(
                    call("123", expected_overrides) in
                    mock_uep.setContentOverrides.mock_calls)

                self.invoker.return_value.update.assert_called_with()
                self.assertEqual(1, result)
Exemple #3
0
    def test_does_not_enable_nonmatching_repos(self):
        repo_settings = {
            'enabled': '0',
        }
        self.invoker.get_repos.return_value = [
            Repo('x', repo_settings.items()),
        ]
        self.repo_file.items.return_value = repo_settings.items()
        result = api.enable_yum_repositories('hello')

        self.assertFalse(call.write() in self.repo_file.mock_calls)
        self.assertEquals(0, result)
    def test_does_not_enable_nonmatching_repos(self):
        repo_settings = {
            'enabled': '0',
        }
        self.invoker.return_value.get_repos.return_value = [
            Repo('x', list(repo_settings.items())),
        ]
        self.repo_file.items.return_value = list(repo_settings.items())
        result = api.enable_yum_repositories('hello')

        self.assertEqual(0, len(self.repo_file.return_value.write.mock_calls))
        self.assertEqual(0, result)
    def test_enable_repo(self):
        repo_settings = {
            'enabled': '0',
        }
        self.invoker.return_value.get_repos.return_value = [
            Repo('hello', list(repo_settings.items())),
        ]
        self.repo_file.items.return_value = list(repo_settings.items())
        result = api.enable_yum_repositories('hello')

        self.repo_file.return_value.write.assert_called_with()
        self.assertEqual(1, result)
Exemple #6
0
    def test_does_not_enable_nonmatching_repos(self):
        repo_settings = {
            "enabled": "0",
        }
        self.invoker.return_value.get_repos.return_value = [
            Repo("x", list(repo_settings.items())),
        ]
        self.repo_file.items.return_value = list(repo_settings.items())
        result = api.enable_yum_repositories("hello")

        self.assertEqual(0, len(self.repo_file.return_value.write.mock_calls))
        self.assertEqual(0, result)
Exemple #7
0
    def test_enable_repo(self):
        repo_settings = {
            "enabled": "0",
        }
        self.invoker.return_value.get_repos.return_value = [
            Repo("hello", list(repo_settings.items())),
        ]
        self.repo_file.items.return_value = list(repo_settings.items())
        result = api.enable_yum_repositories("hello")

        self.repo_file.return_value.write.assert_called_with()
        self.assertEqual(1, result)
Exemple #8
0
    def test_enable_repo(self):
        repo_settings = {
            'enabled': '0',
        }
        self.invoker.return_value.get_repos.return_value = [
            Repo('hello', repo_settings.items()),
        ]
        self.repo_file.items.return_value = repo_settings.items()
        result = api.enable_yum_repositories('hello')

        self.repo_file.return_value.write.assert_called_with()
        self.assertEquals(1, result)
    def test_enable_repo_wildcard(self):
        repo_settings = {
            'enabled': '0',
        }

        self.invoker.return_value.get_repos.return_value = [
            Repo('hello', repo_settings.copy().items()),
            Repo('helium', repo_settings.copy().items()),
        ]
        self.repo_file.items.return_value = repo_settings.copy().items()

        result = api.enable_yum_repositories('he*')
        self.repo_file.return_value.write.assert_called_with()
        self.assertEquals(2, result)
Exemple #10
0
    def test_enable_repo_wildcard(self):
        repo_settings = {
            'enabled': '0',
        }

        self.invoker.return_value.get_repos.return_value = [
            Repo('hello', list(repo_settings.copy().items())),
            Repo('helium', list(repo_settings.copy().items())),
        ]
        self.repo_file.items.return_value = list(repo_settings.copy().items())

        result = api.enable_yum_repositories('he*')
        self.repo_file.return_value.write.assert_called_with()
        self.assertEqual(2, result)
Exemple #11
0
    def test_enable_repo_wildcard(self):
        repo_settings = {
            'enabled': '0',
        }

        self.invoker.get_repos.return_value = [
            Repo('hello', repo_settings.copy().items()),
            Repo('helium', repo_settings.copy().items()),
        ]
        self.repo_file.items.return_value = repo_settings.copy().items()

        result = api.enable_yum_repositories('he*')

        self.assertTrue(call.write() in self.repo_file.mock_calls)
        self.assertEquals(2, result)
Exemple #12
0
def postverifytrans_hook(conduit):
    if not attempted:
        return

    used_repos = set(p.repoid for p in conduit.getTsInfo().getMembersWithState(output_states=TS_INSTALL_STATES))
    helpful_new_repos = used_repos - old_enabled_repos

    if prompt_permanently_enable_repos(conduit, helpful_new_repos):
        for repo in helpful_new_repos:
            try:
                enabled = api.enable_yum_repositories(repo)
            except Exception:
                enabled = 0

            if enabled:
                conduit.info(logging.DEBUG, 'Repo permanently enabled: %s' % repo)
            else:
                conduit.info(logging.DEBUG, 'Failed to permanently enable repo: %s' % repo)
Exemple #13
0
 def munge_injection():
     self._inject_mock_valid_consumer("123")
     return api.enable_yum_repositories('hello')