Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
ee7a5369
Commit
ee7a5369
authored
4 years ago
by
Nick Ethier
Browse files
Options
Download
Email Patches
Plain Diff
scheduler: add tests and fix for detected host_network and to port field changes
parent
caa21c23
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scheduler/util.go
+16
-6
scheduler/util.go
scheduler/util_test.go
+57
-0
scheduler/util_test.go
with
73 additions
and
6 deletions
+73
-6
scheduler/util.go
+
16
-
6
View file @
ee7a5369
...
...
@@ -534,16 +534,26 @@ func networkUpdated(netA, netB []*structs.NetworkResource) bool {
return
false
}
// networkPortMap takes a network resource and returns a
map of port labels to
//
values.
The value for dynamic ports is disregarded even if it is set. This
// networkPortMap takes a network resource and returns a
AllocatedPorts.
// The value for dynamic ports is disregarded even if it is set. This
// makes this function suitable for comparing two network resources for changes.
func
networkPortMap
(
n
*
structs
.
NetworkResource
)
map
[
string
]
int
{
m
:=
make
(
map
[
string
]
int
,
len
(
n
.
DynamicPorts
)
+
len
(
n
.
Reserv
edPorts
))
func
networkPortMap
(
n
*
structs
.
NetworkResource
)
structs
.
AllocatedPorts
{
var
m
structs
.
Allocat
edPorts
for
_
,
p
:=
range
n
.
ReservedPorts
{
m
[
p
.
Label
]
=
p
.
Value
m
=
append
(
m
,
structs
.
AllocatedPortMapping
{
Label
:
p
.
Label
,
Value
:
p
.
Value
,
To
:
p
.
To
,
HostIP
:
p
.
HostNetwork
,
})
}
for
_
,
p
:=
range
n
.
DynamicPorts
{
m
[
p
.
Label
]
=
-
1
m
=
append
(
m
,
structs
.
AllocatedPortMapping
{
Label
:
p
.
Label
,
Value
:
-
1
,
To
:
p
.
To
,
HostIP
:
p
.
HostNetwork
,
})
}
return
m
}
...
...
This diff is collapsed.
Click to expand it.
scheduler/util_test.go
+
57
-
0
View file @
ee7a5369
...
...
@@ -762,6 +762,63 @@ func TestTasksUpdated_connectServiceUpdated(t *testing.T) {
})
}
func
TestNetworkUpdated
(
t
*
testing
.
T
)
{
t
.
Parallel
()
cases
:=
[]
struct
{
name
string
a
[]
*
structs
.
NetworkResource
b
[]
*
structs
.
NetworkResource
updated
bool
}{
{
name
:
"mode updated"
,
a
:
[]
*
structs
.
NetworkResource
{
{
Mode
:
"host"
},
},
b
:
[]
*
structs
.
NetworkResource
{
{
Mode
:
"bridge"
},
},
updated
:
true
,
},
{
name
:
"host_network updated"
,
a
:
[]
*
structs
.
NetworkResource
{
{
DynamicPorts
:
[]
structs
.
Port
{
{
Label
:
"http"
,
To
:
8080
},
}},
},
b
:
[]
*
structs
.
NetworkResource
{
{
DynamicPorts
:
[]
structs
.
Port
{
{
Label
:
"http"
,
To
:
8080
,
HostNetwork
:
"public"
},
}},
},
updated
:
true
,
},
{
name
:
"port.To updated"
,
a
:
[]
*
structs
.
NetworkResource
{
{
DynamicPorts
:
[]
structs
.
Port
{
{
Label
:
"http"
,
To
:
8080
},
}},
},
b
:
[]
*
structs
.
NetworkResource
{
{
DynamicPorts
:
[]
structs
.
Port
{
{
Label
:
"http"
,
To
:
8088
},
}},
},
updated
:
true
,
},
}
for
i
:=
range
cases
{
c
:=
cases
[
i
]
t
.
Run
(
c
.
name
,
func
(
tc
*
testing
.
T
)
{
tc
.
Parallel
()
require
.
Equal
(
tc
,
c
.
updated
,
networkUpdated
(
c
.
a
,
c
.
b
),
"unexpected network updated result"
)
})
}
}
func
TestEvictAndPlace_LimitLessThanAllocs
(
t
*
testing
.
T
)
{
_
,
ctx
:=
testContext
(
t
)
allocs
:=
[]
allocTuple
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment