Пример #1
0
    def test_upgrade_dryrun(self, needupdate):
        args = self.Args({'dry_run': True})
        db = self.PartialMockDb(args, None)
        self.mox.StubOutWithMock(db, 'get_current_db_version')
        self.mox.StubOutWithMock(db, 'sql_version_matrix')
        self.mox.StubOutWithMock(db, 'sql_version_resolve')
        self.mox.StubOutWithMock(db, 'check_connection')
        # Stub out to ensure it's NOT called
        self.mox.StubOutWithMock(db, 'psql')

        db.check_connection()

        versions = ['OMERO4.4__0', 'OMERO5.0__0']
        if needupdate:
            db.get_current_db_version().AndReturn(('OMERO4.4', '0'))
            db.sql_version_matrix().AndReturn(([], versions))
            db.sql_version_resolve([], versions, versions[0]).AndReturn(
                ['./sql/psql/OMERO5.0__0/OMERO4.4__0.sql'])
        else:
            db.get_current_db_version().AndReturn(('OMERO5.0', '0'))
            db.sql_version_matrix().AndReturn(([], versions))

        self.mox.ReplayAll()

        if needupdate:
            with pytest.raises(Stop) as excinfo:
                db.upgrade()
            assert excinfo.value.rc == 2
            assert excinfo.value.msg == (
                'Database upgrade required OMERO4.4__0->OMERO5.0__0')
        else:
            db.upgrade()
        self.mox.VerifyAll()
Пример #2
0
    def test_upgrade(self, needupdate):
        args = self.Args({'dry_run': False})
        db = self.PartialMockDb(args, None)
        self.mox.StubOutWithMock(db, 'get_current_db_version')
        self.mox.StubOutWithMock(db, 'sql_version_matrix')
        self.mox.StubOutWithMock(db, 'sql_version_resolve')
        self.mox.StubOutWithMock(db, 'check_connection')
        self.mox.StubOutWithMock(db, 'psql')

        db.check_connection()

        versions = ['OMERO3.0__0', 'OMERO4.4__0', 'OMERO5.0__0']
        if needupdate:
            db.get_current_db_version().AndReturn(('OMERO3.0', '0'))
            db.sql_version_matrix().AndReturn(([], versions))
            db.sql_version_resolve([], versions, versions[0]).AndReturn([
                './sql/psql/OMERO4.4__0/OMERO3.0__0.sql',
                './sql/psql/OMERO5.0__0/OMERO4.4__0.sql'
            ])
            db.psql('-f', './sql/psql/OMERO4.4__0/OMERO3.0__0.sql')
            db.psql('-f', './sql/psql/OMERO5.0__0/OMERO4.4__0.sql')
        else:
            db.get_current_db_version().AndReturn(('OMERO5.0', '0'))
            db.sql_version_matrix().AndReturn(([], versions))

        self.mox.ReplayAll()

        db.upgrade()
        self.mox.VerifyAll()
Пример #3
0
    def test_init(self, sqlfile, dryrun):
        ext = self.mox.CreateMock(external.External)
        if sqlfile != 'notprovided':
            omerosql = 'omero.sql'
        else:
            omerosql = None
        args = self.Args({
            'omerosql': omerosql,
            'rootpass': '******',
            'dry_run': dryrun
        })
        db = self.PartialMockDb(args, ext)
        self.mox.StubOutWithMock(db, 'psql')
        self.mox.StubOutWithMock(omero_server_setup.db, 'timestamp_filename')
        self.mox.StubOutWithMock(os.path, 'exists')
        self.mox.StubOutWithMock(db, 'check_connection')
        self.mox.StubOutWithMock(db, 'upgrade')
        self.mox.StubOutWithMock(os, 'remove')

        db.check_connection()
        if sqlfile == 'notprovided':
            omerosql = 'omero-00000000-000000-000000.sql'
            omero_server_setup.db.timestamp_filename('omero',
                                                     'sql').AndReturn(omerosql)
        else:
            os.path.exists(omerosql).AndReturn(sqlfile == 'exists')

        if sqlfile == 'notprovided' and not dryrun:
            ext.omero_cli(
                ['db', 'script', '-f', omerosql, '', '', args.rootpass])

        if sqlfile == 'exists':
            db.upgrade()

        if sqlfile != 'missing' and not dryrun:
            db.psql('-f', omerosql)

        if sqlfile == 'notprovided' and not dryrun:
            os.remove('omero-00000000-000000-000000.sql')

        self.mox.ReplayAll()

        if sqlfile == 'missing':
            with pytest.raises(Stop) as excinfo:
                db.init()
            assert excinfo.value.msg == 'SQL file not found'
        else:
            db.init()
        self.mox.VerifyAll()
Пример #4
0
    def test_upgrade_not_initialised(self, dryrun):
        args = self.Args({'dry_run': dryrun})
        db = self.PartialMockDb(args, None)
        self.mox.StubOutWithMock(db, 'get_current_db_version')
        self.mox.StubOutWithMock(db, 'check_connection')

        db.check_connection()
        exc = external.RunException('test psql failure', 'psql', [], -1, '',
                                    '')
        db.get_current_db_version().AndRaise(exc)

        self.mox.ReplayAll()

        with pytest.raises(Stop) as excinfo:
            db.upgrade()
        assert excinfo.value.rc == 3
        assert excinfo.value.msg == 'Unable to get database version'
        self.mox.VerifyAll()
Пример #5
0
    def test_check_connection(self, connected):
        db = self.PartialMockDb(None, None)
        self.mox.StubOutWithMock(db, 'psql')

        if connected:
            db.psql('-c', r'\conninfo')
        else:
            db.psql('-c', r'\conninfo').AndRaise(
                external.RunException('', '', [], 1, '', ''))
        self.mox.ReplayAll()

        if connected:
            db.check_connection()
        else:
            with pytest.raises(Stop) as excinfo:
                db.check_connection()
            assert excinfo.value.msg == 'Database connection check failed'

        self.mox.VerifyAll()
Пример #6
0
    def test_dump(self, dumpfile, dryrun):
        args = self.Args({'dry_run': dryrun, 'dumpfile': dumpfile})
        db = self.PartialMockDb(args, None)
        self.mox.StubOutWithMock(omero_server_setup.db, 'timestamp_filename')
        self.mox.StubOutWithMock(db, 'get_db_args_env')
        self.mox.StubOutWithMock(db, 'pgdump')
        self.mox.StubOutWithMock(db, 'check_connection')

        db.check_connection()
        if not dumpfile:
            db.get_db_args_env().AndReturn(self.create_db_test_params())

            dumpfile = 'omero-database-name-00000000-000000-000000.pgdump'
            omero_server_setup.db.timestamp_filename(
                'omero-database-name', 'pgdump').AndReturn(dumpfile)

        if not dryrun:
            db.pgdump('-Fc', '-f', dumpfile).AndReturn('')

        self.mox.ReplayAll()

        db.dump()
        self.mox.VerifyAll()