Exemplo n.º 1
0
func (*environSuite) TestAttemptCreateServiceCreatesService(c *C) {
	prefix := "myservice"
	affinityGroup := "affinity-group"
	location := "location"
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(makeAvailabilityResponse(c), http.StatusOK, nil),
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
	requests := gwacl.PatchManagementAPIResponses(responses)
	azure, err := gwacl.NewManagementAPI("subscription", "", "West US")
	c.Assert(err, IsNil)

	service, err := attemptCreateService(azure, prefix, affinityGroup, location)
	c.Assert(err, IsNil)

	c.Assert(*requests, HasLen, 2)
	body := parseCreateServiceRequest(c, (*requests)[1])
	c.Check(body.ServiceName, Equals, service.ServiceName)
	c.Check(body.AffinityGroup, Equals, affinityGroup)
	c.Check(service.ServiceName, Matches, prefix+".*")
	c.Check(service.Location, Equals, location)

	label, err := base64.StdEncoding.DecodeString(service.Label)
	c.Assert(err, IsNil)
	c.Check(string(label), Equals, service.ServiceName)
}
Exemplo n.º 2
0
func preparePortChangeConversation(
	c *C, service *gwacl.HostedServiceDescriptor,
	deployments ...gwacl.Deployment) []gwacl.DispatcherResponse {
	// Construct the series of responses to expected requests.
	responses := []gwacl.DispatcherResponse{
		// First, GetHostedServiceProperties
		gwacl.NewDispatcherResponse(
			serialize(c, &gwacl.HostedService{
				Deployments:             deployments,
				HostedServiceDescriptor: *service,
				XMLNS: gwacl.XMLNS,
			}),
			http.StatusOK, nil),
	}
	for _, deployment := range deployments {
		for _, role := range deployment.RoleList {
			// GetRole returns a PersistentVMRole.
			persistentRole := &gwacl.PersistentVMRole{
				XMLNS:             gwacl.XMLNS,
				RoleName:          role.RoleName,
				ConfigurationSets: role.ConfigurationSets,
			}
			responses = append(responses, gwacl.NewDispatcherResponse(
				serialize(c, persistentRole), http.StatusOK, nil))
			// UpdateRole expects a 200 response, that's all.
			responses = append(responses,
				gwacl.NewDispatcherResponse(nil, http.StatusOK, nil))
		}
	}
	return responses
}
Exemplo n.º 3
0
func (*EnvironSuite) TestDestroyVirtualNetwork(c *C) {
	env := makeEnviron(c)
	// Prepare a configuration with a single virtual network.
	existingConfig := &gwacl.NetworkConfiguration{
		XMLNS: gwacl.XMLNS_NC,
		VirtualNetworkSites: &[]gwacl.VirtualNetworkSite{
			{Name: env.getVirtualNetworkName()},
		},
	}
	body, err := existingConfig.Serialize()
	c.Assert(err, IsNil)
	responses := []gwacl.DispatcherResponse{
		// Return existing configuration.
		gwacl.NewDispatcherResponse([]byte(body), http.StatusOK, nil),
		// Accept upload of new configuration.
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
	requests := gwacl.PatchManagementAPIResponses(responses)

	env.deleteVirtualNetwork()

	c.Assert(*requests, HasLen, 2)
	// One request to get the existing network configuration.
	getRequest := (*requests)[0]
	c.Check(getRequest.Method, Equals, "GET")
	// One request to update the network configuration.
	putRequest := (*requests)[1]
	c.Check(putRequest.Method, Equals, "PUT")
	newConfig := gwacl.NetworkConfiguration{}
	err = xml.Unmarshal(putRequest.Payload, &newConfig)
	c.Assert(err, IsNil)
	// The new configuration has no VirtualNetworkSites.
	c.Check(newConfig.VirtualNetworkSites, IsNil)
}
Exemplo n.º 4
0
// buildDestroyAzureServiceResponses returns a slice containing the responses that a fake Azure server
// can use to simulate the deletion of the given list of services.
func buildDestroyAzureServiceResponses(c *C, services []*gwacl.HostedService) []gwacl.DispatcherResponse {
	responses := []gwacl.DispatcherResponse{}
	for _, service := range services {
		// When destroying a hosted service, gwacl first issues a Get request
		// to fetch the properties of the services.  Then it destroys all the
		// deployments found in this service (none in this case, we make sure
		// the service does not contain deployments to keep the testing simple)
		// And it finally deletes the service itself.
		if len(service.Deployments) != 0 {
			panic("buildDestroyAzureServiceResponses does not support services with deployments!")
		}
		serviceXML, err := service.Serialize()
		c.Assert(err, IsNil)
		serviceGetResponse := gwacl.NewDispatcherResponse(
			[]byte(serviceXML),
			http.StatusOK,
			nil,
		)
		responses = append(responses, serviceGetResponse)
		serviceDeleteResponse := gwacl.NewDispatcherResponse(
			nil,
			http.StatusOK,
			nil,
		)
		responses = append(responses, serviceDeleteResponse)
	}
	return responses
}
Exemplo n.º 5
0
func (*environSuite) TestAttemptCreateServicePropagatesOtherFailure(c *C) {
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(makeAvailabilityResponse(c), http.StatusOK, nil),
		gwacl.NewDispatcherResponse(nil, http.StatusNotFound, nil),
	}
	gwacl.PatchManagementAPIResponses(responses)
	azure, err := gwacl.NewManagementAPI("subscription", "", "West US")
	c.Assert(err, IsNil)

	_, err = attemptCreateService(azure, "service", "affinity-group", "location")
	c.Assert(err, NotNil)
	c.Check(err, ErrorMatches, ".*Not Found.*")
}
Exemplo n.º 6
0
func preparePortChangeConversation(c *gc.C, role *gwacl.Role) []gwacl.DispatcherResponse {
	persistentRole := &gwacl.PersistentVMRole{
		XMLNS:             gwacl.XMLNS,
		RoleName:          role.RoleName,
		ConfigurationSets: role.ConfigurationSets,
	}
	return []gwacl.DispatcherResponse{
		// GetRole returns a PersistentVMRole.
		gwacl.NewDispatcherResponse(serialize(c, persistentRole), http.StatusOK, nil),
		// UpdateRole expects a 200 response, that's all.
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
}
Exemplo n.º 7
0
// getVnetAndAffinityGroupCleanupResponses returns the responses
// (gwacl.DispatcherResponse) that a fake http server should return
// when gwacl's RemoveVirtualNetworkSite() and DeleteAffinityGroup()
// are called.
func getVnetAndAffinityGroupCleanupResponses(c *C) []gwacl.DispatcherResponse {
	existingConfig := &gwacl.NetworkConfiguration{
		XMLNS:               gwacl.XMLNS_NC,
		VirtualNetworkSites: nil,
	}
	body, err := existingConfig.Serialize()
	c.Assert(err, IsNil)
	cleanupResponses := []gwacl.DispatcherResponse{
		// Return empty net configuration.
		gwacl.NewDispatcherResponse([]byte(body), http.StatusOK, nil),
		// Accept deletion of affinity group.
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
	return cleanupResponses
}
Exemplo n.º 8
0
func (*environSuite) TestStopInstancesWhenStoppingMachinesFails(c *C) {
	cleanup := setServiceDeletionConcurrency(3)
	defer cleanup()
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(nil, http.StatusConflict, nil),
	}
	service1Name := "service1"
	_, service1Desc := makeAzureService(service1Name)
	service2Name := "service2"
	service2, service2Desc := makeAzureService(service2Name)
	services := []*gwacl.HostedService{service2}
	destroyResponses := buildDestroyAzureServiceResponses(c, services)
	responses = append(responses, destroyResponses...)
	requests := gwacl.PatchManagementAPIResponses(responses)
	env := makeEnviron(c)
	instances := convertToInstances(
		[]gwacl.HostedServiceDescriptor{*service1Desc, *service2Desc}, env)

	err := env.StopInstances(instances)
	c.Check(err, ErrorMatches, ".*Conflict.*")

	c.Check(len(*requests), Equals, 3)
	assertOneRequestMatches(c, *requests, "GET", ".*"+service1Name+".")
	assertOneRequestMatches(c, *requests, "GET", ".*"+service2Name+".")
	// Only one of the services was deleted.
	assertOneRequestMatches(c, *requests, "DELETE", ".*")
}
Exemplo n.º 9
0
func (s *azureVolumeSuite) TestListVolumes(c *gc.C) {
	vs := s.volumeSource(c, nil)

	type disks struct {
		Disks []gwacl.Disk `xml:"Disk"`
	}

	listDisksResponse, err := xml.Marshal(&disks{Disks: []gwacl.Disk{{
		MediaLink:       mediaLinkPrefix + "volume-1.vhd",
		LogicalSizeInGB: 22,
	}, {
		MediaLink:       mediaLinkPrefix + "volume-0.vhd",
		LogicalSizeInGB: 11,
	}, {
		MediaLink:       "someOtherJunk.vhd",
		LogicalSizeInGB: 33,
	}}})
	c.Assert(err, jc.ErrorIsNil)

	gwacl.PatchManagementAPIResponses([]gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(listDisksResponse, http.StatusOK, nil),
	})

	volIds, err := vs.ListVolumes()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(volIds, jc.SameContents, []string{"volume-0.vhd", "volume-1.vhd"})
}
Exemplo n.º 10
0
func (s *azureVolumeSuite) TestAttachVolumesNotAttached(c *gc.C) {
	vs := s.volumeSource(c, nil)

	machine := names.NewMachineTag("0")
	volume := names.NewVolumeTag("0")

	env := makeEnviron(c)
	prefix := env.getEnvPrefix()
	service := makeDeployment(env, prefix+"service")
	roleName := service.Deployments[0].RoleList[0].RoleName
	inst, err := env.getInstance(service, roleName)
	c.Assert(err, jc.ErrorIsNil)

	getRoleResponse, err := xml.Marshal(&gwacl.PersistentVMRole{})
	c.Assert(err, jc.ErrorIsNil)

	gwacl.PatchManagementAPIResponses([]gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(getRoleResponse, http.StatusOK, nil),
	})

	results, err := vs.AttachVolumes([]storage.VolumeAttachmentParams{{
		Volume:   volume,
		VolumeId: "volume-0.vhd",
		AttachmentParams: storage.AttachmentParams{
			Machine:    machine,
			InstanceId: inst.Id(),
		},
	}})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(results, gc.HasLen, 1)
	c.Assert(results[0].Error, gc.ErrorMatches, "attaching volumes not supported")
}
Exemplo n.º 11
0
func prepareDeploymentInfoResponse(
	c *gc.C, dep gwacl.Deployment) []gwacl.DispatcherResponse {
	return []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(
			serialize(c, &dep), http.StatusOK, nil),
	}
}
Exemplo n.º 12
0
func (*environSuite) TestNewHostedServiceRetriesIfNotUnique(c *C) {
	errorBody := makeNonAvailabilityResponse(c)
	okBody := makeAvailabilityResponse(c)
	// In this scenario, the first two names that we try are already
	// taken.  The third one is unique though, so we succeed.
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(errorBody, http.StatusOK, nil),
		gwacl.NewDispatcherResponse(errorBody, http.StatusOK, nil),
		gwacl.NewDispatcherResponse(okBody, http.StatusOK, nil),
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
	requests := gwacl.PatchManagementAPIResponses(responses)
	azure, err := gwacl.NewManagementAPI("subscription", "", "West US")
	c.Assert(err, IsNil)

	service, err := newHostedService(azure, "service", "affinity-group", "location")
	c.Check(err, IsNil)

	c.Assert(*requests, HasLen, 4)
	// How many names have been attempted, and how often?
	// There is a minute chance that this tries the same name twice, and
	// then this test will fail.  If that happens, try seeding the
	// randomizer with some fixed seed that doens't produce the problem.
	attemptedNames := make(map[string]int)
	for _, request := range *requests {
		// Exit the loop if we hit the request to create the service, it comes
		// after the check calls.
		if request.Method == "POST" {
			break
		}
		// Name is the last part of the URL from the GET requests that check
		// availability.
		_, name := path.Split(strings.TrimRight(request.URL, "/"))
		attemptedNames[name] += 1
	}
	// The three attempts we just made all had different service names.
	c.Check(attemptedNames, HasLen, 3)

	// Once newHostedService succeeds, we get a hosted service with the
	// last requested name.
	c.Check(
		service.ServiceName,
		Equals,
		parseCreateServiceRequest(c, (*requests)[3]).ServiceName)
}
Exemplo n.º 13
0
func (*environSuite) TestDestroyDeletesVirtualNetworkAndAffinityGroup(c *C) {
	env := makeEnviron(c)
	cleanup := setDummyStorage(c, env)
	defer cleanup()
	services := []gwacl.HostedServiceDescriptor{}
	responses := getAzureServiceListResponse(c, services)
	// Prepare a configuration with a single virtual network.
	existingConfig := &gwacl.NetworkConfiguration{
		XMLNS: gwacl.XMLNS_NC,
		VirtualNetworkSites: &[]gwacl.VirtualNetworkSite{
			{Name: env.getVirtualNetworkName()},
		},
	}
	body, err := existingConfig.Serialize()
	c.Assert(err, IsNil)
	cleanupResponses := []gwacl.DispatcherResponse{
		// Return existing configuration.
		gwacl.NewDispatcherResponse([]byte(body), http.StatusOK, nil),
		// Accept upload of new configuration.
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
		// Accept deletion of affinity group.
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
	responses = append(responses, cleanupResponses...)
	requests := gwacl.PatchManagementAPIResponses(responses)
	instances := convertToInstances([]gwacl.HostedServiceDescriptor{}, env)

	err = env.Destroy(instances)
	c.Check(err, IsNil)

	c.Assert(*requests, HasLen, 4)
	// One request to get the network configuration.
	getRequest := (*requests)[1]
	c.Check(getRequest.Method, Equals, "GET")
	c.Check(strings.HasSuffix(getRequest.URL, "services/networking/media"), Equals, true)
	// One request to upload the new version of the network configuration.
	putRequest := (*requests)[2]
	c.Check(putRequest.Method, Equals, "PUT")
	c.Check(strings.HasSuffix(putRequest.URL, "services/networking/media"), Equals, true)
	// One request to delete the Affinity Group.
	agRequest := (*requests)[3]
	c.Check(strings.Contains(agRequest.URL, env.getAffinityGroupName()), IsTrue)
	c.Check(agRequest.Method, Equals, "DELETE")

}
Exemplo n.º 14
0
// getAzureServiceResponses returns the slice of responses
// (gwacl.DispatcherResponse) which correspond to the API requests used to
// get the properties of a Service.
func getAzureServiceResponses(c *C, service gwacl.HostedService) []gwacl.DispatcherResponse {
	serviceXML, err := service.Serialize()
	c.Assert(err, IsNil)
	responses := []gwacl.DispatcherResponse{gwacl.NewDispatcherResponse(
		[]byte(serviceXML),
		http.StatusOK,
		nil,
	)}
	return responses
}
Exemplo n.º 15
0
func getAzureServiceListResponse(c *C, services []gwacl.HostedServiceDescriptor) []gwacl.DispatcherResponse {
	list := gwacl.HostedServiceDescriptorList{HostedServices: services}
	listXML, err := list.Serialize()
	c.Assert(err, IsNil)
	responses := []gwacl.DispatcherResponse{gwacl.NewDispatcherResponse(
		[]byte(listXML),
		http.StatusOK,
		nil,
	)}
	return responses
}
Exemplo n.º 16
0
func (*EnvironSuite) TestCreateVirtualNetwork(c *C) {
	env := makeEnviron(c)
	responses := []gwacl.DispatcherResponse{
		// No existing configuration found.
		gwacl.NewDispatcherResponse(nil, http.StatusNotFound, nil),
		// Accept upload of new configuration.
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
	requests := gwacl.PatchManagementAPIResponses(responses)

	env.createVirtualNetwork()

	c.Assert(*requests, HasLen, 2)
	request := (*requests)[1]
	body := gwacl.NetworkConfiguration{}
	err := xml.Unmarshal(request.Payload, &body)
	c.Assert(err, IsNil)
	networkConf := (*body.VirtualNetworkSites)[0]
	c.Check(networkConf.Name, Equals, env.getVirtualNetworkName())
	c.Check(networkConf.AffinityGroup, Equals, env.getAffinityGroupName())
}
Exemplo n.º 17
0
func (*environSuite) TestAttemptCreateServiceReturnsNilIfNameNotUnique(c *C) {
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(makeNonAvailabilityResponse(c), http.StatusOK, nil),
	}
	gwacl.PatchManagementAPIResponses(responses)
	azure, err := gwacl.NewManagementAPI("subscription", "", "West US")
	c.Assert(err, IsNil)

	service, err := attemptCreateService(azure, "service", "affinity-group", "location")
	c.Check(err, IsNil)
	c.Check(service, IsNil)
}
Exemplo n.º 18
0
func (*environSuite) TestUpdateStorageAccountKeyReturnsError(c *C) {
	env := makeEnviron(c)
	env.storageAccountKey = ""
	gwacl.PatchManagementAPIResponses([]gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(nil, http.StatusInternalServerError, nil),
	})

	_, err := env.updateStorageAccountKey(env.getSnapshot())
	c.Assert(err, NotNil)

	c.Check(err, ErrorMatches, "cannot obtain storage account keys: GET request failed.*Internal Server Error.*")
	c.Check(env.storageAccountKey, Equals, "")
}
Exemplo n.º 19
0
func (*EnvironSuite) TestAttemptCreateServiceReturnsNilIfNameNotUnique(c *C) {
	errorBody := makeServiceNameAlreadyTakenError(c)
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(errorBody, http.StatusConflict, nil),
	}
	gwacl.PatchManagementAPIResponses(responses)
	azure, err := gwacl.NewManagementAPI("subscription", "certfile.pem")
	c.Assert(err, IsNil)

	service, err := attemptCreateService(azure, "service", "affinity-group")
	c.Check(err, IsNil)
	c.Check(service, IsNil)
}
Exemplo n.º 20
0
func (*environSuite) TestGetStorageContextFailsIfNoKeyAvailable(c *C) {
	env := makeEnviron(c)
	env.storageAccountKey = ""
	azureResponse, err := xml.Marshal(gwacl.StorageAccountKeys{})
	c.Assert(err, IsNil)
	gwacl.PatchManagementAPIResponses([]gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(azureResponse, http.StatusOK, nil),
	})

	_, err = env.getStorageContext()
	c.Assert(err, NotNil)

	c.Check(err, ErrorMatches, "no keys available for storage account")
}
Exemplo n.º 21
0
func (*EnvironSuite) TestDestroyAffinityGroup(c *C) {
	env := makeEnviron(c)
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
	requests := gwacl.PatchManagementAPIResponses(responses)

	env.deleteAffinityGroup()

	c.Assert(*requests, HasLen, 1)
	request := (*requests)[0]
	c.Check(strings.Contains(request.URL, env.getAffinityGroupName()), IsTrue)
	c.Check(request.Method, Equals, "DELETE")
}
Exemplo n.º 22
0
func (*EnvironSuite) TestNewHostedServiceFailsIfUnableToFindUniqueName(c *C) {
	errorBody := makeServiceNameAlreadyTakenError(c)
	responses := []gwacl.DispatcherResponse{}
	for counter := 0; counter < 100; counter++ {
		responses = append(responses, gwacl.NewDispatcherResponse(errorBody, http.StatusConflict, nil))
	}
	gwacl.PatchManagementAPIResponses(responses)
	azure, err := gwacl.NewManagementAPI("subscription", "certfile.pem")
	c.Assert(err, IsNil)

	_, err = newHostedService(azure, "service", "affinity-group")
	c.Assert(err, NotNil)
	c.Check(err, ErrorMatches, "could not come up with a unique hosted service name.*")
}
Exemplo n.º 23
0
func (*environSuite) TestUpdateStorageAccountKeyGetsFreshKey(c *C) {
	env := makeEnviron(c)
	keysInAzure := gwacl.StorageAccountKeys{Primary: "my-key"}
	azureResponse, err := xml.Marshal(keysInAzure)
	c.Assert(err, IsNil)
	gwacl.PatchManagementAPIResponses([]gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(azureResponse, http.StatusOK, nil),
	})

	key, err := env.updateStorageAccountKey(env.getSnapshot())
	c.Assert(err, IsNil)

	c.Check(key, Equals, keysInAzure.Primary)
	c.Check(env.storageAccountKey, Equals, keysInAzure.Primary)
}
Exemplo n.º 24
0
func (*EnvironSuite) TestNewHostedServiceRetriesIfNotUnique(c *C) {
	errorBody := makeServiceNameAlreadyTakenError(c)
	// In this scenario, the first two names that we try are already
	// taken.  The third one is unique though, so we succeed.
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(errorBody, http.StatusConflict, nil),
		gwacl.NewDispatcherResponse(errorBody, http.StatusConflict, nil),
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
	requests := gwacl.PatchManagementAPIResponses(responses)
	azure, err := gwacl.NewManagementAPI("subscription", "certfile.pem")
	c.Assert(err, IsNil)

	service, err := newHostedService(azure, "service", "affinity-group")
	c.Check(err, IsNil)

	c.Assert(*requests, HasLen, 3)
	// How many names have been attempted, and how often?
	// There is a minute chance that this tries the same name twice, and
	// then this test will fail.  If that happens, try seeding the
	// randomizer with some fixed seed that doens't produce the problem.
	attemptedNames := make(map[string]int)
	for _, request := range *requests {
		name := parseCreateServiceRequest(c, request).ServiceName
		attemptedNames[name] += 1
	}
	// The three attempts we just made all had different service names.
	c.Check(attemptedNames, HasLen, 3)

	// Once newHostedService succeeds, we get a hosted service with the
	// last requested name.
	c.Check(
		service.ServiceName,
		Equals,
		parseCreateServiceRequest(c, (*requests)[2]).ServiceName)
}
Exemplo n.º 25
0
func (*instanceSuite) TestClosePortsFailsWhenUnableToGetServiceProperties(c *C) {
	service := makeHostedServiceDescriptor("service-name")
	responses := []gwacl.DispatcherResponse{
		// GetHostedServiceProperties breaks.
		gwacl.NewDispatcherResponse(nil, http.StatusInternalServerError, nil),
	}
	record := gwacl.PatchManagementAPIResponses(responses)
	azInstance := azureInstance{*service, makeEnviron(c)}

	err := azInstance.ClosePorts("machine-id", []instance.Port{
		{"tcp", 79}, {"tcp", 587}, {"udp", 9},
	})

	c.Check(err, ErrorMatches, "GET request failed [(]500: Internal Server Error[)]")
	c.Check(*record, HasLen, 1)
}
Exemplo n.º 26
0
func (*environSuite) TestQueryStorageAccountKeyGetsKey(c *C) {
	env := makeEnviron(c)
	keysInAzure := gwacl.StorageAccountKeys{Primary: "a-key"}
	azureResponse, err := xml.Marshal(keysInAzure)
	c.Assert(err, IsNil)
	requests := gwacl.PatchManagementAPIResponses([]gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(azureResponse, http.StatusOK, nil),
	})

	returnedKey, err := env.queryStorageAccountKey()
	c.Assert(err, IsNil)

	c.Check(returnedKey, Equals, keysInAzure.Primary)
	c.Assert(*requests, HasLen, 1)
	c.Check((*requests)[0].Method, Equals, "GET")
}
Exemplo n.º 27
0
func (*environSuite) TestGetStorageContextQueriesStorageAccountKeyIfNeeded(c *C) {
	env := makeEnviron(c)
	env.storageAccountKey = ""
	keysInAzure := gwacl.StorageAccountKeys{Primary: "my-key"}
	azureResponse, err := xml.Marshal(keysInAzure)
	c.Assert(err, IsNil)
	gwacl.PatchManagementAPIResponses([]gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(azureResponse, http.StatusOK, nil),
	})

	storage, err := env.getStorageContext()
	c.Assert(err, IsNil)

	c.Check(storage.Key, Equals, keysInAzure.Primary)
	c.Check(env.storageAccountKey, Equals, keysInAzure.Primary)
}
Exemplo n.º 28
0
func (*EnvironSuite) TestCreateAffinityGroup(c *C) {
	env := makeEnviron(c)
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(nil, http.StatusCreated, nil),
	}
	requests := gwacl.PatchManagementAPIResponses(responses)

	env.createAffinityGroup()

	c.Assert(*requests, HasLen, 1)
	request := (*requests)[0]
	body := gwacl.CreateAffinityGroup{}
	err := xml.Unmarshal(request.Payload, &body)
	c.Assert(err, IsNil)
	c.Check(body.Name, Equals, env.getAffinityGroupName())
	c.Check(body.Location, Equals, serviceLocation)
}
Exemplo n.º 29
0
func (s *azureVolumeSuite) TestCreateVolumesNoLuns(c *gc.C) {
	vs := s.volumeSource(c, nil)

	machine := names.NewMachineTag("123")
	volume := names.NewVolumeTag("0")

	env := makeEnviron(c)
	prefix := env.getEnvPrefix()
	serviceName := "service"
	service := makeDeployment(env, prefix+serviceName)
	roleName := service.Deployments[0].RoleList[0].RoleName
	inst, err := env.getInstance(service, roleName)
	c.Assert(err, jc.ErrorIsNil)

	params := []storage.VolumeParams{{
		Tag:      volume,
		Size:     10 * 1000,
		Provider: storageProviderType,
		Attachment: &storage.VolumeAttachmentParams{
			AttachmentParams: storage.AttachmentParams{
				Machine:    machine,
				InstanceId: inst.Id(),
			},
		},
	}}

	dataVirtualHardDisks := make([]gwacl.DataVirtualHardDisk, 32)
	for i := range dataVirtualHardDisks {
		dataVirtualHardDisks[i].LUN = i
	}
	getRoleResponse, err := xml.Marshal(&gwacl.PersistentVMRole{
		DataVirtualHardDisks: &dataVirtualHardDisks,
	})
	c.Assert(err, jc.ErrorIsNil)

	gwacl.PatchManagementAPIResponses([]gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(getRoleResponse, http.StatusOK, nil),
	})

	results, err := vs.CreateVolumes(params)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(results, gc.HasLen, 1)
	c.Assert(results[0].Error, gc.ErrorMatches, "choosing LUN: all LUNs are in use")
}
Exemplo n.º 30
0
func (*EnvironSuite) TestNewHostedServiceCreatesService(c *C) {
	prefix := "myservice"
	affinityGroup := "affinity-group"
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(nil, http.StatusOK, nil),
	}
	requests := gwacl.PatchManagementAPIResponses(responses)
	azure, err := gwacl.NewManagementAPI("subscription", "certfile.pem")
	c.Assert(err, IsNil)

	service, err := newHostedService(azure, prefix, affinityGroup)
	c.Assert(err, IsNil)

	c.Assert(*requests, HasLen, 1)
	body := parseCreateServiceRequest(c, (*requests)[0])
	c.Check(body.ServiceName, Equals, service.ServiceName)
	c.Check(body.AffinityGroup, Equals, affinityGroup)
	c.Check(service.ServiceName, Matches, prefix+".*")
}