示例#1
0
    def test_remove_console(self):
        instance_id = self._create_instance()
        console_id = self.console.add_console(self.context, instance_id)
        self.console.remove_console(self.context, console_id)

        self.assertRaises(exception.NotFound,
                          db.console_get,
                          self.context,
                          console_id)
        db.instance_destroy(self.context, instance_id)
示例#2
0
    def test_add_console(self):
        instance_id = self._create_instance()
        self.console.add_console(self.context, instance_id)
        instance = db.instance_get(self.context, instance_id)
        pool = db.console_pool_get_by_host_type(self.context,
                                                instance['host'],
                                                self.console.host,
                                            self.console.driver.console_type)

        console_instances = [con['instance_id'] for con in pool.consoles]
        self.assert_(instance_id in console_instances)
        db.instance_destroy(self.context, instance_id)
示例#3
0
 def test_instance_get_all_by_filters_deleted(self):
     args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
     inst1 = db.instance_create(self.context, args1)
     args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'}
     inst2 = db.instance_create(self.context, args2)
     db.instance_destroy(self.context, inst1.id)
     result = db.instance_get_all_by_filters(self.context.elevated(), {})
     self.assertEqual(2, len(result))
     self.assertIn(inst1.id, [result[0].id, result[1].id])
     self.assertIn(inst2.id, [result[0].id, result[1].id])
     if inst1.id == result[0].id:
         self.assertTrue(result[0].deleted)
     else:
         self.assertTrue(result[1].deleted)
示例#4
0
 def test_instance_get_all_by_filters_deleted(self):
     args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
     inst1 = db.instance_create(self.context, args1)
     args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'}
     inst2 = db.instance_create(self.context, args2)
     db.instance_destroy(self.context, inst1.id)
     result = db.instance_get_all_by_filters(self.context.elevated(), {})
     self.assertEqual(2, len(result))
     self.assertIn(inst1.id, [result[0].id, result[1].id])
     self.assertIn(inst2.id, [result[0].id, result[1].id])
     if inst1.id == result[0].id:
         self.assertTrue(result[0].deleted)
     else:
         self.assertTrue(result[1].deleted)
示例#5
0
 def test_too_many_cores(self):
     instance_ids = []
     instance_id = self._create_instance(cores=4)
     instance_ids.append(instance_id)
     inst_type = instance_types.get_instance_type_by_name('m1.small')
     image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
     self.assertRaises(exception.QuotaError, compute.API().create,
                                         self.context,
                                         min_count=1,
                                         max_count=1,
                                         instance_type=inst_type,
                                         image_href=image_uuid)
     for instance_id in instance_ids:
         db.instance_destroy(self.context, instance_id)
示例#6
0
 def test_too_many_cores(self):
     instance_ids = []
     instance_id = self._create_instance(cores=4)
     instance_ids.append(instance_id)
     inst_type = instance_types.get_instance_type_by_name('m1.small')
     image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
     self.assertRaises(exception.QuotaError,
                       compute.API().create,
                       self.context,
                       min_count=1,
                       max_count=1,
                       instance_type=inst_type,
                       image_href=image_uuid)
     for instance_id in instance_ids:
         db.instance_destroy(self.context, instance_id)
示例#7
0
    def test_run_attach_detach_volume(self):
        """Make sure volume can be attached and detached from instance."""
        inst = {}
        inst['image_id'] = 1
        inst['reservation_id'] = 'r-fakeres'
        inst['launch_time'] = '10'
        inst['user_id'] = 'fake'
        inst['project_id'] = 'fake'
        inst['instance_type_id'] = '2'  # m1.tiny
        inst['ami_launch_index'] = 0
        instance_id = db.instance_create(self.context, inst)['id']
        mountpoint = "/dev/sdf"
        volume_id = self._create_volume()
        self.volume.create_volume(self.context, volume_id)
        if FLAGS.fake_tests:
            db.volume_attached(self.context, volume_id, instance_id,
                               mountpoint)
        else:
            self.compute.attach_volume(self.context,
                                       instance_id,
                                       volume_id,
                                       mountpoint)
        vol = db.volume_get(context.get_admin_context(), volume_id)
        self.assertEqual(vol['status'], "in-use")
        self.assertEqual(vol['attach_status'], "attached")
        self.assertEqual(vol['mountpoint'], mountpoint)
        instance_ref = db.volume_get_instance(self.context, volume_id)
        self.assertEqual(instance_ref['id'], instance_id)

        self.assertRaises(exception.Error,
                          self.volume.delete_volume,
                          self.context,
                          volume_id)
        if FLAGS.fake_tests:
            db.volume_detached(self.context, volume_id)
        else:
            self.compute.detach_volume(self.context,
                                       instance_id,
                                       volume_id)
        vol = db.volume_get(self.context, volume_id)
        self.assertEqual(vol['status'], "available")

        self.volume.delete_volume(self.context, volume_id)
        self.assertRaises(exception.VolumeNotFound,
                          db.volume_get,
                          self.context,
                          volume_id)
        db.instance_destroy(self.context, instance_id)
示例#8
0
    def test_run_attach_detach_volume(self):
        """Make sure volume can be attached and detached from instance."""
        inst = {}
        inst['image_id'] = 1
        inst['reservation_id'] = 'r-fakeres'
        inst['launch_time'] = '10'
        inst['user_id'] = 'fake'
        inst['project_id'] = 'fake'
        inst['instance_type_id'] = '2'  # m1.tiny
        inst['ami_launch_index'] = 0
        instance_id = db.instance_create(self.context, inst)['id']
        mountpoint = "/dev/sdf"
        volume_id = self._create_volume()
        self.volume.create_volume(self.context, volume_id)
        if FLAGS.fake_tests:
            db.volume_attached(self.context, volume_id, instance_id,
                               mountpoint)
        else:
            self.compute.attach_volume(self.context, instance_id, volume_id,
                                       mountpoint)
        vol = db.volume_get(context.get_admin_context(), volume_id)
        self.assertEqual(vol['status'], "in-use")
        self.assertEqual(vol['attach_status'], "attached")
        self.assertEqual(vol['mountpoint'], mountpoint)
        instance_ref = db.volume_get_instance(self.context, volume_id)
        self.assertEqual(instance_ref['id'], instance_id)

        self.assertRaises(exception.Error, self.volume.delete_volume,
                          self.context, volume_id)
        if FLAGS.fake_tests:
            db.volume_detached(self.context, volume_id)
        else:
            self.compute.detach_volume(self.context, instance_id, volume_id)
        vol = db.volume_get(self.context, volume_id)
        self.assertEqual(vol['status'], "available")

        self.volume.delete_volume(self.context, volume_id)
        self.assertRaises(exception.VolumeNotFound, db.volume_get,
                          self.context, volume_id)
        db.instance_destroy(self.context, instance_id)
示例#9
0
 def test_add_console_does_not_duplicate(self):
     instance_id = self._create_instance()
     cons1 = self.console.add_console(self.context, instance_id)
     cons2 = self.console.add_console(self.context, instance_id)
     self.assertEqual(cons1, cons2)
     db.instance_destroy(self.context, instance_id)
示例#10
0
 def tearDown(self):
     db.instance_destroy(self.context, self.instance_id)
     super(VolumeTestCase, self).tearDown()
示例#11
0
 def tearDown(self):
     db.instance_destroy(self.context, self.instance_id)
     super(VolumeTestCase, self).tearDown()