Ejemplo n.º 1
0
 def test_creates_populates_and_removes_new_directory(self):
     fixture = MAASRootFixture()
     with fixture:
         self.assertThat(fixture.path, PathExists())
         self.assertThat(fixture.path, Not(SamePath(self.skel)))
         files_expected = set(listdirs(self.skel))
         files_observed = set(listdirs(fixture.path))
         self.assertThat(files_observed, Equals(files_expected))
     self.assertThat(fixture.path, Not(PathExists()))
Ejemplo n.º 2
0
    def test_clean_old_plugins(self, mock_os_system):
        """Make sure old plugin directories are excluded."""
        plugins = ["test1_plugin", "test2_plugin", "test3_plugin"]
        kept_plugins = []
        detached_plugins_dir = "/var/cache/jenkins/war/WEB-INF/detached-plugins"
        os_expected_calls = [mock.call("sudo rm -r %s" % detached_plugins_dir)]

        os.mkdir(detached_plugins_dir)
        for plugin in plugins:
            # Create old plugins directories and .jpi files with no version
            plugin_dir = os.path.join(paths.PLUGINS, plugin)
            plugin_file = os.path.join(paths.PLUGINS, "%s.jpi" % plugin)
            os.mkdir(plugin_dir)
            with open(plugin_file, "w") as fd:
                fd.write("")
            # And expect them to be removed
            os_expected_calls.append(mock.call("sudo rm -r %s/" % plugin_dir))
            os_expected_calls.append(mock.call("sudo rm %s" % plugin_file))

            # Create plugins with version that should not be removed
            plugin_to_keep = os.path.join(paths.PLUGINS, "%s-1.jpi" % plugin)
            kept_plugins.append(plugin_to_keep)
            with open(plugin_to_keep, "w") as fd:
                fd.write("")

        self.packages.clean_old_plugins()
        self.assertThat(paths.PLUGINS, PathExists())
        self.assertCountEqual(mock_os_system.mock_calls, os_expected_calls)
        mock_os_system.assert_has_calls(os_expected_calls, any_order=True)
Ejemplo n.º 3
0
    def test_install_do_remove_unlisted(self, mock_get_plugins_to_install,
                                        mock_install_plugins,
                                        mock_restart_jenkins):
        """
        If remove-unlisted-plugins is set to 'yes', then unlisted plugins
        are removed from disk.
        """
        plugin_name = "plugin"
        plugin_path = os.path.join(paths.PLUGINS,
                                   "{}-1.jpi".format(plugin_name))
        mock_get_plugins_to_install.return_value = {plugin_name}
        mock_install_plugins.return_value = {plugin_path}
        orig_remove_unlisted_plugins = hookenv.config(
        )["remove-unlisted-plugins"]
        try:
            hookenv.config()["remove-unlisted-plugins"] = "yes"
            unlisted_plugin = os.path.join(paths.PLUGINS, "unlisted.jpi")
            with open(unlisted_plugin, "w"):
                pass
            self.plugins.install(plugin_name)
            self.assertThat(unlisted_plugin, Not(PathExists()))

        finally:
            hookenv.config(
            )["remove-unlisted-plugins"] = orig_remove_unlisted_plugins
Ejemplo n.º 4
0
    def testDirtySuites(self):
        """publish-distro can be told to publish specific suites."""
        archive = self.factory.makeArchive(distribution=self.ubuntutest)
        self.layer.txn.commit()

        # publish-distro has nothing to publish.
        self.runPublishDistro(['--ppa'])
        breezy_release_path = os.path.join(
            getPubConfig(archive).distsroot, 'breezy-autotest', 'Release')
        self.assertThat(breezy_release_path, Not(PathExists()))

        # ... but it will publish a suite anyway if it is marked as dirty.
        archive.markSuiteDirty(
            archive.distribution.getSeries('breezy-autotest'),
            PackagePublishingPocket.RELEASE)
        self.runPublishDistro(['--ppa'])
        self.assertThat(breezy_release_path, PathExists())
Ejemplo n.º 5
0
 def test_equivalent_to_standard_path_exists(self, path):
     """
     path_exists is to FilePaths what PathExists is to normal paths.
     """
     self.assertThat(
         path_exists().match(path),
         is_equivalent_mismatch(PathExists().match(path.path)),
     )
Ejemplo n.º 6
0
 def test_install_do_remove_unlisted(self):
     """
     If remove-unlisted-plugins is set to 'no', then unlisted plugins
     will be left on disk.
     """
     unlisted_plugin = os.path.join(paths.PLUGINS, "unlisted.hpi")
     with open(unlisted_plugin, "w"):
         pass
     self.plugins.install("plugin")
     self.assertThat(unlisted_plugin, PathExists())
Ejemplo n.º 7
0
 def test_install_skip_non_file_unlisted(self):
     """
     If an unlisted plugin is not actually a file, it's just skipped and
     doesn't get removed.
     """
     self.fakes.juju.config["remove-unlisted-plugins"] = "yes"
     unlisted_plugin = os.path.join(paths.PLUGINS, "unlisted.hpi")
     os.mkdir(unlisted_plugin)
     self.plugins.install("plugin")
     self.assertThat(unlisted_plugin, PathExists())
Ejemplo n.º 8
0
    def testCarefulRelease(self):
        """publish-distro can be asked to just rewrite Release files."""
        archive = self.factory.makeArchive(distribution=self.ubuntutest)
        pub_source = self.getPubSource(filecontent='foo', archive=archive)

        self.setUpRequireSigningKeys()
        yield self.useFixture(InProcessKeyServerFixture()).start()
        key_path = os.path.join(gpgkeysdir, '*****@*****.**')
        yield IArchiveSigningKey(archive).setSigningKey(key_path,
                                                        async_keyserver=True)

        self.layer.txn.commit()

        self.runPublishDistro(['--ppa'])

        pub_source.sync()
        self.assertEqual(PackagePublishingStatus.PUBLISHED, pub_source.status)

        dists_path = getPubConfig(archive).distsroot
        hoary_inrelease_path = os.path.join(dists_path, 'hoary-test',
                                            'InRelease')
        breezy_inrelease_path = os.path.join(dists_path, 'breezy-autotest',
                                             'InRelease')
        self.assertThat(hoary_inrelease_path, Not(PathExists()))
        os.unlink(breezy_inrelease_path)

        self.runPublishDistro(['--ppa', '--careful-release'])
        self.assertThat(hoary_inrelease_path, Not(PathExists()))
        self.assertThat(breezy_inrelease_path, Not(PathExists()))

        self.runPublishDistro([
            '--ppa',
            '--careful-release',
            '--include-non-pending',
            '--disable-publishing',
            '--disable-domination',
            '--disable-apt',
        ])
        # hoary-test never had indexes created, so is untouched.
        self.assertThat(hoary_inrelease_path, Not(PathExists()))
        # breezy-autotest has its Release files rewritten.
        self.assertThat(breezy_inrelease_path, PathExists())
Ejemplo n.º 9
0
    def test_mktemp_doesnt_exist(self, test):
        """
        ``mktemp`` returns a path that doesn't exist inside a directory that
        does.
        """
        temp_path = FilePath(test.mktemp())
        self.addCleanup(_remove_dir, temp_path.parent())

        self.expectThat(temp_path.parent().path, DirExists())
        self.expectThat(temp_path.path, Not(PathExists()))
        self.assertThat(temp_path, BelowPath(FilePath(os.getcwd())))
Ejemplo n.º 10
0
 def test_install_dont_remove_unlisted(self):
     """
     If remove-unlisted-plugins is set to 'yes', then unlisted plugins
     are removed from disk.
     """
     self.fakes.juju.config["remove-unlisted-plugins"] = "yes"
     unlisted_plugin = os.path.join(paths.PLUGINS, "unlisted.hpi")
     with open(unlisted_plugin, "w"):
         pass
     self.plugins.install("plugin")
     self.assertThat(unlisted_plugin, Not(PathExists()))
Ejemplo n.º 11
0
 def match(self, path):
     mismatch = PathExists().match(path)
     if mismatch is not None:
         return mismatch
     if self.encoding is None:
         # Binary match.
         with open(path, "rb") as fd:
             actual_contents = fd.read()
     else:
         # Text/Unicode match.
         with open(path, "r", encoding=self.encoding) as fd:
             actual_contents = fd.read()
     return self.matcher.match(actual_contents)
Ejemplo n.º 12
0
    def test_mktemp_doesnt_exist(self, base_test_case):
        """
        ``mktemp`` returns a path that doesn't exist inside a directory that
        does.
        """
        class SomeTest(base_test_case):
            def test_pass(self):
                pass

        test = SomeTest('test_pass')
        temp_path = FilePath(test.mktemp())
        self.addCleanup(_remove_dir, temp_path.parent())

        self.expectThat(temp_path.parent().path, DirExists())
        self.expectThat(temp_path.path, Not(PathExists()))
        self.assertThat(temp_path, BelowPath(FilePath(os.getcwd())))
Ejemplo n.º 13
0
 def test_install_jenkins_bundle_no_file(self):
     """
     If the 'release' config is set to 'bundle' but no jenkins.deb file is
     present, an error is raised.
     """
     orig_release = hookenv.config()["release"]
     try:
         hookenv.config()["release"] = "bundle"
         path = os.path.join(hookenv.charm_dir(), "files", "jenkins.deb")
         self.assertThat(path, Not(PathExists()))
         error = self.assertRaises(Exception, self.packages._install_from_bundle)
         self.assertEqual(
             "'{}' doesn't exist. No package bundled.".format(path),
             str(error))
     finally:
         hookenv.config()["release"] = orig_release
Ejemplo n.º 14
0
 def test_install_skip_non_file_unlisted(self, mock_get_plugins_to_install, mock_install_plugins,  mock_restart_jenkins):
     """
     If an unlisted plugin is not actually a file, it's just skipped and
     doesn't get removed.
     """
     mock_get_plugins_to_install.return_value = {"plugin"}
     mock_install_plugins.return_value = {
         os.path.join(paths.PLUGINS, "plugin.jpi")}
     orig_remove_unlisted_plugins = hookenv.config()["remove-unlisted-plugins"]
     try:
         hookenv.config()["remove-unlisted-plugins"] = "yes"
         unlisted_plugin = os.path.join(paths.PLUGINS, "unlisted.hpi")
         os.mkdir(unlisted_plugin)
         self.plugins.install("plugin")
         self.assertThat(unlisted_plugin, PathExists())
     finally:
         hookenv.config()["remove-unlisted-plugins"] = orig_remove_unlisted_plugins
Ejemplo n.º 15
0
 def test_remove_plugin(self, mock_restart_jenkins):
     """
     The given plugin file is removed from disk.
     """
     plugin_name = "plugin"
     plugin_path = os.path.join(paths.PLUGINS, "{}-1.jpi".format(plugin_name))
     orig_remove_unlisted_plugins = hookenv.config()["remove-unlisted-plugins"]
     try:
         hookenv.config()["remove-unlisted-plugins"] = "yes"
         with open(plugin_path, "w"):
             pass
         # When using a non-existent path it returns None
         self.assertIsNone(self.plugins._remove_plugin(plugin_name))
         self.plugins._remove_plugin(plugin_path)
         self.assertThat(plugin_path, Not(PathExists()))
     finally:
         hookenv.config()["remove-unlisted-plugins"] = orig_remove_unlisted_plugins
Ejemplo n.º 16
0
    def test_non_ubuntu_ppa(self):
        """A meta-data upload to a non-Ubuntu PPA is not published.

        The meta-data directory is currently only defined for Ubuntu PPAs.
        """
        archive = self.factory.makeArchive(
            distribution=self.factory.makeDistribution())
        packageupload = self.factory.makePackageUpload(archive=archive)
        libraryfilealias = self.factory.makeLibraryFileAlias(db_only=True)
        logger = BufferLogger()
        MetaDataUpload(logger=logger).process(packageupload, libraryfilealias)
        self.assertEqual(
            "DEBUG Skipping meta-data for archive without metaroot.\n",
            logger.getLogBuffer())
        published_file = os.path.join(
            getPubConfig(archive).distroroot, archive.owner.name, "meta",
            archive.name, libraryfilealias.filename)
        self.assertThat(published_file, Not(PathExists()))
Ejemplo n.º 17
0
 def test_not_exists(self):
     doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
     mismatch = PathExists().match(doesntexist)
     self.assertThat(
         "%s does not exist." % doesntexist, Equals(mismatch.describe()))
Ejemplo n.º 18
0
 def test_stopService_deletes_socket(self):
     socket_path = self.patch_socket_path()
     service = LeaseSocketService(sentinel.service, reactor)
     service.startService()
     yield service.stopService()
     self.assertThat(socket_path, Not(PathExists()))
Ejemplo n.º 19
0
 def test_startService_creates_socket(self):
     socket_path = self.patch_socket_path()
     service = LeaseSocketService(sentinel.service, reactor)
     service.startService()
     self.addCleanup(service.stopService)
     self.assertThat(socket_path, PathExists())
Ejemplo n.º 20
0
 def test_sign_without_signing_key(self):
     filename = os.path.join(getPubConfig(self.archive).archiveroot, "file")
     self.assertIsNone(self.archive.signing_key)
     custom_processor = CustomUpload()
     custom_processor.sign(self.archive, "suite", filename)
     self.assertThat("%s.gpg" % filename, Not(PathExists()))
Ejemplo n.º 21
0
 def test_bundle_download(self):
     bundle_path = os.path.join(hookenv.charm_dir(), "jenkins.deb")
     self.packages._bundle_download(bundle_path)
     self.assertThat(bundle_path, PathExists())
Ejemplo n.º 22
0
 def test_exists(self):
     tempdir = self.mkdtemp()
     self.assertThat(tempdir, PathExists())
Ejemplo n.º 23
0
 def test_not_exists(self):
     doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
     mismatch = PathExists().match(doesntexist)
     self.assertThat("%s does not exist." % doesntexist,
                     Equals(mismatch.describe()))
Ejemplo n.º 24
0
 def test_not_exists(self):
     doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
     mismatch = FileContains('').match(doesntexist)
     self.assertThat(PathExists().match(doesntexist).describe(),
                     Equals(mismatch.describe()))