Ejemplo n.º 1
0
    def test_remind_reminds(self):
        server_mgr = self.fake_client_set.compute.servers
        instances.admin_client_set().AndReturn(self.fake_client_set)
        user_mgr = self.fake_client_set.identity_admin.users
        server = doubles.make(self.mox,
                              doubles.Server,
                              id='v2',
                              name='instance-2',
                              user_id='UID')
        user = doubles.make(self.mox,
                            doubles.User,
                            id='UID',
                            name='user',
                            email='*****@*****.**',
                            fullname='The Test User Fullname')
        expires = datetime(2013, 1, 19, 11, 12, 13)

        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.remind_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v2',
                                         expires_at=expires)])

        server_mgr.get('v2').AndReturn(server)
        user_mgr.get('UID').AndReturn(user)
        instances.send_instance_reminder(user.email,
                                         'instance-2',
                                         'v2',
                                         expires,
                                         greeting=user.fullname)
        instances.InstanceDataDAO.update('v2', remind_at=None)

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.remind_about_instances()
Ejemplo n.º 2
0
    def test_remind_reminds(self):
        server_mgr = self.fake_client_set.compute.servers
        instances.admin_client_set().AndReturn(self.fake_client_set)
        user_mgr = self.fake_client_set.identity_admin.users
        server = doubles.make(self.mox, doubles.Server,
                              id='v2', name='instance-2', user_id='UID')
        user = doubles.make(self.mox, doubles.User,
                            id='UID', name='user', email='*****@*****.**',
                            fullname='The Test User Fullname')
        expires = datetime(2013, 1, 19, 11, 12, 13)

        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.remind_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v2',
                                         expires_at=expires)])

        server_mgr.get('v2').AndReturn(server)
        user_mgr.get('UID').AndReturn(user)
        instances.send_instance_reminder(user.email, 'instance-2', 'v2',
                                         expires, greeting=user.fullname)
        instances.InstanceDataDAO.update('v2', remind_at=None)

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.remind_about_instances()
Ejemplo n.º 3
0
    def test_instance_data_gc_works(self):
        server_mgr = self.fake_client_set.compute.servers

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.InstanceDataDAO.list_all()\
                .AndReturn([InstanceData(instance_id='v1'),
                            InstanceData(instance_id='v2')])
        server_mgr.get('v1').AndRaise(osc_exc.NotFound('deleted'))
        instances.InstanceDataDAO.delete('v1')
        server_mgr.get('v2')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.instance_data_gc()
Ejemplo n.º 4
0
    def test_instance_data_gc_works(self):
        server_mgr = self.fake_client_set.compute.servers

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.InstanceDataDAO.list_all()\
                .AndReturn([InstanceData(instance_id='v1'),
                            InstanceData(instance_id='v2')])
        server_mgr.get('v1').AndRaise(osc_exc.NotFound('deleted'))
        instances.InstanceDataDAO.delete('v1')
        server_mgr.get('v2')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.instance_data_gc()
Ejemplo n.º 5
0
    def test_instance_data_gc_other_exception(self):
        server_mgr = self.fake_client_set.compute.servers

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.InstanceDataDAO.list_all()\
                .AndReturn([InstanceData(instance_id='v1'),
                            InstanceData(instance_id='v2')])
        server_mgr.get('v1').AndRaise(RuntimeError('log me'))
        self.app.logger.exception(mox.IsA(basestring))
        server_mgr.get('v2')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.instance_data_gc()
Ejemplo n.º 6
0
    def test_instance_data_gc_other_exception(self):
        server_mgr = self.fake_client_set.compute.servers

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.InstanceDataDAO.list_all()\
                .AndReturn([InstanceData(instance_id='v1'),
                            InstanceData(instance_id='v2')])
        server_mgr.get('v1').AndRaise(RuntimeError('log me'))
        self.app.logger.exception(mox.IsA(basestring))
        server_mgr.get('v2')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.instance_data_gc()
Ejemplo n.º 7
0
    def test_remind_server_not_found(self):
        server_mgr = self.fake_client_set.compute.servers
        expires = datetime(2013, 1, 19, 11, 12, 13)

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.remind_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1',
                                         expires_at=expires)])
        server_mgr.get('v1').AndRaise(osc_exc.NotFound('deleted'))
        instances.InstanceDataDAO.delete('v1')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.remind_about_instances()
Ejemplo n.º 8
0
    def test_remind_other_exception(self):
        server_mgr = self.fake_client_set.compute.servers
        expires = datetime(2013, 1, 19, 11, 12, 13)

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.remind_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1',
                                         expires_at=expires)])
        server_mgr.get('v1').AndRaise(RuntimeError('log me'))
        self.app.logger.exception(mox.IsA(basestring))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.remind_about_instances()
Ejemplo n.º 9
0
    def test_remind_server_not_found(self):
        server_mgr = self.fake_client_set.compute.servers
        expires = datetime(2013, 1, 19, 11, 12, 13)

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.remind_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1',
                                         expires_at=expires)])
        server_mgr.get('v1').AndRaise(osc_exc.NotFound('deleted'))
        instances.InstanceDataDAO.delete('v1')

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.remind_about_instances()
Ejemplo n.º 10
0
    def test_remind_other_exception(self):
        server_mgr = self.fake_client_set.compute.servers
        expires = datetime(2013, 1, 19, 11, 12, 13)

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.remind_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1',
                                         expires_at=expires)])
        server_mgr.get('v1').AndRaise(RuntimeError('log me'))
        self.app.logger.exception(mox.IsA(basestring))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.remind_about_instances()
Ejemplo n.º 11
0
    def test_rip_expired_instances_not_found(self):
        server_mgr = self.fake_client_set.compute.servers
        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.expired_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1'),
                            InstanceData(instance_id='v2')])
        server_mgr.delete('v1').AndRaise(osc_exc.NotFound('deleted'))
        instances.InstanceDataDAO.delete('v1')

        # check we continued to iterate after exception
        server_mgr.delete('v2')
        instances.AuditDAO.create_record(mox.IsA(dict))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.rip_expired_instances()
Ejemplo n.º 12
0
    def test_rip_expired_instances_other_exception(self):
        server_mgr = self.fake_client_set.compute.servers
        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.expired_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1'),
                            InstanceData(instance_id='v2')])
        server_mgr.delete('v1').AndRaise(RuntimeError('log me'))
        self.app.logger.exception(mox.IsA(basestring))

        # check we continued to iterate after exception
        server_mgr.delete('v2')
        instances.AuditDAO.create_record(mox.IsA(dict))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.rip_expired_instances()
Ejemplo n.º 13
0
    def test_rip_expired_instances_not_found(self):
        server_mgr = self.fake_client_set.compute.servers
        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.expired_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1'),
                            InstanceData(instance_id='v2')])
        server_mgr.delete('v1').AndRaise(osc_exc.NotFound('deleted'))
        instances.InstanceDataDAO.delete('v1')

        # check we continued to iterate after exception
        server_mgr.delete('v2')
        instances.AuditDAO.create_record(mox.IsA(dict))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.rip_expired_instances()
Ejemplo n.º 14
0
    def test_rip_expired_instances_other_exception(self):
        server_mgr = self.fake_client_set.compute.servers
        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.expired_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1'),
                            InstanceData(instance_id='v2')])
        server_mgr.delete('v1').AndRaise(RuntimeError('log me'))
        self.app.logger.exception(mox.IsA(basestring))

        # check we continued to iterate after exception
        server_mgr.delete('v2')
        instances.AuditDAO.create_record(mox.IsA(dict))

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.rip_expired_instances()
Ejemplo n.º 15
0
    def test_rip_expired_instances(self):
        server_mgr = self.fake_client_set.compute.servers
        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.expired_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1')])
        server_mgr.delete('v1')
        instances.AuditDAO.create_record({
            'resource': '/v1/instances/v1',
            'method': 'DELETE',
            'response_status': 200,
            'message': 'Automatically deleted expired instance'
        })

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.rip_expired_instances()
Ejemplo n.º 16
0
    def test_remind_user_not_found(self):
        server_mgr = self.fake_client_set.compute.servers
        user_mgr = self.fake_client_set.identity_admin.users
        server = doubles.make(self.mox, doubles.Server,
                              id='v2', name='instance-2', user_id='UID')
        expires = datetime(2013, 1, 19, 11, 12, 13)

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.remind_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v2',
                                         expires_at=expires)])

        server_mgr.get('v2').AndReturn(server)
        user_mgr.get('UID').AndRaise(osc_exc.NotFound('deleted'))
        instances.InstanceDataDAO.update('v2', remind_at=None)

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.remind_about_instances()
Ejemplo n.º 17
0
    def test_rip_expired_instances(self):
        server_mgr = self.fake_client_set.compute.servers
        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.expired_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v1')])
        server_mgr.delete('v1')
        instances.AuditDAO.create_record({
            'resource':
            '/v1/instances/v1',
            'method':
            'DELETE',
            'response_status':
            200,
            'message':
            'Automatically deleted expired instance'
        })

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.rip_expired_instances()
Ejemplo n.º 18
0
    def test_remind_user_not_found(self):
        server_mgr = self.fake_client_set.compute.servers
        user_mgr = self.fake_client_set.identity_admin.users
        server = doubles.make(self.mox,
                              doubles.Server,
                              id='v2',
                              name='instance-2',
                              user_id='UID')
        expires = datetime(2013, 1, 19, 11, 12, 13)

        instances.admin_client_set().AndReturn(self.fake_client_set)
        instances.datetime.utcnow().AndReturn('UTCNOW')
        instances.InstanceDataDAO.remind_list('UTCNOW')\
                .AndReturn([InstanceData(instance_id='v2',
                                         expires_at=expires)])

        server_mgr.get('v2').AndReturn(server)
        user_mgr.get('UID').AndRaise(osc_exc.NotFound('deleted'))
        instances.InstanceDataDAO.update('v2', remind_at=None)

        self.mox.ReplayAll()
        with self.app.test_request_context():
            instances.remind_about_instances()