Commit f2f15bb6 authored by Boxiang Sun's avatar Boxiang Sun

peertube: backup test fixup

parent 9faa3e08
Pipeline #24977 passed with stage
in 0 seconds
...@@ -54,4 +54,4 @@ md5sum = 58d1a4fe246169dea94d7d243b4bac9e ...@@ -54,4 +54,4 @@ md5sum = 58d1a4fe246169dea94d7d243b4bac9e
[template-peertube-restore-script] [template-peertube-restore-script]
filename = template-peertube-restore.sh.in filename = template-peertube-restore.sh.in
md5sum = ad94a08007a879af14c35f0f58503f1e md5sum = 75f8ddfe15d087294dece94029417193
...@@ -28,6 +28,9 @@ $${postgresql:bin}/pg_restore -h $${postgresql:pgdata-directory} --exit-on-error ...@@ -28,6 +28,9 @@ $${postgresql:bin}/pg_restore -h $${postgresql:pgdata-directory} --exit-on-error
# 3. # 3.
echo "Starting postgresql..." echo "Starting postgresql..."
$${postgresql:bin}/psql -D $${postgresql:pgdata-directory}
die() { die() {
echo "$*" 1>&2 echo "$*" 1>&2
exit 1 exit 1
......
...@@ -265,37 +265,75 @@ class TestTheiaResiliencePeertube(test_resiliency.TestTheiaResilience): ...@@ -265,37 +265,75 @@ class TestTheiaResiliencePeertube(test_resiliency.TestTheiaResilience):
postgresql_srv = os.path.join(postgresql_partition, 'srv', 'postgresql') postgresql_srv = os.path.join(postgresql_partition, 'srv', 'postgresql')
peertube_conenction_info = self._getPeertubeConnexionParameters() peertube_conenction_info = self._getPeertubeConnexionParameters()
raise NotImplementedError(peertube_conenction_info) frontend_url = peertube_conenction_info['frontend-url']
# Change the email address of the user 'peertube'
output = subprocess.check_output( frontend_url = self.connection_parameters['frontend-url']
(postgresql_bin, '-h', postgresql_srv, '-U', 'peertube', '-d', 'peertube_prod', # frontend_url: https://[2001:67c:1254:fd::9ee2]:9443
'-c', 'UPDATE "user" SET "email"=\'aaa\' WHERE "username"=\'root\''), # self.connection_parameters
universal_newlines=True) # {'backend-url': 'https://[2001:67c:1254:fd::9ee2]:9443', 'frontend-hostname': '[2001:67c:1254:fd::9ee2]:9443', 'frontend-url': 'https://[2001:67c:1254:fd::9ee2]:9443', 'password': '8ydTfRpv', 'username': 'root'}
self.assertIn("UPDATE", output) response = requests.get(frontend_url + '/api/v1/oauth-clients/local', verify=False)
self.assertEqual(requests.codes['OK'], response.status_code)
# Checked the modification has been updated in the database try:
output = subprocess.check_output( data = response.json()
(postgresql_bin, '-h', postgresql_srv, '-U', 'peertube', '-d', 'peertube_prod', except JSONDecodeError:
'-c', 'SELECT * FROM "user"'), self.fail("No json file returned! Maybe your Peertube API is incorrect.")
universal_newlines=True)
self.assertIn("aaa", output) client_id = data['client_id']
client_secret = data['client_secret']
# Change the email address of the user 'peertube' username = self.connection_parameters['username']
output = subprocess.check_output( password = self.connection_parameters['password']
(postgresql_bin, '-h', postgresql_srv, '-U', 'peertube', '-d', 'peertube_prod', auth_data = {
'-c', 'UPDATE "user" SET "email"=\'bbb\' WHERE "username"=\'root\''), 'client_id': client_id,
universal_newlines=True) 'client_secret': client_secret,
self.assertIn("UPDATE", output) 'grant_type': 'password',
'response_type': 'code',
'username': username,
'password': password
}
auth_result = requests.post(frontend_url + '/api/v1/users/token', data=auth_data, verify=False)
try:
auth_result_json = auth_result.json()
except JSONDecodeError:
self.fail("No json file returned! Maybe your Peertube API is incorrect.")
token_type = auth_result_json['token_type']
access_token = auth_result_json['access_token']
headers = {
'Authorization': token_type + ' ' + access_token
}
video_name = "Small test video"
file_path = "../../peertube/small.mp4"
file_mime_type = guess_type(file_path)[0]
with open(file_path, 'rb') as f:
video_data = {
'channelId': 1,
'name': video_name,
'commentEnabled': False,
}
upload_response = requests.post(
frontend_url + '/api/v1/videos/upload',
headers=headers,
data=video_data,
files={'videofile': (os.path.basename(file_path), f, file_mime_type)},
verify=False
)
try:
video_ids = upload_response.json()
except JSONDecodeError:
self.fail("No json file returned! Maybe your Peertube API is incorrect.")
# e.g: {'video': {'id': 7, 'shortUUID': 'nrnKJNCsRP7NkwRr51TK3e', 'uuid': 'ad9ae99d-07db-4e4c-adc3-73566d59a4c5'}}
self.assertIn('video', video_ids)
# Checked the modification has been updated in the database # Checked the modification has been updated in the database
output = subprocess.check_output( output = subprocess.check_output(
(postgresql_bin, '-h', postgresql_srv, '-U', 'peertube', '-d', 'peertube_prod', (postgresql_bin, '-h', postgresql_srv, '-U', 'peertube', '-d', 'peertube_prod',
'-c', 'SELECT * FROM "user"'), '-c', 'SELECT * FROM "video"'),
universal_newlines=True) universal_newlines=True)
self.assertIn("bbb", output) self.assertIn("Small test video", output)
# Do a fake periodically update # Do a fake periodically update
# Compute backup date in the near future # Compute backup date in the near future
soon = (datetime.now() + timedelta(minutes=4)).replace(second=0) soon = (datetime.now() + timedelta(minutes=4)).replace(second=0)
frequency = '%d * * * *' % soon.minute frequency = '%d * * * *' % soon.minute
...@@ -318,14 +356,8 @@ class TestTheiaResiliencePeertube(test_resiliency.TestTheiaResilience): ...@@ -318,14 +356,8 @@ class TestTheiaResiliencePeertube(test_resiliency.TestTheiaResilience):
self.callSlapos('node', 'status') self.callSlapos('node', 'status')
# Check that postgresql backup has started # Check that postgresql backup has started
# which contains this file: ./peertube_prod-dump.db postgresql_backup = os.path.join(postgresql_partition, 'srv', 'backup')
postgresql_backup = os.path.join(postgresql_partition, 'var', 'www', 'peertube') self.assertIn('peertube_prod-dump.db', os.listdir(postgresql_backup))
self.assertIn('peertube_prod-dump.sql', os.listdir(postgresql_backup))
# Check the backup contains the changes
with open(os.path.join(psql_backup, 'peertube_prod-dump.sql')) as f:
msg = "Postgres backup peertube_prod-dump.sql is not up to date"
self.assertIn("bbb", f.read(), msg)
def _checkTakeover(self): def _checkTakeover(self):
super(TestTheiaResiliencePeertube, self)._checkTakeover() super(TestTheiaResiliencePeertube, self)._checkTakeover()
...@@ -335,22 +367,6 @@ class TestTheiaResiliencePeertube(test_resiliency.TestTheiaResilience): ...@@ -335,22 +367,6 @@ class TestTheiaResiliencePeertube(test_resiliency.TestTheiaResilience):
postgres_bin = os.path.join(postgresql_partition, 'bin', 'postgres') postgres_bin = os.path.join(postgresql_partition, 'bin', 'postgres')
postgresql_srv = os.path.join(postgresql_partition, 'srv', 'postgresql') postgresql_srv = os.path.join(postgresql_partition, 'srv', 'postgresql')
# Check that the mariadb catalog is not yet restored
output = subprocess.check_output(
(postgresql_bin, '-h', postgresql_srv, '-U', 'peertube', '-d', 'peertube_prod',
'-c', 'SELECT * FROM "user"'),
universal_newlines=True)
self.assertNotIn("bbb", output)
# Stop all services
print("Stop all services")
self.callSlapos('node', 'stop', 'all')
# Manually restore postgresql from backup
postgresql_restore_script = os.path.join(mariadb_partition, 'bin', 'restore-from-backup')
print("Restore mariadb from backup")
subprocess.check_call(postgresql_restore_script)
# Check that the test instance is properly redeployed after restoring postgresql # Check that the test instance is properly redeployed after restoring postgresql
# This restarts the services and checks the promises of the test instance # This restarts the services and checks the promises of the test instance
# Process twice to propagate state change # Process twice to propagate state change
...@@ -360,9 +376,9 @@ class TestTheiaResiliencePeertube(test_resiliency.TestTheiaResilience): ...@@ -360,9 +376,9 @@ class TestTheiaResiliencePeertube(test_resiliency.TestTheiaResilience):
# Check that the postgresql catalog was properly restored # Check that the postgresql catalog was properly restored
output = subprocess.check_output( output = subprocess.check_output(
(postgresql_bin, '-h', postgresql_srv, '-U', 'peertube', '-d', 'peertube_prod', (postgresql_bin, '-h', postgresql_srv, '-U', 'peertube', '-d', 'peertube_prod',
'-c', 'SELECT * FROM "user"'), '-c', 'SELECT * FROM "video"'),
universal_newlines=True) universal_newlines=True)
self.assertIn("bbb", output) self.assertIn("Small test video", output)
def _getPeertubePartition(self, servicename): def _getPeertubePartition(self, servicename):
p = subprocess.Popen( p = subprocess.Popen(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment