本文整理汇总了Golang中launchpad/net/gwacl.PatchManagementAPIResponses函数的典型用法代码示例。如果您正苦于以下问题:Golang PatchManagementAPIResponses函数的具体用法?Golang PatchManagementAPIResponses怎么用?Golang PatchManagementAPIResponses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PatchManagementAPIResponses函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAttemptCreateServiceCreatesService
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: TestDestroyVirtualNetwork
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: TestStopInstancesWhenStoppingMachinesFails
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: TestAttachVolumesNotAttached
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: TestAddresses
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: TestListVolumes
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: TestOpenPorts
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: TestStopInstancesDestroysMachines
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: TestClosePorts
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: TestClosePortsFailsWhenUnableToGetRole
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: TestClosePortsFailsWhenUnableToUpdateRole
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: TestPortsReturnsEmptySliceIfNoDeployment
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: TestClosePorts
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: TestAttemptCreateServicePropagatesOtherFailure
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: TestPortsErrorsIfMoreThanOneRole
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.*")
}