Example #1
0
    def test_migration_get_unconfirmed_by_dest_compute(self):
        ctxt = context.get_admin_context()

        # Ensure no migrations are returned.
        results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host")
        self.assertEqual(0, len(results))

        # Ensure no migrations are returned.
        results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host2")
        self.assertEqual(0, len(results))

        updated_at = datetime.datetime(2000, 01, 01, 12, 00, 00)
        values = {"status": "finished", "updated_at": updated_at, "dest_compute": "fake_host2"}
        migration = db.migration_create(ctxt, values)

        # Ensure different host is not returned
        results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host")
        self.assertEqual(0, len(results))

        # Ensure one migration older than 10 seconds is returned.
        results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host2")
        self.assertEqual(1, len(results))
        db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})

        # Ensure the new migration is not returned.
        updated_at = timeutils.utcnow()
        values = {"status": "finished", "updated_at": updated_at, "dest_compute": "fake_host2"}
        migration = db.migration_create(ctxt, values)
        results = db.migration_get_unconfirmed_by_dest_compute(ctxt, 10, "fake_host2")
        self.assertEqual(0, len(results))
        db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})
Example #2
0
    def _create(self, status='migrating', source_compute='host1',
                dest_compute='host2'):

        values = {'host': source_compute}
        instance = db.instance_create(self.ctxt, values)

        values = {'status': status, 'source_compute': source_compute,
                  'dest_compute': dest_compute,
                  'instance_uuid': instance['uuid']}
        db.migration_create(self.ctxt, values)
Example #3
0
 def test_create(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'migration_create')
     db.migration_create(ctxt, {'source_compute': 'foo'}).AndReturn(
         fake_migration)
     self.mox.ReplayAll()
     mig = migration.Migration()
     mig.source_compute = 'foo'
     mig.create(ctxt)
     self.assertEqual(fake_migration['dest_compute'], mig.dest_compute)
Example #4
0
 def test_recreate_fails(self):
     ctxt = context.get_admin_context()
     fake_migration = fake_db_migration()
     self.mox.StubOutWithMock(db, 'migration_create')
     db.migration_create(ctxt, {'source_compute': 'foo'}).AndReturn(
         fake_migration)
     self.mox.ReplayAll()
     mig = migration.Migration(context=ctxt)
     mig.source_compute = 'foo'
     mig.create()
     self.assertRaises(exception.ObjectActionError, mig.create)
Example #5
0
 def test_create(self):
     ctxt = context.get_admin_context()
     fake_migration = fake_db_migration()
     self.mox.StubOutWithMock(db, 'migration_create')
     db.migration_create(ctxt, {'source_compute': 'foo'}).AndReturn(
         fake_migration)
     self.mox.ReplayAll()
     mig = migration.Migration(context=ctxt)
     mig.source_compute = 'foo'
     mig.create()
     self.assertEqual(fake_migration['dest_compute'], mig.dest_compute)
Example #6
0
 def test_recreate_fails(self):
     ctxt = context.get_admin_context()
     fake_migration = fake_db_migration()
     self.mox.StubOutWithMock(db, 'migration_create')
     db.migration_create(ctxt, {'source_compute': 'foo'}).AndReturn(
         fake_migration)
     self.mox.ReplayAll()
     mig = migration.Migration(context=ctxt)
     mig.source_compute = 'foo'
     mig.create()
     self.assertRaises(exception.ObjectActionError, mig.create,
                       self.context)
Example #7
0
 def test_migration_create(self):
     inst = {'uuid': 'fake-uuid',
             'host': 'fake-host',
             'node': 'fake-node'}
     self.mox.StubOutWithMock(db, 'migration_create')
     db.migration_create(self.context.elevated(),
                         {'instance_uuid': inst['uuid'],
                          'source_compute': inst['host'],
                          'source_node': inst['node'],
                          'fake-key': 'fake-value'}).AndReturn('result')
     self.mox.ReplayAll()
     result = self.conductor.migration_create(self.context, inst,
                                              {'fake-key': 'fake-value'})
     self.assertEqual(result, 'result')
Example #8
0
 def test_migration_create(self):
     inst = {'uuid': 'fake-uuid', 'host': 'fake-host', 'node': 'fake-node'}
     self.mox.StubOutWithMock(db, 'migration_create')
     db.migration_create(
         self.context.elevated(), {
             'instance_uuid': inst['uuid'],
             'source_compute': inst['host'],
             'source_node': inst['node'],
             'fake-key': 'fake-value'
         }).AndReturn('result')
     self.mox.ReplayAll()
     result = self.conductor.migration_create(self.context, inst,
                                              {'fake-key': 'fake-value'})
     self.assertEqual(result, 'result')
Example #9
0
 def test_migration_create(self):
     inst = {"uuid": "fake-uuid", "host": "fake-host", "node": "fake-node"}
     self.mox.StubOutWithMock(db, "migration_create")
     db.migration_create(
         self.context.elevated(),
         {
             "instance_uuid": inst["uuid"],
             "source_compute": inst["host"],
             "source_node": inst["node"],
             "fake-key": "fake-value",
         },
     ).AndReturn("result")
     self.mox.ReplayAll()
     result = self.conductor.migration_create(self.context, inst, {"fake-key": "fake-value"})
     self.assertEqual(result, "result")
Example #10
0
 def create(self, context):
     updates = {}
     for key in self.obj_what_changed():
         updates[key] = self[key]
     updates.pop('id', None)
     db_migration = db.migration_create(context, updates)
     self._from_db_object(context, self, db_migration)
Example #11
0
 def create(self, context):
     updates = {}
     for key in self.obj_what_changed():
         updates[key] = self[key]
     updates.pop('id', None)
     db_migration = db.migration_create(context, updates)
     self._from_db_object(context, self, db_migration)
Example #12
0
 def create(self, context):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self.obj_get_changes()
     db_migration = db.migration_create(context, updates)
     self._from_db_object(context, self, db_migration)
Example #13
0
    def _create_migration(self, context, instance, instance_type):
        """Create a migration record for the upcoming resize.  This should
        be done while the COMPUTE_RESOURCES_SEMAPHORE is held so the resource
        claim will not be lost if the audit process starts.
        """
        # TODO(russellb): no-db-compute: Send the old instance type
        # info that is needed via rpc so db access isn't required
        # here.
        old_instance_type_id = instance["instance_type_id"]
        old_instance_type = instance_types.get_instance_type(old_instance_type_id)

        return db.migration_create(
            context.elevated(),
            {
                "instance_uuid": instance["uuid"],
                "source_compute": instance["host"],
                "source_node": instance["node"],
                "dest_compute": self.host,
                "dest_node": self.nodename,
                "dest_host": self.driver.get_host_ip_addr(),
                "old_instance_type_id": old_instance_type["id"],
                "new_instance_type_id": instance_type["id"],
                "status": "pre-migrating",
            },
        )
Example #14
0
 def test_migration_get(self):
     migration = db.migration_create(self.context.elevated(),
             {'instance_uuid': 'fake-uuid',
              'status': 'migrating'})
     self.assertEqual(jsonutils.to_primitive(migration),
                      self.conductor.migration_get(self.context,
                                                   migration['id']))
Example #15
0
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self.obj_get_changes()
     db_migration = db.migration_create(self._context, updates)
     self._from_db_object(self._context, self, db_migration)
Example #16
0
 def test_migration_get(self):
     migration = db.migration_create(self.context.elevated(),
             {'instance_uuid': 'fake-uuid',
              'status': 'migrating'})
     self.assertEqual(jsonutils.to_primitive(migration),
                      self.conductor.migration_get(self.context,
                                                   migration['id']))
Example #17
0
 def test_migration_update(self):
     migration = db.migration_create(self.context.elevated(),
             {'instance_uuid': 'fake-uuid',
              'status': 'migrating'})
     migration_p = jsonutils.to_primitive(migration)
     migration = self.conductor.migration_update(self.context, migration_p,
                                                 'finished')
     self.assertEqual(migration['status'], 'finished')
Example #18
0
 def test_migration_update(self):
     migration = db.migration_create(self.context.elevated(),
             {'instance_uuid': 'fake-uuid',
              'status': 'migrating'})
     migration_p = jsonutils.to_primitive(migration)
     migration = self.conductor.migration_update(self.context, migration_p,
                                                 'finished')
     self.assertEqual(migration['status'], 'finished')
Example #19
0
 def create(self):
     if self.obj_attr_is_set("id"):
         raise exception.ObjectActionError(action="create", reason="already created")
     updates = self.obj_get_changes()
     if "migration_type" not in updates:
         raise exception.ObjectActionError(
             action="create", reason="cannot create a Migration object without a " "migration_type set"
         )
     db_migration = db.migration_create(self._context, updates)
     self._from_db_object(self._context, self, db_migration)
 def create(self):
     if self.obj_attr_is_set('id'):
         raise exception.ObjectActionError(action='create',
                                           reason='already created')
     updates = self.obj_get_changes()
     if 'migration_type' not in updates:
         raise exception.ObjectActionError(
             action="create",
             reason="cannot create a Migration object without a "
             "migration_type set")
     db_migration = db.migration_create(self._context, updates)
     self._from_db_object(self._context, self, db_migration)
Example #21
0
    def test_migration_get_all_unconfirmed(self):
        ctxt = context.get_admin_context()

        # Ensure no migrations are returned.
        results = db.migration_get_all_unconfirmed(ctxt, 10)
        self.assertEqual(0, len(results))

        # Ensure one migration older than 10 seconds is returned.
        updated_at = datetime.datetime(2000, 01, 01, 12, 00, 00)
        values = {"status": "FINISHED", "updated_at": updated_at}
        migration = db.migration_create(ctxt, values)
        results = db.migration_get_all_unconfirmed(ctxt, 10)
        self.assertEqual(1, len(results))
        db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})

        # Ensure the new migration is not returned.
        updated_at = datetime.datetime.utcnow()
        values = {"status": "FINISHED", "updated_at": updated_at}
        migration = db.migration_create(ctxt, values)
        results = db.migration_get_all_unconfirmed(ctxt, 10)
        self.assertEqual(0, len(results))
        db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})
Example #22
0
    def test_migration_get_all_unconfirmed(self):
        ctxt = context.get_admin_context()

        # Ensure no migrations are returned.
        results = db.migration_get_all_unconfirmed(ctxt, 10)
        self.assertEqual(0, len(results))

        # Ensure one migration older than 10 seconds is returned.
        updated_at = datetime.datetime(2000, 01, 01, 12, 00, 00)
        values = {"status": "FINISHED", "updated_at": updated_at}
        migration = db.migration_create(ctxt, values)
        results = db.migration_get_all_unconfirmed(ctxt, 10)
        self.assertEqual(1, len(results))
        db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})

        # Ensure the new migration is not returned.
        updated_at = datetime.datetime.utcnow()
        values = {"status": "FINISHED", "updated_at": updated_at}
        migration = db.migration_create(ctxt, values)
        results = db.migration_get_all_unconfirmed(ctxt, 10)
        self.assertEqual(0, len(results))
        db.migration_update(ctxt, migration.id, {"status": "CONFIRMED"})
Example #23
0
 def test_create_uuid_on_load(self):
     values = {'source_compute': 'src',
               'dest_compute': 'dst',
               'source_node': 'srcnode',
               'dest_node': 'dstnode',
               'instance_uuid': 'fake',
               'status': 'faking',
               'migration_type': 'migration',
               'created_at': None,
               'deleted_at': None,
               'updated_at': None}
     db_mig = db.migration_create(self.context, values)
     mig = objects.Migration.get_by_id(self.context, db_mig.id)
     self.assertIn('uuid', mig)
     uuid = mig.uuid
     # Make sure that it was saved and we get the same one back
     mig = objects.Migration.get_by_id(self.context, db_mig.id)
     self.assertEqual(uuid, mig.uuid)
Example #24
0
    def _create_migration(self, context, instance, instance_type):
        """Create a migration record for the upcoming resize.  This should
        be done while the COMPUTE_RESOURCES_SEMAPHORE is held so the resource
        claim will not be lost if the audit process starts.
        """
        # TODO(russellb): no-db-compute: Send the old instance type
        # info that is needed via rpc so db access isn't required
        # here.
        old_instance_type_id = instance['instance_type_id']
        old_instance_type = instance_types.get_instance_type(
                old_instance_type_id)

        return db.migration_create(context.elevated(),
                {'instance_uuid': instance['uuid'],
                 'source_compute': instance['host'],
                 'dest_compute': self.host,
                 'dest_host': self.driver.get_host_ip_addr(),
                 'old_instance_type_id': old_instance_type['id'],
                 'new_instance_type_id': instance_type['id'],
                 'status': 'pre-migrating'})
Example #25
0
    def _create_migration(self, context, instance, instance_type):
        """Create a migration record for the upcoming resize.  This should
        be done while the COMPUTE_RESOURCES_SEMAPHORE is held so the resource
        claim will not be lost if the audit process starts.
        """
        # TODO(russellb): no-db-compute: Send the old instance type
        # info that is needed via rpc so db access isn't required
        # here.
        old_instance_type_id = instance['instance_type_id']
        old_instance_type = instance_types.get_instance_type(
                old_instance_type_id)

        return db.migration_create(context.elevated(),
                {'instance_uuid': instance['uuid'],
                 'source_compute': instance['host'],
                 'dest_compute': self.host,
                 'dest_host': self.driver.get_host_ip_addr(),
                 'old_instance_type_id': old_instance_type['id'],
                 'new_instance_type_id': instance_type['id'],
                 'status': 'pre-migrating'})
Example #26
0
    def setUp(self):
        super(XenAPIMigrateInstance, self).setUp()
        self.stubs = stubout.StubOutForTesting()
        self.flags(target_host='127.0.0.1',
                xenapi_connection_url='test_url',
                xenapi_connection_password='******')
        db_fakes.stub_out_db_instance_api(self.stubs)
        stubs.stub_out_get_target(self.stubs)
        xenapi_fake.reset()
        xenapi_fake.create_network('fake', FLAGS.flat_network_bridge)
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        self.instance_values = {'id': 1,
                  'project_id': self.project_id,
                  'user_id': self.user_id,
                  'image_ref': 1,
                  'kernel_id': None,
                  'ramdisk_id': None,
                  'local_gb': 5,
                  'instance_type_id': '3',  # m1.large
                  'os_type': 'linux',
                  'architecture': 'x86-64'}

        migration_values = {
            'source_compute': 'nova-compute',
            'dest_compute': 'nova-compute',
            'dest_host': '10.127.5.114',
            'status': 'post-migrating',
            'instance_uuid': '15f23e6a-cc6e-4d22-b651-d9bdaac316f7',
            'old_instance_type_id': 5,
            'new_instance_type_id': 1
        }
        self.migration = db.migration_create(
            context.get_admin_context(), migration_values)

        fake_utils.stub_out_utils_execute(self.stubs)
        stubs.stub_out_migration_methods(self.stubs)
        stubs.stubout_get_this_vm_uuid(self.stubs)
        glance_stubs.stubout_glance_client(self.stubs)
Example #27
0
    def setUp(self):
        super(XenAPIMigrateInstance, self).setUp()
        self.stubs = stubout.StubOutForTesting()
        self.flags(target_host='127.0.0.1',
                xenapi_connection_url='test_url',
                xenapi_connection_password='******')
        db_fakes.stub_out_db_instance_api(self.stubs)
        stubs.stub_out_get_target(self.stubs)
        xenapi_fake.reset()
        xenapi_fake.create_network('fake', FLAGS.flat_network_bridge)
        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.RequestContext(self.user_id, self.project_id)
        self.instance_values = {'id': 1,
                  'project_id': self.project_id,
                  'user_id': self.user_id,
                  'image_ref': 1,
                  'kernel_id': None,
                  'ramdisk_id': None,
                  'local_gb': 5,
                  'instance_type_id': '3',  # m1.large
                  'os_type': 'linux',
                  'architecture': 'x86-64'}

        migration_values = {
            'source_compute': 'nova-compute',
            'dest_compute': 'nova-compute',
            'dest_host': '10.127.5.114',
            'status': 'post-migrating',
            'instance_uuid': '15f23e6a-cc6e-4d22-b651-d9bdaac316f7',
            'old_instance_type_id': 5,
            'new_instance_type_id': 1
        }
        self.migration = db.migration_create(
            context.get_admin_context(), migration_values)

        fake_utils.stub_out_utils_execute(self.stubs)
        stubs.stub_out_migration_methods(self.stubs)
        stubs.stubout_get_this_vm_uuid(self.stubs)
        glance_stubs.stubout_glance_client(self.stubs)
Example #28
0
 def test_migration_update(self):
     migration = db.migration_create(self.context.elevated(), {"instance_uuid": "fake-uuid", "status": "migrating"})
     migration_p = jsonutils.to_primitive(migration)
     migration = self.conductor.migration_update(self.context, migration_p, "finished")
     self.assertEqual(migration["status"], "finished")
Example #29
0
 def test_migration_get(self):
     migration = db.migration_create(self.context.elevated(), {"instance_uuid": "fake-uuid", "status": "migrating"})
     self.assertEqual(jsonutils.to_primitive(migration), self.conductor.migration_get(self.context, migration["id"]))
Example #30
0
 def create(self, context):
     updates = self.obj_get_changes()
     updates.pop('id', None)
     db_migration = db.migration_create(context, updates)
     self._from_db_object(context, self, db_migration)
Example #31
0
 def create(self, context):
     updates = self.obj_get_changes()
     updates.pop('id', None)
     db_migration = db.migration_create(context, updates)
     self._from_db_object(context, self, db_migration)