Beispiel #1
0
    def test_migrate_none_or_zero_ratio_with_none_ratio_conf(self):
        cn1 = fake_compute_obj.obj_clone()
        cn1._context = self.context
        cn1.create()

        db.compute_node_update(
            self.context, cn1.id, {
                'cpu_allocation_ratio': 0.0,
                'disk_allocation_ratio': 0.0,
                'ram_allocation_ratio': 0.0
            })

        self.flags(initial_cpu_allocation_ratio=32.0)
        self.flags(initial_ram_allocation_ratio=8.0)
        self.flags(initial_disk_allocation_ratio=2.0)

        res = compute_node.migrate_empty_ratio(self.context, 1)
        self.assertEqual(res, (1, 1))

        # the ratio is refreshed to CONF.initial_xxx_allocation_ratio
        # beacause CONF.xxx_allocation_ratio is None
        cns = db.compute_node_get_all(self.context)
        # the ratio is refreshed to CONF.xxx_allocation_ratio
        for cn in cns:
            for x in ['cpu', 'disk', 'ram']:
                conf_key = 'initial_%s_allocation_ratio' % x
                key = '%s_allocation_ratio' % x
                self.assertEqual(getattr(CONF, conf_key), cn[key])
Beispiel #2
0
    def test_migrate_none_or_zero_ratio_with_none_ratio_conf(self):
        cn1 = fake_compute_obj.obj_clone()
        cn1._context = self.context
        cn1.create()

        db.compute_node_update(self.context, cn1.id,
                               {'cpu_allocation_ratio': 0.0,
                                'disk_allocation_ratio': 0.0,
                                'ram_allocation_ratio': 0.0})

        self.flags(initial_cpu_allocation_ratio=32.0)
        self.flags(initial_ram_allocation_ratio=8.0)
        self.flags(initial_disk_allocation_ratio=2.0)

        res = compute_node.migrate_empty_ratio(self.context, 1)
        self.assertEqual(res, (1, 1))

        # the ratio is refreshed to CONF.initial_xxx_allocation_ratio
        # beacause CONF.xxx_allocation_ratio is None
        cns = db.compute_node_get_all(self.context)
        # the ratio is refreshed to CONF.xxx_allocation_ratio
        for cn in cns:
            for x in ['cpu', 'disk', 'ram']:
                conf_key = 'initial_%s_allocation_ratio' % x
                key = '%s_allocation_ratio' % x
                self.assertEqual(getattr(CONF, conf_key), cn[key])
Beispiel #3
0
    def test_migrate_none_or_zero_ratio_with_not_empty_ratio(self):
        cn1 = fake_compute_obj.obj_clone()
        cn1._context = self.context
        cn1.create()

        db.compute_node_update(self.context, cn1.id,
                               {'cpu_allocation_ratio': 32.0,
                                'ram_allocation_ratio': 4.0,
                                'disk_allocation_ratio': 3.0})

        res = compute_node.migrate_empty_ratio(self.context, 1)
        # the non-empty ratio will not be refreshed
        self.assertEqual(res, (0, 0))

        cns = db.compute_node_get_all(self.context)
        for cn in cns:
            self.assertEqual(32.0, cn['cpu_allocation_ratio'])
            self.assertEqual(4.0, cn['ram_allocation_ratio'])
            self.assertEqual(3.0, cn['disk_allocation_ratio'])
Beispiel #4
0
    def test_migrate_none_or_zero_ratio_with_not_empty_ratio(self):
        cn1 = fake_compute_obj.obj_clone()
        cn1._context = self.context
        cn1.create()

        db.compute_node_update(self.context, cn1.id,
                               {'cpu_allocation_ratio': 32.0,
                                'ram_allocation_ratio': 4.0,
                                'disk_allocation_ratio': 3.0})

        res = compute_node.migrate_empty_ratio(self.context, 1)
        # the non-empty ratio will not be refreshed
        self.assertEqual(res, (0, 0))

        cns = db.compute_node_get_all(self.context)
        for cn in cns:
            self.assertEqual(32.0, cn['cpu_allocation_ratio'])
            self.assertEqual(4.0, cn['ram_allocation_ratio'])
            self.assertEqual(3.0, cn['disk_allocation_ratio'])
Beispiel #5
0
    def test_ratio_online_migration_when_load(self):
        # set cpu and disk, and leave ram unset(None)
        self.flags(cpu_allocation_ratio=1.0)
        self.flags(disk_allocation_ratio=2.0)

        self._create_zero_and_none_cn()

        # trigger online migration
        objects.ComputeNodeList.get_all(self.context)

        cns = db.compute_node_get_all(self.context)

        for cn in cns:
            # the cpu/disk ratio is refreshed to CONF.xxx_allocation_ratio
            self.assertEqual(CONF.cpu_allocation_ratio,
                             cn['cpu_allocation_ratio'])
            self.assertEqual(CONF.disk_allocation_ratio,
                             cn['disk_allocation_ratio'])
            # the ram ratio is refreshed to CONF.initial_xxx_allocation_ratio
            self.assertEqual(CONF.initial_ram_allocation_ratio,
                             cn['ram_allocation_ratio'])
Beispiel #6
0
    def test_ratio_online_migration_when_load(self):
        # set cpu and disk, and leave ram unset(None)
        self.flags(cpu_allocation_ratio=1.0)
        self.flags(disk_allocation_ratio=2.0)

        self._create_zero_and_none_cn()

        # trigger online migration
        objects.ComputeNodeList.get_all(self.context)

        cns = db.compute_node_get_all(self.context)

        for cn in cns:
            # the cpu/disk ratio is refreshed to CONF.xxx_allocation_ratio
            self.assertEqual(CONF.cpu_allocation_ratio,
                             cn['cpu_allocation_ratio'])
            self.assertEqual(CONF.disk_allocation_ratio,
                             cn['disk_allocation_ratio'])
            # the ram ratio is refreshed to CONF.initial_xxx_allocation_ratio
            self.assertEqual(CONF.initial_ram_allocation_ratio,
                             cn['ram_allocation_ratio'])
Beispiel #7
0
 def get_all(cls, context):
     db_computes = db.compute_node_get_all(context)
     return base.obj_make_list(context, cls(context), objects.ComputeNode,
                               db_computes)