Skip to content

Commit fea3927

Browse files
committed
MBS-11677: Selenium CAA setup
1 parent 4f4621a commit fea3927

File tree

14 files changed

+657
-5
lines changed

14 files changed

+657
-5
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
executors:
44
musicbrainz-tests:
55
docker:
6-
- image: metabrainz/musicbrainz-tests:v-2021-05
6+
- image: metabrainz/musicbrainz-tests:v-2021-05-caa
77
user: root
88
working_directory: /home/musicbrainz/musicbrainz-server
99

docker/Dockerfile.tests

+43
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,22 @@ RUN apt-get update && \
7676
redis-server \
7777
runit \
7878
runit-systemd \
79+
software-properties-common \
7980
sudo \
8081
unzip \
8182
virtualenv \
8283
wget \
8384
yarn \
8485
zlib1g-dev && \
86+
add-apt-repository -y ppa:deadsnakes/ppa && \
87+
apt install \
88+
--no-install-recommends \
89+
--no-install-suggests \
90+
-y \
91+
python3.9 \
92+
python3.9-dev \
93+
python3.9-distutils \
94+
python3.9-venv && \
8595
rm -rf /var/lib/apt/lists/* && \
8696
rm google-chrome-stable_current_amd64.deb && \
8797
rm nodejs_16.1.0-deb-1nodesource1_amd64.deb && \
@@ -142,6 +152,22 @@ RUN sudo -E -H -u musicbrainz git clone https://github.com/metabrainz/sir.git &&
142152
sudo -E -H -u musicbrainz sh -c 'virtualenv --python=python2 venv; . venv/bin/activate; pip install -r requirements.txt; pip install git+git://github.com/esnme/ultrajson.git@7d0f4fb7e911120fd09075049233b587936b0a65' && \
143153
cd /home/musicbrainz
144154

155+
ENV ARTWORK_INDEXER_COMMIT c8731b5
156+
157+
RUN sudo -E -H -u musicbrainz git clone https://github.com/metabrainz/artwork-indexer.git && \
158+
cd artwork-indexer && \
159+
sudo -E -H -u musicbrainz git reset --hard $ARTWORK_INDEXER_COMMIT && \
160+
sudo -E -H -u musicbrainz sh -c 'python3.9 -m venv venv; . venv/bin/activate; pip install -r requirements.txt' && \
161+
cd /home/musicbrainz
162+
163+
ENV ARTWORK_REDIRECT_COMMIT origin/eaa
164+
165+
RUN sudo -E -H -u musicbrainz git clone https://github.com/metabrainz/artwork-redirect.git && \
166+
cd artwork-redirect && \
167+
sudo -E -H -u musicbrainz git reset --hard $ARTWORK_REDIRECT_COMMIT && \
168+
sudo -E -H -u musicbrainz sh -c 'python3.9 -m venv venv; . venv/bin/activate; pip install -r requirements.txt' && \
169+
cd /home/musicbrainz
170+
145171
RUN curl -sLO https://chromedriver.storage.googleapis.com/90.0.4430.24/chromedriver_linux64.zip && \
146172
unzip chromedriver_linux64.zip -d /usr/local/bin && \
147173
chmod +x /usr/local/bin/chromedriver && \
@@ -174,8 +200,16 @@ COPY --chown=postgres:postgres \
174200
RUN sudo -E -H -u postgres touch \
175201
$PGDATA/pg_ident.conf
176202

203+
COPY docker/musicbrainz-tests/artwork-indexer-config.ini artwork-indexer/config.ini
204+
COPY docker/musicbrainz-tests/artwork-redirect-config.ini artwork-redirect/config.ini
177205
COPY docker/musicbrainz-tests/sir-config.ini sir/config.ini
178206

207+
COPY \
208+
docker/musicbrainz-tests/artwork-indexer.service \
209+
/etc/service/artwork-indexer/run
210+
COPY \
211+
docker/musicbrainz-tests/artwork-redirect.service \
212+
/etc/service/artwork-redirect/run
179213
COPY \
180214
docker/musicbrainz-tests/chrome.service \
181215
/etc/service/chrome/run
@@ -191,6 +225,9 @@ COPY \
191225
COPY \
192226
docker/musicbrainz-tests/solr.service \
193227
/etc/service/solr/run
228+
COPY \
229+
docker/musicbrainz-tests/ssssss.service \
230+
/etc/service/ssssss/run
194231
COPY \
195232
docker/scripts/start_template_renderer.sh \
196233
/etc/service/template-renderer/run
@@ -201,20 +238,26 @@ COPY \
201238
docker/musicbrainz-tests/website.service \
202239
/etc/service/website/run
203240
RUN chmod 755 \
241+
/etc/service/artwork-indexer/run \
242+
/etc/service/artwork-redirect/run \
204243
/etc/service/chrome/run \
205244
/etc/service/postgresql/run \
206245
/etc/service/redis/run \
207246
/etc/service/sir-queue-purger/run \
208247
/etc/service/solr/run \
248+
/etc/service/ssssss/run \
209249
/etc/service/template-renderer/run \
210250
/etc/service/vnu/run \
211251
/etc/service/website/run
212252
RUN touch \
253+
/etc/service/artwork-indexer/down \
254+
/etc/service/artwork-redirect/down \
213255
/etc/service/chrome/down \
214256
/etc/service/postgresql/down \
215257
/etc/service/redis/down \
216258
/etc/service/sir-queue-purger/down \
217259
/etc/service/solr/down \
260+
/etc/service/ssssss/down \
218261
/etc/service/template-renderer/down \
219262
/etc/service/vnu/down \
220263
/etc/service/website/down

docker/musicbrainz-tests/DBDefs.pm

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ sub CACHE_MANAGER_OPTIONS {
7676

7777
sub CATALYST_DEBUG { 0 }
7878

79+
sub COVER_ART_ARCHIVE_ACCESS_KEY { 'hi_im_public' }
80+
sub COVER_ART_ARCHIVE_SECRET_KEY { 'hi_im_private' }
81+
sub COVER_ART_ARCHIVE_UPLOAD_PREFIXER { shift; sprintf('//localhost:5050/%s', shift) };
82+
sub COVER_ART_ARCHIVE_DOWNLOAD_PREFIX { 'http://localhost:8081' };
83+
sub COVER_ART_ARCHIVE_IA_METADATA_PREFIX { 'http://localhost:5050/metadata' }
84+
7985
sub DATASTORE_REDIS_ARGS {
8086
my $self = shift;
8187
return {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[musicbrainz]
2+
url=http://localhost:5000
3+
database=SELENIUM
4+
5+
[database]
6+
host=localhost
7+
port=5432
8+
user=musicbrainz
9+
database=musicbrainz_selenium
10+
11+
[s3]
12+
url=//localhost:5050/{bucket}?file={file}
13+
access=hi_im_public
14+
secret=hi_im_private
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
cd /home/musicbrainz/artwork-indexer
4+
5+
exec sudo -E -H -u musicbrainz bash -c '. venv/bin/activate; exec python3 indexer.py --max-wait=1'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[database]
2+
user=musicbrainz
3+
name=musicbrainz_selenium
4+
host=localhost
5+
port=5432
6+
7+
[listen]
8+
address=localhost
9+
port=8081
10+
11+
[s3]
12+
prefix=//localhost:5050/
13+
14+
[sentry]
15+
dsn=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
cd /home/musicbrainz/artwork-redirect
4+
5+
exec sudo -E -H -u musicbrainz bash -c '. venv/bin/activate; exec python3 artwork_redirect_server.py'

docker/musicbrainz-tests/run_selenium_tests.sh

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ rabbitmqctl add_user sir sir
2626
rabbitmqctl add_vhost /sir-test
2727
rabbitmqctl set_permissions -p /sir-test sir '.*' '.*' '.*'
2828

29+
sudo -u postgres psql -U musicbrainz -d musicbrainz_selenium -c <<'EOSQL'
30+
ALTER SCHEMA amqp OWNER TO musicbrainz;
31+
ALTER TABLE amqp.broker OWNER TO musicbrainz;
32+
EOSQL
33+
2934
# Install the sir triggers into musicbrainz_selenium.
3035
export SIR_DIR=/home/musicbrainz/sir
3136
cd "$SIR_DIR"
@@ -35,8 +40,20 @@ sudo -u postgres psql -U musicbrainz -f sql/CreateFunctions.sql musicbrainz_sele
3540
sudo -u postgres psql -U musicbrainz -f sql/CreateTriggers.sql musicbrainz_selenium
3641
rm /etc/service/sir-queue-purger/down && sv start sir-queue-purger
3742

43+
# Install the artwork_indexer schema into musicbrainz_selenium.
44+
cd /home/musicbrainz/artwork-indexer
45+
sudo -u postgres psql -U musicbrainz -f sql/create.sql musicbrainz_selenium
46+
sudo -u postgres psql -U musicbrainz -f sql/caa_functions.sql musicbrainz_selenium
47+
sudo -u postgres psql -U musicbrainz -f sql/caa_triggers.sql musicbrainz_selenium
48+
sudo -u postgres psql -U musicbrainz -f sql/eaa_functions.sql musicbrainz_selenium
49+
sudo -u postgres psql -U musicbrainz -f sql/eaa_triggers.sql musicbrainz_selenium
50+
3851
cd /home/musicbrainz/musicbrainz-server
3952

53+
# Start the various CAA-related services.
54+
rm /etc/service/{artwork-indexer,artwork-redirect,ssssss}/down
55+
sv start artwork-indexer artwork-redirect ssssss
56+
4057
# Compile static resources.
4158
sudo -E -H -u musicbrainz yarn
4259
sudo -E -H -u musicbrainz make -C po all_quiet deploy
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
cd /home/musicbrainz/musicbrainz-server
4+
5+
export SSSSSS_STORAGE=/var/ssssss
6+
mkdir -p "$SSSSSS_STORAGE"
7+
chown musicbrainz:musicbrainz "$SSSSSS_STORAGE"
8+
9+
exec sudo -E -H -u musicbrainz carton exec -- plackup --port 5050 -r contrib/ssssss.psgi

lib/MusicBrainz/Server/Controller/WS/js.pm

+3-3
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ sub cover_art_upload : Chained('root') PathPart('cover-art-upload') Args(1)
312312
$bucket_uri->scheme('https');
313313

314314
if (
315-
DBDefs->DEVELOPMENT_SERVER &&
315+
(DBDefs->DEVELOPMENT_SERVER || DBDefs->DB_STAGING_TESTING_FEATURES) &&
316316
$bucket_uri->authority !~ m/\.archive\.org$/
317317
) {
318318
# This allows using contrib/ssssss.psgi for testing, but
@@ -418,7 +418,7 @@ sub cover_art_upload : Chained('root') PathPart('cover-art-upload') Args(1)
418418
my $id = $c->request->params->{image_id} // $c->model('CoverArtArchive')->fresh_id;
419419

420420
if ($c->model('CoverArtArchive')->is_id_in_use($id)) {
421-
$self->detach_with_error($c, {message => "The ID $id is already in use."});
421+
$self->detach_with_error($c, {message => "The ID $id is already in use (1)."});
422422
}
423423

424424
# Create a nonce associated with this image ID which we'll later
@@ -428,7 +428,7 @@ sub cover_art_upload : Chained('root') PathPart('cover-art-upload') Args(1)
428428
my $nonce_key = 'cover_art_upload_nonce:' . $id;
429429
my $existing_nonce = $context->store->get($nonce_key);
430430
if ($existing_nonce) {
431-
$self->detach_with_error($c, {message => "The ID $id is already in use."});
431+
$self->detach_with_error($c, {message => "The ID $id is already in use (2)."});
432432
}
433433
my $nonce = $c->generate_nonce;
434434
$context->store->set($nonce_key, $nonce);

root/static/scripts/edit/MB/CoverArt.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,16 @@ MB.CoverArt.file_data_uri = function (file) {
180180
MB.CoverArt.sign_upload = function (fileUpload, gid, mimeType) {
181181
var deferred = $.Deferred();
182182

183+
const data = {mime_type: mimeType};
184+
/* global COVER_ART_IMAGE_ID */
185+
if (typeof COVER_ART_IMAGE_ID === 'number') {
186+
/* eslint-disable-next-line no-global-assign */
187+
data.image_id = COVER_ART_IMAGE_ID++;
188+
}
189+
183190
var postfields = $.ajax({
184191
url: '/ws/js/cover-art-upload/' + gid,
185-
data: {mime_type: mimeType},
192+
data,
186193
dataType: 'json',
187194
cache: false,
188195
});

script/dbdefs_to_js.pl

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
GOOGLE_CUSTOM_SEARCH
3939
MAPBOX_ACCESS_TOKEN
4040
MAPBOX_MAP_ID
41+
MB_SERVER_ROOT
4142
RENDERER_SOCKET
4243
SENTRY_DSN
4344
SENTRY_DSN_PUBLIC

t/selenium.js

+11
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ const KEY_CODES = {
268268
'${KEY_HOME}': Key.HOME,
269269
'${KEY_SHIFT}': Key.SHIFT,
270270
'${KEY_TAB}': Key.TAB,
271+
'${MBS_ROOT}': DBDefs.MB_SERVER_ROOT.replace(/\/$/, ''),
271272
};
272273

273274
function getPageErrors() {
@@ -334,6 +335,15 @@ async function handleCommand({command, target, value}, t) {
334335

335336
let element;
336337
switch (command) {
338+
case 'assertArtworkJson':
339+
const artworkJson = JSON.parse(await driver.executeAsyncScript(`
340+
var callback = arguments[arguments.length - 1];
341+
fetch('http://localhost:8081/release/${target}')
342+
.then(x => x.text().then(callback));
343+
`));
344+
t.deepEqual2(artworkJson, value);
345+
break;
346+
337347
case 'assertAttribute':
338348
const splitAt = target.indexOf('@');
339349
const locator = target.slice(0, splitAt);
@@ -486,6 +496,7 @@ const seleniumTests = [
486496
{name: 'MBS-10188.json5', login: true, sql: 'mbs-10188.sql'},
487497
{name: 'MBS-10510.json5', login: true, sql: 'mbs-10510.sql'},
488498
{name: 'Artist_Credit_Editor.json5', login: true},
499+
{name: 'CAA.json5', login: true},
489500
{name: 'External_Links_Editor.json5', login: true},
490501
{name: 'Work_Editor.json5', login: true},
491502
{name: 'Redirect_Merged_Entities.json5', login: true},

0 commit comments

Comments
 (0)