Exemplo n.º 1
0
def remind_about_instances():
    """Run periodically to send reminding emails"""
    cs = admin_client_set()
    server_mgr = cs.compute.servers
    user_mgr = cs.identity_admin.users
    for instance_data in InstanceDataDAO.remind_list(datetime.utcnow()):
        try:
            try:
                server = server_mgr.get(instance_data.instance_id)
            except osc_exc.NotFound:
                InstanceDataDAO.delete(instance_data.instance_id)
                continue

            try:
                user = user_mgr.get(server.user_id)
            except osc_exc.NotFound:
                pass
            else:
                send_instance_reminder(user.email,
                                       server.name,
                                       server.id,
                                       instance_data.expires_at,
                                       greeting=getattr(user, 'fullname', ''))
            InstanceDataDAO.update(instance_data.instance_id, remind_at=None)
        except Exception:
            current_app.logger.exception(
                'Failed to send reminder email about instance %r' %
                instance_data.instance_id)
Exemplo n.º 2
0
def remind_about_instances():
    """Run periodically to send reminding emails"""
    cs = admin_client_set()
    server_mgr = cs.compute.servers
    user_mgr = cs.identity_admin.users
    for instance_data in InstanceDataDAO.remind_list(datetime.utcnow()):
        try:
            try:
                server = server_mgr.get(instance_data.instance_id)
            except osc_exc.NotFound:
                InstanceDataDAO.delete(instance_data.instance_id)
                continue

            try:
                user = user_mgr.get(server.user_id)
            except osc_exc.NotFound:
                pass
            else:
                send_instance_reminder(user.email, server.name,
                                 server.id, instance_data.expires_at,
                                 greeting=getattr(user, 'fullname', ''))
            InstanceDataDAO.update(instance_data.instance_id, remind_at=None)
        except Exception:
            current_app.logger.exception(
                'Failed to send reminder email about instance %r'
                % instance_data.instance_id)
Exemplo n.º 3
0
    def test_send_instance_reminder_works_without_expires(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertEquals('Reminder about instance VM_NAME',
                                  message.subject)
                self.assertTrue('DELETED' not in message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())
        self.mox.ReplayAll()

        with self.app.test_request_context():
            g.config = self.config
            mail.send_instance_reminder('*****@*****.**',
                                  'VM_NAME', 'VM_ID')
Exemplo n.º 4
0
    def test_send_instance_reminder_works_without_expires(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertEquals('Reminder about instance VM_NAME',
                                  message.subject)
                self.assertTrue('DELETED' not in message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())
        self.mox.ReplayAll()

        with self.app.test_request_context():
            g.config = self.config
            mail.send_instance_reminder('*****@*****.**', 'VM_NAME',
                                        'VM_ID')
Exemplo n.º 5
0
    def test_send_instance_reminder_works(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertEquals('Reminder about instance VM_NAME',
                                  message.subject)
                self.assertTrue('2013-01-18 17:16:15 UTC' in message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())
        self.mox.ReplayAll()

        with self.app.test_request_context():
            g.config = self.config
            mail.send_instance_reminder('*****@*****.**',
                                  'VM_NAME', 'VM_ID',
                                  datetime(2013, 1, 18, 17, 16, 15, 14))
Exemplo n.º 6
0
    def test_send_instance_reminder_works(self):
        class IsCorrectMail(mox.Comparator):
            def equals(inner_self, message):
                self.assertEquals('Reminder about instance VM_NAME',
                                  message.subject)
                self.assertTrue('2013-01-18 17:16:15 UTC' in message.body)
                return True

        mail.mail.Mail(mail.current_app).send(IsCorrectMail())
        self.mox.ReplayAll()

        with self.app.test_request_context():
            g.config = self.config
            mail.send_instance_reminder('*****@*****.**', 'VM_NAME',
                                        'VM_ID',
                                        datetime(2013, 1, 18, 17, 16, 15, 14))