diff options
author | Chocobozzz <me@florianbigard.com> | 2023-05-23 10:49:45 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-05-23 10:49:45 +0200 |
commit | f89189907bbdff6c4bc6d3460ed9ef4c49515f17 (patch) | |
tree | c55e50e3fc02ae9b3f2d1d19d95160af98cc7d7c /shared/server-commands | |
parent | 41cde76bbf5ac16a90b5f158672523069db74009 (diff) | |
download | PeerTube-f89189907bbdff6c4bc6d3460ed9ef4c49515f17.tar.gz PeerTube-f89189907bbdff6c4bc6d3460ed9ef4c49515f17.tar.zst PeerTube-f89189907bbdff6c4bc6d3460ed9ef4c49515f17.zip |
Prevent object storage mock conflicts
When running tests in parallel
Diffstat (limited to 'shared/server-commands')
-rw-r--r-- | shared/server-commands/server/object-storage-command.ts | 103 | ||||
-rw-r--r-- | shared/server-commands/server/server.ts | 3 | ||||
-rw-r--r-- | shared/server-commands/videos/live-command.ts | 20 |
3 files changed, 75 insertions, 51 deletions
diff --git a/shared/server-commands/server/object-storage-command.ts b/shared/server-commands/server/object-storage-command.ts index a1fe4f0f7..7d8ec93cd 100644 --- a/shared/server-commands/server/object-storage-command.ts +++ b/shared/server-commands/server/object-storage-command.ts | |||
@@ -1,34 +1,17 @@ | |||
1 | 1 | import { randomInt } from 'crypto' | |
2 | import { HttpStatusCode } from '@shared/models' | 2 | import { HttpStatusCode } from '@shared/models' |
3 | import { makePostBodyRequest } from '../requests' | 3 | import { makePostBodyRequest } from '../requests' |
4 | import { AbstractCommand } from '../shared' | ||
5 | |||
6 | export class ObjectStorageCommand extends AbstractCommand { | ||
7 | static readonly DEFAULT_PLAYLIST_MOCK_BUCKET = 'streaming-playlists' | ||
8 | static readonly DEFAULT_WEBTORRENT_MOCK_BUCKET = 'videos' | ||
9 | 4 | ||
5 | export class ObjectStorageCommand { | ||
10 | static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test' | 6 | static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test' |
11 | 7 | ||
12 | // --------------------------------------------------------------------------- | 8 | private readonly bucketsCreated: string[] = [] |
13 | 9 | private readonly seed: number | |
14 | static getDefaultMockConfig () { | ||
15 | return { | ||
16 | object_storage: { | ||
17 | enabled: true, | ||
18 | endpoint: 'http://' + this.getMockEndpointHost(), | ||
19 | region: this.getMockRegion(), | ||
20 | |||
21 | credentials: this.getMockCredentialsConfig(), | ||
22 | 10 | ||
23 | streaming_playlists: { | 11 | // --------------------------------------------------------------------------- |
24 | bucket_name: this.DEFAULT_PLAYLIST_MOCK_BUCKET | ||
25 | }, | ||
26 | 12 | ||
27 | videos: { | 13 | constructor () { |
28 | bucket_name: this.DEFAULT_WEBTORRENT_MOCK_BUCKET | 14 | this.seed = randomInt(0, 10000) |
29 | } | ||
30 | } | ||
31 | } | ||
32 | } | 15 | } |
33 | 16 | ||
34 | static getMockCredentialsConfig () { | 17 | static getMockCredentialsConfig () { |
@@ -46,35 +29,79 @@ export class ObjectStorageCommand extends AbstractCommand { | |||
46 | return 'us-east-1' | 29 | return 'us-east-1' |
47 | } | 30 | } |
48 | 31 | ||
49 | static getMockWebTorrentBaseUrl () { | 32 | getDefaultMockConfig () { |
50 | return `http://${this.DEFAULT_WEBTORRENT_MOCK_BUCKET}.${this.getMockEndpointHost()}/` | 33 | return { |
34 | object_storage: { | ||
35 | enabled: true, | ||
36 | endpoint: 'http://' + ObjectStorageCommand.getMockEndpointHost(), | ||
37 | region: ObjectStorageCommand.getMockRegion(), | ||
38 | |||
39 | credentials: ObjectStorageCommand.getMockCredentialsConfig(), | ||
40 | |||
41 | streaming_playlists: { | ||
42 | bucket_name: this.getMockStreamingPlaylistsBucketName() | ||
43 | }, | ||
44 | |||
45 | videos: { | ||
46 | bucket_name: this.getMockWebVideosBucketName() | ||
47 | } | ||
48 | } | ||
49 | } | ||
51 | } | 50 | } |
52 | 51 | ||
53 | static getMockPlaylistBaseUrl () { | 52 | getMockWebVideosBaseUrl () { |
54 | return `http://${this.DEFAULT_PLAYLIST_MOCK_BUCKET}.${this.getMockEndpointHost()}/` | 53 | return `http://${this.getMockWebVideosBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/` |
55 | } | 54 | } |
56 | 55 | ||
57 | static async prepareDefaultMockBuckets () { | 56 | getMockPlaylistBaseUrl () { |
58 | await this.createMockBucket(this.DEFAULT_PLAYLIST_MOCK_BUCKET) | 57 | return `http://${this.getMockStreamingPlaylistsBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/` |
59 | await this.createMockBucket(this.DEFAULT_WEBTORRENT_MOCK_BUCKET) | ||
60 | } | 58 | } |
61 | 59 | ||
62 | static async createMockBucket (name: string) { | 60 | async prepareDefaultMockBuckets () { |
61 | await this.createMockBucket(this.getMockStreamingPlaylistsBucketName()) | ||
62 | await this.createMockBucket(this.getMockWebVideosBucketName()) | ||
63 | } | ||
64 | |||
65 | async createMockBucket (name: string) { | ||
66 | this.bucketsCreated.push(name) | ||
67 | |||
68 | await this.deleteMockBucket(name) | ||
69 | |||
63 | await makePostBodyRequest({ | 70 | await makePostBodyRequest({ |
64 | url: this.getMockEndpointHost(), | 71 | url: ObjectStorageCommand.getMockEndpointHost(), |
65 | path: '/ui/' + name + '?delete', | 72 | path: '/ui/' + name + '?create', |
66 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | 73 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 |
67 | }) | 74 | }) |
68 | 75 | ||
69 | await makePostBodyRequest({ | 76 | await makePostBodyRequest({ |
70 | url: this.getMockEndpointHost(), | 77 | url: ObjectStorageCommand.getMockEndpointHost(), |
71 | path: '/ui/' + name + '?create', | 78 | path: '/ui/' + name + '?make-public', |
72 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | 79 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 |
73 | }) | 80 | }) |
81 | } | ||
74 | 82 | ||
83 | async cleanupMock () { | ||
84 | for (const name of this.bucketsCreated) { | ||
85 | await this.deleteMockBucket(name) | ||
86 | } | ||
87 | } | ||
88 | |||
89 | getMockStreamingPlaylistsBucketName (name = 'streaming-playlists') { | ||
90 | return this.getMockBucketName(name) | ||
91 | } | ||
92 | |||
93 | getMockWebVideosBucketName (name = 'web-videos') { | ||
94 | return this.getMockBucketName(name) | ||
95 | } | ||
96 | |||
97 | getMockBucketName (name: string) { | ||
98 | return `${this.seed}-${name}` | ||
99 | } | ||
100 | |||
101 | private async deleteMockBucket (name: string) { | ||
75 | await makePostBodyRequest({ | 102 | await makePostBodyRequest({ |
76 | url: this.getMockEndpointHost(), | 103 | url: ObjectStorageCommand.getMockEndpointHost(), |
77 | path: '/ui/' + name + '?make-public', | 104 | path: '/ui/' + name + '?delete', |
78 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | 105 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 |
79 | }) | 106 | }) |
80 | } | 107 | } |
diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts index 66b7ff09d..70f7a3ee2 100644 --- a/shared/server-commands/server/server.ts +++ b/shared/server-commands/server/server.ts | |||
@@ -48,7 +48,6 @@ import { DebugCommand } from './debug-command' | |||
48 | import { FollowsCommand } from './follows-command' | 48 | import { FollowsCommand } from './follows-command' |
49 | import { JobsCommand } from './jobs-command' | 49 | import { JobsCommand } from './jobs-command' |
50 | import { MetricsCommand } from './metrics-command' | 50 | import { MetricsCommand } from './metrics-command' |
51 | import { ObjectStorageCommand } from './object-storage-command' | ||
52 | import { PluginsCommand } from './plugins-command' | 51 | import { PluginsCommand } from './plugins-command' |
53 | import { RedundancyCommand } from './redundancy-command' | 52 | import { RedundancyCommand } from './redundancy-command' |
54 | import { ServersCommand } from './servers-command' | 53 | import { ServersCommand } from './servers-command' |
@@ -140,7 +139,6 @@ export class PeerTubeServer { | |||
140 | servers?: ServersCommand | 139 | servers?: ServersCommand |
141 | login?: LoginCommand | 140 | login?: LoginCommand |
142 | users?: UsersCommand | 141 | users?: UsersCommand |
143 | objectStorage?: ObjectStorageCommand | ||
144 | videoStudio?: VideoStudioCommand | 142 | videoStudio?: VideoStudioCommand |
145 | videos?: VideosCommand | 143 | videos?: VideosCommand |
146 | videoStats?: VideoStatsCommand | 144 | videoStats?: VideoStatsCommand |
@@ -429,7 +427,6 @@ export class PeerTubeServer { | |||
429 | this.login = new LoginCommand(this) | 427 | this.login = new LoginCommand(this) |
430 | this.users = new UsersCommand(this) | 428 | this.users = new UsersCommand(this) |
431 | this.videos = new VideosCommand(this) | 429 | this.videos = new VideosCommand(this) |
432 | this.objectStorage = new ObjectStorageCommand(this) | ||
433 | this.videoStudio = new VideoStudioCommand(this) | 430 | this.videoStudio = new VideoStudioCommand(this) |
434 | this.videoStats = new VideoStatsCommand(this) | 431 | this.videoStats = new VideoStatsCommand(this) |
435 | this.views = new ViewsCommand(this) | 432 | this.views = new ViewsCommand(this) |
diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts index 73f4eefd3..44d625970 100644 --- a/shared/server-commands/videos/live-command.ts +++ b/shared/server-commands/videos/live-command.ts | |||
@@ -192,7 +192,7 @@ export class LiveCommand extends AbstractCommand { | |||
192 | videoUUID: string | 192 | videoUUID: string |
193 | playlistNumber: number | 193 | playlistNumber: number |
194 | segment: number | 194 | segment: number |
195 | objectStorage: boolean | 195 | objectStorage?: ObjectStorageCommand |
196 | objectStorageBaseUrl?: string | 196 | objectStorageBaseUrl?: string |
197 | }) { | 197 | }) { |
198 | const { | 198 | const { |
@@ -201,12 +201,12 @@ export class LiveCommand extends AbstractCommand { | |||
201 | playlistNumber, | 201 | playlistNumber, |
202 | segment, | 202 | segment, |
203 | videoUUID, | 203 | videoUUID, |
204 | objectStorageBaseUrl = ObjectStorageCommand.getMockPlaylistBaseUrl() | 204 | objectStorageBaseUrl |
205 | } = options | 205 | } = options |
206 | 206 | ||
207 | const segmentName = `${playlistNumber}-00000${segment}.ts` | 207 | const segmentName = `${playlistNumber}-00000${segment}.ts` |
208 | const baseUrl = objectStorage | 208 | const baseUrl = objectStorage |
209 | ? join(objectStorageBaseUrl, 'hls') | 209 | ? join(objectStorageBaseUrl || objectStorage.getMockPlaylistBaseUrl(), 'hls') |
210 | : server.url + '/static/streaming-playlists/hls' | 210 | : server.url + '/static/streaming-playlists/hls' |
211 | 211 | ||
212 | let error = true | 212 | let error = true |
@@ -226,7 +226,7 @@ export class LiveCommand extends AbstractCommand { | |||
226 | const hlsPlaylist = video.streamingPlaylists[0] | 226 | const hlsPlaylist = video.streamingPlaylists[0] |
227 | 227 | ||
228 | // Check SHA generation | 228 | // Check SHA generation |
229 | const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: objectStorage }) | 229 | const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: !!objectStorage }) |
230 | if (!shaBody[segmentName]) { | 230 | if (!shaBody[segmentName]) { |
231 | throw new Error('Segment SHA does not exist') | 231 | throw new Error('Segment SHA does not exist') |
232 | } | 232 | } |
@@ -261,13 +261,13 @@ export class LiveCommand extends AbstractCommand { | |||
261 | videoUUID: string | 261 | videoUUID: string |
262 | playlistNumber: number | 262 | playlistNumber: number |
263 | segment: number | 263 | segment: number |
264 | objectStorage?: boolean // default false | 264 | objectStorage?: ObjectStorageCommand |
265 | }) { | 265 | }) { |
266 | const { playlistNumber, segment, videoUUID, objectStorage = false } = options | 266 | const { playlistNumber, segment, videoUUID, objectStorage } = options |
267 | 267 | ||
268 | const segmentName = `${playlistNumber}-00000${segment}.ts` | 268 | const segmentName = `${playlistNumber}-00000${segment}.ts` |
269 | const baseUrl = objectStorage | 269 | const baseUrl = objectStorage |
270 | ? ObjectStorageCommand.getMockPlaylistBaseUrl() | 270 | ? objectStorage.getMockPlaylistBaseUrl() |
271 | : `${this.server.url}/static/streaming-playlists/hls` | 271 | : `${this.server.url}/static/streaming-playlists/hls` |
272 | 272 | ||
273 | const url = `${baseUrl}/${videoUUID}/${segmentName}` | 273 | const url = `${baseUrl}/${videoUUID}/${segmentName}` |
@@ -284,12 +284,12 @@ export class LiveCommand extends AbstractCommand { | |||
284 | getPlaylistFile (options: OverrideCommandOptions & { | 284 | getPlaylistFile (options: OverrideCommandOptions & { |
285 | videoUUID: string | 285 | videoUUID: string |
286 | playlistName: string | 286 | playlistName: string |
287 | objectStorage?: boolean // default false | 287 | objectStorage?: ObjectStorageCommand |
288 | }) { | 288 | }) { |
289 | const { playlistName, videoUUID, objectStorage = false } = options | 289 | const { playlistName, videoUUID, objectStorage } = options |
290 | 290 | ||
291 | const baseUrl = objectStorage | 291 | const baseUrl = objectStorage |
292 | ? ObjectStorageCommand.getMockPlaylistBaseUrl() | 292 | ? objectStorage.getMockPlaylistBaseUrl() |
293 | : `${this.server.url}/static/streaming-playlists/hls` | 293 | : `${this.server.url}/static/streaming-playlists/hls` |
294 | 294 | ||
295 | const url = `${baseUrl}/${videoUUID}/${playlistName}` | 295 | const url = `${baseUrl}/${videoUUID}/${playlistName}` |