github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/provider/azure/instancetype_test.go (about)

     1  // Copyright 2022 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package azure
     5  
     6  import (
     7  	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
     8  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v2"
     9  	"github.com/juju/collections/set"
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/environs/instances"
    14  	"github.com/juju/juju/testing"
    15  )
    16  
    17  type InstanceTypeSuite struct {
    18  	testing.BaseSuite
    19  }
    20  
    21  var _ = gc.Suite(&InstanceTypeSuite{})
    22  
    23  func (s *InstanceTypeSuite) TestNoDupes(c *gc.C) {
    24  	names := set.NewStrings()
    25  	for _, n := range machineSizeCost {
    26  		if names.Contains(n) {
    27  			c.Fatalf("duplicate size name %q", n)
    28  		}
    29  		names.Add(n)
    30  	}
    31  }
    32  
    33  func (s *InstanceTypeSuite) TestStandard(c *gc.C) {
    34  	vm := armcompute.VirtualMachineSize{
    35  		Name:           to.Ptr("Standard_A2"),
    36  		MemoryInMB:     to.Ptr(int32(100)),
    37  		NumberOfCores:  to.Ptr(int32(2)),
    38  		OSDiskSizeInMB: to.Ptr(int32(1024 * 1024)),
    39  	}
    40  	inst := newInstanceType(vm)
    41  	c.Assert(inst, jc.DeepEquals, instances.InstanceType{
    42  		Id:       "Standard_A2",
    43  		Name:     "Standard_A2",
    44  		Arch:     "amd64",
    45  		VirtType: to.Ptr("Hyper-V"),
    46  		CpuCores: 2,
    47  		Mem:      100,
    48  		Cost:     700, // 7 * 100
    49  		RootDisk: 1000 * 1000,
    50  	})
    51  }
    52  
    53  func (s *InstanceTypeSuite) TestStandardVersioned(c *gc.C) {
    54  	vm := armcompute.VirtualMachineSize{
    55  		Name:           to.Ptr("Standard_A2_v4"),
    56  		MemoryInMB:     to.Ptr(int32(100)),
    57  		NumberOfCores:  to.Ptr(int32(2)),
    58  		OSDiskSizeInMB: to.Ptr(int32(1024 * 1024)),
    59  	}
    60  	inst := newInstanceType(vm)
    61  	c.Assert(inst, jc.DeepEquals, instances.InstanceType{
    62  		Id:       "Standard_A2_v4",
    63  		Name:     "Standard_A2_v4",
    64  		Arch:     "amd64",
    65  		VirtType: to.Ptr("Hyper-V"),
    66  		CpuCores: 2,
    67  		Mem:      100,
    68  		Cost:     696, // 7 * 100 - 4
    69  		RootDisk: 1000 * 1000,
    70  	})
    71  }
    72  
    73  func (s *InstanceTypeSuite) TestStandardPromo(c *gc.C) {
    74  	vm := armcompute.VirtualMachineSize{
    75  		Name:           to.Ptr("Standard_A2_v4_Promo"),
    76  		MemoryInMB:     to.Ptr(int32(100)),
    77  		NumberOfCores:  to.Ptr(int32(2)),
    78  		OSDiskSizeInMB: to.Ptr(int32(1024 * 1024)),
    79  	}
    80  	inst := newInstanceType(vm)
    81  	c.Assert(inst, jc.DeepEquals, instances.InstanceType{
    82  		Id:       "Standard_A2_v4_Promo",
    83  		Name:     "Standard_A2_v4_Promo",
    84  		Arch:     "amd64",
    85  		VirtType: to.Ptr("Hyper-V"),
    86  		CpuCores: 2,
    87  		Mem:      100,
    88  		Cost:     40300, // len(costs),
    89  		RootDisk: 1000 * 1000,
    90  	})
    91  }
    92  
    93  func (s *InstanceTypeSuite) TestBasic(c *gc.C) {
    94  	vm := armcompute.VirtualMachineSize{
    95  		Name:           to.Ptr("Basic_A2"),
    96  		MemoryInMB:     to.Ptr(int32(100)),
    97  		NumberOfCores:  to.Ptr(int32(2)),
    98  		OSDiskSizeInMB: to.Ptr(int32(1024 * 1024)),
    99  	}
   100  	inst := newInstanceType(vm)
   101  	c.Assert(inst, jc.DeepEquals, instances.InstanceType{
   102  		Id:       "Basic_A2",
   103  		Name:     "Basic_A2",
   104  		Arch:     "amd64",
   105  		VirtType: to.Ptr("Hyper-V"),
   106  		CpuCores: 2,
   107  		Mem:      100,
   108  		Cost:     40300, // len(costs),
   109  		RootDisk: 1000 * 1000,
   110  	})
   111  }
   112  
   113  func (s *InstanceTypeSuite) TestDeleteInstanceFamily(c *gc.C) {
   114  	instanceTypes := map[string]instances.InstanceType{
   115  		"D6_v4":          {Name: "Standard_D6_v4"},
   116  		"Standard_D6_v4": {Name: "Standard_D6_v4"},
   117  		"Standard_D6_v5": {Name: "Standard_D6_v5"},
   118  		"D6_v5":          {Name: "Standard_D6_v5"},
   119  		"Standard_A2_v2": {Name: "Standard_A2_v2"},
   120  		"A2_v2":          {Name: "Standard_A2_v2"},
   121  	}
   122  	deleteInstanceFamily(instanceTypes, "Standard_D6_v5")
   123  	c.Assert(instanceTypes, jc.DeepEquals, map[string]instances.InstanceType{
   124  		"Standard_A2_v2": {Name: "Standard_A2_v2"},
   125  		"A2_v2":          {Name: "Standard_A2_v2"},
   126  	})
   127  }