This commit is contained in:
Anshul Verma 2022-12-15 13:55:56 +05:30
Родитель 71f9453d94
Коммит 077062c645
3 изменённых файлов: 12 добавлений и 15 удалений

Просмотреть файл

@ -65,7 +65,7 @@ func newAzureSideFetcher(resourceGroupName string, subscriptionDoc *api.Subscrip
}
}
func newRealFetcher(log *logrus.Entry, dialer proxy.Dialer, doc *api.OpenShiftClusterDocument, azureazureSideFetcher azureSideFetcher) (*realFetcher, error) {
func newRealFetcher(log *logrus.Entry, dialer proxy.Dialer, doc *api.OpenShiftClusterDocument, azureSideFetcher azureSideFetcher) (*realFetcher, error) {
restConfig, err := restconfig.RestConfig(dialer, doc.OpenShiftCluster)
if err != nil {
log.Error(err)
@ -94,7 +94,7 @@ func newRealFetcher(log *logrus.Entry, dialer proxy.Dialer, doc *api.OpenShiftCl
configCli: configCli,
kubernetesCli: kubernetesCli,
machineClient: machineClient,
azureSideFetcher: azureazureSideFetcher,
azureSideFetcher: azureSideFetcher,
}, nil
}

Просмотреть файл

@ -15,9 +15,9 @@ import (
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/features"
)
// Creating local vars for these functions in order to make them testable. The function definition will is altered while in the tests written.
var NewResourceClientFunction = features.NewResourcesClient
var NewVirtualMachineClientFunction = compute.NewVirtualMachinesClient
// Creating local vars for these functions in order to make them swappable to make them testable. The function definition will is altered in the tests written.
var newResourceClientFunction = features.NewResourcesClient
var newVirtualMachineClientFunction = compute.NewVirtualMachinesClient
type MachinesInformation struct {
Name string `json:"name"`
@ -85,19 +85,15 @@ func (f *realFetcher) VMAllocationStatus(ctx context.Context) (VMAllocationStatu
}
// Getting Virtual Machine resources through the Cluster's Resource Group
computeResources, err := NewResourceClientFunction(env.Environment(), subscriptionDoc.ID, fpAuth).ListByResourceGroup(ctx, clusterRGName, "resourceType eq 'Microsoft.Compute/virtualMachines'", "", nil)
computeResources, err := newResourceClientFunction(env.Environment(), subscriptionDoc.ID, fpAuth).ListByResourceGroup(ctx, clusterRGName, "resourceType eq 'Microsoft.Compute/virtualMachines'", "", nil)
if err != nil {
return nil, err
}
vmAllocationStatus := make(VMAllocationStatus)
virtualMachineClient := NewVirtualMachineClientFunction(env.Environment(), subscriptionDoc.ID, fpAuth)
virtualMachineClient := newVirtualMachineClientFunction(env.Environment(), subscriptionDoc.ID, fpAuth)
for _, res := range computeResources {
var vmName, allocationStatus string
if *res.Type != "Microsoft.Compute/virtualMachines" {
continue
}
vm, err := virtualMachineClient.Get(ctx, clusterRGName, *res.Name, mgmtcompute.InstanceView)
if err != nil {
f.log.Warn(err) // can happen when the ARM cache is lagging

Просмотреть файл

@ -117,17 +117,18 @@ func TestVMAllocationStatus(t *testing.T) {
controller := gomock.NewController(t)
mockResourcesClient := mock_features.NewMockResourcesClient(controller)
mockVirtualMachinesClient := mock_compute.NewMockVirtualMachinesClient(controller)
NewResourceClientFunction = func(environment *azureclient.AROEnvironment,
newResourceClientFunction = func(environment *azureclient.AROEnvironment,
subscriptionID string,
authorizer autorest.Authorizer) features.ResourcesClient {
return mockResourcesClient
}
NewVirtualMachineClientFunction = func(environment *azureclient.AROEnvironment, subscriptionID string, authorizer autorest.Authorizer) compute.VirtualMachinesClient {
newVirtualMachineClientFunction = func(environment *azureclient.AROEnvironment, subscriptionID string, authorizer autorest.Authorizer) compute.VirtualMachinesClient {
return mockVirtualMachinesClient
}
defer func() {
NewResourceClientFunction = features.NewResourcesClient
newResourceClientFunction = features.NewResourcesClient
newVirtualMachineClientFunction = compute.NewVirtualMachinesClient
}()
type test struct {
@ -137,7 +138,7 @@ func TestVMAllocationStatus(t *testing.T) {
}
for _, tt := range []*test{
{
name: "Everything runs fine",
name: "Successfully fetching VMs allocation status. Calling all the required methods.",
mocks: func(tt *test,
env *mock_env.MockInterface,
authorizer *mock_refreshable.MockAuthorizer,