@@ -40,6 +40,8 @@ import (
4040 "sigs.k8s.io/controller-runtime/pkg/client/fake"
4141)
4242
43+ var fdList = []string {"FAULT-DOMAIN-1" , "FAULT-DOMAIN-2" , "FAULT-DOMAIN-3" }
44+
4345func TestInstanceReconciliation (t * testing.T ) {
4446 var (
4547 ms * MachineScope
@@ -277,6 +279,47 @@ func TestInstanceReconciliation(t *testing.T) {
277279 })).Return (core.LaunchInstanceResponse {}, nil )
278280 },
279281 },
282+ {
283+ name : "try all fds" ,
284+ errorExpected : true ,
285+ matchError : TestError {errorString : ociutil .OutOfHostCapacityErr },
286+ testSpecificSetup : func (machineScope * MachineScope , computeClient * mock_compute.MockComputeClient ) {
287+ setupAllParams (ms )
288+ computeClient .EXPECT ().ListInstances (gomock .Any (), gomock .Eq (core.ListInstancesRequest {
289+ DisplayName : common .String ("name" ),
290+ CompartmentId : common .String ("test" ),
291+ })).Return (core.ListInstancesResponse {}, nil )
292+
293+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
294+ return instanceFDMatcher (request , "FAULT-DOMAIN-1" )
295+ })).Return (core.LaunchInstanceResponse {}, TestError {errorString : ociutil .OutOfHostCapacityErr })
296+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
297+ return instanceFDMatcher (request , "FAULT-DOMAIN-2" )
298+ })).Return (core.LaunchInstanceResponse {}, TestError {errorString : ociutil .OutOfHostCapacityErr })
299+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
300+ return instanceFDMatcher (request , "FAULT-DOMAIN-3" )
301+ })).Return (core.LaunchInstanceResponse {}, TestError {errorString : ociutil .OutOfHostCapacityErr })
302+ },
303+ },
304+ {
305+ name : "second fd works" ,
306+ errorExpected : false ,
307+ matchError : TestError {errorString : ociutil .OutOfHostCapacityErr },
308+ testSpecificSetup : func (machineScope * MachineScope , computeClient * mock_compute.MockComputeClient ) {
309+ setupAllParams (ms )
310+ computeClient .EXPECT ().ListInstances (gomock .Any (), gomock .Eq (core.ListInstancesRequest {
311+ DisplayName : common .String ("name" ),
312+ CompartmentId : common .String ("test" ),
313+ })).Return (core.ListInstancesResponse {}, nil )
314+
315+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
316+ return anyFdMatcher (request )
317+ })).Return (core.LaunchInstanceResponse {}, TestError {errorString : ociutil .OutOfHostCapacityErr })
318+ computeClient .EXPECT ().LaunchInstance (gomock .Any (), Eq (func (request interface {}) error {
319+ return anyFdMatcher (request )
320+ })).Return (core.LaunchInstanceResponse {}, nil )
321+ },
322+ },
280323 {
281324 name : "check compartment at cluster" ,
282325 errorExpected : false ,
@@ -341,6 +384,7 @@ func TestInstanceReconciliation(t *testing.T) {
341384 BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
342385 },
343386 AvailabilityDomain : common .String ("ad2" ),
387+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
344388 CompartmentId : common .String ("test" ),
345389 IsPvEncryptionInTransitEnabled : common .Bool (true ),
346390 DefinedTags : map [string ]map [string ]interface {}{},
@@ -379,6 +423,7 @@ func TestInstanceReconciliation(t *testing.T) {
379423 },
380424 Shape : common .String ("shape" ),
381425 AvailabilityDomain : common .String ("ad2" ),
426+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
382427 CompartmentId : common .String ("test" ),
383428 IsPvEncryptionInTransitEnabled : common .Bool (true ),
384429 DefinedTags : map [string ]map [string ]interface {}{},
@@ -425,6 +470,7 @@ func TestInstanceReconciliation(t *testing.T) {
425470 BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
426471 },
427472 AvailabilityDomain : common .String ("ad2" ),
473+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
428474 CompartmentId : common .String ("test" ),
429475 IsPvEncryptionInTransitEnabled : common .Bool (true ),
430476 DefinedTags : map [string ]map [string ]interface {}{},
@@ -473,6 +519,7 @@ func TestInstanceReconciliation(t *testing.T) {
473519 BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
474520 },
475521 AvailabilityDomain : common .String ("ad2" ),
522+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
476523 CompartmentId : common .String ("test" ),
477524 IsPvEncryptionInTransitEnabled : common .Bool (true ),
478525 DefinedTags : map [string ]map [string ]interface {}{},
@@ -525,6 +572,7 @@ func TestInstanceReconciliation(t *testing.T) {
525572 BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
526573 },
527574 AvailabilityDomain : common .String ("ad2" ),
575+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
528576 CompartmentId : common .String ("test" ),
529577 IsPvEncryptionInTransitEnabled : common .Bool (true ),
530578 DefinedTags : map [string ]map [string ]interface {}{},
@@ -578,6 +626,7 @@ func TestInstanceReconciliation(t *testing.T) {
578626 BaselineOcpuUtilization : core .LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8 ,
579627 },
580628 AvailabilityDomain : common .String ("ad2" ),
629+ FaultDomain : common .String ("FAULT-DOMAIN-2" ),
581630 CompartmentId : common .String ("test" ),
582631 IsPvEncryptionInTransitEnabled : common .Bool (true ),
583632 DefinedTags : map [string ]map [string ]interface {}{},
@@ -636,6 +685,30 @@ func instanceCompartmentIDMatcher(request interface{}, matchStr string) error {
636685 return nil
637686}
638687
688+ func instanceFDMatcher (request interface {}, matchStr string ) error {
689+ r , ok := request .(core.LaunchInstanceRequest )
690+ if ! ok {
691+ return errors .New ("expecting LaunchInstanceRequest type" )
692+ }
693+ if * r .LaunchInstanceDetails .FaultDomain != matchStr {
694+ return errors .New (fmt .Sprintf ("expecting fd as %s" , matchStr ))
695+ }
696+ return nil
697+ }
698+
699+ func anyFdMatcher (request interface {}) error {
700+ r , ok := request .(core.LaunchInstanceRequest )
701+ if ! ok {
702+ return errors .New ("expecting LaunchInstanceRequest type" )
703+ }
704+ for _ , f := range fdList {
705+ if f == * r .FaultDomain {
706+ return nil
707+ }
708+ }
709+ return errors .New (fmt .Sprintf ("invalid fd" ))
710+ }
711+
639712func TestLBReconciliationCreation (t * testing.T ) {
640713 var (
641714 ms * MachineScope
@@ -1304,6 +1377,7 @@ func setupAllParams(ms *MachineScope) {
13041377 "2" : {
13051378 Attributes : map [string ]string {
13061379 "AvailabilityDomain" : "ad2" ,
1380+ "FaultDomain" : "FAULT-DOMAIN-2" ,
13071381 },
13081382 },
13091383 "3" : {
@@ -1312,6 +1386,17 @@ func setupAllParams(ms *MachineScope) {
13121386 },
13131387 },
13141388 }
1389+ ms .OCICluster .Status .AvailabilityDomains = map [string ]infrastructurev1beta1.OCIAvailabilityDomain {
1390+ "ad1" : {
1391+ FaultDomains : fdList ,
1392+ },
1393+ "ad2" : {
1394+ FaultDomains : fdList ,
1395+ },
1396+ "ad3" : {
1397+ FaultDomains : fdList ,
1398+ },
1399+ }
13151400 ms .Machine .Spec .FailureDomain = common .String ("2" )
13161401 ms .OCICluster .Spec .NetworkSpec .Vcn .Subnets = []* infrastructurev1beta1.Subnet {
13171402 {
@@ -1323,3 +1408,13 @@ func setupAllParams(ms *MachineScope) {
13231408 ms .OCICluster .Spec .OCIResourceIdentifier = "resource_uid"
13241409 ms .OCIMachine .UID = "machineuid"
13251410}
1411+
1412+ // The error built-in interface type is the conventional interface for
1413+ // representing an error condition, with the nil value representing no error.
1414+ type TestError struct {
1415+ errorString string
1416+ }
1417+
1418+ func (t TestError ) Error () string {
1419+ return t .errorString
1420+ }
0 commit comments