Skip to content

Commit

Permalink
[Automation] Added a test for credential changing the Azure environme…
Browse files Browse the repository at this point in the history
…nt (rancher#11033)

* [Automation] Added a test for credential changing the Azure environment
  • Loading branch information
eva-vashkevich authored May 16, 2024
1 parent f3ce655 commit ee44a98
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function cloudCredentialCreatePayload(credName: string, accessToken: string):object {
export function cloudCredentialCreatePayloadDO(credName: string, accessToken: string):object {
return {
type: 'provisioning.cattle.io/cloud-credential',
metadata: {
Expand All @@ -12,3 +12,19 @@ export function cloudCredentialCreatePayload(credName: string, accessToken: stri
name: credName
};
}
export function cloudCredentialCreatePayloadAzure(credName: string, environment: string, subscriptionId: string, clientId: string, clientSecret: string):object {
return {
type: 'provisioning.cattle.io/cloud-credential',
metadata: {
generateName: 'cc-',
namespace: 'fleet-default'
},
_name: credName,
annotations: { 'provisioning.cattle.io/driver': 'azure' },
azurecredentialConfig: {
clientId, clientSecret, environment, subscriptionId
},
_type: 'provisioning.cattle.io/cloud-credential',
name: credName
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PagePo from '@/cypress/e2e/po/pages/page.po';
import ClusterManagerCreatePagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create.po';
import MachinePoolRke2 from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/tabs/machine-pools-tab-rke2.po';
import MachinePoolAzureRke2 from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/tabs/machine-pools-tab-azure-rke2.po';
import BasicsRke2 from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/tabs/basics-tab-rke2.po';
import AzureCloudCredentialsCreateEditPo from '@/cypress/e2e/po/edit/cloud-credentials-azure.po';

Expand All @@ -24,8 +24,8 @@ export default class ClusterManagerCreateRke2AzurePagePo extends ClusterManagerC
return new AzureCloudCredentialsCreateEditPo();
}

machinePoolTab(): MachinePoolRke2 {
return new MachinePoolRke2();
machinePoolTab(): MachinePoolAzureRke2 {
return new MachinePoolAzureRke2();
}

basicsTab(): BasicsRke2 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { CypressChainable } from '@/cypress/e2e/po/po.types';
import MachinePoolRke2 from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/tabs/machine-pools-tab-rke2.po';
import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po';

export default class MachinePoolAzureRke2 extends MachinePoolRke2 {
environment(): CypressChainable {
return this.self().find('[data-testid="machineConfig-azure-environment-value"] span');
}

location(): LabeledSelectPo {
return new LabeledSelectPo('[data-testid="machineConfig-azure-location"]', this.self());
}
}
134 changes: 131 additions & 3 deletions cypress/e2e/tests/pages/manager/cloud-credential.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { cloudCredentialCreatePayload } from '@/cypress/e2e/blueprints/manager/cloud-credential-create-payload';
import { cloudCredentialCreatePayloadDO, cloudCredentialCreatePayloadAzure } from '@/cypress/e2e/blueprints/manager/cloud-credential-create-payload';
import { clusterProvDigitalOceanSingleResponse } from '@/cypress/e2e/blueprints/manager/digital-ocean-cluster-provisioning-response';
import { machinePoolConfigResponse } from '@/cypress/e2e/blueprints/manager/machine-pool-config-response';
import ClusterManagerListPagePo from '@/cypress/e2e/po/pages/cluster-manager/cluster-manager-list.po';
import ClusterManagerEditGenericPagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/edit/cluster-edit-generic.po';
import ClusterManagerCreateRke2AzurePagePo from '@/cypress/e2e/po/edit/provisioning.cattle.io.cluster/create/cluster-create-rke2-azure.po';

describe('Cloud Credential', () => {
const clusterList = new ClusterManagerListPagePo();

before(() => {
beforeEach(() => {
cy.login();

clusterList.goTo();
Expand Down Expand Up @@ -62,7 +63,7 @@ describe('Cloud Credential', () => {
const createdCloudCredsIds = [];

for (let i = 0; i < cloudCredsToCreate.length; i++) {
cy.createRancherResource('v3', 'cloudcredentials', JSON.stringify(cloudCredentialCreatePayload(cloudCredsToCreate[i].name, cloudCredsToCreate[i].token))).then((resp: Cypress.Response<any>) => {
cy.createRancherResource('v3', 'cloudcredentials', JSON.stringify(cloudCredentialCreatePayloadDO(cloudCredsToCreate[i].name, cloudCredsToCreate[i].token))).then((resp: Cypress.Response<any>) => {
createdCloudCredsIds.push(resp.body.id);

if (i === 0) {
Expand Down Expand Up @@ -92,4 +93,131 @@ describe('Cloud Credential', () => {
});
}
});
it('Changing credential environment should change the list of locations when creating an Azure cluster', { tags: ['@manager', '@adminUser'] }, () => {
const clusterName = 'test-cluster-azure';
const machinePoolId = 'dummy-id';

const createRKE2AzureClusterPage = new ClusterManagerCreateRke2AzurePagePo();

// intercept GET of machine configs and pass a mock (Azure)
cy.intercept('GET', `/v1/rke-machine-config.cattle.io.azureconfigs/fleet-default/*`, (req) => {
req.reply({
statusCode: 200,
body: machinePoolConfigResponse(clusterName, machinePoolId),
});
}).as('dummyMachinePoolLoad1');

// create some cloud credentials with different environments
const cloudCredsToCreate = [
{
name: 'publicCloud',
environment: 'AzurePublicCloud',
subscriptionId: 'testSubscription',
clientId: 'testClientId',
clientSecret: 'testClientSecret',
body: [
{
name: 'public',
displayName: 'public'
}
]
},
{
name: 'chinaCloud',
environment: 'AzureChinaCloud',
subscriptionId: 'testSubscription',
clientId: 'testClientId',
clientSecret: 'testClientSecret',
body: [
{
name: 'china',
displayName: 'china'
}
]
},
{
name: 'USGovernment',
environment: 'AzureUSGovernmentCloud',
subscriptionId: 'testSubscription',
clientId: 'testClientId',
clientSecret: 'testClientSecret',
body: [
{
name: 'USGovernment',
displayName: 'USGovernment'
}
]
},
];

cy.intercept('GET', `/meta/aksVMSizesV2*`, (req) => {
req.reply({
statusCode: 200,
body: [{
Name: 'Standard_B2pls_v2',
AcceleratedNetworkingSupported: true,
AvailabilityZones: []
}],
});
}).as('aksVMSizesV2Load');

const createdCloudCredsIds = [];

ClusterManagerListPagePo.navTo();
clusterList.waitForPage();

for (let i = 0; i < cloudCredsToCreate.length; i++) {
cy.createRancherResource('v3', 'cloudcredentials', JSON.stringify(cloudCredentialCreatePayloadAzure(
cloudCredsToCreate[i].name,
cloudCredsToCreate[i].environment,
cloudCredsToCreate[i].subscriptionId,
cloudCredsToCreate[i].clientId,
cloudCredsToCreate[i].clientSecret,
))).then((resp: Cypress.Response<any>) => {
createdCloudCredsIds.push(resp.body.id);

if (i === cloudCredsToCreate.length - 1) {
cy.intercept('GET', `/meta/aksLocations?cloudCredentialId=${ encodeURIComponent(createdCloudCredsIds[0]) }`, (req) => {
req.reply({
statusCode: 200,
body: cloudCredsToCreate[0].body,
});
}).as('aksLocations0');
cy.intercept('GET', `/meta/aksLocations?cloudCredentialId=${ encodeURIComponent(createdCloudCredsIds[1]) }`, (req) => {
req.reply({
statusCode: 200,
body: cloudCredsToCreate[1].body,
});
}).as('aksLocations1');
cy.intercept('GET', `/meta/aksLocations?cloudCredentialId=${ encodeURIComponent(createdCloudCredsIds[2]) }`, (req) => {
req.reply({
statusCode: 200,
body: cloudCredsToCreate[2].body,
});
}).as('aksLocations2');

clusterList.checkIsCurrentPage();
clusterList.createCluster();
createRKE2AzureClusterPage.rkeToggle().set('RKE2/K3s');
createRKE2AzureClusterPage.selectCreate(1);
createRKE2AzureClusterPage.rke2PageTitle().should('include', 'Create Azure');
createRKE2AzureClusterPage.waitForPage('type=azure&rkeType=rke2');
createRKE2AzureClusterPage.selectOptionForCloudCredentialWithLabel(`${ cloudCredsToCreate[0].name }`);

createRKE2AzureClusterPage.machinePoolTab().location().checkOptionSelected(cloudCredsToCreate[0].body[0].name);
createRKE2AzureClusterPage.machinePoolTab().environment().should('have.text', cloudCredsToCreate[0].environment );

createRKE2AzureClusterPage.selectOptionForCloudCredentialWithLabel(`${ cloudCredsToCreate[1].name }`);

createRKE2AzureClusterPage.machinePoolTab().environment().should('have.text', cloudCredsToCreate[1].environment );
createRKE2AzureClusterPage.machinePoolTab().location().checkOptionSelected(cloudCredsToCreate[1].body[0].name );

createRKE2AzureClusterPage.selectOptionForCloudCredentialWithLabel(`${ cloudCredsToCreate[2].name }`);

createRKE2AzureClusterPage.machinePoolTab().environment().should('have.text', cloudCredsToCreate[2].environment );
createRKE2AzureClusterPage.machinePoolTab().location().checkOptionSelected(cloudCredsToCreate[2].body[0].name );
}
});
}
});
});
3 changes: 2 additions & 1 deletion shell/machine-config/azure.vue
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,11 @@ export default {
:required="true"
:label="t('cluster.machineConfig.azure.location.label')"
:disabled="disabled"
data-testid="machineConfig-azure-location"
@input="setLocation"
/>
</div>
<div>
<div data-testid="machineConfig-azure-environment-value">
<label
v-clean-tooltip="t('cluster.machineConfig.azure.environment.tooltip')"
:style="{'display':'block'}"
Expand Down

0 comments on commit ee44a98

Please sign in to comment.