def test_hourly_script(self):
     """Ensure garbo-hourly.py actually runs."""
     rv, out, err = run_script(
         "cronscripts/garbo-hourly.py", ["-q"], expect_returncode=0)
     self.failIf(out.strip(), "Output to stdout: %s" % out)
     self.failIf(err.strip(), "Output to stderr: %s" % err)
     DatabaseLayer.force_dirty_database()
 def test_run_reprocessing_script_no_params(self):
     # cronscripts/reprocess-hwdb-submissions.py needs at least the
     # parameter --start-file
     retcode, stdout, stderr = run_script(
         'cronscripts/reprocess-hwdb-submissions.py', [])
     self.assertThat(stderr, Contains('Option --start-file not specified.'))
     DatabaseLayer.force_dirty_database()
Beispiel #3
0
 def __iter__(self):
     try:
         # Reset the session.
         LaunchpadLayer.resetSessionDb()
         # Yield control to asyncore for a second, just to be a
         # little bit nice.  We could be even nicer by moving this
         # whole teardown/setup dance to a thread and waiting for
         # it to be done, but there's not a (known) compelling need
         # for that right now, and doing it this way is slightly
         # simpler.
         yield ''
         DatabaseLayer.testSetUp()
         yield ''
         # Reset the librarian.
         LibrarianLayer.testTearDown()
         yield ''
         # Reset the database.
         DatabaseLayer.testTearDown()
         yield ''
         LibrarianLayer.testSetUp()
     except (SystemExit, KeyboardInterrupt):
         raise
     except:
         print "Hm, serious error when trying to clean up the test."
         traceback.print_exc()
     # We're done, so we can yield the body.
     yield '\n'
 def test_run_reprocessing_script_no_params(self):
     # cronscripts/reprocess-hwdb-submissions.py needs at least the
     # parameter --start-file
     retcode, stdout, stderr = run_script(
         'cronscripts/reprocess-hwdb-submissions.py', [])
     self.assertThat(
         stderr, Contains('Option --start-file not specified.'))
     DatabaseLayer.force_dirty_database()
 def test_run_reprocessing_script_max_submission_not_integer(self):
     # If the parameter --max-submissions is not an integer,
     # cronscripts/reprocess-hwdb-submissions.py reports an error.
     retcode, stdout, stderr = run_script(
         'cronscripts/reprocess-hwdb-submissions.py',
         ['--max-submissions', 'nonsense'])
     expected = "Invalid value for --max_submissions specified: 'nonsense'"
     self.assertThat(stderr, Contains(expected))
     DatabaseLayer.force_dirty_database()
 def test_remoteAddFileDoesntSendDatabaseName(self):
     # remoteAddFile should send the Database-Name header as well.
     client = InstrumentedLibrarianClient()
     # Because the remoteAddFile call commits to the database in a
     # different process, we need to explicitly tell the DatabaseLayer to
     # fully tear down and set up the database.
     DatabaseLayer.force_dirty_database()
     client.remoteAddFile("sample.txt", 6, StringIO("sample"), "text/plain")
     self.failUnless(client.sentDatabaseName, "Database-Name header not sent by remoteAddFile")
Beispiel #7
0
 def test_remoteAddFileDoesntSendDatabaseName(self):
     # remoteAddFile should send the Database-Name header as well.
     client = InstrumentedLibrarianClient()
     # Because the remoteAddFile call commits to the database in a
     # different process, we need to explicitly tell the DatabaseLayer to
     # fully tear down and set up the database.
     DatabaseLayer.force_dirty_database()
     client.remoteAddFile('sample.txt', 6, StringIO('sample'), 'text/plain')
     self.assertTrue(client.sentDatabaseName,
                     "Database-Name header not sent by remoteAddFile")
 def test_run_reprocessing_script_startfile_does_not_exist(self):
     # If the specified start file does not exist,
     # cronscripts/reprocess-hwdb-submissions.py reports an error.
     does_not_exist = mktemp()
     retcode, stdout, stderr = run_script(
         'cronscripts/reprocess-hwdb-submissions.py',
         ['--start-file', does_not_exist])
     self.assertThat(
         stderr, Contains('Cannot access file %s' % does_not_exist))
     DatabaseLayer.force_dirty_database()
 def test_BadSubmissions_respects_start(self):
     # It is possible to request a start id. Previous entries are ignored.
     submission1 = self.factory.makeHWSubmission(
         status=HWSubmissionProcessingStatus.INVALID)
     submission2 = self.factory.makeHWSubmission(
         status=HWSubmissionProcessingStatus.INVALID)
     self.assertTrue(submission1.id < submission2.id)
     loop = self._makeBadSubmissionsLoop(submission2.id)
     # The sample data already contains one submission.
     submissions = loop.getUnprocessedSubmissions(2)
     self.assertEqual([submission2], submissions)
     DatabaseLayer.force_dirty_database()
 def test_run_reprocessing_script_startfile_with_negative_integer(self):
     # If the specified start file contains any non-integer string,
     # cronscripts/reprocess-hwdb-submissions.py reports an error.
     start_file_name = mktemp()
     start_file = open(start_file_name, 'w')
     start_file.write('-1')
     start_file.close()
     retcode, stdout, stderr = run_script(
         'cronscripts/reprocess-hwdb-submissions.py',
         ['--start-file', start_file_name])
     self.assertThat(
         stderr,
         Contains('%s must contain a positive integer' % start_file_name))
     DatabaseLayer.force_dirty_database()
Beispiel #11
0
    def testHideLibrarian(self):
        # First perform a successful upload:
        client = LibrarianClient()
        data = 'foo'
        client.remoteAddFile('foo', len(data), StringIO(data), 'text/plain')
        # The database was committed to, but not by this process, so we need
        # to ensure that it is fully torn down and recreated.
        DatabaseLayer.force_dirty_database()

        # Hide the librarian, and show that the upload fails:
        LibrarianLayer.hide()
        self.assertRaises(UploadFailed, client.remoteAddFile, 'foo', len(data),
                          StringIO(data), 'text/plain')

        # Reveal the librarian again, allowing uploads:
        LibrarianLayer.reveal()
        client.remoteAddFile('foo', len(data), StringIO(data), 'text/plain')
Beispiel #12
0
 def testLaunchpadDbAvailable(self):
     if not self.want_launchpad_database:
         self.assertEqual(None, DatabaseLayer._db_fixture)
         return
     con = DatabaseLayer.connect()
     cur = con.cursor()
     cur.execute("SELECT id FROM Person LIMIT 1")
     self.assertNotEqual(None, cur.fetchone())
 def testLaunchpadDbAvailable(self):
     if not self.want_launchpad_database:
         self.assertEqual(None, DatabaseLayer._db_fixture)
         return
     con = DatabaseLayer.connect()
     cur = con.cursor()
     cur.execute("SELECT id FROM Person LIMIT 1")
     self.assertNotEqual(None, cur.fetchone())
 def setup():
     # This code needs to be run after other zcml setup happens in
     # runlaunchpad, so it is passed in as a callable.  We set up layers
     # here because we need to control fixtures within this process, and
     # because we want interactive tests to be as similar as possible to
     # tests run in the testrunner.
     # Note that this changes the config instance-name, with the result
     # that the configuration of utilities may become invalidated.
     # XXX Robert Collins, bug=883980: In short, we should derive the
     # other services from the test runner, rather than duplicating
     # the work of test setup within the slave appserver. That will
     # permit reuse of the librarian, DB, rabbit etc, and
     # correspondingly easier assertions and inspection of interactions
     # with other services. That would mean we do not need to set up rabbit
     # or the librarian here: the test runner would control and take care
     # of that.
     BaseLayer.setUp()
     teardowns.append(BaseLayer.tearDown)
     RabbitMQLayer.setUp()
     teardowns.append(RabbitMQLayer.tearDown)
     # We set up the database here even for the test suite because we want
     # to be able to control the database here in the subprocess.  It is
     # possible to do that when setting the database up in the parent
     # process, but it is messier.  This is simple.
     installFakeConnect()
     teardowns.append(uninstallFakeConnect)
     DatabaseLayer.setUp()
     teardowns.append(DatabaseLayer.tearDown)
     # The Librarian needs access to the database, so setting it up here
     # where we are setting up the database makes the most sense.
     LibrarianLayer.setUp()
     teardowns.append(LibrarianLayer.tearDown)
     # Switch to the appserver config.
     fixture = ConfigUseFixture(BaseLayer.appserver_config_name)
     fixture.setUp()
     teardowns.append(fixture.cleanUp)
     # Interactive tests always need this.  We let functional tests use
     # a local one too because of simplicity.
     LayerProcessController.startSMTPServer()
     teardowns.append(LayerProcessController.stopSMTPServer)
     if interactive_tests:
         root_url = config.appserver_root_url()
         print '*' * 70
         print 'In a few seconds, go to ' + root_url + '/+yuitest'
         print '*' * 70
    def testHideLibrarian(self):
        # First perform a successful upload:
        client = LibrarianClient()
        data = 'foo'
        client.remoteAddFile(
            'foo', len(data), StringIO(data), 'text/plain')
        # The database was committed to, but not by this process, so we need
        # to ensure that it is fully torn down and recreated.
        DatabaseLayer.force_dirty_database()

        # Hide the librarian, and show that the upload fails:
        LibrarianLayer.hide()
        self.assertRaises(UploadFailed, client.remoteAddFile,
                          'foo', len(data), StringIO(data), 'text/plain')

        # Reveal the librarian again, allowing uploads:
        LibrarianLayer.reveal()
        client.remoteAddFile(
            'foo', len(data), StringIO(data), 'text/plain')
Beispiel #16
0
 def test_db_is_reset(self):
     con = DatabaseLayer.connect()
     cur = con.cursor()
     cur.execute("DELETE FROM Wikiname")
     self.failUnlessEqual(self.getWikinameCount(con), 0)
     con.commit()
     # Run the per-test code for the Database layer.
     DatabaseLayer.testTearDown()
     DatabaseLayer.testSetUp()
     # Wikiname table should have been restored.
     con = DatabaseLayer.connect()
     self.assertNotEqual(0, self.getWikinameCount(con))
 def test_db_is_reset(self):
     con = DatabaseLayer.connect()
     cur = con.cursor()
     cur.execute("DELETE FROM Wikiname")
     self.failUnlessEqual(self.getWikinameCount(con), 0)
     con.commit()
     # Run the per-test code for the Database layer.
     DatabaseLayer.testTearDown()
     DatabaseLayer.testSetUp()
     # Wikiname table should have been restored.
     con = DatabaseLayer.connect()
     self.assertNotEqual(0, self.getWikinameCount(con))
 def test_cronscript(self):
     run_script(
         'cronscripts/process-job-source.py',
         ['IInitializeDistroSeriesJobSource'])
     DatabaseLayer.force_dirty_database()
Beispiel #19
0
def updateRemoteProductTeardown(test):
    # Mark the DB as dirty, since we run a script in a sub process.
    DatabaseLayer.force_dirty_database()
    tearDown(test)
Beispiel #20
0
def peopleKarmaTearDown(test):
    """Restore the database after testing karma."""
    # We can't detect db changes made by the subprocess (yet).
    DatabaseLayer.force_dirty_database()
    tearDown(test)
Beispiel #21
0
 def testConnect(self):
     DatabaseLayer.connect()
Beispiel #22
0
def peopleKarmaTearDown(test):
    """Restore the database after testing karma."""
    # We can't detect db changes made by the subprocess (yet).
    DatabaseLayer.force_dirty_database()
    tearDown(test)
Beispiel #23
0
    def testCopyArchiveCreation(self):
        """Start archive population, check data before and after.

        Use the hoary-RELEASE suite along with the main component.
        """
        # XXX: JamesWestby 2010-06-21 bug=596984: it is not clear
        # what this test is testing that is not covered in more
        # specific tests. It should be removed if there is nothing
        # else as it is fragile due to use of sampledata.
        DatabaseLayer.force_dirty_database()
        # Make sure a copy archive with the desired name does
        # not exist yet.
        distro_name = 'ubuntu'
        distro = getUtility(IDistributionSet).getByName(distro_name)

        archive_name = "msa%s" % int(time.time())
        copy_archive = getUtility(IArchiveSet).getByDistroPurpose(
            distro, ArchivePurpose.COPY, archive_name)
        # This is a sanity check: a copy archive with this name should not
        # exist yet.
        self.assertTrue(copy_archive is None)

        hoary = getUtility(IDistributionSet)[distro_name]['hoary']

        # Verify that we have the right source packages in the sample data.
        self._verifyPackagesInSampleData(hoary)

        # Command line arguments required for the invocation of the
        # 'populate-archive.py' script.
        extra_args = [
            '-a', '386',
            '--from-distribution', distro_name, '--from-suite', 'hoary',
            '--to-distribution', distro_name, '--to-suite', 'hoary',
            '--to-archive', archive_name, '--to-user', 'salgado', '--reason',
            '"copy archive from %s"' % datetime.ctime(datetime.utcnow()),
            ]

        # Start archive population now!
        (exitcode, out, err) = self.runWrapperScript(extra_args)
        # Check for zero exit code.
        self.assertEqual(
            exitcode, 0, "\n=> %s\n=> %s\n=> %s\n" % (exitcode, out, err))

        # Make sure the copy archive with the desired name was
        # created
        copy_archive = getUtility(IArchiveSet).getByDistroPurpose(
            distro, ArchivePurpose.COPY, archive_name)
        self.assertTrue(copy_archive is not None)

        # Make sure the right source packages were cloned.
        self._verifyClonedSourcePackages(copy_archive, hoary)

        # Now check that we have build records for the sources cloned.
        builds = list(getUtility(IBinaryPackageBuildSet).getBuildsForArchive(
            copy_archive, status=BuildStatus.NEEDSBUILD))

        # Please note: there will be no build for the pmount package
        # since it is architecture independent and the 'hoary'
        # DistroSeries in the sample data has no DistroArchSeries
        # with chroots set up.
        build_spns = [
            get_spn(removeSecurityProxy(build)).name for build in builds]

        self.assertEqual(build_spns, self.expected_build_spns)
 def testConnect(self):
     DatabaseLayer.connect()
Beispiel #25
0
def updateRemoteProductTeardown(test):
    # Mark the DB as dirty, since we run a script in a sub process.
    DatabaseLayer.force_dirty_database()
    tearDown(test)
 def test_cronscript(self):
     run_script("cronscripts/process-job-source.py", ["IInitializeDistroSeriesJobSource"])
     DatabaseLayer.force_dirty_database()