Change hardcoded kick command to after_sync_commands from config
This commit is contained in:
parent
399f79c8cd
commit
dd3c505ecb
@ -184,6 +184,8 @@ class CB:
|
|||||||
self._services = cfg.get('services', {})
|
self._services = cfg.get('services', {})
|
||||||
self._scripts = cfg.get('scripts', {})
|
self._scripts = cfg.get('scripts', {})
|
||||||
|
|
||||||
|
self._after_sync_commands = cfg.get('after_sync_commands', [])
|
||||||
|
|
||||||
self.key = cfg.get('key')
|
self.key = cfg.get('key')
|
||||||
if isinstance(self.key, int):
|
if isinstance(self.key, int):
|
||||||
self.key = '{:X}'.format(self.key)
|
self.key = '{:X}'.format(self.key)
|
||||||
@ -702,12 +704,22 @@ Dir::Etc::preferencesparts "/var/empty";
|
|||||||
self.call(['gpg2', '--yes', '-basu', self.key, sum_file])
|
self.call(['gpg2', '--yes', '-basu', self.key, sum_file])
|
||||||
shutil.copyfile(sum_file + '.asc', 'SHA256SUMS.gpg')
|
shutil.copyfile(sum_file + '.asc', 'SHA256SUMS.gpg')
|
||||||
|
|
||||||
def kick(self):
|
def after_sync_commands(self):
|
||||||
remote = self._remote
|
remote = self._remote
|
||||||
colon = remote.find(':')
|
colon = remote.find(':')
|
||||||
if colon != -1:
|
if colon != -1:
|
||||||
host = remote[:colon]
|
host = remote[:colon]
|
||||||
self.call(['ssh', host, 'kick'])
|
|
||||||
|
def cmd(command):
|
||||||
|
return ['ssh', host, command]
|
||||||
|
else:
|
||||||
|
host = remote
|
||||||
|
|
||||||
|
def cmd(command):
|
||||||
|
return [command]
|
||||||
|
|
||||||
|
for command in self._after_sync_commands:
|
||||||
|
self.call(cmd(command))
|
||||||
|
|
||||||
def sync(self, create_remote_dirs: bool = False) -> None:
|
def sync(self, create_remote_dirs: bool = False) -> None:
|
||||||
for branch in self.branches:
|
for branch in self.branches:
|
||||||
@ -724,4 +736,4 @@ Dir::Etc::preferencesparts "/var/empty";
|
|||||||
cmd.append('--delete')
|
cmd.append('--delete')
|
||||||
self.call(cmd)
|
self.call(cmd)
|
||||||
|
|
||||||
self.kick()
|
self.after_sync_commands()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
---
|
---
|
||||||
remote: remote:/pub/images/{branch}/cloud
|
remote: remote:/pub/images/{branch}/cloud
|
||||||
|
after_sync_commands: ['kick']
|
||||||
key: 0x00000000
|
key: 0x00000000
|
||||||
try_build_all: False
|
try_build_all: False
|
||||||
repository_url: http://mirror.yandex.ru/altlinux/{branch}/branch
|
repository_url: http://mirror.yandex.ru/altlinux/{branch}/branch
|
||||||
|
60
tests/test_after_sync_commands.py
Normal file
60
tests/test_after_sync_commands.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from unittest import TestCase
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from cloud_build import CB
|
||||||
|
|
||||||
|
import tests.call as call
|
||||||
|
|
||||||
|
|
||||||
|
DS = {'rsync': [call.return_d(0), call.nop_d]}
|
||||||
|
|
||||||
|
|
||||||
|
class TestAfterSyncCommands(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.data_dir = Path(tempfile.mkdtemp(prefix='cloud_build'))
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
shutil.rmtree(self.data_dir)
|
||||||
|
|
||||||
|
@mock.patch('subprocess.call', call.Call(decorators=DS))
|
||||||
|
def test_run_after_sync_remote_commands(self):
|
||||||
|
cb = CB(
|
||||||
|
config='tests/test_run_after_sync_remote_commands.yaml',
|
||||||
|
data_dir=self.data_dir,
|
||||||
|
)
|
||||||
|
cb.create_images(no_tests=True)
|
||||||
|
regex = r'ssh.*kick'
|
||||||
|
self.assertRaisesRegex(
|
||||||
|
Exception,
|
||||||
|
regex,
|
||||||
|
cb.sync,
|
||||||
|
create_remote_dirs=True
|
||||||
|
)
|
||||||
|
|
||||||
|
@mock.patch('subprocess.call', call.Call(decorators=DS))
|
||||||
|
def test_run_after_sync_local_commands(self):
|
||||||
|
cb = CB(
|
||||||
|
config='tests/test_run_after_sync_local_commands.yaml',
|
||||||
|
data_dir=self.data_dir,
|
||||||
|
)
|
||||||
|
cb.create_images(no_tests=True)
|
||||||
|
regex = r'\[\'kick'
|
||||||
|
self.assertRaisesRegex(
|
||||||
|
Exception,
|
||||||
|
regex,
|
||||||
|
cb.sync,
|
||||||
|
create_remote_dirs=True
|
||||||
|
)
|
||||||
|
|
||||||
|
@mock.patch('subprocess.call', call.Call(decorators=DS))
|
||||||
|
def test_dont_run_after_sync_local_commands(self):
|
||||||
|
cb = CB(
|
||||||
|
config='tests/minimal_config.yaml',
|
||||||
|
data_dir=self.data_dir,
|
||||||
|
)
|
||||||
|
cb.create_images(no_tests=True)
|
||||||
|
cb.sync(create_remote_dirs=False)
|
15
tests/test_run_after_sync_local_commands.yaml
Normal file
15
tests/test_run_after_sync_local_commands.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
remote: '/var/empty'
|
||||||
|
after_sync_commands: ['kick']
|
||||||
|
|
||||||
|
images:
|
||||||
|
rootfs-minimal:
|
||||||
|
target: ve/docker
|
||||||
|
kinds:
|
||||||
|
- tar.xz
|
||||||
|
|
||||||
|
branches:
|
||||||
|
Sisyphus:
|
||||||
|
arches:
|
||||||
|
x86_64:
|
||||||
|
...
|
15
tests/test_run_after_sync_remote_commands.yaml
Normal file
15
tests/test_run_after_sync_remote_commands.yaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
remote: 'example.com:/var/empty'
|
||||||
|
after_sync_commands: ['kick']
|
||||||
|
|
||||||
|
images:
|
||||||
|
rootfs-minimal:
|
||||||
|
target: ve/docker
|
||||||
|
kinds:
|
||||||
|
- tar.xz
|
||||||
|
|
||||||
|
branches:
|
||||||
|
Sisyphus:
|
||||||
|
arches:
|
||||||
|
x86_64:
|
||||||
|
...
|
Loading…
Reference in New Issue
Block a user