@@ -54,8 +54,11 @@ var _ = Describe("UpdateStatus", func() {
5454 BeforeEach (func () {
5555 ctx = suite .NewTestContextForVCSim (builder.VCSimTestConfig {})
5656
57+ nsInfo := ctx .CreateWorkloadNamespace ()
58+
5759 vm := builder .DummyVirtualMachine ()
5860 vm .Name = "update-status-test"
61+ vm .Namespace = nsInfo .Namespace
5962
6063 vmCtx = pkgctx.VirtualMachineContext {
6164 Context : ctx ,
@@ -67,6 +70,14 @@ var _ = Describe("UpdateStatus", func() {
6770 vcVM , err = ctx .Finder .VirtualMachine (ctx , "DC0_C0_RP0_VM0" )
6871 Expect (err ).ToNot (HaveOccurred ())
6972
73+ nsRP := ctx .GetResourcePoolForNamespace (nsInfo .Namespace , "" , "" )
74+ task , err := vcVM .Relocate (ctx , vimtypes.VirtualMachineRelocateSpec {
75+ Folder : ptr .To (nsInfo .Folder .Reference ()),
76+ Pool : ptr .To (nsRP .Reference ()),
77+ }, vimtypes .VirtualMachineMovePriorityDefaultPriority )
78+ Expect (err ).ToNot (HaveOccurred ())
79+ Expect (task .Wait (ctx )).To (Succeed ())
80+
7081 // Initialize with the expected properties. Tests can overwrite this if needed.
7182 Expect (vcVM .Properties (
7283 ctx ,
@@ -2470,6 +2481,79 @@ var _ = Describe("UpdateStatus", func() {
24702481 })
24712482 })
24722483
2484+ Context ("Zone" , func () {
2485+ var zoneName string
2486+
2487+ BeforeEach (func () {
2488+ delete (vmCtx .VM .Labels , corev1 .LabelTopologyZone )
2489+ vmCtx .VM .Status .Zone = ""
2490+
2491+ zoneName = ctx .GetFirstZoneName ()
2492+ })
2493+
2494+ assertZones := func () {
2495+ GinkgoHelper ()
2496+ Expect (vmCtx .VM .Labels ).To (HaveKeyWithValue (corev1 .LabelTopologyZone , zoneName ))
2497+ Expect (vmCtx .VM .Status .Zone ).To (Equal (zoneName ))
2498+ }
2499+
2500+ Context ("Neither label and status are set" , func () {
2501+ It ("Sets Zone" , assertZones )
2502+ })
2503+
2504+ Context ("Label and status are both set" , func () {
2505+ BeforeEach (func () {
2506+ vmCtx .VM .Labels [corev1 .LabelTopologyZone ] = zoneName
2507+ vmCtx .VM .Status .Zone = zoneName
2508+ })
2509+ It ("Zone still set" , assertZones )
2510+ })
2511+
2512+ Context ("Label is set but status is not" , func () {
2513+ BeforeEach (func () {
2514+ vmCtx .VM .Labels [corev1 .LabelTopologyZone ] = zoneName
2515+ })
2516+ It ("Sets Zone" , assertZones )
2517+ })
2518+
2519+ Context ("Label is not set but status is" , func () {
2520+ BeforeEach (func () {
2521+ vmCtx .VM .Status .Zone = zoneName
2522+ })
2523+ It ("Sets Zone" , assertZones )
2524+ })
2525+
2526+ Context ("Label is not set but status is" , func () {
2527+ BeforeEach (func () {
2528+ vmCtx .VM .Status .Zone = zoneName
2529+ })
2530+ It ("Sets Zone" , assertZones )
2531+ })
2532+
2533+ Context ("Label is not set but status is" , func () {
2534+ BeforeEach (func () {
2535+ vmCtx .VM .Status .Zone = zoneName
2536+ })
2537+ It ("Sets Zone" , assertZones )
2538+ })
2539+
2540+ Context ("Label is set to incorrect value" , func () {
2541+ BeforeEach (func () {
2542+ vmCtx .VM .Labels [corev1 .LabelTopologyZone ] = "bogus"
2543+ vmCtx .VM .Status .Zone = zoneName
2544+ })
2545+ It ("Sets Zone" , assertZones )
2546+ })
2547+
2548+ Context ("Status is set to incorrect value" , func () {
2549+ BeforeEach (func () {
2550+ vmCtx .VM .Labels [corev1 .LabelTopologyZone ] = zoneName
2551+ vmCtx .VM .Status .Zone = "bogus"
2552+ })
2553+ It ("Sets Zone" , assertZones )
2554+ })
2555+ })
2556+
24732557 Context ("Controllers" , func () {
24742558 When ("moVM.Config is nil" , func () {
24752559 BeforeEach (func () {
0 commit comments