Skip to content
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

test: [M3-7315] - Add tests assgining VPCs during Linode creation flow #9939

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 197 additions & 5 deletions packages/manager/cypress/e2e/core/linodes/create-linode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ import {
fbtClick,
fbtVisible,
getClick,
getVisible,
} from 'support/helpers';
import { ui } from 'support/ui';
import { apiMatcher } from 'support/util/intercepts';
import { randomString, randomLabel } from 'support/util/random';
import { randomString, randomLabel, randomNumber } from 'support/util/random';
import { chooseRegion } from 'support/util/regions';
import { getRegionById } from 'support/util/regions';
import { linodeFactory, regionFactory } from '@src/factories';
import {
subnetFactory,
vpcFactory,
linodeFactory,
linodeConfigFactory,
regionFactory,
VLANFactory,
LinodeConfigInterfaceFactory,
LinodeConfigInterfaceFactoryWithVPC,
} from '@src/factories';
import { authenticate } from 'support/api/authentication';
import { cleanUp } from 'support/util/cleanup';
import { mockGetRegions } from 'support/intercepts/regions';
Expand All @@ -19,19 +29,24 @@ import {
dcPricingDocsLabel,
dcPricingDocsUrl,
} from 'support/constants/dc-specific-pricing';
import { mockCreateLinode } from 'support/intercepts/linodes';
import { mockGetVLANs } from 'support/intercepts/vlans';
import { mockGetLinodeConfigs } from 'support/intercepts/configs';
import {
mockCreateLinode,
mockGetLinodeType,
mockGetLinodeTypes,
mockGetLinodeDisks,
mockGetLinodeVolumes,
} from 'support/intercepts/linodes';

import type { Region } from '@linode/api-v4';
import { mockGetVPC, mockGetVPCs } from 'support/intercepts/vpc';
import {
mockAppendFeatureFlags,
mockGetFeatureFlagClientstream,
} from 'support/intercepts/feature-flags';
import { makeFeatureFlagData } from 'support/util/feature-flags';

import type { Config, VLAN, VPC, Disk, Region } from '@linode/api-v4';

const mockRegions: Region[] = [
regionFactory.build({
capabilities: ['Linodes'],
Expand Down Expand Up @@ -318,4 +333,181 @@ describe('create linode', () => {
fbtVisible(linodeLabel);
cy.contains('RUNNING', { timeout: 300000 }).should('be.visible');
});

it("prevents a VPC from being assigned in a region that doesn't support VPCs during the Linode Create flow", () => {
const region: Region = getRegionById('us-southeast');
const mockNoVPCRegion = regionFactory.build({
id: region.id,
label: region.label,
capabilities: ['Linodes'],
});

// Mock requests to get individual types.
mockGetLinodeType(dcPricingMockLinodeTypes[0]);
mockGetLinodeType(dcPricingMockLinodeTypes[1]);
mockGetLinodeTypes(dcPricingMockLinodeTypes).as('getLinodeTypes');

mockAppendFeatureFlags({
vpc: makeFeatureFlagData(true),
}).as('getFeatureFlags');
mockGetFeatureFlagClientstream().as('getClientStream');

mockGetRegions([mockNoVPCRegion]).as('getRegions');

// intercept request
cy.visitWithLogin('/linodes/create');
cy.wait(['@getLinodeTypes', '@getClientStream', '@getFeatureFlags']);

cy.get('[data-qa-header="Create"]').should('have.text', 'Create');

// Check the 'Backups' add on
cy.get('[data-testid="backups"]').should('be.visible').click();
ui.regionSelect.find().click().type(`${region.label} {enter}`);
fbtClick('Shared CPU');
getClick(`[id="${dcPricingMockLinodeTypes[0].id}"]`);

// the "VPC" section is present
getVisible('[data-testid="vpc-panel"]').within(() => {
containsVisible(
'Allow Linode to communicate in an isolated environment.'
);
// Helper text appears if VPC is not available in selected region.
containsVisible('VPC is not available in the selected region.');
});
});

it('assigns a VPC to the linode during create flow', () => {
const rootpass = randomString(32);
const linodeLabel = randomLabel();
const region: Region = getRegionById('us-southeast');
const diskLabel: string = 'Debian 10 Disk';
const mockLinode = linodeFactory.build({
label: linodeLabel,
region: region.id,
type: dcPricingMockLinodeTypes[0].id,
});
const mockVLANs: VLAN[] = VLANFactory.buildList(2);
const mockSubnet = subnetFactory.build({
id: randomNumber(2),
label: randomLabel(),
});
const mockVPCs: VPC[] = vpcFactory.buildList(5, {
region: 'us-southeast',
subnets: [mockSubnet],
});
const mockVPC = mockVPCs[0];
const mockVPCRegion = regionFactory.build({
id: region.id,
label: region.label,
capabilities: ['Linodes', 'VPCs', 'Vlans'],
});
const mockPublicConfigInterface = LinodeConfigInterfaceFactory.build({
ipam_address: null,
purpose: 'public',
});
const mockVlanConfigInterface = LinodeConfigInterfaceFactory.build();
const mockVpcConfigInterface = LinodeConfigInterfaceFactoryWithVPC.build({
vpc_id: mockVPC.id,
});
const mockConfig: Config = linodeConfigFactory.build({
id: randomNumber(),
interfaces: [
// The order of this array is significant. Index 0 (eth0) should be public.
mockPublicConfigInterface,
mockVlanConfigInterface,
mockVpcConfigInterface,
],
});
const mockDisks: Disk[] = [
{
id: 44311273,
status: 'ready',
label: diskLabel,
created: '2020-08-21T17:26:14',
updated: '2020-08-21T17:26:30',
filesystem: 'ext4',
size: 81408,
},
{
id: 44311274,
status: 'ready',
label: '512 MB Swap Image',
created: '2020-08-21T17:26:14',
updated: '2020-08-21T17:26:31',
filesystem: 'swap',
size: 512,
},
];

// Mock requests to get individual types.
mockGetLinodeType(dcPricingMockLinodeTypes[0]);
mockGetLinodeType(dcPricingMockLinodeTypes[1]);
mockGetLinodeTypes(dcPricingMockLinodeTypes).as('getLinodeTypes');

mockAppendFeatureFlags({
vpc: makeFeatureFlagData(true),
}).as('getFeatureFlags');
mockGetFeatureFlagClientstream().as('getClientStream');

mockGetRegions([mockVPCRegion]).as('getRegions');

mockGetVLANs(mockVLANs);
mockGetVPC(mockVPC).as('getVPC');
mockGetVPCs(mockVPCs).as('getVPCs');
mockCreateLinode(mockLinode).as('linodeCreated');
mockGetLinodeConfigs(mockLinode.id, [mockConfig]).as('getLinodeConfigs');
mockGetLinodeDisks(mockLinode.id, mockDisks).as('getDisks');
mockGetLinodeVolumes(mockLinode.id, []).as('getVolumes');

// intercept request
cy.visitWithLogin('/linodes/create');
cy.wait([
'@getLinodeTypes',
'@getClientStream',
'@getFeatureFlags',
'@getVPCs',
]);

cy.get('[data-qa-header="Create"]').should('have.text', 'Create');

// Check the 'Backups' add on
cy.get('[data-testid="backups"]').should('be.visible').click();
ui.regionSelect.find().click().type(`${region.label} {enter}`);
fbtClick('Shared CPU');
getClick(`[id="${dcPricingMockLinodeTypes[0].id}"]`);

// the "VPC" section is present, and the VPC in the same region of
// the linode can be selected.
getVisible('[data-testid="vpc-panel"]').within(() => {
containsVisible('Assign this Linode to an existing VPC.');
// select VPC
cy.get('[data-qa-enhanced-select="None"]')
.should('be.visible')
.click()
.type(`${mockVPCs[0].label}{enter}`);
// select subnet
cy.findByText('Select Subnet')
.should('be.visible')
.click()
.type(`${mockSubnet.label}{enter}`);
});

getClick('#linode-label').clear().type(linodeLabel);
cy.get('#root-password').type(rootpass);
getClick('[data-qa-deploy-linode]');
cy.wait('@linodeCreated').its('response.statusCode').should('eq', 200);
fbtVisible(linodeLabel);
cy.contains('RUNNING', { timeout: 300000 }).should('be.visible');

fbtClick('Configurations');
cy.wait(['@getLinodeConfigs', '@getVPC', '@getDisks', '@getVolumes']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this error repeatedly across runs -- I think it originates from this line.
Screenshot 2024-01-22 at 4 42 18 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be related to this 404? Do we need to add a mock for this route?
Screenshot 2024-01-22 at 4 44 34 PM


// Confirm that VLAN and VPC have been assigned.
cy.findByLabelText('List of Configurations').within(() => {
cy.get('tr').should('have.length', 2);
containsVisible(`${mockConfig.label} – GRUB 2`);
containsVisible('eth0 – Public Internet');
containsVisible(`eth2 – VPC: ${mockVPC.label}`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export const dcPricingMockLinodeTypes = linodeTypeFactory.buildList(3, {
id: 'us-west',
monthly: 4.17,
},
{
hourly: 0.006,
id: 'us-southeast',
monthly: 4.67,
},
],
},
},
Expand All @@ -69,6 +74,11 @@ export const dcPricingMockLinodeTypes = linodeTypeFactory.buildList(3, {
id: 'us-west',
monthly: 12.2,
},
{
hourly: 0.006,
id: 'us-southeast',
monthly: 4.67,
},
],
});

Expand All @@ -92,6 +102,11 @@ export const dcPricingMockLinodeTypesForBackups = linodeTypeFactory.buildList(
id: 'us-west',
monthly: 4.17,
},
{
hourly: 0.006,
id: 'us-southeast',
monthly: 4.67,
},
],
},
},
Expand Down