2
2
3
3
import { execSync } from 'child_process' ;
4
4
import { browser , by , ExpectedConditions as until } from 'protractor' ;
5
- import { appHost , testName } from '../../protractor.conf' ;
6
- import { resourceRowsPresent , filterForName , deleteRow , isLoaded , createItemButton , errorMessage } from '../../views/crud.view' ;
7
- import * as vmView from '../../views/kubevirt/vm.view' ;
8
5
import { OrderedMap } from 'immutable' ;
9
6
7
+ import { appHost , testName } from '../../protractor.conf' ;
8
+ import { resourceRowsPresent , filterForName , deleteRow , createItemButton , isLoaded , errorMessage } from '../../views/crud.view' ;
9
+ import { removeLeakedResources } from './utils' ;
10
+ import { testNAD } from './mocks' ;
11
+ import * as vmView from '../../views/kubevirt/vm.view' ;
10
12
11
13
describe ( 'Kubevirt create VM using wizard' , ( ) => {
12
14
const leakedResources = new Set < string > ( ) ;
@@ -16,19 +18,7 @@ describe('Kubevirt create VM using wizard', () => {
16
18
const workloadProfile = 'generic' ;
17
19
const sourceURL = 'https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img' ;
18
20
const sourceContainer = 'kubevirt/cirros-registry-disk-demo:latest' ;
19
- const networkDefinitionName = `${ testName } -ovs-net-1` ;
20
21
const pxeInterface = 'eth1' ;
21
- const testNAD = {
22
- apiVersion : 'k8s.cni.cncf.io/v1' ,
23
- kind : 'NetworkAttachmentDefinition' ,
24
- metadata : {
25
- name : networkDefinitionName ,
26
- namespace : testName ,
27
- } ,
28
- spec : {
29
- config : '{ "cniVersion": "0.3.1", "type": "ovs", "bridge": "br0" }' ,
30
- } ,
31
- } ;
32
22
const provisionMethods = OrderedMap < string , ( provisionSource : string ) => void > ( )
33
23
. set ( 'PXE' , async function ( provisionSource ) {
34
24
await vmView . provisionSourceButton . click ( ) ;
@@ -47,96 +37,74 @@ describe('Kubevirt create VM using wizard', () => {
47
37
await vmView . provisionSourceURL . sendKeys ( sourceURL ) ;
48
38
} ) ;
49
39
50
- beforeAll ( async ( ) => {
51
- execSync ( `echo '${ JSON . stringify ( testNAD ) } ' | kubectl create -f -` ) ;
52
- } ) ;
53
-
54
- afterAll ( async ( ) => {
55
- execSync ( `kubectl delete -n ${ testName } net-attach-def ${ networkDefinitionName } ` ) ;
56
- const leakedArray : Array < string > = [ ...leakedResources ] ;
57
- if ( leakedArray . length > 0 ) {
58
- console . error ( `Leaked ${ leakedArray . join ( ) } ` ) ;
59
- leakedArray . map ( r => JSON . parse ( r ) as { name : string , namespace : string , kind : string } )
60
- . forEach ( ( { name, namespace, kind} ) => {
61
- try {
62
- execSync ( `kubectl delete -n ${ namespace } --cascade ${ kind } ${ name } ` ) ;
63
- } catch ( error ) {
64
- console . error ( `Failed to delete ${ kind } ${ name } :\n${ error } ` ) ;
65
- }
66
- } ) ;
67
- }
68
- } ) ;
69
-
70
- provisionMethods . forEach ( ( provisionMethod , methodName ) => {
71
- describe ( `Using ${ methodName } method.` , ( ) => {
72
- it ( 'Navigates to VMs' , async ( ) => {
73
- await browser . get ( `${ appHost } /k8s/all-namespaces/virtualmachines` ) ;
74
- await isLoaded ( ) ;
75
- } ) ;
76
-
77
- it ( 'Opens VM wizard' , async ( ) => {
78
- await createItemButton . click ( ) . then ( ( ) => vmView . createWithWizardLink . click ( ) ) ;
79
- } ) ;
80
-
81
- it ( 'Configures VM Basic Settings' , async ( ) => {
82
- await browser . wait ( until . presenceOf ( vmView . nameInput ) , 10000 ) ;
83
- await vmView . nameInput . sendKeys ( vmName ) ;
40
+ async function fillBasicSettings ( provisionMethod : ( provisionSource : string ) => void , provisionSourceName : string ) {
41
+ await browser . wait ( until . presenceOf ( vmView . nameInput ) , 10000 ) ;
42
+ await vmView . nameInput . sendKeys ( vmName ) ;
84
43
85
- await vmView . namespaceButton . click ( ) ;
86
- await vmView . namespaceMenu . element ( by . linkText ( testName ) ) . click ( ) ;
44
+ await vmView . namespaceButton . click ( ) ;
45
+ await vmView . namespaceMenu . element ( by . linkText ( testName ) ) . click ( ) ;
87
46
88
- await provisionMethod ( methodName ) ;
47
+ await provisionMethod ( provisionSourceName ) ;
89
48
90
- await vmView . operatingSystemButton . click ( ) ;
91
- await vmView . operatingSystemMenu . element ( by . linkText ( operatingSystem ) ) . click ( ) ;
49
+ await vmView . operatingSystemButton . click ( ) ;
50
+ await vmView . operatingSystemMenu . element ( by . linkText ( operatingSystem ) ) . click ( ) ;
92
51
93
- await vmView . flavorButton . click ( ) ;
94
- await vmView . flavorSourceMenu . element ( by . linkText ( flavor ) ) . click ( ) ;
52
+ await vmView . flavorButton . click ( ) ;
53
+ await vmView . flavorSourceMenu . element ( by . linkText ( flavor ) ) . click ( ) ;
95
54
96
- await vmView . workloadProfileButton . click ( ) ;
97
- await vmView . workloadProfileMenu . element ( by . linkText ( workloadProfile ) ) . click ( ) ;
55
+ await vmView . workloadProfileButton . click ( ) ;
56
+ await vmView . workloadProfileMenu . element ( by . linkText ( workloadProfile ) ) . click ( ) ;
98
57
99
- await vmView . startVMOnCreation . click ( ) ;
58
+ await vmView . startVMOnCreation . click ( ) ;
100
59
101
- await vmView . nextButton . click ( ) ;
102
- } ) ;
60
+ await vmView . nextButton . click ( ) ;
61
+ }
103
62
104
- it ( 'Configures VM Networking' , async ( ) => {
105
- if ( methodName === 'PXE' ) {
106
- await vmView . createNIC . click ( ) ;
63
+ async function fillVMNetworking ( provisionSourceName : string ) {
64
+ if ( provisionSourceName === 'PXE' ) {
65
+ await vmView . createNIC . click ( ) ;
107
66
108
- await vmView . networkDefinitionButton . click ( ) ;
109
- await vmView . networkDefinitionMenu . element ( by . linkText ( networkDefinitionName ) ) . click ( ) ;
67
+ await vmView . networkDefinitionButton . click ( ) ;
68
+ await vmView . networkDefinitionMenu . element ( by . linkText ( testNAD . metadata . name ) ) . click ( ) ;
110
69
111
- await vmView . pxeNICButton . click ( ) ;
112
- await vmView . pxeNICMenu . element ( by . linkText ( pxeInterface ) ) . click ( ) ;
113
- await vmView . applyButton . click ( ) ;
114
- }
115
- await vmView . nextButton . click ( ) ;
116
- } ) ;
117
-
118
- it ( 'Configures VM Storage' , async ( ) => {
119
- await vmView . nextButton . click ( ) ;
120
- } ) ;
121
-
122
- it ( 'Confirms to create VM' , async ( ) => {
123
- await browser . wait ( until . elementToBeClickable ( vmView . nextButton ) , 5000 ) . then ( ( ) => vmView . nextButton . click ( ) ) ;
70
+ await vmView . pxeNICButton . click ( ) ;
71
+ await vmView . pxeNICMenu . element ( by . linkText ( pxeInterface ) ) . click ( ) ;
72
+ await vmView . applyButton . click ( ) ;
73
+ }
74
+ await vmView . nextButton . click ( ) ;
75
+ }
124
76
125
- expect ( errorMessage . isPresent ( ) ) . toBe ( false ) ;
126
- leakedResources . add ( JSON . stringify ( { name : vmName , namespace : testName , kind : 'vm' } ) ) ;
127
- } ) ;
77
+ beforeAll ( async ( ) => {
78
+ console . log ( testNAD ) ;
79
+ execSync ( `echo '${ JSON . stringify ( testNAD ) } ' | kubectl create -f -` ) ;
80
+ } ) ;
128
81
129
- it ( 'Verifies created VM' , async ( ) => {
130
- await browser . wait ( until . invisibilityOf ( vmView . wizardHeader ) , 5000 ) ;
131
- await filterForName ( vmName ) ;
132
- await resourceRowsPresent ( ) ;
133
- await browser . wait ( until . textToBePresentInElement ( vmView . firstRowVMStatus , 'Running' ) , 20000 ) ;
134
- } ) ;
82
+ afterAll ( async ( ) => {
83
+ execSync ( `kubectl delete -n ${ testName } net-attach-def ${ testNAD . metadata . name } ` ) ;
84
+ removeLeakedResources ( leakedResources ) ;
85
+ } ) ;
135
86
136
- it ( 'Removes created VM' , async ( ) => {
137
- await deleteRow ( 'VirtualMachine' ) ( vmName ) ;
138
- leakedResources . delete ( JSON . stringify ( { name : vmName , namespace : testName , kind : 'vm' } ) ) ;
139
- } ) ;
87
+ provisionMethods . forEach ( ( provisionMethod , methodName ) => {
88
+ it ( `Using ${ methodName } provision source.` , async ( ) => {
89
+ await browser . get ( `${ appHost } /k8s/all-namespaces/virtualmachines` ) ;
90
+ await isLoaded ( ) ;
91
+ await createItemButton . click ( ) . then ( ( ) => vmView . createWithWizardLink . click ( ) ) ;
92
+ await fillBasicSettings ( provisionMethod , methodName ) ;
93
+ await fillVMNetworking ( methodName ) ;
94
+ // Use default storage settings
95
+ await vmView . nextButton . click ( ) ;
96
+ // Confirm to create VM
97
+ await browser . wait ( until . elementToBeClickable ( vmView . nextButton ) , 5000 ) . then ( ( ) => vmView . nextButton . click ( ) ) ;
98
+ expect ( errorMessage . isPresent ( ) ) . toBe ( false ) ;
99
+ leakedResources . add ( JSON . stringify ( { name : vmName , namespace : testName , kind : 'vm' } ) ) ;
100
+ // Verify VM is created and running
101
+ await browser . wait ( until . invisibilityOf ( vmView . wizardHeader ) , 5000 ) ;
102
+ await filterForName ( vmName ) ;
103
+ await resourceRowsPresent ( ) ;
104
+ await browser . wait ( until . textToBePresentInElement ( vmView . firstRowVMStatus , 'Running' ) , 20000 ) ;
105
+ // Delete VM
106
+ await deleteRow ( 'VirtualMachine' ) ( vmName ) ;
107
+ leakedResources . delete ( JSON . stringify ( { name : vmName , namespace : testName , kind : 'vm' } ) ) ;
140
108
} ) ;
141
109
} ) ;
142
110
} ) ;
0 commit comments