From 4db286412b81bb31385cdb06e329eadd4e784842 Mon Sep 17 00:00:00 2001 From: Mikhail Gordeev Date: Wed, 6 May 2020 16:03:06 +0300 Subject: [PATCH] Add no_delete parameter to config --- cloud_build/cloud_build.py | 5 ++- example-config.yaml | 1 + tests/test_no_delete.py | 55 +++++++++++++++++++++++++++++++++ tests/test_no_delete_false.yaml | 16 ++++++++++ tests/test_no_delete_true.yaml | 16 ++++++++++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tests/test_no_delete.py create mode 100644 tests/test_no_delete_false.yaml create mode 100644 tests/test_no_delete_true.yaml diff --git a/cloud_build/cloud_build.py b/cloud_build/cloud_build.py index 543ec0e..6c0aa10 100755 --- a/cloud_build/cloud_build.py +++ b/cloud_build/cloud_build.py @@ -166,6 +166,8 @@ class CB: self.try_build_all = cfg.get('try_build_all', False) + self.no_delete = cfg.get('no_delete', True) + self.bad_arches = cfg.get('bad_arches', []) self.external_files = cfg.get('external_files') @@ -678,9 +680,10 @@ Dir::Etc::preferencesparts "/var/empty"; 'rsync', f'{self.images_dir}/{branch}/', '-rv', - '--delete', remote, ] + if not self.no_delete: + cmd.append('--delete') self.call(cmd) self.kick() diff --git a/example-config.yaml b/example-config.yaml index b63cb69..ef0d221 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -4,6 +4,7 @@ key: 0x00000000 try_build_all: False repository_url: http://mirror.yandex.ru/altlinux/{branch}/branch log_level: info +no_delete: True bad_arches: - armh diff --git a/tests/test_no_delete.py b/tests/test_no_delete.py new file mode 100644 index 0000000..8e9093c --- /dev/null +++ b/tests/test_no_delete.py @@ -0,0 +1,55 @@ +from pathlib import Path +from unittest import TestCase +from unittest import mock + +import shutil +import tempfile + +from cloud_build import CB + +import tests.call as call + + +class TestNoDelete(TestCase): + def setUp(self): + self.data_dir = Path(tempfile.mkdtemp(prefix='cloud_build')) + self.images_dir = Path('/tmp/cloud-build-test_no_delete/') + self.images_dir.mkdir() + + def tearDown(self): + shutil.rmtree(self.data_dir) + shutil.rmtree(self.images_dir) + + @mock.patch('subprocess.call', call.Call()) + def test_no_delete_false(self): + cb = CB( + config='tests/test_no_delete_false.yaml', + data_dir=self.data_dir, + no_tests=True, + create_remote_dirs=True, + ) + other_file = self.images_dir / 'other_file.txt' + other_file.write_text('Some text') + cb.create_images() + cb.sync() + del cb + msg = 'Other files shoud be deleted if not no_delete' + if other_file.exists(): + self.fail(msg) + + @mock.patch('subprocess.call', call.Call()) + def test_no_delete_true(self): + cb = CB( + config='tests/test_no_delete_true.yaml', + data_dir=self.data_dir, + no_tests=True, + create_remote_dirs=True, + ) + other_file = self.images_dir / 'other_file.txt' + other_file.write_text('Some text') + cb.create_images() + cb.sync() + del cb + msg = 'Other files shoud not be deleted if no_delete' + if not other_file.exists(): + self.fail(msg) diff --git a/tests/test_no_delete_false.yaml b/tests/test_no_delete_false.yaml new file mode 100644 index 0000000..ab755b6 --- /dev/null +++ b/tests/test_no_delete_false.yaml @@ -0,0 +1,16 @@ +--- +remote: '/tmp/cloud-build-test_no_delete' +key: 0x00000000 +no_delete: False + +images: + rootfs-minimal: + target: ve/docker + kinds: + - tar.xz + +branches: + Sisyphus: + arches: + x86_64: +... diff --git a/tests/test_no_delete_true.yaml b/tests/test_no_delete_true.yaml new file mode 100644 index 0000000..46507fa --- /dev/null +++ b/tests/test_no_delete_true.yaml @@ -0,0 +1,16 @@ +--- +remote: '/tmp/cloud-build-test_no_delete' +key: 0x00000000 +no_delete: True + +images: + rootfs-minimal: + target: ve/docker + kinds: + - tar.xz + +branches: + Sisyphus: + arches: + x86_64: +...