Skip to content

Commit

Permalink
(google) Add support for subnetwork config default and gce_subnetwork…
Browse files Browse the repository at this point in the history
… extended attribute. (#170)
  • Loading branch information
Matt Duftler authored Jan 28, 2017
1 parent c69d724 commit 3f24c2b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public class GCEBakeHandler extends CloudProviderBakeHandler {
parameterMap.gce_account_file = managedGoogleAccount.jsonPath
}

if (gceBakeryDefaults.subnetwork) {
parameterMap.gce_subnetwork = gceBakeryDefaults.subnetwork
}

if (gceBakeryDefaults.useInternalIp != null) {
parameterMap.gce_use_internal_ip = gceBakeryDefaults.useInternalIp
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.netflix.spinnaker.rosco.providers.google.GCEBakeHandler
import com.netflix.spinnaker.rosco.providers.registry.CloudProviderBakeHandlerRegistry
import groovy.transform.AutoClone
import groovy.transform.AutoCloneStyle
import groovy.transform.ToString
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.ConfigurationProperties
Expand All @@ -48,9 +49,12 @@ class RoscoGoogleConfiguration {
new GCEBakeryDefaults()
}

@AutoClone(style = AutoCloneStyle.SIMPLE)
@ToString(includeNames = true)
static class GCEBakeryDefaults {
String zone
String network
String subnetwork
Boolean useInternalIp
String templateFile
List<GCEOperatingSystemVirtualizationSettings> baseImages = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,18 @@ class GCEBakeHandlerSpec extends Specification implements TestDefaults{
package_name: PACKAGES_NAME,
base_os: "precise",
cloud_provider_type: BakeRequest.CloudProviderType.gce,
extended_attributes: [gce_zone: "europe-west1-b", gce_network: "other-network"])
extended_attributes: [
gce_zone: "europe-west1-b",
gce_network: "other-network",
gce_subnetwork: "custom-subnetwork"
])
def targetImageName = "kato-x8664-timestamp-precise"
def osPackages = parseDebOsPackageNames(bakeRequest.package_name)
def parameterMap = [
gce_project_id: googleConfigurationProperties.accounts.get(0).project,
gce_zone: "europe-west1-b",
gce_network: "other-network",
gce_subnetwork: "custom-subnetwork",
gce_source_image: SOURCE_PRECISE_IMAGE_NAME,
gce_target_image: targetImageName,
repository: DEBIAN_REPOSITORY,
Expand All @@ -437,6 +442,49 @@ class GCEBakeHandlerSpec extends Specification implements TestDefaults{
1 * packerCommandFactoryMock.buildPackerCommand("", parameterMap, null, "$configDir/$gceBakeryDefaults.templateFile")
}

void 'produces packer command with all required parameters for precise, and respects optional subnetwork config default'() {
setup:
def imageNameFactoryMock = Mock(ImageNameFactory)
def packerCommandFactoryMock = Mock(PackerCommandFactory)
def bakeRequest = new BakeRequest(user: "[email protected]",
package_name: PACKAGES_NAME,
base_os: "precise",
cloud_provider_type: BakeRequest.CloudProviderType.gce)
def targetImageName = "kato-x8664-timestamp-precise"
def osPackages = parseDebOsPackageNames(bakeRequest.package_name)
def parameterMap = [
gce_project_id: googleConfigurationProperties.accounts.get(0).project,
gce_zone: gceBakeryDefaults.zone,
gce_network: gceBakeryDefaults.network,
gce_subnetwork: "custom-subnetwork",
gce_source_image: SOURCE_PRECISE_IMAGE_NAME,
gce_target_image: targetImageName,
repository: DEBIAN_REPOSITORY,
package_type: DEB_PACKAGE_TYPE.packageType,
packages: PACKAGES_NAME,
configDir: configDir
]
def gceBakeryDefaultsAugmented = gceBakeryDefaults.clone()
gceBakeryDefaultsAugmented.subnetwork = "custom-subnetwork"

@Subject
GCEBakeHandler gceBakeHandler = new GCEBakeHandler(configDir: configDir,
gceBakeryDefaults: gceBakeryDefaultsAugmented,
googleConfigurationProperties: googleConfigurationProperties,
imageNameFactory: imageNameFactoryMock,
packerCommandFactory: packerCommandFactoryMock,
debianRepository: DEBIAN_REPOSITORY)

when:
gceBakeHandler.producePackerCommand(REGION, bakeRequest)

then:
1 * imageNameFactoryMock.buildImageName(bakeRequest, osPackages) >> targetImageName
1 * imageNameFactoryMock.buildAppVersionStr(bakeRequest, osPackages) >> null
1 * imageNameFactoryMock.buildPackagesParameter(DEB_PACKAGE_TYPE, osPackages) >> PACKAGES_NAME
1 * packerCommandFactoryMock.buildPackerCommand("", parameterMap, null, "$configDir/$gceBakeryDefaults.templateFile")
}

void 'produces packer command with all required parameters for trusty'() {
setup:
def imageNameFactoryMock = Mock(ImageNameFactory)
Expand Down
2 changes: 2 additions & 0 deletions rosco-web/config/packer/gce.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"gce_account_file": "",
"gce_zone": null,
"gce_network": null,
"gce_subnetwork": "",
"gce_source_image": "",
"gce_source_image_family": "",
"gce_target_image": null,
Expand All @@ -22,6 +23,7 @@
"account_file": "{{user `gce_account_file`}}",
"zone": "{{user `gce_zone`}}",
"network": "{{user `gce_network`}}",
"subnetwork": "{{user `gce_subnetwork`}}",
"state_timeout": "15m",
"ssh_username": "packerio",
"ssh_pty": true,
Expand Down

0 comments on commit 3f24c2b

Please sign in to comment.