Пример #1
0
    def _register_consumer(self, name, facts, owner, env, callback):
        """
        method run in the worker thread.
        """
        try:
            installed_mgr = InstalledProductsManager()
            retval = self.backend.admin_uep.registerConsumer(
                name=name,
                facts=facts.get_facts(),
                owner=owner,
                environment=env,
                installed_products=installed_mgr.format_for_server())

            # Facts and installed products went out with the registration
            # request, manually write caches to disk:
            facts.write_cache()
            installed_mgr.write_cache()

            ProfileManager().update_check(self.backend.admin_uep,
                                          retval['uuid'])

            # We have new credentials, restart virt-who
            restart_virt_who()

            self.queue.put((callback, retval, None))
        except Exception, e:
            self.queue.put((callback, None, e))
Пример #2
0
    def setUp(self):
        current_pkgs = [
            Package(name="package1", version="1.0.0", release=1,
                    arch="x86_64"),
            Package(name="package2", version="2.0.0", release=2, arch="x86_64")
        ]
        temp_repo_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, temp_repo_dir)
        repo_file_name = os.path.join(temp_repo_dir, 'awesome.repo')
        with open(repo_file_name, 'w') as repo_file:
            repo_file.write(CONTENT_REPO_FILE)

        patcher = patch('rhsm.profile.dnf')
        self.addCleanup(patcher.stop)
        dnf_mock = patcher.start()
        dnf_mock.dnf = Mock()
        mock_db = Mock()
        mock_db.conf = Mock()
        mock_db.conf.substitutions = {'releasever': '1', 'basearch': 'x86_64'}
        dnf_mock.dnf.Base = Mock(return_value=mock_db)

        self.current_profile = self._mock_pkg_profile(current_pkgs,
                                                      repo_file_name,
                                                      ENABLED_MODULES)
        self.profile_mgr = ProfileManager()
        self.profile_mgr.current_profile = self.current_profile
Пример #3
0
 def setUp(self):
     current_pkgs = [
         Package(name="package1", version="1.0.0", release=1,
                 arch="x86_64"),
         Package(name="package2", version="2.0.0", release=2, arch="x86_64")
     ]
     self.current_profile = self._mock_pkg_profile(current_pkgs)
     self.profile_mgr = ProfileManager(current_profile=self.current_profile)
 def setUp(self):
     current_pkgs = [
         Package(name="package1", version="1.0.0", release=1,
                 arch="x86_64"),
         Package(name="package2", version="2.0.0", release=2, arch="x86_64")
     ]
     temp_repo_dir = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, temp_repo_dir)
     repo_file_name = os.path.join(temp_repo_dir, 'awesome.repo')
     with open(repo_file_name, 'w') as repo_file:
         repo_file.write(CONTENT_REPO_FILE)
     self.current_profile = self._mock_pkg_profile(current_pkgs,
                                                   repo_file_name,
                                                   ENABLED_MODULES)
     self.profile_mgr = ProfileManager()
     self.profile_mgr.current_profile = self.current_profile
Пример #5
0
def list_pools(uep, consumer_uuid, facts, list_all=False, active_on=None):
    """
    Wrapper around the UEP call to fetch pools, which forces a facts update
    if anything has changed before making the request. This ensures the
    rule checks server side will have the most up to date info about the
    consumer possible.
    """
    facts.update_check(uep, consumer_uuid)

    profile_mgr = ProfileManager()
    profile_mgr.update_check(uep, consumer_uuid)

    owner = uep.getOwner(consumer_uuid)
    ownerid = owner['key']
    return uep.getPoolsList(consumer=consumer_uuid,
                            listAll=list_all,
                            active_on=active_on,
                            owner=ownerid)
Пример #6
0
    def _register_consumer(self, name, facts, owner, env, activation_keys, callback):
        """
        method run in the worker thread.
        """
        try:
            installed_mgr = InstalledProductsManager()

            self.plugin_manager.run("pre_register_consumer", name=name,
                facts=facts.get_facts())
            retval = self.backend.cp_provider.get_basic_auth_cp().registerConsumer(name=name,
                    facts=facts.get_facts(), owner=owner, environment=env,
                    keys=activation_keys,
                    installed_products=installed_mgr.format_for_server())
            self.plugin_manager.run("post_register_consumer", consumer=retval,
                facts=facts.get_facts())

            # Facts and installed products went out with the registration
            # request, manually write caches to disk:
            facts.write_cache()
            installed_mgr.write_cache()

            cp = self.backend.cp_provider.get_basic_auth_cp()

            # In practice, the only time this condition should be true is
            # when we are working with activation keys.  See BZ #888790.
            if not self.backend.cp_provider.get_basic_auth_cp().username and \
                not self.backend.cp_provider.get_basic_auth_cp().password:
                # Write the identity cert to disk
                managerlib.persist_consumer_cert(retval)
                self.backend.update()
                cp = self.backend.cp_provider.get_consumer_auth_cp()

            ProfileManager().update_check(cp, retval['uuid'])

            # We have new credentials, restart virt-who
            restart_virt_who()

            self.queue.put((callback, retval, None))
        except Exception:
            self.queue.put((callback, None, sys.exc_info()))