-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for retrieving Azure config values. (#100)
- Loading branch information
1 parent
a636d6d
commit 5eb055a
Showing
8 changed files
with
354 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...-core/src/main/groovy/com/netflix/spinnaker/rosco/providers/azure/AzureBakeHandler.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2016 Microsoft, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.rosco.providers.azure | ||
|
||
import com.netflix.spinnaker.rosco.api.Bake | ||
import com.netflix.spinnaker.rosco.api.BakeOptions | ||
import com.netflix.spinnaker.rosco.api.BakeRequest | ||
import com.netflix.spinnaker.rosco.providers.CloudProviderBakeHandler | ||
import com.netflix.spinnaker.rosco.providers.azure.config.RoscoAzureConfiguration | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
public class AzureBakeHandler extends CloudProviderBakeHandler{ | ||
|
||
private static final String BUILDER_TYPE = "azure-arm" | ||
private static final String IMAGE_NAME_TOKEN = "OSDiskUri:" | ||
|
||
@Autowired | ||
RoscoAzureConfiguration.AzureBakeryDefaults azureBakeryDefaults | ||
|
||
@Override | ||
def getBakeryDefaults() { | ||
return azureBakeryDefaults | ||
} | ||
|
||
@Override | ||
BakeOptions getBakeOptions() { | ||
new BakeOptions( | ||
cloudProvider: BakeRequest.CloudProviderType.azure, | ||
baseImages: azureBakeryDefaults?.baseImages?.collect { it.baseImage } | ||
) | ||
} | ||
|
||
@Override | ||
boolean isProducerOf(String logsContentFirstLine) { | ||
logsContentFirstLine =~ BUILDER_TYPE | ||
} | ||
|
||
@Override | ||
Bake scrapeCompletedBakeResults(String region, String bakeId, String logsContent) { | ||
String imageName | ||
|
||
// TODO(duftler): Presently scraping the logs for the image name. Would be better to not be reliant on the log | ||
// format not changing. Resolve this by storing bake details in redis. | ||
logsContent.eachLine { String line -> | ||
if (line =~ IMAGE_NAME_TOKEN) { | ||
imageName = line.split("/").last() | ||
} | ||
} | ||
|
||
return new Bake(id: bakeId, image_name: imageName) | ||
} | ||
|
||
@Override | ||
def findVirtualizationSettings(String region, BakeRequest bakeRequest) { | ||
return null | ||
} | ||
|
||
@Override | ||
Map buildParameterMap(String region, Object virtualizationSettings, String imageName, BakeRequest bakeRequest) { | ||
return null | ||
} | ||
|
||
@Override | ||
String getTemplateFileName() { | ||
return azureBakeryDefaults.templateFile | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
.../groovy/com/netflix/spinnaker/rosco/providers/azure/config/RoscoAzureConfiguration.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2016 Microsoft, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.rosco.providers.azure.config | ||
|
||
import com.netflix.spinnaker.rosco.api.BakeOptions | ||
import com.netflix.spinnaker.rosco.api.BakeRequest | ||
import com.netflix.spinnaker.rosco.providers.azure.AzureBakeHandler | ||
import com.netflix.spinnaker.rosco.providers.registry.CloudProviderBakeHandlerRegistry | ||
import groovy.transform.AutoClone | ||
import groovy.transform.AutoCloneStyle | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.context.annotation.Configuration | ||
|
||
import javax.annotation.PostConstruct | ||
|
||
@Configuration | ||
@ConditionalOnProperty('azure.enabled') | ||
@ComponentScan('com.netflix.spinnaker.rosco.providers.azure') | ||
class RoscoAzureConfiguration { | ||
|
||
@Autowired | ||
CloudProviderBakeHandlerRegistry cloudProviderBakeHandlerRegistry | ||
|
||
@Autowired | ||
AzureBakeHandler azureBakeHandler | ||
|
||
@Bean | ||
@ConfigurationProperties('azure.bakeryDefaults') | ||
AzureBakeryDefaults azureBakeryDefaults() { | ||
new AzureBakeryDefaults() | ||
} | ||
|
||
@PostConstruct | ||
void init() { | ||
cloudProviderBakeHandlerRegistry.register(BakeRequest.CloudProviderType.azure, azureBakeHandler) | ||
} | ||
|
||
static class AzureBakeryDefaults { | ||
String azureClientId | ||
String azureClientSecret | ||
String azureResourceGroup | ||
String templateFile | ||
List<AzureOperatingSystemVirtualizationSettings> baseImages = [] | ||
} | ||
|
||
static class AzureOperatingSystemVirtualizationSettings { | ||
BakeOptions.BaseImage baseImage | ||
List<AzureVirtualizationSettings> vitualizationSettings = [] | ||
} | ||
|
||
@AutoClone(style = AutoCloneStyle.SIMPLE) | ||
static class AzureVirtualizationSettings { | ||
String region | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
...e/src/test/groovy/com/netflix/spinnaker/rosco/providers/azure/AzureBakeHandlerSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright 2016 Microsoft, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.rosco.providers.azure | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.netflix.spinnaker.rosco.api.Bake | ||
import com.netflix.spinnaker.rosco.api.BakeOptions | ||
import com.netflix.spinnaker.rosco.api.BakeRequest | ||
import com.netflix.spinnaker.rosco.providers.azure.config.RoscoAzureConfiguration | ||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
class AzureBakeHandlerSpec extends Specification{ | ||
|
||
@Shared | ||
String configDir = "/some/path" | ||
|
||
@Shared | ||
RoscoAzureConfiguration.AzureBakeryDefaults azureBakeryDefaults | ||
|
||
void setupSpec() { | ||
def azureBakeryDefaultsJson = [ | ||
templateFile: "azure-linux.json", | ||
baseImages: [ | ||
[ | ||
baseImage: [ | ||
id: "ubuntu", | ||
detailedDescription: "Ubuntu Server 14.04.4-LTS", | ||
packageType: "DEB", | ||
] | ||
], | ||
[ | ||
baseImage: [ | ||
id: "centos", | ||
detailedDescription: "OpenLogic CentOS 7.1.20150731", | ||
packageType: "RPM", | ||
] | ||
] | ||
] | ||
] | ||
|
||
azureBakeryDefaults = new ObjectMapper().convertValue(azureBakeryDefaultsJson, RoscoAzureConfiguration.AzureBakeryDefaults) | ||
} | ||
|
||
void 'can scrape packer logs for image name'() { | ||
setup: | ||
@Subject | ||
AzureBakeHandler azureBakeHandler = new AzureBakeHandler() | ||
|
||
when: | ||
def logsContent = | ||
"==> azure-arm: Deleting the temporary OS disk ...\n" + | ||
"==> azure-arm: -> OS Disk : 'https://lgpackervms.blob.core.windows.net/images/pkroswfvmtp50x8.vhd'\n" + | ||
"==> azure-arm:\n" + | ||
"==> azure-arm: Cleanup requested, deleting resource group ...\n" + | ||
"==> azure-arm: Error deleting resource group. Please delete it manually.\n" + | ||
"==> azure-arm:\n" + | ||
"==> azure-arm: Name: packer-Resource-Group-wfvmtp50x8\n" + | ||
"==> azure-arm: Error: azure#updatePollingState: Azure Polling Error - Unable to obtain polling URI for DELETE : StatusCode=0\n" + | ||
"==> azure-arm: Resource group has been deleted.\n" + | ||
"Build 'azure-arm' finished.\n" + | ||
"\n" + | ||
"==> Builds finished. The artifacts of successful builds are:\n" + | ||
"--> azure-arm: Azure.ResourceManagement.VMImage:\n" + | ||
"\n" + | ||
"StorageAccountLocation: westus\n" + | ||
"OSDiskUri: https://lgpackervms.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-osDisk.0425d8dd-45a0-4f2e-aabb-b5f9a03b08c9.vhd\n" + | ||
"OSDiskUriReadOnlySas: https://lgpackervms.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-osDisk.0425d8dd-45a0-4f2e-aabb-b5f9a03b08c9.vhd?se=2016-06-24T18%3A16%3A46Z&sig=RHZXFGD3gZq6BGo%2BOb09FXHW6BAYULVJ8thlBEblkmo%3D&sp=r&sr=b&sv=2015-02-21" | ||
|
||
|
||
Bake bake = azureBakeHandler.scrapeCompletedBakeResults(null, "123", logsContent) | ||
|
||
then: | ||
with (bake) { | ||
id == "123" | ||
!ami | ||
image_name == "packer-osDisk.0425d8dd-45a0-4f2e-aabb-b5f9a03b08c9.vhd" | ||
} | ||
} | ||
|
||
void 'template file name data is serialized as expected'() { | ||
setup: | ||
@Subject | ||
AzureBakeHandler azureBakeHandler = new AzureBakeHandler(azureBakeryDefaults: azureBakeryDefaults) | ||
|
||
when: | ||
String templateFileName = azureBakeHandler.getTemplateFileName() | ||
|
||
then: | ||
templateFileName == "azure-linux.json" | ||
} | ||
|
||
void 'image config data is serialized as expected'() { | ||
setup: | ||
@Subject | ||
AzureBakeHandler azureBakeHandler = new AzureBakeHandler(azureBakeryDefaults: azureBakeryDefaults) | ||
|
||
when: | ||
BakeOptions bakeOptions = azureBakeHandler.getBakeOptions() | ||
|
||
then: | ||
with(bakeOptions) { | ||
baseImages.size() == 2 | ||
cloudProvider == BakeRequest.CloudProviderType.azure.toString() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"variables": { | ||
"azure_client_id": "", | ||
"azure_client_secret": "", | ||
"azure_resource_group": "", | ||
"azure_storage_account": "", | ||
"azure_subscription_id": "", | ||
"azure_tenant_id": "", | ||
"azure_image_publisher": "", | ||
"azure_image_offer": "", | ||
"azure_image_sku": "", | ||
"azure_location": "", | ||
"azure_vm_size": "", | ||
"azure_image_name": "", | ||
|
||
"appversion": "", | ||
"build_host": "", | ||
"repository": "", | ||
"package_type": "", | ||
"packages": "", | ||
"upgrade": "", | ||
"configDir": null | ||
}, | ||
"builders": [{ | ||
"type": "azure-arm", | ||
|
||
"client_id": "{{user `client_id`}}", | ||
"client_secret": "{{user `client_secret`}}", | ||
"resource_group_name": "{{user `resource_group`}}", | ||
"storage_account": "{{user `storage_account`}}", | ||
"subscription_id": "{{user `subscription_id`}}", | ||
"tenant_id": "{{user `tenant_id`}}", | ||
|
||
"capture_container_name": "images", | ||
"capture_name_prefix": "{{user `appversion`}}", | ||
|
||
"os_type": "Linux", | ||
"image_publisher": "{{user `azure_image_publisher`}}", | ||
"image_offer": "{{user `azure_image_offer`}}", | ||
"image_sku": "{{user `azure_image_sku`}}", | ||
|
||
"location": "{{user `azure_location`}}", | ||
"vm_size": "{{user `azure_vm_size`}}" | ||
}], | ||
"provisioners": [{ | ||
"type": "shell", | ||
"script": "{{user `configDir`}}/install_packages.sh", | ||
"environment_vars": [ | ||
"repository={{user `repository`}}", | ||
"package_type={{user `package_type`}}", | ||
"packages={{user `packages`}}", | ||
"upgrade={{user `upgrade`}}" | ||
], | ||
"pause_before": "30s" | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters