Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
b3738a0c
Unverified
Commit
b3738a0c
authored
6 years ago
by
Preetha Appan
Browse files
Options
Download
Email Patches
Plain Diff
unit test plan apply with preemptions
parent
35d31f8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nomad/plan_apply.go
+3
-2
nomad/plan_apply.go
nomad/plan_apply_test.go
+115
-0
nomad/plan_apply_test.go
with
118 additions
and
2 deletions
+118
-2
nomad/plan_apply.go
+
3
-
2
View file @
b3738a0c
...
...
@@ -187,7 +187,7 @@ func (p *planner) applyPlan(plan *structs.Plan, result *structs.PlanResult, snap
alloc
.
ModifyTime
=
now
}
// Set
create and
modify time for preempted allocs if any
// Set modify time for preempted allocs if any
// Also gather jobids to create follow up evals
preemptedJobIDs
:=
make
(
map
[
structs
.
NamespacedID
]
struct
{})
for
_
,
alloc
:=
range
req
.
NodePreemptions
{
...
...
@@ -358,9 +358,10 @@ func evaluatePlanPlacements(pool *EvaluatePool, snap *state.StateSnapshot, plan
}
if
nodePreemptions
:=
plan
.
NodePreemptions
[
nodeID
];
nodePreemptions
!=
nil
{
var
filteredNodePreemptions
[]
*
structs
.
Allocation
// Do a pass over preempted allocs in the plan to check
// whether the alloc is already in a terminal state
var
filteredNodePreemptions
[]
*
structs
.
Allocation
for
_
,
preemptedAlloc
:=
range
nodePreemptions
{
alloc
,
err
:=
snap
.
AllocByID
(
nil
,
preemptedAlloc
.
ID
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
nomad/plan_apply_test.go
+
115
-
0
View file @
b3738a0c
...
...
@@ -12,6 +12,7 @@ import (
"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/raft"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const
(
...
...
@@ -271,6 +272,120 @@ func TestPlanApply_EvalPlan_Simple(t *testing.T) {
}
}
func
TestPlanApply_EvalPlan_Preemption
(
t
*
testing
.
T
)
{
t
.
Parallel
()
state
:=
testStateStore
(
t
)
node
:=
mock
.
Node
()
node
.
NodeResources
=
&
structs
.
NodeResources
{
Cpu
:
structs
.
NodeCpuResources
{
CpuShares
:
2000
,
},
Memory
:
structs
.
NodeMemoryResources
{
MemoryMB
:
4192
,
},
Disk
:
structs
.
NodeDiskResources
{
DiskMB
:
30
*
1024
,
},
Networks
:
[]
*
structs
.
NetworkResource
{
{
Device
:
"eth0"
,
CIDR
:
"192.168.0.100/32"
,
MBits
:
1000
,
},
},
}
state
.
UpsertNode
(
1000
,
node
)
preemptedAlloc
:=
mock
.
Alloc
()
preemptedAlloc
.
NodeID
=
node
.
ID
preemptedAlloc
.
AllocatedResources
=
&
structs
.
AllocatedResources
{
Shared
:
structs
.
AllocatedSharedResources
{
DiskMB
:
25
*
1024
,
},
Tasks
:
map
[
string
]
*
structs
.
AllocatedTaskResources
{
"web"
:
{
Cpu
:
structs
.
AllocatedCpuResources
{
CpuShares
:
1500
,
},
Memory
:
structs
.
AllocatedMemoryResources
{
MemoryMB
:
4000
,
},
Networks
:
[]
*
structs
.
NetworkResource
{
{
Device
:
"eth0"
,
IP
:
"192.168.0.100"
,
ReservedPorts
:
[]
structs
.
Port
{{
Label
:
"admin"
,
Value
:
5000
}},
MBits
:
800
,
DynamicPorts
:
[]
structs
.
Port
{{
Label
:
"http"
,
Value
:
9876
}},
},
},
},
},
}
// Insert a preempted alloc such that the alloc will fit only after preemption
state
.
UpsertAllocs
(
1001
,
[]
*
structs
.
Allocation
{
preemptedAlloc
})
alloc
:=
mock
.
Alloc
()
alloc
.
AllocatedResources
=
&
structs
.
AllocatedResources
{
Shared
:
structs
.
AllocatedSharedResources
{
DiskMB
:
24
*
1024
,
},
Tasks
:
map
[
string
]
*
structs
.
AllocatedTaskResources
{
"web"
:
{
Cpu
:
structs
.
AllocatedCpuResources
{
CpuShares
:
1500
,
},
Memory
:
structs
.
AllocatedMemoryResources
{
MemoryMB
:
3200
,
},
Networks
:
[]
*
structs
.
NetworkResource
{
{
Device
:
"eth0"
,
IP
:
"192.168.0.100"
,
ReservedPorts
:
[]
structs
.
Port
{{
Label
:
"admin"
,
Value
:
5000
}},
MBits
:
800
,
DynamicPorts
:
[]
structs
.
Port
{{
Label
:
"http"
,
Value
:
9876
}},
},
},
},
},
}
plan
:=
&
structs
.
Plan
{
Job
:
alloc
.
Job
,
NodeAllocation
:
map
[
string
][]
*
structs
.
Allocation
{
node
.
ID
:
{
alloc
},
},
NodePreemptions
:
map
[
string
][]
*
structs
.
Allocation
{
node
.
ID
:
{
preemptedAlloc
},
},
Deployment
:
mock
.
Deployment
(),
DeploymentUpdates
:
[]
*
structs
.
DeploymentStatusUpdate
{
{
DeploymentID
:
uuid
.
Generate
(),
Status
:
"foo"
,
StatusDescription
:
"bar"
,
},
},
}
snap
,
_
:=
state
.
Snapshot
()
pool
:=
NewEvaluatePool
(
workerPoolSize
,
workerPoolBufferSize
)
defer
pool
.
Shutdown
()
result
,
err
:=
evaluatePlan
(
pool
,
snap
,
plan
,
testlog
.
HCLogger
(
t
))
require
:=
require
.
New
(
t
)
require
.
NoError
(
err
)
require
.
NotNil
(
result
)
require
.
Equal
(
result
.
NodeAllocation
,
plan
.
NodeAllocation
)
require
.
Equal
(
result
.
Deployment
,
plan
.
Deployment
)
require
.
Equal
(
result
.
DeploymentUpdates
,
plan
.
DeploymentUpdates
)
require
.
Equal
(
result
.
NodePreemptions
,
plan
.
NodePreemptions
)
}
func
TestPlanApply_EvalPlan_Partial
(
t
*
testing
.
T
)
{
t
.
Parallel
()
state
:=
testStateStore
(
t
)
...
...
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
Menu
Projects
Groups
Snippets
Help