Set 'deployed_before' attribute in cluster attributes if not present
Before this change if master node had been upgraded to Fuel of versions >= 8.0, attempt to re/deploy existing clusters would have failed as attributes of those clusters would have lack 'deployed_before' field. Since processing of the flag is temporary solution it should not be coded in data base migration logic. Thus the change introduces creating of the attribute with given value if it is not already present. Change-Id: I302ddb340d2ecf14b1fa414fda71aa7f32363bdf Closes-Bug: #1551339
This commit is contained in:
parent
fb12cc5b22
commit
cfa146e9dd
|
@ -338,7 +338,12 @@ class ClusterStopDeploymentValidator(base.BaseDefferedTaskValidator):
|
|||
# FIXME(aroma): remove when stop action will be reworked for ha
|
||||
# cluster. To get more details, please, refer to [1]
|
||||
# [1]: https://bugs.launchpad.net/fuel/+bug/1529691
|
||||
if cluster.attributes.generated['deployed_before']['value']:
|
||||
# NOTE(aroma): the check must regard the case when stop deployment
|
||||
# is called for cluster that was created before master node upgrade
|
||||
# to versions >= 8.0 and so having 'deployed_before' flag absent
|
||||
# in their attributes.
|
||||
generated = cluster.attributes.generated
|
||||
if generated.get('deployed_before', {}).get('value'):
|
||||
raise errors.CannotBeStopped()
|
||||
|
||||
|
||||
|
|
|
@ -1403,15 +1403,20 @@ class Cluster(NailgunObject):
|
|||
:param value: new value for flag
|
||||
:type value: bool
|
||||
"""
|
||||
if instance.attributes.generated['deployed_before']['value'] != value:
|
||||
# TODO(aroma): remove unnecessary copying when enhancement
|
||||
# of Mutable types will be introduced for corresponding
|
||||
# fields of ORM models
|
||||
generated_attrs = copy.deepcopy(instance.attributes.generated)
|
||||
generated_attrs['deployed_before']['value'] = value
|
||||
instance.attributes.generated = generated_attrs
|
||||
generated = copy.deepcopy(instance.attributes.generated)
|
||||
|
||||
db.flush()
|
||||
if 'deployed_before' not in generated:
|
||||
# NOTE(aroma): this is needed for case when master node has
|
||||
# been upgraded and there is attempt to re/deploy previously
|
||||
# existing clusters. As long as setting the flag is temporary
|
||||
# solution data base migration code should not be mangled
|
||||
# in order to support it
|
||||
generated['deployed_before'] = {'value': value}
|
||||
elif generated['deployed_before']['value'] != value:
|
||||
generated['deployed_before']['value'] = value
|
||||
|
||||
instance.attributes.generated = generated
|
||||
db.flush()
|
||||
|
||||
@classmethod
|
||||
def get_nodes_count_unmet_status(cls, instance, status):
|
||||
|
|
|
@ -139,16 +139,33 @@ class TestClusterValidator(BaseTestCase):
|
|||
|
||||
class TestClusterStopDeploymentValidator(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestClusterStopDeploymentValidator, self).setUp()
|
||||
self.cluster = self.env.create_cluster(api=False)
|
||||
|
||||
# FIXME(aroma): remove this test when stop action will be reworked for ha
|
||||
# cluster. To get more details, please, refer to [1]
|
||||
# [1]: https://bugs.launchpad.net/fuel/+bug/1529691
|
||||
def test_stop_deployment_failed_for_once_deployed_cluster(self):
|
||||
cluster = self.env.create_cluster(api=False)
|
||||
|
||||
objects.Cluster.set_deployed_before_flag(cluster, value=True)
|
||||
objects.Cluster.set_deployed_before_flag(self.cluster, value=True)
|
||||
|
||||
self.assertRaises(
|
||||
errors.CannotBeStopped,
|
||||
ClusterStopDeploymentValidator.validate,
|
||||
cluster
|
||||
self.cluster
|
||||
)
|
||||
|
||||
# FIXME(aroma): remove this test when stop action will be reworked for ha
|
||||
# cluster. To get more details, please, refer to [1]
|
||||
# [1]: https://bugs.launchpad.net/fuel/+bug/1529691
|
||||
def test_no_key_error_if_deployed_before_is_absent(self):
|
||||
# 'deployed_before' is absent in attributes of clusters
|
||||
# that was created before upgrading of master node to
|
||||
# Fuel w/ versions >= 8.0
|
||||
|
||||
del self.cluster.attributes.generated['deployed_before']
|
||||
self.assertNotRaises(
|
||||
KeyError,
|
||||
ClusterStopDeploymentValidator.validate,
|
||||
self.cluster
|
||||
)
|
||||
|
|
|
@ -1110,6 +1110,8 @@ class TestClusterObject(BaseTestCase):
|
|||
# cluster. To get more details, please, refer to [1]
|
||||
# [1]: https://bugs.launchpad.net/fuel/+bug/1529691
|
||||
def test_set_deployed_before_flag(self):
|
||||
# for new clusters that are created by Fuel of version >= 8.0
|
||||
# the flag is set to False by default
|
||||
self.assertFalse(
|
||||
self.cluster.attributes.generated['deployed_before']['value'])
|
||||
|
||||
|
@ -1124,14 +1126,29 @@ class TestClusterObject(BaseTestCase):
|
|||
self.cluster.attributes.generated['deployed_before']['value'])
|
||||
|
||||
# check that flag is not changed when same value is given
|
||||
# and interaction w/ db is not performed
|
||||
with mock.patch.object(self.db, 'flush') as m_flush:
|
||||
objects.Cluster.set_deployed_before_flag(self.cluster,
|
||||
value=False)
|
||||
self.assertFalse(
|
||||
self.cluster.attributes.generated['deployed_before']['value'])
|
||||
objects.Cluster.set_deployed_before_flag(self.cluster, value=False)
|
||||
self.assertFalse(
|
||||
self.cluster.attributes.generated['deployed_before']['value'])
|
||||
|
||||
m_flush.assert_not_called()
|
||||
# FIXME(aroma): remove this test when stop action will be reworked for ha
|
||||
# cluster. To get more details, please, refer to [1]
|
||||
# [1]: https://bugs.launchpad.net/fuel/+bug/1529691
|
||||
def test_set_deployed_before_flag_if_it_is_not_in_generated(self):
|
||||
# there will be no 'deployed_before' attribute present in
|
||||
# existing clusters' attributes after master node upgrade to Fuel of
|
||||
# versions >= 8.0 so it must be set in such case by the method under
|
||||
# the test
|
||||
|
||||
def check_flag_set(value):
|
||||
del self.cluster.attributes.generated['deployed_before']
|
||||
objects.Cluster.set_deployed_before_flag(self.cluster, value)
|
||||
self.assertEqual(
|
||||
self.cluster.attributes.generated['deployed_before']['value'],
|
||||
value
|
||||
)
|
||||
|
||||
for value in (True, False):
|
||||
check_flag_set(value)
|
||||
|
||||
def test_network_defaults(self):
|
||||
cluster = objects.Cluster.get_by_uid(self.env.create(api=True)['id'])
|
||||
|
|
Loading…
Reference in New Issue