16068: Fix process panel test
[arvados-workbench2.git] / cypress / integration / process.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Process tests', function() {
6     let activeUser;
7     let adminUser;
8
9     before(function() {
10         // Only set up common users once. These aren't set up as aliases because
11         // aliases are cleaned up after every test. Also it doesn't make sense
12         // to set the same users on beforeEach() over and over again, so we
13         // separate a little from Cypress' 'Best Practices' here.
14         cy.getUser('admin', 'Admin', 'User', true, true)
15             .as('adminUser').then(function() {
16                 adminUser = this.adminUser;
17             }
18         );
19         cy.getUser('user', 'Active', 'User', false, true)
20             .as('activeUser').then(function() {
21                 activeUser = this.activeUser;
22             }
23         );
24     });
25
26     beforeEach(function() {
27         cy.clearCookies();
28         cy.clearLocalStorage();
29     });
30
31     function setupDockerImage(image_name) {
32         // Create a collection that will be used as a docker image for the tests.
33         cy.createCollection(adminUser.token, {
34             name: 'docker_image',
35             manifest_text: ". d21353cfe035e3e384563ee55eadbb2f+67108864 5c77a43e329b9838cbec18ff42790e57+55605760 0:122714624:sha256:d8309758b8fe2c81034ffc8a10c36460b77db7bc5e7b448c4e5b684f9d95a678.tar\n"
36         }).as('dockerImage').then(function(dockerImage) {
37             // Give read permissions to the active user on the docker image.
38             cy.createLink(adminUser.token, {
39                 link_class: 'permission',
40                 name: 'can_read',
41                 tail_uuid: activeUser.user.uuid,
42                 head_uuid: dockerImage.uuid
43             }).as('dockerImagePermission').then(function() {
44                 // Set-up docker image collection tags
45                 cy.createLink(activeUser.token, {
46                     link_class: 'docker_image_repo+tag',
47                     name: image_name,
48                     head_uuid: dockerImage.uuid,
49                 }).as('dockerImageRepoTag');
50                 cy.createLink(activeUser.token, {
51                     link_class: 'docker_image_hash',
52                     name: 'sha256:d8309758b8fe2c81034ffc8a10c36460b77db7bc5e7b448c4e5b684f9d95a678',
53                     head_uuid: dockerImage.uuid,
54                 }).as('dockerImageHash');
55             })
56         });
57         return cy.getAll('@dockerImage', '@dockerImageRepoTag', '@dockerImageHash',
58             '@dockerImagePermission').then(function([dockerImage]) {
59                 return dockerImage;
60             });
61     }
62
63     function createContainerRequest(user, name, docker_image, command, reuse = false, state = 'Uncommitted') {
64         return setupDockerImage(docker_image).then(function(dockerImage) {
65             return cy.createContainerRequest(user.token, {
66                 name: name,
67                 command: command,
68                 container_image: dockerImage.portable_data_hash, // for some reason, docker_image doesn't work here
69                 output_path: 'stdout.txt',
70                 priority: 1,
71                 runtime_constraints: {
72                     vcpus: 1,
73                     ram: 1,
74                 },
75                 use_existing: reuse,
76                 state: state,
77                 mounts: {
78                     foo: {
79                         kind: 'tmp',
80                         path: '/tmp/foo',
81                     }
82                 }
83             });
84         });
85     }
86
87     it('shows process logs', function() {
88         const crName = 'test_container_request';
89         createContainerRequest(
90             activeUser,
91             crName,
92             'arvados/jobs',
93             ['echo', 'hello world'],
94             false, 'Committed')
95         .then(function(containerRequest) {
96             cy.loginAs(activeUser);
97             cy.goToPath(`/processes/${containerRequest.uuid}`);
98             cy.get('[data-cy=process-details]').should('contain', crName);
99             cy.get('[data-cy=process-logs]')
100                 .should('contain', 'No logs yet')
101                 .and('not.contain', 'hello world');
102             cy.createLog(activeUser.token, {
103                 object_uuid: containerRequest.container_uuid,
104                 properties: {
105                     text: 'hello world'
106                 },
107                 event_type: 'stdout'
108             }).then(function(log) {
109                 cy.get('[data-cy=process-logs]')
110                     .should('not.contain', 'No logs yet')
111                     .and('contain', 'hello world');
112             })
113         });
114     });
115
116     it('filters process logs by event type', function() {
117         const nodeInfoLogs = [
118             'Host Information',
119             'Linux compute-99cb150b26149780de44b929577e1aed-19rgca8vobuvc4p 5.4.0-1059-azure #62~18.04.1-Ubuntu SMP Tue Sep 14 17:53:18 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux',
120             'CPU Information',
121             'processor  : 0',
122             'vendor_id  : GenuineIntel',
123             'cpu family : 6',
124             'model      : 79',
125             'model name : Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz'
126         ];
127         const crunchRunLogs = [
128             '2022-03-22T13:56:22.542417997Z using local keepstore process (pid 3733) at http://localhost:46837, writing logs to keepstore.txt in log collection',
129             '2022-03-22T13:56:26.237571754Z crunch-run 2.4.0~dev20220321141729 (go1.17.1) started',
130             '2022-03-22T13:56:26.244704134Z crunch-run process has uid=0(root) gid=0(root) groups=0(root)',
131             '2022-03-22T13:56:26.244862836Z Executing container \'zzzzz-dz642-1wokwvcct9s9du3\' using docker runtime',
132             '2022-03-22T13:56:26.245037738Z Executing on host \'compute-99cb150b26149780de44b929577e1aed-19rgca8vobuvc4p\'',
133         ];
134         const stdoutLogs = [
135             'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dui nisi, hendrerit porta sapien a, pretium dignissim purus.',
136             'Integer viverra, mauris finibus aliquet ultricies, dui mauris cursus justo, ut venenatis nibh ex eget neque.',
137             'In hac habitasse platea dictumst.',
138             'Fusce fringilla turpis id accumsan faucibus. Donec congue congue ex non posuere. In semper mi quis tristique rhoncus.',
139             'Interdum et malesuada fames ac ante ipsum primis in faucibus.',
140             'Quisque fermentum tortor ex, ut suscipit velit feugiat faucibus.',
141             'Donec vitae porta risus, at luctus nulla. Mauris gravida iaculis ipsum, id sagittis tortor egestas ac.',
142             'Maecenas condimentum volutpat nulla. Integer lacinia maximus risus eu posuere.',
143             'Donec vitae leo id augue gravida bibendum.',
144             'Nam libero libero, pretium ac faucibus elementum, mattis nec ex.',
145             'Nullam id laoreet nibh. Vivamus tellus metus, pretium quis justo ut, bibendum varius metus. Pellentesque vitae accumsan lorem, quis tincidunt augue.',
146             'Aliquam viverra nisi nulla, et efficitur dolor mattis in.',
147             'Sed at enim sit amet nulla tincidunt mattis. Aenean eget aliquet ex, non ultrices ex. Nulla ex tortor, vestibulum aliquam tempor ac, aliquam vel est.',
148             'Fusce auctor faucibus libero id venenatis. Etiam sodales, odio eu cursus efficitur, quam sem blandit ex, quis porttitor enim dui quis lectus. In id tincidunt felis.',
149             'Phasellus non ex quis arcu tempus faucibus molestie in sapien.',
150             'Duis tristique semper dolor, vitae pulvinar risus.',
151             'Aliquam tortor elit, luctus nec tortor eget, porta tristique nulla.',
152             'Nulla eget mollis ipsum.',
153         ];
154
155         createContainerRequest(
156             activeUser,
157             'test_container_request',
158             'arvados/jobs',
159             ['echo', 'hello world'],
160             false, 'Committed')
161         .then(function(containerRequest) {
162             cy.logsForContainer(activeUser.token, containerRequest.container_uuid,
163                 'node-info', nodeInfoLogs).as('nodeInfoLogs');
164             cy.logsForContainer(activeUser.token, containerRequest.container_uuid,
165                 'crunch-run', crunchRunLogs).as('crunchRunLogs');
166             cy.logsForContainer(activeUser.token, containerRequest.container_uuid,
167                 'stdout', stdoutLogs).as('stdoutLogs');
168             cy.getAll('@stdoutLogs', '@nodeInfoLogs', '@crunchRunLogs').then(function() {
169                 cy.loginAs(activeUser);
170                 cy.goToPath(`/processes/${containerRequest.uuid}`);
171                 // Should should all logs
172                 cy.get('[data-cy=process-logs-filter]').should('contain', 'All logs');
173                 cy.get('[data-cy=process-logs]')
174                     .should('contain', stdoutLogs[Math.floor(Math.random() * stdoutLogs.length)])
175                     .and('contain', nodeInfoLogs[Math.floor(Math.random() * nodeInfoLogs.length)])
176                     .and('contain', crunchRunLogs[Math.floor(Math.random() * crunchRunLogs.length)]);
177                 // Select 'node-info' logs
178                 cy.get('[data-cy=process-logs-filter]').click();
179                 cy.get('body').contains('li', 'node-info').click();
180                 cy.get('[data-cy=process-logs]')
181                     .should('not.contain', stdoutLogs[Math.floor(Math.random() * stdoutLogs.length)])
182                     .and('contain', nodeInfoLogs[Math.floor(Math.random() * nodeInfoLogs.length)])
183                     .and('not.contain', crunchRunLogs[Math.floor(Math.random() * crunchRunLogs.length)]);
184                 // Select 'stdout' logs
185                 cy.get('[data-cy=process-logs-filter]').click();
186                 cy.get('body').contains('li', 'stdout').click();
187                 cy.get('[data-cy=process-logs]')
188                     .should('contain', stdoutLogs[Math.floor(Math.random() * stdoutLogs.length)])
189                     .and('not.contain', nodeInfoLogs[Math.floor(Math.random() * nodeInfoLogs.length)])
190                     .and('not.contain', crunchRunLogs[Math.floor(Math.random() * crunchRunLogs.length)]);
191             });
192         });
193     });
194 });