Example #1
0
    def testReplaceUpdatedHtpasswd(self):
        """Test that the htpasswd file is only replaced if it changes."""
        FILE_CONTENT = "Kneel before Zod!"
        # The publisher Config object does not have an interface, so we
        # need to remove the security wrapper.
        pub_config = getPubConfig(self.ppa)
        filename = os.path.join(pub_config.htaccessroot, ".htpasswd")

        # Write out a dummy .htpasswd
        ensure_directory_exists(pub_config.htaccessroot)
        write_file(filename, FILE_CONTENT)

        # Write the same contents in a temp file.
        fd, temp_filename = tempfile.mkstemp(dir=pub_config.htaccessroot)
        file = os.fdopen(fd, "w")
        file.write(FILE_CONTENT)
        file.close()

        # Replacement should not happen.
        script = self.getScript()
        self.assertFalse(script.replaceUpdatedHtpasswd(self.ppa,
                                                       temp_filename))

        # Writing a different .htpasswd should see it get replaced.
        write_file(filename, "Come to me, son of Jor-El!")

        self.assertTrue(script.replaceUpdatedHtpasswd(self.ppa, temp_filename))

        os.remove(filename)
    def updateStagedFilesForSuite(self, archive_config, suite):
        """Install all staged files for a single archive and suite.

        :return: True if any files were installed, otherwise False.
        """
        backup_top = os.path.join(get_backup_dists(archive_config), suite)
        staging_top = os.path.join(archive_config.stagingroot, suite)
        updated = False
        for staging_dir, _, filenames in scandir.walk(staging_top):
            rel_dir = os.path.relpath(staging_dir, staging_top)
            backup_dir = os.path.join(backup_top, rel_dir)
            for filename in filenames:
                new_path = os.path.join(staging_dir, filename)
                current_path = os.path.join(backup_dir, filename)
                if newer_mtime(new_path, current_path):
                    self.logger.debug("Updating %s from %s." %
                                      (current_path, new_path))
                    ensure_directory_exists(os.path.dirname(current_path))
                    # Due to http://bugs.python.org/issue12904, shutil.copy2
                    # doesn't copy timestamps precisely, and unfortunately
                    # it rounds down.  If we must lose accuracy, we need to
                    # round up instead.  This can be removed (and the
                    # try/except replaced by shutil.move) once Launchpad
                    # runs on Python >= 3.3.
                    try:
                        os.rename(new_path, current_path)
                    except OSError:
                        shutil.copy2(new_path, current_path)
                        st = os.stat(new_path)
                        os.utime(
                            current_path,
                            (math.ceil(st.st_atime), math.ceil(st.st_mtime)))
                        os.unlink(new_path)
                    updated = True
        return updated
Example #3
0
    def updateContentsFile(self, suite, arch):
        """Update Contents file, if it has changed."""
        contents_dir = os.path.join(self.content_archive,
                                    self.distribution.name, 'dists', suite)
        staging_dir = os.path.join(self.config.stagingroot, suite)
        contents_filename = "Contents-%s" % arch
        last_contents = os.path.join(contents_dir, ".%s" % contents_filename)
        current_contents = os.path.join(contents_dir, contents_filename)

        # Avoid rewriting unchanged files; mirrors would have to
        # re-fetch them unnecessarily.
        if differ_in_content(current_contents, last_contents):
            self.logger.debug("Staging new Contents file for %s/%s.", suite,
                              arch)

            new_contents = os.path.join(contents_dir,
                                        "%s.gz" % contents_filename)
            contents_dest = os.path.join(staging_dir,
                                         "%s.gz" % contents_filename)

            ensure_directory_exists(os.path.dirname(contents_dest))
            os.rename(current_contents, last_contents)
            os.rename(new_contents, contents_dest)
            os.chmod(contents_dest, 0o664)
        else:
            self.logger.debug("Skipping unmodified Contents file for %s/%s.",
                              suite, arch)
    def makeIndexFiles(self, script, distroseries):
        """Create a limited subset of index files for testing."""
        ensure_directory_exists(script.config.temproot)

        for component in distroseries.components:
            source_index = RepositoryIndexFile(
                get_sources_path(script.config, distroseries.name, component),
                script.config.temproot)
            for spp in distroseries.getSourcePackagePublishing(
                    PackagePublishingPocket.RELEASE, component,
                    distroseries.main_archive):
                stanza = spp.getIndexStanza().encode("utf-8") + "\n\n"
                source_index.write(stanza)
            source_index.close()

            for arch in distroseries.architectures:
                package_index = RepositoryIndexFile(
                    get_packages_path(
                        script.config, distroseries.name, component, arch),
                    script.config.temproot)
                for bpp in distroseries.getBinaryPackagePublishing(
                        arch.architecturetag, PackagePublishingPocket.RELEASE,
                        component, distroseries.main_archive):
                    stanza = bpp.getIndexStanza().encode("utf-8") + "\n\n"
                    package_index.write(stanza)
                package_index.close()
    def testReplaceUpdatedHtpasswd(self):
        """Test that the htpasswd file is only replaced if it changes."""
        FILE_CONTENT = "Kneel before Zod!"
        # The publisher Config object does not have an interface, so we
        # need to remove the security wrapper.
        pub_config = getPubConfig(self.ppa)
        filename = os.path.join(pub_config.htaccessroot, ".htpasswd")

        # Write out a dummy .htpasswd
        ensure_directory_exists(pub_config.htaccessroot)
        write_file(filename, FILE_CONTENT)

        # Write the same contents in a temp file.
        fd, temp_filename = tempfile.mkstemp(dir=pub_config.htaccessroot)
        file = os.fdopen(fd, "w")
        file.write(FILE_CONTENT)
        file.close()

        # Replacement should not happen.
        script = self.getScript()
        self.assertFalse(
            script.replaceUpdatedHtpasswd(self.ppa, temp_filename))

        # Writing a different .htpasswd should see it get replaced.
        write_file(filename, "Come to me, son of Jor-El!")

        self.assertTrue(
            script.replaceUpdatedHtpasswd(self.ppa, temp_filename))

        os.remove(filename)
def start_launchpad(argv=list(sys.argv), setup=None):
    # We really want to replace this with a generic startup harness.
    # However, this should last us until this is developed
    services, argv = split_out_runlaunchpad_arguments(argv[1:])
    argv = process_config_arguments(argv)
    services = get_services_to_run(services)
    # Create the ZCML override file based on the instance.
    config.generate_overrides()
    # Many things rely on a directory called 'logs' existing in the current
    # working directory.
    ensure_directory_exists('logs')
    if setup is not None:
        # This is the setup from start_testapp, above.
        setup()
    try:
        with nested(*services):
            # Store our process id somewhere
            make_pidfile('launchpad')
            if config.launchpad.launch:
                main(argv)
            else:
                # We just need the foreground process to sit around forever
                # waiting for the signal to shut everything down.  Normally,
                # Zope itself would be this master process, but we're not
                # starting that up, so we need to do something else.
                try:
                    signal.pause()
                except KeyboardInterrupt:
                    pass
    except Exception as e:
        print >> sys.stderr, "stopping services on exception %r" % e
        for service in services:
            print >> sys.stderr, service, "fixture details:"
            # There may be no details on some services if they haven't been
            # initialized yet.
            if getattr(service, '_details', None) is None:
                print >> sys.stderr, "(not ready yet?)"
                continue
            details_str = _details_to_str(service.getDetails())
            if details_str:
                print >> sys.stderr, details_str
            else:
                print >> sys.stderr, "(no details present)"
        raise
Example #7
0
def main():
    """Run the HTTP server."""
    # Redirect our service output to a log file.
    global log
    ensure_directory_exists(os.path.dirname(config.google_test_service.log))
    filelog = logging.FileHandler(config.google_test_service.log)
    log.addHandler(filelog)
    log.setLevel(logging.DEBUG)

    # To support service shutdown we need to create a PID file that is
    # understood by the Launchpad services framework.
    global service_name
    make_pidfile(service_name)

    host, port = get_service_endpoint()
    server = HTTPServer((host, port), GoogleRequestHandler)

    log.info("Starting HTTP Google webservice server on port %s", port)
    server.serve_forever()
def main():
    """Run the HTTP server."""
    # Redirect our service output to a log file.
    global log
    ensure_directory_exists(os.path.dirname(config.google_test_service.log))
    filelog = logging.FileHandler(config.google_test_service.log)
    log.addHandler(filelog)
    log.setLevel(logging.DEBUG)

    # To support service shutdown we need to create a PID file that is
    # understood by the Launchpad services framework.
    global service_name
    make_pidfile(service_name)

    host, port = get_service_endpoint()
    server = HTTPServer((host, port), GoogleRequestHandler)

    log.info("Starting HTTP Google webservice server on port %s", port)
    server.serve_forever()
 def test_directory_doesnt_exist(self):
     directory = os.path.join(self.makeTemporaryDirectory(), 'foo/bar/baz')
     self.assertTrue(ensure_directory_exists(directory))
     self.assertTrue(os.path.isdir(directory))
 def test_directory_exists(self):
     directory = self.makeTemporaryDirectory()
     self.assertFalse(ensure_directory_exists(directory))
Example #11
0
 def test_directory_doesnt_exist(self):
     directory = os.path.join(self.makeTemporaryDirectory(), 'foo/bar/baz')
     self.assertTrue(ensure_directory_exists(directory))
     self.assertTrue(os.path.isdir(directory))
Example #12
0
 def test_directory_exists(self):
     directory = self.makeTemporaryDirectory()
     self.assertFalse(ensure_directory_exists(directory))