Added default node filter
If graph does not contain node_filter the default filter will be used. this will help to improve UX when user works with graph concept. Change-Id: I237189436b4ed5dd64ef6d60a05c674d2f974eb4 Closes-Bug: 1630605
This commit is contained in:
parent
c910f056a9
commit
64fce52257
|
@ -131,7 +131,7 @@ class TestSequenceExecutorHandler(base.BaseIntegrationTest):
|
|||
self.cluster = self.env.create(
|
||||
cluster_kwargs={},
|
||||
nodes_kwargs=[
|
||||
{"status": consts.NODE_STATUSES.discover},
|
||||
{"status": consts.NODE_STATUSES.provisioned},
|
||||
],
|
||||
release_kwargs={
|
||||
'version': 'mitaka-9.0',
|
||||
|
|
|
@ -32,7 +32,7 @@ class TestGraphExecutorHandler(base.BaseIntegrationTest):
|
|||
self.cluster = self.env.create(
|
||||
cluster_kwargs={},
|
||||
nodes_kwargs=[
|
||||
{"status": consts.NODE_STATUSES.discover},
|
||||
{"status": consts.NODE_STATUSES.provisioned},
|
||||
],
|
||||
release_kwargs={
|
||||
'version': 'mitaka-9.0',
|
||||
|
|
|
@ -31,8 +31,8 @@ class TestTransactionManager(base.BaseIntegrationTest):
|
|||
self.cluster = self.env.create(
|
||||
cluster_kwargs={},
|
||||
nodes_kwargs=[
|
||||
{"status": consts.NODE_STATUSES.discover},
|
||||
{"status": consts.NODE_STATUSES.discover, "online": False},
|
||||
{"status": consts.NODE_STATUSES.provisioned},
|
||||
{"status": consts.NODE_STATUSES.provisioned, "online": False},
|
||||
],
|
||||
release_kwargs={
|
||||
'version': 'mitaka-9.0',
|
||||
|
@ -481,7 +481,9 @@ class TestTransactionManager(base.BaseIntegrationTest):
|
|||
@mock.patch('nailgun.transactions.manager.rpc')
|
||||
def test_execute_on_one_node(self, rpc_mock):
|
||||
node = self.env.create_node(
|
||||
cluster_id=self.cluster.id, pending_roles=["compute"])
|
||||
cluster_id=self.cluster.id, pending_roles=["compute"],
|
||||
status=consts.NODE_STATUSES.ready
|
||||
)
|
||||
|
||||
task = self.manager.execute(graphs=[
|
||||
{
|
||||
|
@ -585,7 +587,8 @@ class TestTransactionManager(base.BaseIntegrationTest):
|
|||
}))
|
||||
|
||||
node = self.env.create_node(
|
||||
cluster_id=self.cluster.id, roles=["controller"]
|
||||
cluster_id=self.cluster.id, roles=["controller"],
|
||||
status=consts.NODE_STATUSES.stopped
|
||||
)
|
||||
|
||||
task = self.manager.execute(graphs=[
|
||||
|
|
|
@ -358,6 +358,38 @@ class TestGetNodesToRun(BaseUnitTest):
|
|||
mock.ANY, 'id', []
|
||||
)
|
||||
|
||||
@mock.patch('nailgun.transactions.manager.objects')
|
||||
def test_default_node_filter(self, obj_mock):
|
||||
nodes_obj_mock = obj_mock.NodeCollection
|
||||
cluster = mock.MagicMock()
|
||||
nodes_list = [
|
||||
{
|
||||
'id': 1, 'pending_deletion': False, 'pending_addition': False,
|
||||
'status': 'provisioned', 'error_type': None
|
||||
},
|
||||
{
|
||||
'id': 2, 'pending_deletion': False, 'pending_addition': False,
|
||||
'status': 'ready', 'error_type': None
|
||||
},
|
||||
{
|
||||
'id': 3, 'pending_deletion': False, 'pending_addition': False,
|
||||
'status': 'stopped', 'error_type': None
|
||||
},
|
||||
{
|
||||
'id': 4, 'pending_deletion': True, 'pending_addition': False,
|
||||
'status': 'stopped', 'error_type': None
|
||||
},
|
||||
{
|
||||
'id': 5, 'pending_deletion': False, 'pending_addition': True,
|
||||
'status': 'stopped', 'error_type': None
|
||||
},
|
||||
]
|
||||
nodes_obj_mock.to_list.return_value = nodes_list
|
||||
manager._get_nodes_to_run(cluster, None)
|
||||
nodes_obj_mock.filter_by_list.assert_called_once_with(
|
||||
mock.ANY, 'id', [1, 2, 3]
|
||||
)
|
||||
|
||||
|
||||
class TestGetCurrentState(BaseUnitTest):
|
||||
def setUp(self):
|
||||
|
|
|
@ -43,6 +43,11 @@ _DEFAULT_NODE_ATTRIBUTES = {
|
|||
'on_stop': {'status': consts.NODE_STATUSES.stopped},
|
||||
}
|
||||
|
||||
_DEFAULT_NODE_FILTER = (
|
||||
"not $.pending_addition and not $.pending_deletion and "
|
||||
"($.status in [ready, provisioned, stopped] or $.error_type = 'deploy')"
|
||||
)
|
||||
|
||||
|
||||
def _get_node_attributes(graph, kind):
|
||||
r = get_in(graph, kind, 'node_attributes')
|
||||
|
@ -423,6 +428,9 @@ def _get_nodes_to_run(cluster, node_filter, ids=None):
|
|||
nodes = objects.NodeCollection.filter_by(
|
||||
None, cluster_id=cluster.id, online=True)
|
||||
|
||||
if node_filter is None:
|
||||
node_filter = _DEFAULT_NODE_FILTER
|
||||
|
||||
if ids is None and node_filter:
|
||||
logger.debug("applying nodes filter: %s", node_filter)
|
||||
# TODO(bgaifullin) Need to implement adapter for YAQL
|
||||
|
|
Loading…
Reference in New Issue