New method to calculate replicas for armada apps

Introduces _num_replicas_for_platform_app as a replacement
for _num_provisioned_controllers which is used to set the
number of replicas used by an platform armada application.

The new method will use the same unrderlying logic but will
never return a value less than 1. This will prevent having
the replicas set to 0 when there are no provisioned
controllers.

Tested with unit tests and by checking the replica count
after a host lock/unlock cycle.

Partial-Bug: 1922278
Signed-off-by: Isac Souza <IsacSacchi.Souza@windriver.com>
Change-Id: If322ff5d02996c9b853bc350244899c5e22431a2
This commit is contained in:
Isac Souza 2021-04-01 12:20:35 -03:00
parent 7ce5367d57
commit 1128b30ce6
2 changed files with 46 additions and 0 deletions

View File

@ -240,6 +240,20 @@ class BaseHelm(object):
constants.AVAILABILITY_DEGRADED],
vim_progress_status=constants.VIM_SERVICES_ENABLED)
def _num_replicas_for_platform_app(self):
"""
Returns the number of replicas that should be used by
platform managed applications. This method will return
the number of provisioned controllers, with a minimum of 1.
It takes care of the case where one controller is provisioned
and the other is installed but not provisioned. When the second
controller is provisioned, the unlock will check if the
overrides are different and reapply platform managed
applications appropriately
"""
return max(1, self._num_provisioned_controllers())
def _get_address_by_name(self, name, networktype):
"""
Retrieve an address entry by name and scoped by network type

View File

@ -0,0 +1,32 @@
# Copyright (c) 2021 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import mock
from sysinv.helm.base import BaseHelm
from sysinv.helm.helm import HelmOperator
from sysinv.tests import base as test_base
class TestHelmBase(test_base.TestCase):
def test_num_replicas_for_platform_app_0_controllers(self):
self.check_num_replicas_for_platform_app(num_provisioned_controllers=0, expected_replicas=1)
def test_num_replicas_for_platform_app_1_controllers(self):
self.check_num_replicas_for_platform_app(num_provisioned_controllers=1, expected_replicas=1)
def test_num_replicas_for_platform_app_2_controllers(self):
self.check_num_replicas_for_platform_app(num_provisioned_controllers=2, expected_replicas=2)
def check_num_replicas_for_platform_app(self, num_provisioned_controllers, expected_replicas):
mock_operator = mock.MagicMock(spec=HelmOperator)
mock_operator.dbapi = mock.MagicMock()
mock_operator.dbapi.count_hosts_matching_criteria.return_value = num_provisioned_controllers
base = BaseHelm(mock_operator)
actual_replicas = base._num_replicas_for_platform_app()
self.assertEqual(actual_replicas, expected_replicas)