def test_init(self):
        fid = self.write_tempfile(self.repo_cfg)
        content_set = set()

        ostree_config = model.OstreeConfig(repo_file_path=fid.name)

        mock_content = mock.Mock()
        mock_content.url = "/path/from/base/url"
        mock_content.name = "mock-content-example"
        mock_content.gpg = None

        mock_ent_cert = mock.Mock()
        mock_ent_cert.path = "/somewhere/etc/pki/entitlement/123123.pem"

        mock_ent_content = mock.Mock()
        mock_ent_content.content = mock_content
        mock_ent_content.cert = mock_ent_cert

        content_set.add(mock_ent_content)

        updates_builder = model.OstreeConfigUpdatesBuilder(
            ostree_config, content_set)
        updates = updates_builder.build()

        self.assertTrue(len(updates.new.remotes))
        self.assertTrue(isinstance(updates.new.remotes[0], model.OstreeRemote))
        self.assertEquals(updates.new.remotes[0].url, mock_content.url)
        #self.assertEquals(updates.new.remotes[0].name, mock_content.name)
        self.assertEquals(updates.new.remotes[0].gpg_verify, True)
Ejemplo n.º 2
0
    def perform(self):

        # starting state of ostree config
        ostree_config = model.OstreeConfig()

        # populate config, handle exceptions
        self.load_config(ostree_config)

        report = OstreeContentUpdateActionReport()

        # return the composed set oEntitledContents
        entitled_contents = OstreeContents(ent_source=self.ent_source)

        # CALCULATE UPDATES
        # given current config, and the new contents, construct a list
        # of remotes to apply to our local config of remotes.
        updates_builder = \
            model.OstreeConfigUpdatesBuilder(ostree_config,
                                             contents=entitled_contents)
        updates = updates_builder.build()

        log.debug("Updates orig: %s" % updates.orig)
        log.debug("Updates new: %s" % updates.new)
        log.debug("Updates.new.remote_set: %s" % updates.new.remotes)

        # persist the new stuff
        updates.apply()
        updates.save()

        report.orig_remotes = list(updates.orig.remotes)
        report.remote_updates = list(updates.new.remotes)

        # reload the new config, so we have fresh remotes, etc
        self.load_config(ostree_config)

        # Now that we've updated the ostree repo config, we need to
        # update the currently deployed osname tree .origin file:
        self.update_origin_file(ostree_config)

        log.debug("Ostree update report: %s" % report)
        return report
Ejemplo n.º 3
0
    def update_config(self, ostree_config, contents):
        """Update the remotes configured in a OstreeConfig."""

        report = OstreeContentUpdateActionReport()

        updates_builder = model.OstreeConfigUpdatesBuilder(ostree_config,
                                                           contents=contents)
        updates = updates_builder.build()

        for remote in updates.orig.remotes:
            if remote in updates.new.remotes:
                report.remote_updates.append(remote)
            else:
                report.remote_deleted.append(remote)

        for remote in updates.new.remotes:
            if remote not in updates.orig.remotes:
                report.remote_added.append(remote)

        updates.apply()
        updates.save()

        return report