2017-11-16 20:29:55 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-11-15 01:39:55 +00:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
2018-01-05 06:24:44 +00:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/disk"
|
2017-11-15 01:39:55 +00:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/network"
|
2018-01-05 06:24:44 +00:00
|
|
|
"github.com/Azure/azure-sdk-for-go/arm/storage"
|
2017-11-15 01:39:55 +00:00
|
|
|
"github.com/Azure/go-autorest/autorest"
|
2018-01-05 06:24:44 +00:00
|
|
|
"github.com/Azure/go-autorest/autorest/to"
|
2017-11-15 01:39:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type fakeAzureLBClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]network.LoadBalancer
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeAzureLBClient() *fakeAzureLBClient {
|
|
|
|
fLBC := &fakeAzureLBClient{}
|
2017-11-15 01:39:55 +00:00
|
|
|
fLBC.FakeStore = make(map[string]map[string]network.LoadBalancer)
|
|
|
|
fLBC.mutex = &sync.Mutex{}
|
|
|
|
return fLBC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fLBC *fakeAzureLBClient) CreateOrUpdate(resourceGroupName string, loadBalancerName string, parameters network.LoadBalancer, cancel <-chan struct{}) (<-chan network.LoadBalancer, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fLBC.mutex.Lock()
|
|
|
|
defer fLBC.mutex.Unlock()
|
|
|
|
resultChan := make(chan network.LoadBalancer, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result network.LoadBalancer
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
if _, ok := fLBC.FakeStore[resourceGroupName]; !ok {
|
|
|
|
fLBC.FakeStore[resourceGroupName] = make(map[string]network.LoadBalancer)
|
|
|
|
}
|
|
|
|
|
|
|
|
// For dynamic ip allocation, just fill in the PrivateIPAddress
|
|
|
|
if parameters.FrontendIPConfigurations != nil {
|
|
|
|
for idx, config := range *parameters.FrontendIPConfigurations {
|
|
|
|
if config.PrivateIPAllocationMethod == network.Dynamic {
|
2017-11-17 00:09:08 +00:00
|
|
|
// Here we randomly assign an ip as private ip
|
|
|
|
// It dosen't smart enough to know whether it is in the subnet's range
|
|
|
|
(*parameters.FrontendIPConfigurations)[idx].PrivateIPAddress = getRandomIPPtr()
|
2017-11-15 01:39:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fLBC.FakeStore[resourceGroupName][loadBalancerName] = parameters
|
|
|
|
result = fLBC.FakeStore[resourceGroupName][loadBalancerName]
|
2017-11-16 23:04:08 +00:00
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
2017-11-15 01:39:55 +00:00
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fLBC *fakeAzureLBClient) Delete(resourceGroupName string, loadBalancerName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fLBC.mutex.Lock()
|
|
|
|
defer fLBC.mutex.Unlock()
|
|
|
|
respChan := make(chan autorest.Response, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var resp autorest.Response
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
respChan <- resp
|
|
|
|
errChan <- err
|
|
|
|
close(respChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
2017-11-16 19:33:48 +00:00
|
|
|
if rgLBs, ok := fLBC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if _, ok := rgLBs[loadBalancerName]; ok {
|
|
|
|
delete(rgLBs, loadBalancerName)
|
2017-11-15 01:39:55 +00:00
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusAccepted,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
}
|
|
|
|
err = autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such LB",
|
|
|
|
}
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fLBC *fakeAzureLBClient) Get(resourceGroupName string, loadBalancerName string, expand string) (result network.LoadBalancer, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fLBC.mutex.Lock()
|
|
|
|
defer fLBC.mutex.Unlock()
|
|
|
|
if _, ok := fLBC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := fLBC.FakeStore[resourceGroupName][loadBalancerName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such LB",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fLBC *fakeAzureLBClient) List(resourceGroupName string) (result network.LoadBalancerListResult, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fLBC.mutex.Lock()
|
|
|
|
defer fLBC.mutex.Unlock()
|
|
|
|
var value []network.LoadBalancer
|
|
|
|
if _, ok := fLBC.FakeStore[resourceGroupName]; ok {
|
|
|
|
for _, v := range fLBC.FakeStore[resourceGroupName] {
|
|
|
|
value = append(value, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
result.NextLink = nil
|
|
|
|
result.Value = &value
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fLBC *fakeAzureLBClient) ListNextResults(resourceGroupName string, lastResult network.LoadBalancerListResult) (result network.LoadBalancerListResult, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fLBC.mutex.Lock()
|
|
|
|
defer fLBC.mutex.Unlock()
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
result.NextLink = nil
|
|
|
|
result.Value = nil
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeAzurePIPClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]network.PublicIPAddress
|
|
|
|
SubscriptionID string
|
|
|
|
}
|
|
|
|
|
|
|
|
const publicIPAddressIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/publicIPAddresses/%s"
|
|
|
|
|
|
|
|
// returns the full identifier of a publicIPAddress.
|
|
|
|
func getpublicIPAddressID(subscriptionID string, resourceGroupName, pipName string) string {
|
|
|
|
return fmt.Sprintf(
|
|
|
|
publicIPAddressIDTemplate,
|
|
|
|
subscriptionID,
|
|
|
|
resourceGroupName,
|
|
|
|
pipName)
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeAzurePIPClient(subscriptionID string) *fakeAzurePIPClient {
|
|
|
|
fAPC := &fakeAzurePIPClient{}
|
2017-11-15 01:39:55 +00:00
|
|
|
fAPC.FakeStore = make(map[string]map[string]network.PublicIPAddress)
|
|
|
|
fAPC.SubscriptionID = subscriptionID
|
|
|
|
fAPC.mutex = &sync.Mutex{}
|
|
|
|
return fAPC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fAPC *fakeAzurePIPClient) CreateOrUpdate(resourceGroupName string, publicIPAddressName string, parameters network.PublicIPAddress, cancel <-chan struct{}) (<-chan network.PublicIPAddress, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fAPC.mutex.Lock()
|
|
|
|
defer fAPC.mutex.Unlock()
|
|
|
|
resultChan := make(chan network.PublicIPAddress, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result network.PublicIPAddress
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
if _, ok := fAPC.FakeStore[resourceGroupName]; !ok {
|
|
|
|
fAPC.FakeStore[resourceGroupName] = make(map[string]network.PublicIPAddress)
|
|
|
|
}
|
|
|
|
|
|
|
|
// assign id
|
|
|
|
pipID := getpublicIPAddressID(fAPC.SubscriptionID, resourceGroupName, publicIPAddressName)
|
|
|
|
parameters.ID = &pipID
|
|
|
|
|
|
|
|
// only create in the case user has not provided
|
|
|
|
if parameters.PublicIPAddressPropertiesFormat != nil &&
|
|
|
|
parameters.PublicIPAddressPropertiesFormat.PublicIPAllocationMethod == network.Static {
|
|
|
|
// assign ip
|
2017-11-17 00:09:08 +00:00
|
|
|
parameters.IPAddress = getRandomIPPtr()
|
2017-11-15 01:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fAPC.FakeStore[resourceGroupName][publicIPAddressName] = parameters
|
|
|
|
result = fAPC.FakeStore[resourceGroupName][publicIPAddressName]
|
2017-11-16 23:04:08 +00:00
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
2017-11-15 01:39:55 +00:00
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fAPC *fakeAzurePIPClient) Delete(resourceGroupName string, publicIPAddressName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fAPC.mutex.Lock()
|
|
|
|
defer fAPC.mutex.Unlock()
|
|
|
|
respChan := make(chan autorest.Response, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var resp autorest.Response
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
respChan <- resp
|
|
|
|
errChan <- err
|
|
|
|
close(respChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
2017-11-16 19:33:48 +00:00
|
|
|
if rgPIPs, ok := fAPC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if _, ok := rgPIPs[publicIPAddressName]; ok {
|
|
|
|
delete(rgPIPs, publicIPAddressName)
|
2017-11-15 01:39:55 +00:00
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusAccepted,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
}
|
|
|
|
err = autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such PIP",
|
|
|
|
}
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fAPC *fakeAzurePIPClient) Get(resourceGroupName string, publicIPAddressName string, expand string) (result network.PublicIPAddress, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fAPC.mutex.Lock()
|
|
|
|
defer fAPC.mutex.Unlock()
|
|
|
|
if _, ok := fAPC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := fAPC.FakeStore[resourceGroupName][publicIPAddressName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such PIP",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fAPC *fakeAzurePIPClient) ListNextResults(resourceGroupName string, lastResults network.PublicIPAddressListResult) (result network.PublicIPAddressListResult, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fAPC.mutex.Lock()
|
|
|
|
defer fAPC.mutex.Unlock()
|
|
|
|
return network.PublicIPAddressListResult{}, nil
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fAPC *fakeAzurePIPClient) List(resourceGroupName string) (result network.PublicIPAddressListResult, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fAPC.mutex.Lock()
|
|
|
|
defer fAPC.mutex.Unlock()
|
|
|
|
var value []network.PublicIPAddress
|
|
|
|
if _, ok := fAPC.FakeStore[resourceGroupName]; ok {
|
|
|
|
for _, v := range fAPC.FakeStore[resourceGroupName] {
|
|
|
|
value = append(value, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
result.NextLink = nil
|
|
|
|
result.Value = &value
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2017-11-16 19:25:51 +00:00
|
|
|
type fakeAzureInterfacesClient struct {
|
2017-11-15 01:39:55 +00:00
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]network.Interface
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeAzureInterfacesClient() *fakeAzureInterfacesClient {
|
|
|
|
fIC := &fakeAzureInterfacesClient{}
|
2017-11-15 01:39:55 +00:00
|
|
|
fIC.FakeStore = make(map[string]map[string]network.Interface)
|
|
|
|
fIC.mutex = &sync.Mutex{}
|
|
|
|
|
|
|
|
return fIC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fIC *fakeAzureInterfacesClient) CreateOrUpdate(resourceGroupName string, networkInterfaceName string, parameters network.Interface, cancel <-chan struct{}) (<-chan network.Interface, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fIC.mutex.Lock()
|
|
|
|
defer fIC.mutex.Unlock()
|
|
|
|
resultChan := make(chan network.Interface, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result network.Interface
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
if _, ok := fIC.FakeStore[resourceGroupName]; !ok {
|
|
|
|
fIC.FakeStore[resourceGroupName] = make(map[string]network.Interface)
|
|
|
|
}
|
|
|
|
fIC.FakeStore[resourceGroupName][networkInterfaceName] = parameters
|
|
|
|
result = fIC.FakeStore[resourceGroupName][networkInterfaceName]
|
2017-11-16 23:04:08 +00:00
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
2017-11-15 01:39:55 +00:00
|
|
|
err = nil
|
|
|
|
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fIC *fakeAzureInterfacesClient) Get(resourceGroupName string, networkInterfaceName string, expand string) (result network.Interface, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fIC.mutex.Lock()
|
|
|
|
defer fIC.mutex.Unlock()
|
|
|
|
if _, ok := fIC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := fIC.FakeStore[resourceGroupName][networkInterfaceName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such Interface",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fIC *fakeAzureInterfacesClient) GetVirtualMachineScaleSetNetworkInterface(resourceGroupName string, virtualMachineScaleSetName string, virtualmachineIndex string, networkInterfaceName string, expand string) (result network.Interface, err error) {
|
2017-11-21 07:14:27 +00:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2017-11-16 19:25:51 +00:00
|
|
|
type fakeAzureVirtualMachinesClient struct {
|
2017-11-15 01:39:55 +00:00
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]compute.VirtualMachine
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeAzureVirtualMachinesClient() *fakeAzureVirtualMachinesClient {
|
|
|
|
fVMC := &fakeAzureVirtualMachinesClient{}
|
2017-11-15 01:39:55 +00:00
|
|
|
fVMC.FakeStore = make(map[string]map[string]compute.VirtualMachine)
|
|
|
|
fVMC.mutex = &sync.Mutex{}
|
|
|
|
return fVMC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMC *fakeAzureVirtualMachinesClient) CreateOrUpdate(resourceGroupName string, VMName string, parameters compute.VirtualMachine, cancel <-chan struct{}) (<-chan compute.VirtualMachine, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fVMC.mutex.Lock()
|
|
|
|
defer fVMC.mutex.Unlock()
|
|
|
|
resultChan := make(chan compute.VirtualMachine, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result compute.VirtualMachine
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
if _, ok := fVMC.FakeStore[resourceGroupName]; !ok {
|
|
|
|
fVMC.FakeStore[resourceGroupName] = make(map[string]compute.VirtualMachine)
|
|
|
|
}
|
|
|
|
fVMC.FakeStore[resourceGroupName][VMName] = parameters
|
|
|
|
result = fVMC.FakeStore[resourceGroupName][VMName]
|
2017-11-16 23:04:08 +00:00
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
2017-11-15 01:39:55 +00:00
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMC *fakeAzureVirtualMachinesClient) Get(resourceGroupName string, VMName string, expand compute.InstanceViewTypes) (result compute.VirtualMachine, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fVMC.mutex.Lock()
|
|
|
|
defer fVMC.mutex.Unlock()
|
|
|
|
if _, ok := fVMC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := fVMC.FakeStore[resourceGroupName][VMName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such VM",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMC *fakeAzureVirtualMachinesClient) List(resourceGroupName string) (result compute.VirtualMachineListResult, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fVMC.mutex.Lock()
|
|
|
|
defer fVMC.mutex.Unlock()
|
|
|
|
var value []compute.VirtualMachine
|
|
|
|
if _, ok := fVMC.FakeStore[resourceGroupName]; ok {
|
|
|
|
for _, v := range fVMC.FakeStore[resourceGroupName] {
|
|
|
|
value = append(value, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
result.NextLink = nil
|
|
|
|
result.Value = &value
|
|
|
|
return result, nil
|
|
|
|
}
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMC *fakeAzureVirtualMachinesClient) ListNextResults(resourceGroupName string, lastResults compute.VirtualMachineListResult) (result compute.VirtualMachineListResult, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fVMC.mutex.Lock()
|
|
|
|
defer fVMC.mutex.Unlock()
|
|
|
|
return compute.VirtualMachineListResult{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeAzureSubnetsClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]network.Subnet
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeAzureSubnetsClient() *fakeAzureSubnetsClient {
|
|
|
|
fASC := &fakeAzureSubnetsClient{}
|
2017-11-15 01:39:55 +00:00
|
|
|
fASC.FakeStore = make(map[string]map[string]network.Subnet)
|
|
|
|
fASC.mutex = &sync.Mutex{}
|
|
|
|
return fASC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fASC *fakeAzureSubnetsClient) CreateOrUpdate(resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters network.Subnet, cancel <-chan struct{}) (<-chan network.Subnet, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fASC.mutex.Lock()
|
|
|
|
defer fASC.mutex.Unlock()
|
|
|
|
resultChan := make(chan network.Subnet, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result network.Subnet
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
rgVnet := strings.Join([]string{resourceGroupName, virtualNetworkName}, "AND")
|
|
|
|
if _, ok := fASC.FakeStore[rgVnet]; !ok {
|
|
|
|
fASC.FakeStore[rgVnet] = make(map[string]network.Subnet)
|
|
|
|
}
|
|
|
|
fASC.FakeStore[rgVnet][subnetName] = subnetParameters
|
|
|
|
result = fASC.FakeStore[rgVnet][subnetName]
|
2017-11-16 23:04:08 +00:00
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
2017-11-15 01:39:55 +00:00
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fASC *fakeAzureSubnetsClient) Delete(resourceGroupName string, virtualNetworkName string, subnetName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fASC.mutex.Lock()
|
|
|
|
defer fASC.mutex.Unlock()
|
|
|
|
respChan := make(chan autorest.Response, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var resp autorest.Response
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
respChan <- resp
|
|
|
|
errChan <- err
|
|
|
|
close(respChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
rgVnet := strings.Join([]string{resourceGroupName, virtualNetworkName}, "AND")
|
2017-11-16 19:33:48 +00:00
|
|
|
if rgSubnets, ok := fASC.FakeStore[rgVnet]; ok {
|
|
|
|
if _, ok := rgSubnets[subnetName]; ok {
|
|
|
|
delete(rgSubnets, subnetName)
|
2017-11-15 01:39:55 +00:00
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusAccepted,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
}
|
|
|
|
err = autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such Subnet",
|
|
|
|
}
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fASC *fakeAzureSubnetsClient) Get(resourceGroupName string, virtualNetworkName string, subnetName string, expand string) (result network.Subnet, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fASC.mutex.Lock()
|
|
|
|
defer fASC.mutex.Unlock()
|
|
|
|
rgVnet := strings.Join([]string{resourceGroupName, virtualNetworkName}, "AND")
|
|
|
|
if _, ok := fASC.FakeStore[rgVnet]; ok {
|
|
|
|
if entity, ok := fASC.FakeStore[rgVnet][subnetName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such Subnet",
|
|
|
|
}
|
|
|
|
}
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fASC *fakeAzureSubnetsClient) List(resourceGroupName string, virtualNetworkName string) (result network.SubnetListResult, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fASC.mutex.Lock()
|
|
|
|
defer fASC.mutex.Unlock()
|
|
|
|
rgVnet := strings.Join([]string{resourceGroupName, virtualNetworkName}, "AND")
|
|
|
|
var value []network.Subnet
|
|
|
|
if _, ok := fASC.FakeStore[rgVnet]; ok {
|
|
|
|
for _, v := range fASC.FakeStore[rgVnet] {
|
|
|
|
value = append(value, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
result.NextLink = nil
|
|
|
|
result.Value = &value
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeAzureNSGClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]network.SecurityGroup
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeAzureNSGClient() *fakeAzureNSGClient {
|
|
|
|
fNSG := &fakeAzureNSGClient{}
|
2017-11-15 01:39:55 +00:00
|
|
|
fNSG.FakeStore = make(map[string]map[string]network.SecurityGroup)
|
|
|
|
fNSG.mutex = &sync.Mutex{}
|
|
|
|
return fNSG
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fNSG *fakeAzureNSGClient) CreateOrUpdate(resourceGroupName string, networkSecurityGroupName string, parameters network.SecurityGroup, cancel <-chan struct{}) (<-chan network.SecurityGroup, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fNSG.mutex.Lock()
|
|
|
|
defer fNSG.mutex.Unlock()
|
|
|
|
resultChan := make(chan network.SecurityGroup, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result network.SecurityGroup
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
if _, ok := fNSG.FakeStore[resourceGroupName]; !ok {
|
|
|
|
fNSG.FakeStore[resourceGroupName] = make(map[string]network.SecurityGroup)
|
|
|
|
}
|
|
|
|
fNSG.FakeStore[resourceGroupName][networkSecurityGroupName] = parameters
|
|
|
|
result = fNSG.FakeStore[resourceGroupName][networkSecurityGroupName]
|
2017-11-16 23:04:08 +00:00
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
2017-11-15 01:39:55 +00:00
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fNSG *fakeAzureNSGClient) Delete(resourceGroupName string, networkSecurityGroupName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fNSG.mutex.Lock()
|
|
|
|
defer fNSG.mutex.Unlock()
|
|
|
|
respChan := make(chan autorest.Response, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var resp autorest.Response
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
respChan <- resp
|
|
|
|
errChan <- err
|
|
|
|
close(respChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
2017-11-16 19:33:48 +00:00
|
|
|
if rgSGs, ok := fNSG.FakeStore[resourceGroupName]; ok {
|
|
|
|
if _, ok := rgSGs[networkSecurityGroupName]; ok {
|
|
|
|
delete(rgSGs, networkSecurityGroupName)
|
2017-11-15 01:39:55 +00:00
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusAccepted,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
}
|
|
|
|
err = autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such NSG",
|
|
|
|
}
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fNSG *fakeAzureNSGClient) Get(resourceGroupName string, networkSecurityGroupName string, expand string) (result network.SecurityGroup, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fNSG.mutex.Lock()
|
|
|
|
defer fNSG.mutex.Unlock()
|
|
|
|
if _, ok := fNSG.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := fNSG.FakeStore[resourceGroupName][networkSecurityGroupName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such NSG",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fNSG *fakeAzureNSGClient) List(resourceGroupName string) (result network.SecurityGroupListResult, err error) {
|
2017-11-15 01:39:55 +00:00
|
|
|
fNSG.mutex.Lock()
|
|
|
|
defer fNSG.mutex.Unlock()
|
|
|
|
var value []network.SecurityGroup
|
|
|
|
if _, ok := fNSG.FakeStore[resourceGroupName]; ok {
|
|
|
|
for _, v := range fNSG.FakeStore[resourceGroupName] {
|
|
|
|
value = append(value, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
result.NextLink = nil
|
|
|
|
result.Value = &value
|
|
|
|
return result, nil
|
|
|
|
}
|
2017-11-17 00:09:08 +00:00
|
|
|
|
|
|
|
func getRandomIPPtr() *string {
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
return to.StringPtr(fmt.Sprintf("%d.%d.%d.%d", rand.Intn(256), rand.Intn(256), rand.Intn(256), rand.Intn(256)))
|
|
|
|
}
|
2017-12-22 07:10:30 +00:00
|
|
|
|
|
|
|
type fakeVirtualMachineScaleSetVMsClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]compute.VirtualMachineScaleSetVM
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeVirtualMachineScaleSetVMsClient() *fakeVirtualMachineScaleSetVMsClient {
|
|
|
|
fVMC := &fakeVirtualMachineScaleSetVMsClient{}
|
2017-12-22 07:10:30 +00:00
|
|
|
fVMC.FakeStore = make(map[string]map[string]compute.VirtualMachineScaleSetVM)
|
|
|
|
fVMC.mutex = &sync.Mutex{}
|
|
|
|
|
|
|
|
return fVMC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMC *fakeVirtualMachineScaleSetVMsClient) setFakeStore(store map[string]map[string]compute.VirtualMachineScaleSetVM) {
|
|
|
|
fVMC.mutex.Lock()
|
|
|
|
defer fVMC.mutex.Unlock()
|
|
|
|
|
|
|
|
fVMC.FakeStore = store
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fVMC *fakeVirtualMachineScaleSetVMsClient) List(resourceGroupName string, virtualMachineScaleSetName string, filter string, selectParameter string, expand string) (result compute.VirtualMachineScaleSetVMListResult, err error) {
|
2017-12-22 07:10:30 +00:00
|
|
|
fVMC.mutex.Lock()
|
|
|
|
defer fVMC.mutex.Unlock()
|
|
|
|
|
|
|
|
value := []compute.VirtualMachineScaleSetVM{}
|
|
|
|
if _, ok := fVMC.FakeStore[resourceGroupName]; ok {
|
|
|
|
for _, v := range fVMC.FakeStore[resourceGroupName] {
|
|
|
|
value = append(value, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
result.NextLink = nil
|
|
|
|
result.Value = &value
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMC *fakeVirtualMachineScaleSetVMsClient) ListNextResults(resourceGroupName string, lastResults compute.VirtualMachineScaleSetVMListResult) (result compute.VirtualMachineScaleSetVMListResult, err error) {
|
2017-12-22 07:10:30 +00:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMC *fakeVirtualMachineScaleSetVMsClient) Get(resourceGroupName string, VMScaleSetName string, instanceID string) (result compute.VirtualMachineScaleSetVM, err error) {
|
2017-12-22 07:10:30 +00:00
|
|
|
fVMC.mutex.Lock()
|
|
|
|
defer fVMC.mutex.Unlock()
|
|
|
|
|
|
|
|
vmKey := fmt.Sprintf("%s-%s", VMScaleSetName, instanceID)
|
|
|
|
if scaleSetMap, ok := fVMC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := scaleSetMap[vmKey]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "No such VirtualMachineScaleSetVM",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMC *fakeVirtualMachineScaleSetVMsClient) GetInstanceView(resourceGroupName string, VMScaleSetName string, instanceID string) (result compute.VirtualMachineScaleSetVMInstanceView, err error) {
|
2017-12-22 07:10:30 +00:00
|
|
|
_, err = fVMC.Get(resourceGroupName, VMScaleSetName, instanceID)
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeVirtualMachineScaleSetsClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]compute.VirtualMachineScaleSet
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeVirtualMachineScaleSetsClient() *fakeVirtualMachineScaleSetsClient {
|
|
|
|
fVMSSC := &fakeVirtualMachineScaleSetsClient{}
|
2017-12-22 07:10:30 +00:00
|
|
|
fVMSSC.FakeStore = make(map[string]map[string]compute.VirtualMachineScaleSet)
|
|
|
|
fVMSSC.mutex = &sync.Mutex{}
|
|
|
|
|
|
|
|
return fVMSSC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMSSC *fakeVirtualMachineScaleSetsClient) setFakeStore(store map[string]map[string]compute.VirtualMachineScaleSet) {
|
|
|
|
fVMSSC.mutex.Lock()
|
|
|
|
defer fVMSSC.mutex.Unlock()
|
|
|
|
|
|
|
|
fVMSSC.FakeStore = store
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fVMSSC *fakeVirtualMachineScaleSetsClient) CreateOrUpdate(resourceGroupName string, VMScaleSetName string, parameters compute.VirtualMachineScaleSet, cancel <-chan struct{}) (<-chan compute.VirtualMachineScaleSet, <-chan error) {
|
2017-12-22 07:10:30 +00:00
|
|
|
fVMSSC.mutex.Lock()
|
|
|
|
defer fVMSSC.mutex.Unlock()
|
|
|
|
|
|
|
|
resultChan := make(chan compute.VirtualMachineScaleSet, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result compute.VirtualMachineScaleSet
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
if _, ok := fVMSSC.FakeStore[resourceGroupName]; !ok {
|
|
|
|
fVMSSC.FakeStore[resourceGroupName] = make(map[string]compute.VirtualMachineScaleSet)
|
|
|
|
}
|
|
|
|
fVMSSC.FakeStore[resourceGroupName][VMScaleSetName] = parameters
|
|
|
|
result = fVMSSC.FakeStore[resourceGroupName][VMScaleSetName]
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMSSC *fakeVirtualMachineScaleSetsClient) Get(resourceGroupName string, VMScaleSetName string) (result compute.VirtualMachineScaleSet, err error) {
|
2017-12-22 07:10:30 +00:00
|
|
|
fVMSSC.mutex.Lock()
|
|
|
|
defer fVMSSC.mutex.Unlock()
|
|
|
|
|
|
|
|
if scaleSetMap, ok := fVMSSC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := scaleSetMap[VMScaleSetName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "No such ScaleSet",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMSSC *fakeVirtualMachineScaleSetsClient) List(resourceGroupName string) (result compute.VirtualMachineScaleSetListResult, err error) {
|
2017-12-22 07:10:30 +00:00
|
|
|
fVMSSC.mutex.Lock()
|
|
|
|
defer fVMSSC.mutex.Unlock()
|
|
|
|
|
|
|
|
value := []compute.VirtualMachineScaleSet{}
|
|
|
|
if _, ok := fVMSSC.FakeStore[resourceGroupName]; ok {
|
|
|
|
for _, v := range fVMSSC.FakeStore[resourceGroupName] {
|
|
|
|
value = append(value, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
result.NextLink = nil
|
|
|
|
result.Value = &value
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMSSC *fakeVirtualMachineScaleSetsClient) ListNextResults(resourceGroupName string, lastResults compute.VirtualMachineScaleSetListResult) (result compute.VirtualMachineScaleSetListResult, err error) {
|
2017-12-22 07:10:30 +00:00
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fVMSSC *fakeVirtualMachineScaleSetsClient) UpdateInstances(resourceGroupName string, VMScaleSetName string, VMInstanceIDs compute.VirtualMachineScaleSetVMInstanceRequiredIDs, cancel <-chan struct{}) (<-chan compute.OperationStatusResponse, <-chan error) {
|
2017-12-22 07:10:30 +00:00
|
|
|
resultChan := make(chan compute.OperationStatusResponse, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result compute.OperationStatusResponse
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
2018-01-05 06:24:44 +00:00
|
|
|
|
|
|
|
type fakeRoutesClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]network.Route
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeRoutesClient() *fakeRoutesClient {
|
|
|
|
fRC := &fakeRoutesClient{}
|
2018-01-05 06:24:44 +00:00
|
|
|
fRC.FakeStore = make(map[string]map[string]network.Route)
|
|
|
|
fRC.mutex = &sync.Mutex{}
|
|
|
|
return fRC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fRC *fakeRoutesClient) CreateOrUpdate(resourceGroupName string, routeTableName string, routeName string, routeParameters network.Route, cancel <-chan struct{}) (<-chan network.Route, <-chan error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fRC.mutex.Lock()
|
|
|
|
defer fRC.mutex.Unlock()
|
|
|
|
|
|
|
|
resultChan := make(chan network.Route, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result network.Route
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
if _, ok := fRC.FakeStore[routeTableName]; !ok {
|
|
|
|
fRC.FakeStore[routeTableName] = make(map[string]network.Route)
|
|
|
|
}
|
|
|
|
fRC.FakeStore[routeTableName][routeName] = routeParameters
|
|
|
|
result = fRC.FakeStore[routeTableName][routeName]
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fRC *fakeRoutesClient) Delete(resourceGroupName string, routeTableName string, routeName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fRC.mutex.Lock()
|
|
|
|
defer fRC.mutex.Unlock()
|
|
|
|
|
|
|
|
respChan := make(chan autorest.Response, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var resp autorest.Response
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
respChan <- resp
|
|
|
|
errChan <- err
|
|
|
|
close(respChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
if routes, ok := fRC.FakeStore[routeTableName]; ok {
|
|
|
|
if _, ok := routes[routeName]; ok {
|
|
|
|
delete(routes, routeName)
|
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusAccepted,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = nil
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
}
|
|
|
|
err = autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such Route",
|
|
|
|
}
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeRouteTablesClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]network.RouteTable
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeRouteTablesClient() *fakeRouteTablesClient {
|
|
|
|
fRTC := &fakeRouteTablesClient{}
|
2018-01-05 06:24:44 +00:00
|
|
|
fRTC.FakeStore = make(map[string]map[string]network.RouteTable)
|
|
|
|
fRTC.mutex = &sync.Mutex{}
|
|
|
|
return fRTC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fRTC *fakeRouteTablesClient) CreateOrUpdate(resourceGroupName string, routeTableName string, parameters network.RouteTable, cancel <-chan struct{}) (<-chan network.RouteTable, <-chan error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fRTC.mutex.Lock()
|
|
|
|
defer fRTC.mutex.Unlock()
|
|
|
|
|
|
|
|
resultChan := make(chan network.RouteTable, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result network.RouteTable
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
if _, ok := fRTC.FakeStore[resourceGroupName]; !ok {
|
|
|
|
fRTC.FakeStore[resourceGroupName] = make(map[string]network.RouteTable)
|
|
|
|
}
|
|
|
|
fRTC.FakeStore[resourceGroupName][routeTableName] = parameters
|
|
|
|
result = fRTC.FakeStore[resourceGroupName][routeTableName]
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fRTC *fakeRouteTablesClient) Get(resourceGroupName string, routeTableName string, expand string) (result network.RouteTable, err error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fRTC.mutex.Lock()
|
|
|
|
defer fRTC.mutex.Unlock()
|
|
|
|
if _, ok := fRTC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := fRTC.FakeStore[resourceGroupName][routeTableName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such RouteTable",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 22:20:45 +00:00
|
|
|
type fakeFileClient struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fFC *fakeFileClient) createFileShare(accountName, accountKey, name string, sizeGB int) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fFC *fakeFileClient) deleteFileShare(accountName, accountKey, name string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-01-05 06:24:44 +00:00
|
|
|
type fakeStorageAccountClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]storage.Account
|
2018-01-23 05:34:43 +00:00
|
|
|
Keys storage.AccountListKeysResult
|
2018-01-24 22:20:45 +00:00
|
|
|
Accounts storage.AccountListResult
|
2018-01-23 05:34:43 +00:00
|
|
|
Err error
|
2018-01-05 06:24:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeStorageAccountClient() *fakeStorageAccountClient {
|
|
|
|
fSAC := &fakeStorageAccountClient{}
|
2018-01-05 06:24:44 +00:00
|
|
|
fSAC.FakeStore = make(map[string]map[string]storage.Account)
|
|
|
|
fSAC.mutex = &sync.Mutex{}
|
|
|
|
return fSAC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fSAC *fakeStorageAccountClient) Create(resourceGroupName string, accountName string, parameters storage.AccountCreateParameters, cancel <-chan struct{}) (<-chan storage.Account, <-chan error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fSAC.mutex.Lock()
|
|
|
|
defer fSAC.mutex.Unlock()
|
|
|
|
|
|
|
|
resultChan := make(chan storage.Account, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result storage.Account
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
if _, ok := fSAC.FakeStore[resourceGroupName]; !ok {
|
|
|
|
fSAC.FakeStore[resourceGroupName] = make(map[string]storage.Account)
|
|
|
|
}
|
|
|
|
fSAC.FakeStore[resourceGroupName][accountName] = storage.Account{
|
|
|
|
Name: &accountName,
|
|
|
|
Sku: parameters.Sku,
|
|
|
|
Kind: parameters.Kind,
|
|
|
|
Location: parameters.Location,
|
|
|
|
Identity: parameters.Identity,
|
|
|
|
Tags: parameters.Tags,
|
|
|
|
AccountProperties: &storage.AccountProperties{},
|
|
|
|
}
|
|
|
|
result = fSAC.FakeStore[resourceGroupName][accountName]
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fSAC *fakeStorageAccountClient) Delete(resourceGroupName string, accountName string) (result autorest.Response, err error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fSAC.mutex.Lock()
|
|
|
|
defer fSAC.mutex.Unlock()
|
|
|
|
|
|
|
|
if rgAccounts, ok := fSAC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if _, ok := rgAccounts[accountName]; ok {
|
|
|
|
delete(rgAccounts, accountName)
|
|
|
|
result.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusAccepted,
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
}
|
|
|
|
err = autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such StorageAccount",
|
|
|
|
}
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fSAC *fakeStorageAccountClient) ListKeys(resourceGroupName string, accountName string) (result storage.AccountListKeysResult, err error) {
|
2018-01-23 05:34:43 +00:00
|
|
|
return fSAC.Keys, fSAC.Err
|
2018-01-05 06:24:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fSAC *fakeStorageAccountClient) ListByResourceGroup(resourceGroupName string) (result storage.AccountListResult, err error) {
|
2018-01-24 22:20:45 +00:00
|
|
|
return fSAC.Accounts, fSAC.Err
|
2018-01-05 06:24:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fSAC *fakeStorageAccountClient) GetProperties(resourceGroupName string, accountName string) (result storage.Account, err error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fSAC.mutex.Lock()
|
|
|
|
defer fSAC.mutex.Unlock()
|
|
|
|
|
|
|
|
if _, ok := fSAC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := fSAC.FakeStore[resourceGroupName][accountName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such StorageAccount",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeDisksClient struct {
|
|
|
|
mutex *sync.Mutex
|
|
|
|
FakeStore map[string]map[string]disk.Model
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func newFakeDisksClient() *fakeDisksClient {
|
|
|
|
fDC := &fakeDisksClient{}
|
2018-01-05 06:24:44 +00:00
|
|
|
fDC.FakeStore = make(map[string]map[string]disk.Model)
|
|
|
|
fDC.mutex = &sync.Mutex{}
|
|
|
|
return fDC
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fDC *fakeDisksClient) CreateOrUpdate(resourceGroupName string, diskName string, diskParameter disk.Model, cancel <-chan struct{}) (<-chan disk.Model, <-chan error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fDC.mutex.Lock()
|
|
|
|
defer fDC.mutex.Unlock()
|
|
|
|
|
|
|
|
resultChan := make(chan disk.Model, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var result disk.Model
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
resultChan <- result
|
|
|
|
errChan <- err
|
|
|
|
close(resultChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
|
|
|
|
if _, ok := fDC.FakeStore[resourceGroupName]; !ok {
|
|
|
|
fDC.FakeStore[resourceGroupName] = make(map[string]disk.Model)
|
|
|
|
}
|
|
|
|
fDC.FakeStore[resourceGroupName][diskName] = diskParameter
|
|
|
|
result = fDC.FakeStore[resourceGroupName][diskName]
|
|
|
|
result.Response.Response = &http.Response{
|
|
|
|
StatusCode: http.StatusOK,
|
|
|
|
}
|
|
|
|
err = nil
|
|
|
|
return resultChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fDC *fakeDisksClient) Delete(resourceGroupName string, diskName string, cancel <-chan struct{}) (<-chan disk.OperationStatusResponse, <-chan error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fDC.mutex.Lock()
|
|
|
|
defer fDC.mutex.Unlock()
|
|
|
|
|
|
|
|
respChan := make(chan disk.OperationStatusResponse, 1)
|
|
|
|
errChan := make(chan error, 1)
|
|
|
|
var resp disk.OperationStatusResponse
|
|
|
|
var err error
|
|
|
|
defer func() {
|
|
|
|
respChan <- resp
|
|
|
|
errChan <- err
|
|
|
|
close(respChan)
|
|
|
|
close(errChan)
|
|
|
|
}()
|
|
|
|
if rgDisks, ok := fDC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if _, ok := rgDisks[diskName]; ok {
|
|
|
|
delete(rgDisks, diskName)
|
|
|
|
resp.Response = autorest.Response{
|
|
|
|
Response: &http.Response{
|
|
|
|
StatusCode: http.StatusAccepted,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
err = nil
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resp.Response = autorest.Response{
|
|
|
|
Response: &http.Response{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err = autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such Disk",
|
|
|
|
}
|
|
|
|
return respChan, errChan
|
|
|
|
}
|
|
|
|
|
2018-01-15 07:43:48 +00:00
|
|
|
func (fDC *fakeDisksClient) Get(resourceGroupName string, diskName string) (result disk.Model, err error) {
|
2018-01-05 06:24:44 +00:00
|
|
|
fDC.mutex.Lock()
|
|
|
|
defer fDC.mutex.Unlock()
|
|
|
|
|
|
|
|
if _, ok := fDC.FakeStore[resourceGroupName]; ok {
|
|
|
|
if entity, ok := fDC.FakeStore[resourceGroupName][diskName]; ok {
|
|
|
|
return entity, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, autorest.DetailedError{
|
|
|
|
StatusCode: http.StatusNotFound,
|
|
|
|
Message: "Not such Disk",
|
|
|
|
}
|
|
|
|
}
|