-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add offering preset variables for Network and VPC Quota tariffs
#11810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -28,11 +28,12 @@ | |||||
| import com.cloud.dc.ClusterDetailsDao; | ||||||
| import com.cloud.dc.ClusterDetailsVO; | ||||||
| import com.cloud.host.HostTagVO; | ||||||
| import com.cloud.hypervisor.Hypervisor; | ||||||
| import com.cloud.network.dao.NetworkVO; | ||||||
| import com.cloud.network.vpc.VpcOfferingVO; | ||||||
| import com.cloud.network.vpc.VpcVO; | ||||||
| import javax.inject.Inject; | ||||||
|
|
||||||
| import com.cloud.hypervisor.Hypervisor; | ||||||
| import com.cloud.storage.StoragePoolTagVO; | ||||||
| import org.apache.cloudstack.acl.RoleVO; | ||||||
| import org.apache.cloudstack.acl.dao.RoleDao; | ||||||
|
|
@@ -66,6 +67,7 @@ | |||||
| import com.cloud.host.HostVO; | ||||||
| import com.cloud.host.dao.HostDao; | ||||||
| import com.cloud.host.dao.HostTagsDao; | ||||||
| import com.cloud.network.vpc.dao.VpcOfferingDao; | ||||||
| import com.cloud.offerings.NetworkOfferingVO; | ||||||
| import com.cloud.offerings.dao.NetworkOfferingDao; | ||||||
| import com.cloud.server.ResourceTag; | ||||||
|
|
@@ -191,6 +193,9 @@ public class PresetVariableHelper { | |||||
| @Inject | ||||||
| ClusterDetailsDao clusterDetailsDao; | ||||||
|
|
||||||
| @Inject | ||||||
| VpcOfferingDao vpcOfferingDao; | ||||||
|
|
||||||
| protected boolean backupSnapshotAfterTakingSnapshot = SnapshotInfo.BackupSnapshotAfterTakingSnapshot.value(); | ||||||
|
|
||||||
| private List<Integer> runningAndAllocatedVmUsageTypes = Arrays.asList(UsageTypes.RUNNING_VM, UsageTypes.ALLOCATED_VM); | ||||||
|
|
@@ -778,6 +783,19 @@ protected void loadPresetVariableValueForNetwork(UsageVO usageRecord, Value valu | |||||
| value.setId(network.getUuid()); | ||||||
| value.setName(network.getName()); | ||||||
| value.setState(usageRecord.getState()); | ||||||
|
|
||||||
| value.setNetworkOffering(getPresetVariableValueNetworkOffering(network.getNetworkOfferingId())); | ||||||
| } | ||||||
|
|
||||||
| protected GenericPresetVariable getPresetVariableValueNetworkOffering(Long networkOfferingId) { | ||||||
| NetworkOfferingVO networkOfferingVo = networkOfferingDao.findByIdIncludingRemoved(networkOfferingId); | ||||||
| validateIfObjectIsNull(networkOfferingVo, networkOfferingId, "network offering"); | ||||||
|
|
||||||
| GenericPresetVariable networkOffering = new GenericPresetVariable(); | ||||||
| networkOffering.setId(networkOfferingVo.getUuid()); | ||||||
| networkOffering.setName(networkOfferingVo.getName()); | ||||||
|
|
||||||
| return networkOffering; | ||||||
| } | ||||||
|
|
||||||
| protected void loadPresetVariableValueForVpc(UsageVO usageRecord, Value value) { | ||||||
|
|
@@ -793,6 +811,18 @@ protected void loadPresetVariableValueForVpc(UsageVO usageRecord, Value value) { | |||||
|
|
||||||
| value.setId(vpc.getUuid()); | ||||||
| value.setName(vpc.getName()); | ||||||
| value.setVpcOffering(getPresetVariableValueVpcOffering(vpc.getVpcOfferingId())); | ||||||
|
||||||
| } | ||||||
|
|
||||||
| protected GenericPresetVariable getPresetVariableValueVpcOffering(long vpcOfferingId) { | ||||||
|
||||||
| protected GenericPresetVariable getPresetVariableValueVpcOffering(long vpcOfferingId) { | |
| protected GenericPresetVariable getPresetVariableValueVpcOffering(Long vpcOfferingId) { |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -96,6 +96,12 @@ public class Value extends GenericPresetVariable { | |||
|
|
||||
| private String state; | ||||
|
|
||||
| @PresetVariableDefinition(description = "Network offering of the network.", supportedTypes = {QuotaTypes.NETWORK}) | ||||
| private GenericPresetVariable networkOffering; | ||||
|
|
||||
| @PresetVariableDefinition(description = "VPC offering of the VPC.", supportedTypes = {QuotaTypes.VPC}) | ||||
| private GenericPresetVariable vpcOffering; | ||||
|
|
||||
| public Host getHost() { | ||||
| return host; | ||||
| } | ||||
|
|
@@ -255,4 +261,22 @@ public String getState() { | |||
| public void setState(String state) { | ||||
| this.state = state; | ||||
| } | ||||
|
|
||||
| public GenericPresetVariable getNetworkOffering() { | ||||
| return networkOffering; | ||||
| } | ||||
|
|
||||
| public void setNetworkOffering(GenericPresetVariable networkOffering) { | ||||
| this.networkOffering = networkOffering; | ||||
| fieldNamesToIncludeInToString.add("networkOffering"); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is not used anymore. |
||||
| } | ||||
|
|
||||
| public GenericPresetVariable getVpcOffering() { | ||||
| return vpcOffering; | ||||
| } | ||||
|
|
||||
| public void setVpcOffering(GenericPresetVariable vpcOffering) { | ||||
| this.vpcOffering = vpcOffering; | ||||
| fieldNamesToIncludeInToString.add("vpcOffering"); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same as above. |
||||
| } | ||||
| } | ||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -31,6 +31,8 @@ | |||
| import com.cloud.dc.ClusterDetailsVO; | ||||
| import com.cloud.host.HostTagVO; | ||||
| import com.cloud.hypervisor.Hypervisor; | ||||
| import com.cloud.network.vpc.VpcOfferingVO; | ||||
| import com.cloud.network.vpc.dao.VpcOfferingDao; | ||||
| import com.cloud.storage.StoragePoolTagVO; | ||||
| import org.apache.cloudstack.acl.RoleType; | ||||
| import org.apache.cloudstack.acl.RoleVO; | ||||
|
|
@@ -188,6 +190,9 @@ public class PresetVariableHelperTest { | |||
| @Mock | ||||
| BackupOfferingDao backupOfferingDaoMock; | ||||
|
|
||||
| @Mock | ||||
| VpcOfferingDao vpcOfferingDao; | ||||
|
|
||||
| List<Integer> runningAndAllocatedVmUsageTypes = Arrays.asList(UsageTypes.RUNNING_VM, UsageTypes.ALLOCATED_VM); | ||||
| List<Integer> templateAndIsoUsageTypes = Arrays.asList(UsageTypes.TEMPLATE, UsageTypes.ISO); | ||||
|
|
||||
|
|
@@ -1289,4 +1294,36 @@ public void testGetSnapshotImageStoreRefNotNull() { | |||
| Mockito.when(imageStoreDaoMock.findById(1L)).thenReturn(store); | ||||
| Assert.assertNotNull(presetVariableHelperSpy.getSnapshotImageStoreRef(1L, 1L)); | ||||
| } | ||||
|
|
||||
| @Test | ||||
| public void getPresetVariableValueNetworkOfferingTestSetValuesAndReturnObject() { | ||||
| NetworkOfferingVO networkOfferingVoMock = Mockito.mock(NetworkOfferingVO.class); | ||||
| Mockito.doReturn(networkOfferingVoMock).when(networkOfferingDaoMock).findByIdIncludingRemoved(Mockito.anyLong()); | ||||
| mockMethodValidateIfObjectIsNull(); | ||||
|
|
||||
| GenericPresetVariable expected = getGenericPresetVariableForTests(); | ||||
| Mockito.doReturn(expected.getId()).when(networkOfferingVoMock).getUuid(); | ||||
| Mockito.doReturn(expected.getName()).when(networkOfferingVoMock).getName(); | ||||
|
|
||||
| GenericPresetVariable result = presetVariableHelperSpy.getPresetVariableValueNetworkOffering(1L); | ||||
|
|
||||
| assertPresetVariableIdAndName(expected, result); | ||||
| validateFieldNamesToIncludeInToString(Arrays.asList("id", "name"), result); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This method does not exist anymore. |
||||
| } | ||||
|
|
||||
| @Test | ||||
| public void getPresetVariableValueVpcOfferingTestSetValuesAndReturnObject() { | ||||
| VpcOfferingVO vpcOfferingVoMock = Mockito.mock(VpcOfferingVO.class); | ||||
| Mockito.doReturn(vpcOfferingVoMock).when(vpcOfferingDao).findByIdIncludingRemoved(Mockito.anyLong()); | ||||
| mockMethodValidateIfObjectIsNull(); | ||||
|
|
||||
| GenericPresetVariable expected = getGenericPresetVariableForTests(); | ||||
| Mockito.doReturn(expected.getId()).when(vpcOfferingVoMock).getUuid(); | ||||
| Mockito.doReturn(expected.getName()).when(vpcOfferingVoMock).getName(); | ||||
|
|
||||
| GenericPresetVariable result = presetVariableHelperSpy.getPresetVariableValueVpcOffering(1L); | ||||
|
|
||||
| assertPresetVariableIdAndName(expected, result); | ||||
| validateFieldNamesToIncludeInToString(Arrays.asList("id", "name"), result); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same as above. |
||||
| } | ||||
| } | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new networkOffering field is being set in loadPresetVariableValueForNetwork, but there are no tests verifying this integration. Similar methods like loadPresetVariableValueForVolume and loadPresetVariableValueForBackup have comprehensive tests that verify all fields are properly set. Consider adding a test similar to loadPresetVariableValueForBackupTestRecordIsBackupSetAllFields that verifies the networkOffering field is correctly populated.