Exemplo n.º 1
0
    def test_calculate_desired_percentage_negative(self):
        # CHANGE_IN_PERCENTAGE, negative
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -10, None)
        self.assertEqual(9, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -15, None)
        self.assertEqual(9, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -22, None)
        self.assertEqual(8, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -1, None)
        self.assertEqual(9, res)
Exemplo n.º 2
0
    def test_calculate_desired_percentage_negative(self):
        # CHANGE_IN_PERCENTAGE, negative
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -10, None)
        self.assertEqual(9, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -15, None)
        self.assertEqual(9, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -22, None)
        self.assertEqual(8, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -1, None)
        self.assertEqual(9, res)
Exemplo n.º 3
0
    def test_calculate_desired_percentage_positive(self):
        # CHANGE_IN_PERCENTAGE, positive
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 10, None)
        self.assertEqual(11, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 15, None)
        self.assertEqual(11, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 22, None)
        self.assertEqual(12, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 1, None)
        self.assertEqual(11, res)
Exemplo n.º 4
0
    def test_calculate_desired_percentage_positive(self):
        # CHANGE_IN_PERCENTAGE, positive
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 10, None)
        self.assertEqual(11, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 15, None)
        self.assertEqual(11, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 22, None)
        self.assertEqual(12, res)

        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 1, None)
        self.assertEqual(11, res)
Exemplo n.º 5
0
    def do_resize(self):
        adj_type = self.inputs.get(consts.ADJUSTMENT_TYPE, None)
        number = self.inputs.get(consts.ADJUSTMENT_NUMBER, None)
        min_size = self.inputs.get(consts.ADJUSTMENT_MIN_SIZE, None)
        max_size = self.inputs.get(consts.ADJUSTMENT_MAX_SIZE, None)
        min_step = self.inputs.get(consts.ADJUSTMENT_MIN_STEP, None)
        strict = self.inputs.get(consts.ADJUSTMENT_STRICT, False)

        desired = self.cluster.desired_capacity
        if adj_type is not None:
            # number must be not None according to previous tests
            desired = scaleutils.calculate_desired(
                desired, adj_type, number, min_step)

        # truncate adjustment if permitted (strict==False)
        if strict is False:
            desired = scaleutils.truncate_desired(
                self.cluster, desired, min_size, max_size)

        # check provided params against current properties
        # desired is checked when strict is True
        result = scaleutils.check_size_params(self.cluster, desired, min_size,
                                              max_size, strict)
        if result != '':
            return self.RES_ERROR, result

        # save sanitized properties
        self._update_cluster_properties(desired, min_size, max_size)
        node_list = self.cluster.nodes
        current_size = len(node_list)

        # delete nodes if necessary
        if desired < current_size:
            adjustment = current_size - desired
            if 'deletion' not in self.data:
                self.data['deletion'] = {'count': adjustment}
            candidates = []
            # Choose victims randomly
            i = adjustment
            while i > 0:
                r = random.randrange(len(node_list))
                candidates.append(node_list[r].id)
                node_list.remove(node_list[r])
                i = i - 1

            result, reason = self._delete_nodes(candidates)
            if result != self.RES_OK:
                return result, reason

        # Create new nodes if desired_capacity increased
        if desired > current_size:
            delta = desired - current_size
            self.data['creation'] = {'count': delta}
            result, reason = self._create_nodes(delta)
            if result != self.RES_OK:
                return result, reason

        reason = _('Cluster resize succeeded.')
        self.cluster.set_status(self.context, self.cluster.ACTIVE, reason)
        return self.RES_OK, reason
Exemplo n.º 6
0
 def test_calculate_desired_capacity(self):
     # CHANGE_IN_CAPACITY
     for i in range(10):
         current = self.getUniqueInteger()
         for j in range(10):
             number = self.getUniqueInteger()
             res = su.calculate_desired(current, consts.CHANGE_IN_CAPACITY,
                                        number, None)
             self.assertEqual(current + number, res)
Exemplo n.º 7
0
 def test_calculate_desired_capacity(self):
     # CHANGE_IN_CAPACITY
     for i in range(10):
         current = self.getUniqueInteger()
         for j in range(10):
             number = self.getUniqueInteger()
             res = su.calculate_desired(current, consts.CHANGE_IN_CAPACITY,
                                        number, None)
             self.assertEqual(current+number, res)
Exemplo n.º 8
0
    def test_calculate_desired_percentage_with_min_step(self):
        # CHANGE_IN_PERCENTAGE, with min_step 0
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 10, 0)
        self.assertEqual(11, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -10, 0)
        self.assertEqual(9, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 1, 0)
        self.assertEqual(11, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -1, 0)
        self.assertEqual(9, res)

        # CHANGE_IN_PERCENTAGE, with min_step 1
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 10, 1)
        self.assertEqual(11, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -10, 1)
        self.assertEqual(9, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 1, 1)
        self.assertEqual(11, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -1, 1)
        self.assertEqual(9, res)

        # CHANGE_IN_PERCENTAGE, with min_step 2
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 10, 2)
        self.assertEqual(12, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -10, 2)
        self.assertEqual(8, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 1, 2)
        self.assertEqual(12, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -1, 2)
        self.assertEqual(8, res)
Exemplo n.º 9
0
 def test_calculate_desired_exact(self):
     # EXACT_CAPACITY
     for i in range(10):
         desired = self.getUniqueInteger()
         res = su.calculate_desired(0, consts.EXACT_CAPACITY, desired, None)
         self.assertEqual(desired, res)
Exemplo n.º 10
0
    def test_calculate_desired_percentage_with_min_step(self):
        # CHANGE_IN_PERCENTAGE, with min_step 0
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 10, 0)
        self.assertEqual(11, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -10, 0)
        self.assertEqual(9, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 1, 0)
        self.assertEqual(11, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -1, 0)
        self.assertEqual(9, res)

        # CHANGE_IN_PERCENTAGE, with min_step 1
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 10, 1)
        self.assertEqual(11, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -10, 1)
        self.assertEqual(9, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 1, 1)
        self.assertEqual(11, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -1, 1)
        self.assertEqual(9, res)

        # CHANGE_IN_PERCENTAGE, with min_step 2
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 10, 2)
        self.assertEqual(12, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -10, 2)
        self.assertEqual(8, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, 1, 2)
        self.assertEqual(12, res)
        res = su.calculate_desired(10, consts.CHANGE_IN_PERCENTAGE, -1, 2)
        self.assertEqual(8, res)
Exemplo n.º 11
0
 def test_calculate_desired_exact(self):
     # EXACT_CAPACITY
     for i in range(10):
         desired = self.getUniqueInteger()
         res = su.calculate_desired(0, consts.EXACT_CAPACITY, desired, None)
         self.assertEqual(desired, res)