[#306] netmap: Allow to select empty set of nodes
All checks were successful
Tests and linters / Lint (pull_request) Successful in 2m18s
DCO / DCO (pull_request) Successful in 2m19s
Tests and linters / Tests (pull_request) Successful in 2m21s

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-12-05 15:30:53 +03:00
parent 0352b5b191
commit f7da6ba99c
Signed by: fyrchik
SSH key fingerprint: SHA256:m/TTwCzjnRkXgnzEx9X92ccxy1CcVeinOgDb3NPWWmg
7 changed files with 43 additions and 15 deletions

View file

@ -114,7 +114,7 @@ func (c *context) getSelection(s netmap.Selector) ([]nodes, error) {
}
if len(res) < bucketCount {
if len(res) == 0 {
if c.strict && len(res) == 0 {
return nil, errNotEnoughNodes
}
bucketCount = len(res)

View file

@ -254,6 +254,39 @@ func TestPlacementPolicy_ProcessSelectors(t *testing.T) {
}
}
func TestPlacementPolicy_PartiallyMissingContainer(t *testing.T) {
s := `REP 2 IN D1OBJ
REP 2 IN D2OBJ
CBF 2
SELECT 2 FROM PRIMARY AS D1OBJ
SELECT 2 FROM SECONDARY AS D2OBJ
FILTER ClusterName EQ D1OBJ AS PRIMARY
FILTER ClusterName EQ D2OBJ AS SECONDARY`
var p PlacementPolicy
require.NoError(t, p.DecodeString(s))
nodes := []NodeInfo{
nodeInfoFromAttributes("ClusterName", "D1OBJ", "ID", "1"),
nodeInfoFromAttributes("ClusterName", "D1OBJ", "ID", "2"),
nodeInfoFromAttributes("ClusterName", "D1OBJ", "ID", "3"),
nodeInfoFromAttributes("ClusterName", "D1OBJ", "ID", "4"),
nodeInfoFromAttributes("ClusterName", "D1OBJ", "ID", "5"),
nodeInfoFromAttributes("ClusterName", "D1OBJ", "ID", "6"),
nodeInfoFromAttributes("ClusterName", "D1OBJ", "ID", "7"),
nodeInfoFromAttributes("ClusterName", "D1OBJ", "ID", "8"),
}
var nm NetMap
nm.SetNodes(nodes)
res, err := nm.ContainerNodes(p, nil)
require.NoError(t, err)
require.Len(t, res, 2)
require.Len(t, res[0], 4)
require.Len(t, res[1], 0)
}
func TestPlacementPolicy_Like(t *testing.T) {
nodes := []NodeInfo{
nodeInfoFromAttributes("Country", "Russia"),

View file

@ -84,8 +84,15 @@ func TestPlacementPolicy_Interopability(t *testing.T) {
t.Run(name, func(t *testing.T) {
v, err := nm.ContainerNodes(tt.Policy, tt.Pivot)
if tt.Result == nil {
require.Error(t, err)
require.Contains(t, err.Error(), tt.Error)
if tt.Error != "" {
require.Error(t, err)
require.Contains(t, err.Error(), tt.Error)
} else {
require.Len(t, v, tt.Policy.NumberOfReplicas())
for i := range v {
require.Len(t, v[i], 0)
}
}
} else {
require.NoError(t, err)
require.Equal(t, srcNodes, tc.Nodes)

View file

@ -107,7 +107,6 @@ tests:
op: EQ
value: Value2
filters: []
error: not enough nodes
bad rating:
policy:
replicas:
@ -157,7 +156,6 @@ tests:
op: EQ
value: Value2
filters: []
error: not enough nodes
bad param:
policy:
replicas:
@ -207,4 +205,3 @@ tests:
op: EQ
value: Value2
filters: []
error: not enough nodes

View file

@ -24,7 +24,6 @@ tests:
op: LE
value: '8'
filters: []
error: not enough nodes
non-empty string is not casted to a number:
policy:
replicas:
@ -42,4 +41,3 @@ tests:
op: GE
value: '0'
filters: []
error: not enough nodes

View file

@ -42,7 +42,6 @@ tests:
op: GE
value: '5'
filters: []
error: not enough nodes
GT true:
policy:
replicas:
@ -79,7 +78,6 @@ tests:
op: GT
value: '4'
filters: []
error: not enough nodes
LE true:
policy:
replicas:
@ -116,7 +114,6 @@ tests:
op: LE
value: '3'
filters: []
error: not enough nodes
LT true:
policy:
replicas:
@ -153,7 +150,6 @@ tests:
op: LT
value: '4'
filters: []
error: not enough nodes
EQ true:
policy:
replicas:
@ -190,7 +186,6 @@ tests:
op: EQ
value: China
filters: []
error: not enough nodes
NE true:
policy:
replicas:
@ -227,4 +222,3 @@ tests:
op: NE
value: Germany
filters: []
error: not enough nodes

View file

@ -45,4 +45,3 @@ tests:
op: EQ
value: Moon
filters: []
error: not enough nodes