Skip to content

Commit

Permalink
check iaas before deciding to ask for availability zones
Browse files Browse the repository at this point in the history
we can ask for this on azure
  • Loading branch information
Zachary Gershman committed Mar 10, 2017
1 parent 38d693b commit 3c85589
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 14 deletions.
14 changes: 8 additions & 6 deletions api/diagnostic_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ type DiagnosticProduct struct {
}

type DiagnosticReport struct {
Stemcells []string
StagedProducts []DiagnosticProduct
DeployedProducts []DiagnosticProduct
InfrastructureType string `json:"infrastructure_type"`
Stemcells []string
StagedProducts []DiagnosticProduct
DeployedProducts []DiagnosticProduct
}

type DiagnosticReportUnavailable struct{}
Expand Down Expand Up @@ -76,8 +77,9 @@ func (ds DiagnosticService) Report() (DiagnosticReport, error) {
}

return DiagnosticReport{
Stemcells: apiResponse.Stemcells,
StagedProducts: apiResponse.AddedProducts.StagedProducts,
DeployedProducts: apiResponse.AddedProducts.DeployedProducts,
InfrastructureType: apiResponse.DiagnosticReport.InfrastructureType,
Stemcells: apiResponse.Stemcells,
StagedProducts: apiResponse.AddedProducts.StagedProducts,
DeployedProducts: apiResponse.AddedProducts.DeployedProducts,
}, nil
}
2 changes: 2 additions & 0 deletions api/diagnostic_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

const report = `{
"infrastructure_type": "azure",
"stemcells": ["light-bosh-stemcell-3263.8-aws-xen-hvm-ubuntu-trusty-go_agent.tgz"],
"added_products": {
"deployed": [
Expand Down Expand Up @@ -64,6 +65,7 @@ var _ = Describe("DiagnosticService", func() {
Expect(request.Method).To(Equal("GET"))
Expect(request.URL.Path).To(Equal("/api/v0/diagnostic_report"))

Expect(report.InfrastructureType).To(Equal("azure"))
Expect(report.Stemcells).To(Equal([]string{"light-bosh-stemcell-3263.8-aws-xen-hvm-ubuntu-trusty-go_agent.tgz"}))
Expect(report.StagedProducts).To(Equal([]api.DiagnosticProduct{
{
Expand Down
22 changes: 14 additions & 8 deletions commands/configure_bosh.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c ConfigureBosh) Execute(args []string) error {
panic(err)
}

err = c.configureNetworkForm(networksConfigurationPath, c.Options.NetworksConfiguration)
err = c.configureNetworkForm(networksConfigurationPath, c.Options.NetworksConfiguration, report)
if err != nil {
return err
}
Expand All @@ -149,9 +149,12 @@ func (c ConfigureBosh) Execute(args []string) error {
}
config.NetworkGUID = networks[config.UserProvidedNetworkName]

availabilityZones, err := c.boshService.AvailabilityZones()
if err != nil {
return err
var availabilityZones map[string]string
if report.InfrastructureType != "azure" {
availabilityZones, err = c.boshService.AvailabilityZones()
if err != nil {
return err
}
}

if azGUID, ok := availabilityZones[config.UserProvidedAZName]; ok {
Expand Down Expand Up @@ -233,7 +236,7 @@ func (c ConfigureBosh) postForm(path string, initialConfig BoshConfiguration) er
return nil
}

func (c ConfigureBosh) configureNetworkForm(path, configuration string) error {
func (c ConfigureBosh) configureNetworkForm(path string, configuration string, report api.DiagnosticReport) error {
form, err := c.boshService.GetForm(path)
if err != nil {
return fmt.Errorf("could not fetch form: %s", err)
Expand All @@ -245,9 +248,12 @@ func (c ConfigureBosh) configureNetworkForm(path, configuration string) error {
return fmt.Errorf("could not decode json: %s", err)
}

azMap, err := c.boshService.AvailabilityZones()
if err != nil {
return fmt.Errorf("could not fetch availability zones: %s", err)
var azMap map[string]string
if report.InfrastructureType != "azure" {
azMap, err = c.boshService.AvailabilityZones()
if err != nil {
return fmt.Errorf("could not fetch availability zones: %s", err)
}
}

for n, network := range initialConfig.Networks {
Expand Down
72 changes: 72 additions & 0 deletions commands/configure_bosh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,78 @@ var _ = Describe("ConfigureBosh", func() {
})
})

Context("when the iaas is azure", func() {
It("does not attempt to get the availability zones", func() {
command := commands.NewConfigureBosh(boshService, diagnosticService, logger)

boshService.GetFormReturns(api.Form{
Action: "form-action",
AuthenticityToken: "some-auth-token",
RailsMethod: "the-rails",
}, nil)

diagnosticService.ReportReturns(api.DiagnosticReport{
InfrastructureType: "azure",
}, nil)

boshService.NetworksReturns(map[string]string{
"some-network-name": "some-network-guid",
"some-other-network-name": "some-other-network-guid",
}, nil)

err := command.Execute([]string{
"--iaas-configuration",
`{
"project": "some-project",
"default_deployment_tag": "my-vms",
"auth_json": "{\"some-auth-field\": \"some-service-key\",\"some-private_key\": \"some-key\"}"
}`,
"--director-configuration",
`{
"ntp_servers_string": "some-ntp-servers-string",
"metrics_ip": "some-metrics-ip",
"hm_pager_duty_options": {
"enabled": true
}
}
}`,
"--security-configuration",
`{
"trusted_certificates": "some-trusted-certificates",
"vm_password_type": "some-vm-password-type"
}`,
"--network-assignment",
`{
"singleton_availability_zone": "some-az-name",
"network": "some-other-network-name"
}`,
"--networks-configuration",
`{
"icmp_checks_enabled": false,
"networks": [
{
"name": "opsman-network",
"subnets": [
{
"iaas_identifier": "vpc-subnet-id-1",
"cidr": "10.0.0.0/24",
"reserved_ip_ranges": "10.0.0.0-10.0.0.4",
"dns": "8.8.8.8",
"gateway": "10.0.0.1",
"availability_zones": ["some-az1"]
}
]
}
]
}`,
})

Expect(err).NotTo(HaveOccurred())

Expect(boshService.AvailabilityZonesCallCount()).To(Equal(0))
})
})

Context("when the network is configured and deployed", func() {
It("ignores all network changes", func() {
command := commands.NewConfigureBosh(boshService, diagnosticService, logger)
Expand Down

0 comments on commit 3c85589

Please sign in to comment.