Example #1
0
File: api.py Project: ed-/reddwarf
 def has_finished_migration(self, context, instance_id):
     """Returns true if an instance has a finished migration."""
     try:
         db.migration_get_by_instance_and_status(context, instance_id, "finished")
         return True
     except exception.NotFound:
         return False
Example #2
0
 def has_finished_migration(self, context, instance_id):
     """Returns true if an instance has a finished migration."""
     try:
         db.migration_get_by_instance_and_status(context, instance_id,
                                                 'finished')
         return True
     except exception.NotFound:
         return False
Example #3
0
 def has_finished_migration(self, context, instance_id):
     """Retrieves whether or not a finished migration exists for
     an instance"""
     try:
         db.migration_get_by_instance_and_status(context, instance_id,
                 'finished')
         return True
     except exception.NotFound:
         return False
Example #4
0
 def has_finished_migration(self, context, instance_id):
     """Retrieves whether or not a finished migration exists for
     an instance"""
     try:
         db.migration_get_by_instance_and_status(context, instance_id,
                                                 'finished')
         return True
     except exception.NotFound:
         return False
Example #5
0
 def test_get_by_instance_and_status(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'migration_get_by_instance_and_status')
     db.migration_get_by_instance_and_status(
         ctxt, fake_migration['id'], 'migrating').AndReturn(fake_migration)
     self.mox.ReplayAll()
     mig = migration.Migration.get_by_instance_and_status(
         ctxt, fake_migration['id'], 'migrating')
     self._compare(mig, fake_migration)
Example #6
0
 def test_get_by_instance_and_status(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'migration_get_by_instance_and_status')
     db.migration_get_by_instance_and_status(ctxt,
                                             fake_migration['id'],
                                             'migrating'
                                             ).AndReturn(fake_migration)
     self.mox.ReplayAll()
     mig = migration.Migration.get_by_instance_and_status(
         ctxt, fake_migration['id'], 'migrating')
     self._compare(mig, fake_migration)
Example #7
0
 def _test_delete_resized_part(self, inst):
     migration = {'source_compute': 'foo'}
     self.context.elevated().AndReturn(self.context)
     db.migration_get_by_instance_and_status(
         self.context, inst.uuid, 'finished').AndReturn(migration)
     self.compute_api._downsize_quota_delta(self.context, inst
                                            ).AndReturn('deltas')
     self.compute_api._reserve_quota_delta(self.context, 'deltas'
                                           ).AndReturn('rsvs')
     self.compute_api._record_action_start(
         self.context, inst, instance_actions.CONFIRM_RESIZE)
     self.compute_api.compute_rpcapi.confirm_resize(
         self.context, inst, migration,
         host=migration['source_compute'],
         cast=False, reservations='rsvs')
Example #8
0
 def _test_delete_resized_part(self, inst):
     migration = {'source_compute': 'foo'}
     self.context.elevated().AndReturn(self.context)
     db.migration_get_by_instance_and_status(
         self.context, inst.uuid, 'finished').AndReturn(migration)
     self.compute_api._downsize_quota_delta(self.context, inst
                                            ).AndReturn('deltas')
     self.compute_api._reserve_quota_delta(self.context, 'deltas'
                                           ).AndReturn('rsvs')
     self.compute_api._record_action_start(
         self.context, inst, instance_actions.CONFIRM_RESIZE)
     self.compute_api.compute_rpcapi.confirm_resize(
         self.context, inst, migration,
         host=migration['source_compute'],
         cast=False, reservations='rsvs')
Example #9
0
    def test_resize_instance_notification(self):
        """Ensure notifications on instance migrate/resize"""
        instance_id = self._create_instance()
        context = self.context.elevated()
        inst_ref = db.instance_get(context, instance_id)

        self.compute.run_instance(self.context, instance_id)
        test_notifier.NOTIFICATIONS = []

        db.instance_update(self.context, instance_id, {'host': 'foo'})
        self.compute.prep_resize(context, inst_ref['uuid'], 1)
        migration_ref = db.migration_get_by_instance_and_status(
            context, inst_ref['uuid'], 'pre-migrating')

        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], 'INFO')
        self.assertEquals(msg['event_type'], 'compute.instance.resize.prep')
        payload = msg['payload']
        self.assertEquals(payload['tenant_id'], self.project_id)
        self.assertEquals(payload['user_id'], self.user_id)
        self.assertEquals(payload['instance_id'], instance_id)
        self.assertEquals(payload['instance_type'], 'm1.tiny')
        type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
        self.assertEquals(str(payload['instance_type_id']), str(type_id))
        self.assertTrue('display_name' in payload)
        self.assertTrue('created_at' in payload)
        self.assertTrue('launched_at' in payload)
        self.assertEquals(payload['image_ref'], '1')
        self.compute.terminate_instance(context, instance_id)
Example #10
0
    def test_resize_instance_notification(self):
        """Ensure notifications on instance migrate/resize"""
        instance_id = self._create_instance()
        context = self.context.elevated()
        inst_ref = db.instance_get(context, instance_id)

        self.compute.run_instance(self.context, instance_id)
        test_notifier.NOTIFICATIONS = []

        db.instance_update(self.context, instance_id, {'host': 'foo'})
        self.compute.prep_resize(context, inst_ref['uuid'], 1)
        migration_ref = db.migration_get_by_instance_and_status(context,
                inst_ref['uuid'], 'pre-migrating')

        self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
        msg = test_notifier.NOTIFICATIONS[0]
        self.assertEquals(msg['priority'], 'INFO')
        self.assertEquals(msg['event_type'], 'compute.instance.resize.prep')
        payload = msg['payload']
        self.assertEquals(payload['tenant_id'], self.project_id)
        self.assertEquals(payload['user_id'], self.user_id)
        self.assertEquals(payload['instance_id'], instance_id)
        self.assertEquals(payload['instance_type'], 'm1.tiny')
        type_id = instance_types.get_instance_type_by_name('m1.tiny')['id']
        self.assertEquals(str(payload['instance_type_id']), str(type_id))
        self.assertTrue('display_name' in payload)
        self.assertTrue('created_at' in payload)
        self.assertTrue('launched_at' in payload)
        self.assertEquals(payload['image_ref'], '1')
        self.compute.terminate_instance(context, instance_id)
Example #11
0
 def test_resize_instance(self):
     """Ensure instance can be migrated/resized"""
     instance_id = self._create_instance()
     context = self.context.elevated()
     self.compute.run_instance(self.context, instance_id)
     db.instance_update(self.context, instance_id, {'host': 'foo'})
     self.compute.prep_resize(context, instance_id)
     migration_ref = db.migration_get_by_instance_and_status(context,
             instance_id, 'pre-migrating')
     self.compute.resize_instance(context, instance_id,
             migration_ref['id'])
     self.compute.terminate_instance(context, instance_id)
    def test_resize_instance(self):
        """Ensure instance can be migrated/resized"""
        instance_id = self._create_instance()
        context = self.context.elevated()

        self.compute.run_instance(self.context, instance_id)
        db.instance_update(self.context, instance_id, {'host': 'foo'})
        self.compute.prep_resize(context, instance_id, 1)
        migration_ref = db.migration_get_by_instance_and_status(
            context, instance_id, 'pre-migrating')
        self.compute.resize_instance(context, instance_id, migration_ref['id'])
        self.compute.terminate_instance(context, instance_id)
Example #13
0
    def test_finish_revert_resize(self):
        """Ensure that the flavor is reverted to the original on revert"""
        context = self.context.elevated()
        instance_id = self._create_instance()

        def fake(*args, **kwargs):
            pass

        self.stubs.Set(self.compute.driver, 'finish_migration', fake)
        self.stubs.Set(self.compute.driver, 'revert_migration', fake)
        self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake)

        self.compute.run_instance(self.context, instance_id)

        # Confirm the instance size before the resize starts
        inst_ref = db.instance_get(context, instance_id)
        instance_type_ref = db.instance_type_get(context,
                                                 inst_ref['instance_type_id'])
        self.assertEqual(instance_type_ref['flavorid'], 1)

        db.instance_update(self.context, instance_id, {'host': 'foo'})

        self.compute.prep_resize(context, inst_ref['uuid'], 3)

        migration_ref = db.migration_get_by_instance_and_status(
            context, inst_ref['uuid'], 'pre-migrating')

        self.compute.resize_instance(context, inst_ref['uuid'],
                                     migration_ref['id'])
        self.compute.finish_resize(context, inst_ref['uuid'],
                                   int(migration_ref['id']), {})

        # Prove that the instance size is now the new size
        inst_ref = db.instance_get(context, instance_id)
        instance_type_ref = db.instance_type_get(context,
                                                 inst_ref['instance_type_id'])
        self.assertEqual(instance_type_ref['flavorid'], 3)

        # Finally, revert and confirm the old flavor has been applied
        self.compute.revert_resize(context, inst_ref['uuid'],
                                   migration_ref['id'])
        self.compute.finish_revert_resize(context, inst_ref['uuid'],
                                          migration_ref['id'])

        inst_ref = db.instance_get(context, instance_id)
        instance_type_ref = db.instance_type_get(context,
                                                 inst_ref['instance_type_id'])
        self.assertEqual(instance_type_ref['flavorid'], 1)

        self.compute.terminate_instance(context, instance_id)
Example #14
0
    def test_finish_revert_resize(self):
        """Ensure that the flavor is reverted to the original on revert"""
        context = self.context.elevated()
        instance_id = self._create_instance()

        def fake(*args, **kwargs):
            pass

        self.stubs.Set(self.compute.driver, 'finish_migration', fake)
        self.stubs.Set(self.compute.driver, 'revert_migration', fake)
        self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake)

        self.compute.run_instance(self.context, instance_id)

        # Confirm the instance size before the resize starts
        inst_ref = db.instance_get(context, instance_id)
        instance_type_ref = db.instance_type_get(context,
                inst_ref['instance_type_id'])
        self.assertEqual(instance_type_ref['flavorid'], 1)

        db.instance_update(self.context, instance_id, {'host': 'foo'})

        self.compute.prep_resize(context, inst_ref['uuid'], 3)

        migration_ref = db.migration_get_by_instance_and_status(context,
                inst_ref['uuid'], 'pre-migrating')

        self.compute.resize_instance(context, inst_ref['uuid'],
                migration_ref['id'])
        self.compute.finish_resize(context, inst_ref['uuid'],
                    int(migration_ref['id']), {})

        # Prove that the instance size is now the new size
        inst_ref = db.instance_get(context, instance_id)
        instance_type_ref = db.instance_type_get(context,
                inst_ref['instance_type_id'])
        self.assertEqual(instance_type_ref['flavorid'], 3)

        # Finally, revert and confirm the old flavor has been applied
        self.compute.revert_resize(context, inst_ref['uuid'],
                migration_ref['id'])
        self.compute.finish_revert_resize(context, inst_ref['uuid'],
                migration_ref['id'])

        inst_ref = db.instance_get(context, instance_id)
        instance_type_ref = db.instance_type_get(context,
                inst_ref['instance_type_id'])
        self.assertEqual(instance_type_ref['flavorid'], 1)

        self.compute.terminate_instance(context, instance_id)
Example #15
0
    def test_finish_resize(self):
        """Contrived test to ensure finish_resize doesn't raise anything"""

        def fake(*args, **kwargs):
            pass

        self.stubs.Set(self.compute.driver, 'finish_resize', fake)
        context = self.context.elevated()
        instance_id = self._create_instance()
        self.compute.prep_resize(context, instance_id, 1)
        migration_ref = db.migration_get_by_instance_and_status(context,
                instance_id, 'pre-migrating')
        try:
            self.compute.finish_resize(context, instance_id,
                    int(migration_ref['id']), {})
        except KeyError, e:
            # Only catch key errors. We want other reasons for the test to
            # fail to actually error out so we don't obscure anything
            self.fail()
Example #16
0
    def test_finish_resize(self):
        """Contrived test to ensure finish_resize doesn't raise anything"""
        def fake(*args, **kwargs):
            pass

        self.stubs.Set(self.compute.driver, 'finish_migration', fake)
        self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake)
        context = self.context.elevated()
        instance_id = self._create_instance()
        instance_ref = db.instance_get(context, instance_id)
        self.compute.prep_resize(context, instance_ref['uuid'], 1)
        migration_ref = db.migration_get_by_instance_and_status(
            context, instance_ref['uuid'], 'pre-migrating')
        try:
            self.compute.finish_resize(context, instance_ref['uuid'],
                                       int(migration_ref['id']), {})
        except KeyError, e:
            # Only catch key errors. We want other reasons for the test to
            # fail to actually error out so we don't obscure anything
            self.fail()
Example #17
0
 def get_by_instance_and_status(cls, context, instance_uuid, status):
     db_migration = db.migration_get_by_instance_and_status(
         context, instance_uuid, status)
     return cls._from_db_object(context, cls(), db_migration)
Example #18
0
 def get_by_instance_and_status(cls, context, instance_uuid, status):
     db_migration = db.migration_get_by_instance_and_status(
         context, instance_uuid, status)
     return cls._from_db_object(context, cls(), db_migration)