@@ -835,7 +835,9 @@ func (e *environSuite) TestAllRunningInstancesExtraUnrelatedInstance(c *gc.C) {
835
835
c .Check (len (ids ), gc .Equals , 2 )
836
836
}
837
837
838
- func (e * environSuite ) setupLaunchInstanceExpectations (isController bool , tags map [string ]string ) {
838
+ func (e * environSuite ) setupLaunchInstanceExpectations (
839
+ isController bool , tags map [string ]string , publicIP bool , launchInstanceMatcher gomock.Matcher ,
840
+ ) {
839
841
inst := ociCore.Instance {
840
842
AvailabilityDomain : makeStringPointer ("fakeZone1" ),
841
843
CompartmentId : & e .testCompartment ,
@@ -849,7 +851,7 @@ func (e *environSuite) setupLaunchInstanceExpectations(isController bool, tags m
849
851
responseLaunch := ociCore.LaunchInstanceResponse {
850
852
Instance : inst ,
851
853
}
852
- e .compute .EXPECT ().LaunchInstance (context .Background (), gomock . Any () ).Return (responseLaunch , nil )
854
+ e .compute .EXPECT ().LaunchInstance (context .Background (), launchInstanceMatcher ).Return (responseLaunch , nil )
853
855
854
856
getInst := inst
855
857
if isController {
@@ -890,8 +892,12 @@ func (e *environSuite) setupLaunchInstanceExpectations(isController bool, tags m
890
892
},
891
893
})
892
894
893
- e .compute .EXPECT ().ListVnicAttachments (context .Background (), attachRequest ).Return (attachResponse , nil )
894
- e .netw .EXPECT ().GetVnic (context .Background (), vnicRequest [0 ]).Return (vnicResponse [0 ], nil )
895
+ // These calls are only expected if we assign a public IP.
896
+ // They occur when polling for the IP after the instance is started.
897
+ if publicIP {
898
+ e .compute .EXPECT ().ListVnicAttachments (context .Background (), attachRequest ).Return (attachResponse , nil )
899
+ e .netw .EXPECT ().GetVnic (context .Background (), vnicRequest [0 ]).Return (vnicResponse [0 ], nil )
900
+ }
895
901
}
896
902
}
897
903
@@ -904,7 +910,8 @@ func (e *environSuite) setupEnsureNetworksExpectations(vcnId string, machineTags
904
910
e .setupListSubnetsExpectations (vcnId , "fakeRouteTableId" , machineTags , 1 )
905
911
}
906
912
907
- func (e * environSuite ) setupStartInstanceExpectations (isController bool ) {
913
+ func (e * environSuite ) setupStartInstanceExpectations (
914
+ isController bool , publicIP bool , launchInstanceMatcher gomock.Matcher ) {
908
915
vcnId := "fakeVCNId"
909
916
machineTags := map [string ]string {
910
917
tags .JujuController : testing .ControllerTag .Id (),
@@ -917,14 +924,41 @@ func (e *environSuite) setupStartInstanceExpectations(isController bool) {
917
924
918
925
e .setupEnsureNetworksExpectations (vcnId , machineTags )
919
926
e .setupListImagesExpectations ()
920
- e .setupLaunchInstanceExpectations (isController , machineTags )
927
+ e .setupLaunchInstanceExpectations (isController , machineTags , publicIP , launchInstanceMatcher )
921
928
}
922
929
923
930
func (e * environSuite ) TestBootstrap (c * gc.C ) {
924
931
ctrl := e .patchEnv (c )
925
932
defer ctrl .Finish ()
926
933
927
- e .setupStartInstanceExpectations (true )
934
+ e .setupStartInstanceExpectations (true , true , gomock .Any ())
935
+
936
+ ctx := envtesting .BootstrapContext (c )
937
+ _ , err := e .env .Bootstrap (ctx , nil ,
938
+ environs.BootstrapParams {
939
+ ControllerConfig : testing .FakeControllerConfig (),
940
+ AvailableTools : makeToolsList ("trusty" ),
941
+ BootstrapSeries : "trusty" ,
942
+ SupportedBootstrapSeries : testing .FakeSupportedJujuSeries ,
943
+ })
944
+ c .Assert (err , gc .IsNil )
945
+ }
946
+
947
+ type noPublicIPMatcher struct {}
948
+
949
+ func (noPublicIPMatcher ) Matches (arg interface {}) bool {
950
+ li := arg .(ociCore.LaunchInstanceRequest )
951
+ assign := * li .CreateVnicDetails .AssignPublicIp
952
+ return ! assign
953
+ }
954
+
955
+ func (noPublicIPMatcher ) String () string { return "" }
956
+
957
+ func (e * environSuite ) TestBootstrapNoAllocatePublicIP (c * gc.C ) {
958
+ ctrl := e .patchEnv (c )
959
+ defer ctrl .Finish ()
960
+
961
+ e .setupStartInstanceExpectations (true , false , noPublicIPMatcher {})
928
962
929
963
ctx := envtesting .BootstrapContext (c )
930
964
_ , err := e .env .Bootstrap (ctx , nil ,
@@ -933,6 +967,7 @@ func (e *environSuite) TestBootstrap(c *gc.C) {
933
967
AvailableTools : makeToolsList ("trusty" ),
934
968
BootstrapSeries : "trusty" ,
935
969
SupportedBootstrapSeries : testing .FakeSupportedJujuSeries ,
970
+ BootstrapConstraints : constraints .MustParse ("allocate-public-ip=false" ),
936
971
})
937
972
c .Assert (err , gc .IsNil )
938
973
}
0 commit comments