Generalize exceptions & structure of strategies
Many strategies execute very similar statements especially in pre_execute and some might raise errors that others might not. This same pattern of many similar statements can also be observed in strategies their tests. This patch addresses these issues, firstly; the BaseStrategy class gets 1 additional method _pre_execute which allows for general logic that most strategies perform at that stage. This method can be executed before the similarly named method of the superclass. A notable change is that _pre_execute now handles common exception handling for ClusterStateStale & ClusterStateNotDefined exceptions. A similar pattern is applied to the test classes of the strategies each of these classes now inherits from the TestBaseStrategy class. This class provides the common attributes almost every test class for the strategies requires such as: The mocked compute_model, mocked audit_scope and an instance of FakerModelCollector. Finally, some minor changes were required in test_strategy_context & test_audit_handlers and exceptions around 0 nodes in cluster or storage are removed. Change-Id: Ia7154376b2448aac65cf17999cc8c3e1c8309b5b
This commit is contained in:
@@ -290,8 +290,8 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
|
||||
return normalized_hosts
|
||||
|
||||
def get_available_nodes(self):
|
||||
return {node_uuid: node for node_uuid, node in
|
||||
self.compute_model.get_all_compute_nodes().items()
|
||||
nodes = self.compute_model.get_all_compute_nodes().items()
|
||||
return {node_uuid: node for node_uuid, node in nodes
|
||||
if node.state == element.ServiceState.ONLINE.value and
|
||||
node.status == element.ServiceState.ENABLED.value}
|
||||
|
||||
@@ -506,14 +506,7 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
|
||||
return self.solution
|
||||
|
||||
def pre_execute(self):
|
||||
LOG.info("Initializing Workload Stabilization")
|
||||
|
||||
if not self.compute_model:
|
||||
raise exception.ClusterStateNotDefined()
|
||||
|
||||
if self.compute_model.stale:
|
||||
raise exception.ClusterStateStale()
|
||||
|
||||
self._pre_execute()
|
||||
self.weights = self.input_parameters.weights
|
||||
self.metrics = self.input_parameters.metrics
|
||||
self.thresholds = self.input_parameters.thresholds
|
||||
|
||||
Reference in New Issue
Block a user