@@ -46,8 +46,17 @@ var _ = Describe("OpenStackMachine API validations", func() {
46
46
namespace = createNamespace ()
47
47
})
48
48
49
- It ("should allow the smallest permissible machine spec" , func () {
50
- Expect (k8sClient .Create (ctx , defaultMachine ())).To (Succeed (), "OpenStackMachine creation should succeed" )
49
+ It ("should allow to create a machine with correct spec" , func () {
50
+ machine := defaultMachine ()
51
+
52
+ By ("Creating the smallest permissible machine spec" )
53
+ Expect (k8sClient .Create (ctx , machine )).To (Succeed (), "OpenStackMachine creation should succeed" )
54
+
55
+ machine = defaultMachine ()
56
+ machine .Spec .IdentityRef = & infrav1.OpenStackIdentityReference {Name : "foobar" , CloudName : "staging" }
57
+
58
+ By ("Creating a machine with spec.identityRef" )
59
+ Expect (k8sClient .Create (ctx , machine )).To (Succeed (), "OpenStackMachine creation with spec.identityRef should succeed" )
51
60
})
52
61
53
62
It ("should only allow the providerID to be set once" , func () {
@@ -65,6 +74,29 @@ var _ = Describe("OpenStackMachine API validations", func() {
65
74
Expect (k8sClient .Update (ctx , machine )).NotTo (Succeed (), "Updating providerID should fail" )
66
75
})
67
76
77
+ It ("should allow the identityRef to be set several times" , func () {
78
+ machine := defaultMachine ()
79
+
80
+ By ("Creating a bare machine" )
81
+ Expect (k8sClient .Create (ctx , machine )).To (Succeed (), "OpenStackMachine creation should succeed" )
82
+
83
+ By ("Setting the identityRef" )
84
+ machine .Spec .IdentityRef = ptr .To (infrav1.OpenStackIdentityReference {Name : "foo" , CloudName : "staging" })
85
+ Expect (k8sClient .Update (ctx , machine )).To (Succeed (), "Setting the identityRef should succeed" )
86
+
87
+ By ("Updating the identityRef.Name" )
88
+ machine .Spec .IdentityRef = ptr .To (infrav1.OpenStackIdentityReference {Name : "bar" , CloudName : "staging" })
89
+ Expect (k8sClient .Update (ctx , machine )).To (Succeed (), "Updating the identityRef.Name should succeed" )
90
+
91
+ By ("Updating the identityRef.CloudName" )
92
+ machine .Spec .IdentityRef = ptr .To (infrav1.OpenStackIdentityReference {Name : "bar" , CloudName : "production" })
93
+ Expect (k8sClient .Update (ctx , machine )).To (Succeed (), "Updating the identityRef.CloudName should succeed" )
94
+
95
+ By ("Clearing the identityRef" )
96
+ machine .Spec .IdentityRef = nil
97
+ Expect (k8sClient .Update (ctx , machine )).To (Succeed (), "Clearing the identityRef should succeed" )
98
+ })
99
+
68
100
It ("should not allow server metadata to exceed 255 characters" , func () {
69
101
machine := defaultMachine ()
70
102
@@ -114,6 +146,28 @@ var _ = Describe("OpenStackMachine API validations", func() {
114
146
Expect (k8sClient .Create (ctx , machine )).NotTo (Succeed (), "Creating a machine with a zero size additional block device should fail" )
115
147
})
116
148
149
+ It ("should allow to create machine with spec.RootVolume and non-root device name in spec.AdditionalBlockDevices" , func () {
150
+ machine := defaultMachine ()
151
+ machine .Spec .RootVolume = & infrav1.RootVolume {SizeGiB : 50 , BlockDeviceVolume : infrav1.BlockDeviceVolume {}}
152
+ machine .Spec .AdditionalBlockDevices = []infrav1.AdditionalBlockDevice {
153
+ {Name : "user" , SizeGiB : 30 , Storage : infrav1.BlockDeviceStorage {}},
154
+ }
155
+
156
+ By ("Creating a machine with spec.RootVolume and non-root device name in spec.AdditionalBlockDevices" )
157
+ Expect (k8sClient .Create (ctx , machine )).To (Succeed (), "OpenStackMachine creation with non-root device name in spec.AdditionalBlockDevices should succeed" )
158
+ })
159
+
160
+ It ("should not allow to create machine with spec.RootVolume and root device name in spec.AdditionalBlockDevices" , func () {
161
+ machine := defaultMachine ()
162
+ machine .Spec .RootVolume = & infrav1.RootVolume {SizeGiB : 50 , BlockDeviceVolume : infrav1.BlockDeviceVolume {}}
163
+ machine .Spec .AdditionalBlockDevices = []infrav1.AdditionalBlockDevice {
164
+ {Name : "root" , SizeGiB : 30 , Storage : infrav1.BlockDeviceStorage {}},
165
+ }
166
+
167
+ By ("Creating a machine with spec.RootVolume and root device name in spec.AdditionalBlockDevices" )
168
+ Expect (k8sClient .Create (ctx , machine )).NotTo (Succeed (), "OpenStackMachine creation with root device name in spec.AdditionalBlockDevices should not succeed" )
169
+ })
170
+
117
171
/* FIXME: These tests are failing
118
172
It("should not allow additional volume with empty name", func() {
119
173
machine.Spec.AdditionalBlockDevices = []infrav1.AdditionalBlockDevice{
0 commit comments