Пример #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)
}
Пример #2
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)
}
Пример #3
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", ".*")
}
Пример #4
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")
}
Пример #5
0
func (s *instanceSuite) TestAddresses(c *gc.C) {
	vnn := s.env.getVirtualNetworkName()
	responses := prepareDeploymentInfoResponse(c, gwacl.Deployment{
		RoleInstanceList: []gwacl.RoleInstance{{
			RoleName:  s.role.RoleName,
			IPAddress: "1.2.3.4",
		}},
		VirtualNetworkName: vnn,
	})
	gwacl.PatchManagementAPIResponses(responses)

	expected := []network.Address{
		network.Address{
			"1.2.3.4",
			network.IPv4Address,
			vnn,
			network.ScopeCloudLocal,
		},
		network.Address{
			s.service.ServiceName + "." + AzureDomainName,
			network.HostName,
			"",
			network.ScopePublic,
		},
	}

	addrs, err := s.instance.Addresses()
	c.Check(err, gc.IsNil)
	c.Check(addrs, jc.SameContents, expected)
}
Пример #6
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"})
}
Пример #7
0
func (s *instanceSuite) TestOpenPorts(c *gc.C) {
	// Close the default ports.
	configSetNetwork((*gwacl.Role)(s.role)).InputEndpoints = nil

	responses := preparePortChangeConversation(c, s.role)
	record := gwacl.PatchManagementAPIResponses(responses)
	err := s.instance.OpenPorts("machine-id", []network.PortRange{
		{79, 79, "tcp"}, {587, 587, "tcp"}, {9, 9, "udp"},
	})
	c.Assert(err, jc.ErrorIsNil)

	assertPortChangeConversation(c, *record, []expectedRequest{
		{"GET", ".*/deployments/deployment-one/roles/role-one"}, // GetRole
		{"PUT", ".*/deployments/deployment-one/roles/role-one"}, // UpdateRole
	})

	// A representative UpdateRole payload includes configuration for the
	// ports requested.
	role := &gwacl.PersistentVMRole{}
	err = role.Deserialize((*record)[1].Payload)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(
		*configSetNetwork((*gwacl.Role)(role)).InputEndpoints,
		gc.DeepEquals,
		[]gwacl.InputEndpoint{
			makeInputEndpoint(79, "tcp"),
			makeInputEndpoint(587, "tcp"),
			makeInputEndpoint(9, "udp"),
		},
	)
}
Пример #8
0
func (*environSuite) TestStopInstancesDestroysMachines(c *C) {
	cleanup := setServiceDeletionConcurrency(3)
	defer cleanup()
	service1Name := "service1"
	service1, service1Desc := makeAzureService(service1Name)
	service2Name := "service2"
	service2, service2Desc := makeAzureService(service2Name)
	services := []*gwacl.HostedService{service1, service2}
	responses := buildDestroyAzureServiceResponses(c, services)
	requests := gwacl.PatchManagementAPIResponses(responses)
	env := makeEnviron(c)
	instances := convertToInstances(
		[]gwacl.HostedServiceDescriptor{*service1Desc, *service2Desc},
		env)

	err := env.StopInstances(instances)
	c.Check(err, IsNil)

	// It takes 2 API calls to delete each service:
	// - one GET request to fetch the service's properties;
	// - one DELETE request to delete the service.
	c.Check(len(*requests), Equals, len(services)*2)
	assertOneRequestMatches(c, *requests, "GET", ".*"+service1Name+".*")
	assertOneRequestMatches(c, *requests, "DELETE", ".*"+service1Name+".*")
	assertOneRequestMatches(c, *requests, "GET", ".*"+service2Name+".")
	assertOneRequestMatches(c, *requests, "DELETE", ".*"+service2Name+".*")
}
Пример #9
0
func (s *instanceSuite) TestClosePorts(c *gc.C) {
	type test struct {
		inputPorts  []network.PortRange
		removePorts []network.PortRange
		outputPorts []network.PortRange
	}

	tests := []test{{
		inputPorts:  []network.PortRange{{1, 1, "tcp"}, {2, 2, "tcp"}, {3, 3, "udp"}},
		removePorts: nil,
		outputPorts: []network.PortRange{{1, 1, "tcp"}, {2, 2, "tcp"}, {3, 3, "udp"}},
	}, {
		inputPorts:  []network.PortRange{{1, 1, "tcp"}},
		removePorts: []network.PortRange{{1, 1, "udp"}},
		outputPorts: []network.PortRange{{1, 1, "tcp"}},
	}, {
		inputPorts:  []network.PortRange{{1, 1, "tcp"}, {2, 2, "tcp"}, {3, 3, "udp"}},
		removePorts: []network.PortRange{{1, 1, "tcp"}, {2, 2, "tcp"}, {3, 3, "udp"}},
		outputPorts: []network.PortRange{},
	}, {
		inputPorts:  []network.PortRange{{1, 1, "tcp"}, {2, 2, "tcp"}, {3, 3, "udp"}},
		removePorts: []network.PortRange{{99, 99, "tcp"}},
		outputPorts: []network.PortRange{{1, 1, "tcp"}, {2, 2, "tcp"}, {3, 3, "udp"}},
	}}

	for i, test := range tests {
		c.Logf("test %d: %#v", i, test)

		inputEndpoints := make([]gwacl.InputEndpoint, len(test.inputPorts))
		for i, port := range test.inputPorts {
			inputEndpoints[i] = makeInputEndpoint(port.FromPort, port.Protocol)
		}
		configSetNetwork(s.role).InputEndpoints = &inputEndpoints
		responses := preparePortChangeConversation(c, s.role)
		record := gwacl.PatchManagementAPIResponses(responses)

		err := s.instance.ClosePorts("machine-id", test.removePorts)
		c.Assert(err, jc.ErrorIsNil)
		assertPortChangeConversation(c, *record, []expectedRequest{
			{"GET", ".*/deployments/deployment-one/roles/role-one"}, // GetRole
			{"PUT", ".*/deployments/deployment-one/roles/role-one"}, // UpdateRole
		})

		// The first UpdateRole removes all endpoints from the role's
		// configuration.
		roleOne := &gwacl.PersistentVMRole{}
		err = roleOne.Deserialize((*record)[1].Payload)
		c.Assert(err, jc.ErrorIsNil)
		endpoints := configSetNetwork((*gwacl.Role)(roleOne)).InputEndpoints
		if len(test.outputPorts) == 0 {
			c.Check(endpoints, gc.IsNil)
		} else {
			c.Check(endpoints, gc.NotNil)
			c.Check(convertAndFilterEndpoints(*endpoints, s.env, false), gc.DeepEquals, test.outputPorts)
		}
	}
}
Пример #10
0
func (s *instanceSuite) TestClosePortsFailsWhenUnableToGetRole(c *gc.C) {
	responses := preparePortChangeConversation(c, s.role)
	failPortChangeConversationAt(1, responses) // 1st request, GetRole
	record := gwacl.PatchManagementAPIResponses(responses)
	err := s.instance.ClosePorts("machine-id", []network.Port{
		{"tcp", 79}, {"tcp", 587}, {"udp", 9},
	})
	c.Check(err, gc.ErrorMatches, "GET request failed [(]500: Internal Server Error[)]")
	c.Check(*record, gc.HasLen, 1)
}
Пример #11
0
func (s *instanceSuite) TestClosePortsFailsWhenUnableToUpdateRole(c *gc.C) {
	responses := preparePortChangeConversation(c, s.role)
	failPortChangeConversationAt(2, responses) // 2nd request, UpdateRole
	record := gwacl.PatchManagementAPIResponses(responses)
	err := s.instance.ClosePorts("machine-id", []network.PortRange{
		{79, 79, "tcp"}, {587, 587, "tcp"}, {9, 9, "udp"},
	})
	c.Check(err, gc.ErrorMatches, "PUT request failed [(]500: Internal Server Error[)]")
	c.Check(*record, gc.HasLen, 2)
}
Пример #12
0
func (*instanceSuite) TestPortsReturnsEmptySliceIfNoDeployment(c *C) {
	service := makeHostedServiceDescriptor("service-name")
	responses := preparePortChangeConversation(c, service)
	gwacl.PatchManagementAPIResponses(responses)
	azInstance := azureInstance{*service, makeEnviron(c)}

	ports, err := azInstance.Ports("machine-id")

	c.Assert(err, IsNil)
	c.Check(ports, HasLen, 0)
}
Пример #13
0
func (*instanceSuite) TestClosePorts(c *C) {
	service := makeHostedServiceDescriptor("service-name")
	responses := preparePortChangeConversation(c, service,
		makeDeployment("deployment-one",
			makeRole("role-one",
				makeInputEndpoint(587, "tcp"),
			),
			makeRole("role-two",
				makeInputEndpoint(79, "tcp"),
				makeInputEndpoint(9, "udp"),
			)),
		makeDeployment("deployment-two",
			makeRole("role-three",
				makeInputEndpoint(9, "tcp"),
				makeInputEndpoint(9, "udp"),
			)))
	record := gwacl.PatchManagementAPIResponses(responses)
	azInstance := azureInstance{*service, makeEnviron(c)}

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

	c.Assert(err, IsNil)
	assertPortChangeConversation(c, *record, []expectedRequest{
		{"GET", ".*/services/hostedservices/service-name[?].*"},   // GetHostedServiceProperties
		{"GET", ".*/deployments/deployment-one/roles/role-one"},   // GetRole
		{"PUT", ".*/deployments/deployment-one/roles/role-one"},   // UpdateRole
		{"GET", ".*/deployments/deployment-one/roles/role-two"},   // GetRole
		{"PUT", ".*/deployments/deployment-one/roles/role-two"},   // UpdateRole
		{"GET", ".*/deployments/deployment-two/roles/role-three"}, // GetRole
		{"PUT", ".*/deployments/deployment-two/roles/role-three"}, // UpdateRole
	})

	// The first UpdateRole removes all endpoints from the role's
	// configuration.
	roleOne := &gwacl.PersistentVMRole{}
	err = roleOne.Deserialize((*record)[2].Payload)
	c.Assert(err, IsNil)
	c.Check(roleOne.ConfigurationSets[0].InputEndpoints, IsNil)

	// The second UpdateRole removes all but 79/TCP.
	roleTwo := &gwacl.PersistentVMRole{}
	err = roleTwo.Deserialize((*record)[4].Payload)
	c.Assert(err, IsNil)
	c.Check(roleTwo.ConfigurationSets[0].InputEndpoints, DeepEquals,
		&[]gwacl.InputEndpoint{makeInputEndpoint(79, "tcp")})

	// The third UpdateRole removes all but 9/TCP.
	roleThree := &gwacl.PersistentVMRole{}
	err = roleThree.Deserialize((*record)[6].Payload)
	c.Assert(err, IsNil)
	c.Check(roleThree.ConfigurationSets[0].InputEndpoints, DeepEquals,
		&[]gwacl.InputEndpoint{makeInputEndpoint(9, "tcp")})
}
Пример #14
0
func (*EnvironSuite) TestAttemptCreateServicePropagatesOtherFailure(c *C) {
	responses := []gwacl.DispatcherResponse{
		gwacl.NewDispatcherResponse(nil, http.StatusNotFound, nil),
	}
	gwacl.PatchManagementAPIResponses(responses)
	azure, err := gwacl.NewManagementAPI("subscription", "certfile.pem")
	c.Assert(err, IsNil)

	_, err = attemptCreateService(azure, "service", "affinity-group")
	c.Assert(err, NotNil)
	c.Check(err, ErrorMatches, ".*Not Found.*")
}
Пример #15
0
func (*instanceSuite) TestPortsErrorsIfMoreThanOneRole(c *C) {
	service := makeHostedServiceDescriptor("service-name")
	responses := preparePortChangeConversation(c, service,
		makeDeployment("deployment-one",
			makeRole("role-one"), makeRole("role-two")))
	gwacl.PatchManagementAPIResponses(responses)
	azInstance := azureInstance{*service, makeEnviron(c)}

	_, err := azInstance.Ports("machine-id")

	c.Check(err, ErrorMatches, ".*more than one Azure role inside the deployment.*")
}
Пример #16
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)
}
Пример #17
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)
}
Пример #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, "")
}
Пример #19
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")
}
Пример #20
0
func (s *instanceSuite) testPorts(c *gc.C, maskStateServerPorts bool) {
	// Update the role's endpoints by hand.
	configSetNetwork(s.role).InputEndpoints = &[]gwacl.InputEndpoint{{
		LocalPort: 223,
		Protocol:  "udp",
		Name:      "test223",
		Port:      2123,
	}, {
		LocalPort: 123,
		Protocol:  "udp",
		Name:      "test123",
		Port:      1123,
	}, {
		LocalPort: 456,
		Protocol:  "tcp",
		Name:      "test456",
		Port:      4456,
	}, {
		LocalPort: s.env.Config().StatePort(),
		Protocol:  "tcp",
		Name:      "stateserver",
		Port:      s.env.Config().StatePort(),
	}, {
		LocalPort: s.env.Config().APIPort(),
		Protocol:  "tcp",
		Name:      "apiserver",
		Port:      s.env.Config().APIPort(),
	}}

	responses := preparePortChangeConversation(c, s.role)
	record := gwacl.PatchManagementAPIResponses(responses)
	s.instance.maskStateServerPorts = maskStateServerPorts
	ports, err := s.instance.Ports("machine-id")
	c.Assert(err, gc.IsNil)
	assertPortChangeConversation(c, *record, []expectedRequest{
		{"GET", ".*/deployments/deployment-one/roles/role-one"}, // GetRole
	})

	expected := []network.Port{
		{Number: 4456, Protocol: "tcp"},
		{Number: 1123, Protocol: "udp"},
		{Number: 2123, Protocol: "udp"},
	}
	if !maskStateServerPorts {
		expected = append(expected, network.Port{Number: s.env.Config().StatePort(), Protocol: "tcp"})
		expected = append(expected, network.Port{Number: s.env.Config().APIPort(), Protocol: "tcp"})
		network.SortPorts(expected)
	}
	c.Check(ports, gc.DeepEquals, expected)
}
Пример #21
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")
}
Пример #22
0
func (*EnvironSuite) TestGetInstance(c *C) {
	env := makeEnviron(c)
	prefix := env.getEnvPrefix()
	serviceName := prefix + "instance-name"
	serviceDesc := gwacl.HostedServiceDescriptor{ServiceName: serviceName}
	service := gwacl.HostedService{HostedServiceDescriptor: serviceDesc}
	responses := getAzureServiceResponses(c, service)
	gwacl.PatchManagementAPIResponses(responses)

	instance, err := env.getInstance("serviceName")
	c.Check(err, IsNil)

	c.Check(string(instance.Id()), Equals, serviceName)
}
Пример #23
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.*")
}
Пример #24
0
func (*instanceSuite) TestClosePortsFailsWhenUnableToUpdateRole(c *C) {
	service := makeHostedServiceDescriptor("service-name")
	responses := preparePortChangeConversation(c, service,
		makeDeployment("deployment-one", makeRole("role-one")))
	failPortChangeConversationAt(3, responses) // 3rd request, UpdateRole
	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, "PUT request failed [(]500: Internal Server Error[)]")
	c.Check(*record, HasLen, 3)
}
Пример #25
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)
}
Пример #26
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)
}
Пример #27
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")
}
Пример #28
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)
}
Пример #29
0
func (*instanceSuite) TestPorts(c *C) {
	service := makeHostedServiceDescriptor("service-name")
	endpoints := []gwacl.InputEndpoint{
		{
			LocalPort: 223,
			Protocol:  "udp",
			Name:      "test223",
			Port:      2123,
		},
		{
			LocalPort: 123,
			Protocol:  "udp",
			Name:      "test123",
			Port:      1123,
		},
		{
			LocalPort: 456,
			Protocol:  "tcp",
			Name:      "test456",
			Port:      4456,
		}}

	responses := preparePortChangeConversation(c, service,
		makeDeployment("deployment-one",
			makeRole("role-one", endpoints...)))
	record := gwacl.PatchManagementAPIResponses(responses)
	azInstance := azureInstance{*service, makeEnviron(c)}

	ports, err := azInstance.Ports("machine-id")

	c.Assert(err, IsNil)
	assertPortChangeConversation(c, *record, []expectedRequest{
		{"GET", ".*/services/hostedservices/service-name[?].*"}, // GetHostedServiceProperties
		{"GET", ".*/deployments/deployment-one/roles/role-one"}, // GetRole
	})

	c.Check(
		ports,
		DeepEquals,
		// The result is sorted using state.SortPorts() (i.e. first by protocol,
		// then by number).
		[]instance.Port{
			{Number: 4456, Protocol: "tcp"},
			{Number: 1123, Protocol: "udp"},
			{Number: 2123, Protocol: "udp"},
		})
}
Пример #30
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)
}