Beispiel #1
0
def deploy(session, task, domain, owner_email, environment_name,
           technical_contact_email, theme_name=None, default_language=u'it',
           database_password=None, enabled=True):

    env = Environment.get(session, environment_name)
    theme = None if not theme_name else Theme.get(session, theme_name)
    owner = User.get(session, owner_email)
    technical_contact = User.get(session, technical_contact_email)

    instance = Instance.deploy(session, domain, owner, env, technical_contact,
                               theme, default_language, database_password,
                               enabled)

    return instance.id
Beispiel #2
0
    def test_deploy(self):

        self.import_data()
        owner = self.session.query(User)\
                .filter(User.email == '*****@*****.**').one()
        theme = self.session.query(Theme)\
                .filter(Theme.name == 'uffizi').one()
        env = Environment.create(self.session, 'testenv',
                                 config=self.config)
        instance = Instance.deploy(self.session, 'www.example.com', owner,
                                   env, owner, theme=theme)

        # vassal config is created only upon session commit
        self.assertFalse(os.path.exists(instance.paths.vassal_config))
        self.session.commit()
        self.assertTrue(os.path.exists(instance.paths.vassal_config))

        # various asserts for consistency
        with self.assertRaises(NotSupported):
            instance.domain = 'www.newdomain.com'
        with self.assertRaises(NotImplementedError):
            nt = self.session.query(Theme)\
                    .filter(Theme.name == 'moma').one()
            instance.theme = nt

        # test reload
        os.unlink(instance.paths.vassal_config)
        instance.reload()
        self.assertFalse(os.path.exists(instance.paths.vassal_config))
        self.session.commit()
        self.assertTrue(os.path.exists(instance.paths.vassal_config))
        self.assertTrue(instance.enabled)

        # test disable
        instance.enabled = False
        self.session.commit()
        self.assertFalse(os.path.exists(instance.paths.vassal_config))
        with self.assertRaises(OperationalError):
            instance.reload()

        # disable an already disable instance is a no-op
        self.assertFalse(instance.enabled)
        instance.enabled = False
        self.session.rollback()
        self.assertFalse(instance.enabled)

        # test enable
        instance.enabled = True
        self.assertFalse(os.path.exists(instance.paths.vassal_config))
        self.session.commit()
        self.assertTrue(os.path.exists(instance.paths.vassal_config))

        # enabling an already enabled instance is a no-op
        self.assertTrue(instance.enabled)
        instance.enabled = True
        self.session.rollback()
        self.assertTrue(instance.enabled)

        # test change environment
        newenv = Environment.create(self.session, 'testenv2',
                                    config=self.config)
        with self.assertRaises(OperationalError):
            instance.environment = newenv
        self.assertEqual(instance.environment, env)

        instance.enabled = False
        self.session.commit()

        instance.environment = newenv
        self.assertFalse(hasattr(instance, "_paths"))
        self.session.commit()

        self.assertEqual(instance.environment, newenv)
        instance.enabled = True
        self.session.commit()

        # "test" migration: call it at least once :(
        instance.upgrade_schema('head')

        # create an archive
        instance.archive(archive_name='test')
        p = os.path.join(instance.environment.paths.archives,
                         "test.tar.gz")
        self.assertTrue(os.path.exists(p))

        # test restore and delete
        with self.assertRaises(OperationalError):
            instance.delete()

        with self.assertRaises(OperationalError):
            instance.restore(archive_name='test')

        instance.enabled = False
        self.session.commit()
        #instance.restore(archive_name='test')

        instance.delete()
        self.assertFalse(os.path.exists(instance.paths.dir))
        self.session.commit()
        self.assertFalse(os.path.exists(instance.paths.dir))

        # todo assert database is not present

        """