From 8597528890d2f85112c555541fa0566593a8e5a9 Mon Sep 17 00:00:00 2001 Message-Id: From: Philipp Hahn Date: Wed, 20 Jan 2016 08:47:29 +0100 Subject: [PATCH 00/14] Assorted ucs-test/docker patches Organization: Univention GmbH, Bremen, Germany debian/rules should be executable. Fix discrepancy in timeout message Fix except SERVER_DOWN Add missing import of fail Fix host name extraction from repo/online/server Add missing dependency for build-essential Fix traceback in error handling: TypeError: not all arguments converted during string formatting Philipp Hahn (14): Bug #40338 test: Whitespace changes Bug #40338 test: Fix dependencies for docker Bug #40338 test: Remove useless statement Bug #40338 test: Move content to external files Bug #40338 test: Allow file mode during creation Bug #40338 test: imports Bug #40338 test: Fix exception Bug #40338 test: Fix error message Bug #40338 test: shell=False Bug #40338 test: Check return value Bug #40338 test: Use constant for directory names Bug #40338 test: Convert open() to context Bug #40338 test: Use .iteritems() Bug #40338 test: "%()s" % ucr .../ucs-4.1/ucs-4.1-0/test/ucs-test/debian/control | 2 + .../ucs-test/tests/80_docker/10_pull_appbox_mini | 6 +- .../ucs-test/tests/80_docker/40_app_install_4_0-3 | 9 +- .../test/ucs-test/tests/80_docker/51_app_install | 6 +- .../tests/80_docker/52_app_install_dc_slave | 12 +- .../tests/80_docker/53_missing_dockerimage | 7 +- .../test/ucs-test/tests/80_docker/54_app_preinst | 9 +- .../test/ucs-test/tests/80_docker/55_app_modproxy | 7 +- .../test/ucs-test/tests/80_docker/56_app_nscd_stop | 11 +- .../tests/80_docker/57_app_without_package | 6 +- .../ucs-test/tests/80_docker/58_app_uninstallation | 12 +- .../tests/80_docker/59_app_center_signature | 27 +- .../tests/80_docker/61_app_updater_identify | 11 +- .../tests/80_docker/62_app_update_available | 23 +- .../tests/80_docker/64_app_container_upgrade | 9 +- .../65_app_container_upgrade_dockerallowedimage | 11 +- .../test/ucs-test/tests/80_docker/70_app_scaling | 18 +- .../tests/80_docker/75_app_ports_exclusive | 11 +- .../ucs-test/tests/80_docker/76_app_ports_redirect | 11 +- .../80_docker/77_app_ports_conflicts_exclusive | 8 +- .../80_docker/78_app_ports_conflicts_redirect | 8 +- .../tests/80_docker/79_app_ports_already_used | 20 +- .../tests/80_docker/80_docker_pull_via_proxy_http | 7 +- .../test/ucs-test/tests/80_docker/categories.ini | 8 + .../tests/80_docker/create_appcenter_json.py | 44 +- .../test/ucs-test/tests/80_docker/dockertest.py | 490 +++++++-------------- .../test/ucs-test/tests/80_docker/dummy.svg | 40 ++ .../tests/80_docker/restore_data_script_4_1.py | 98 +++++ .../test/ucs-test/tests/80_docker/setup.sh | 11 + .../tests/80_docker/store_data_script_4_1.py | 91 ++++ .../ucs-test/univention/testing/debian_package.py | 23 +- 31 files changed, 536 insertions(+), 520 deletions(-) create mode 100644 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/categories.ini create mode 100644 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dummy.svg create mode 100755 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/restore_data_script_4_1.py create mode 100644 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/setup.sh create mode 100755 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/store_data_script_4_1.py -- 2.1.4 From 66519c749ab3a8f4b1c7824cd179c1e31edb6810 Mon Sep 17 00:00:00 2001 Message-Id: <66519c749ab3a8f4b1c7824cd179c1e31edb6810.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 07:22:54 +0100 Subject: [PATCH 01/14] Bug #40338 test: Whitespace changes Organization: Univention GmbH, Bremen, Germany --- .../ucs-test/tests/80_docker/10_pull_appbox_mini | 2 - .../ucs-test/tests/80_docker/40_app_install_4_0-3 | 5 -- .../test/ucs-test/tests/80_docker/51_app_install | 2 - .../tests/80_docker/52_app_install_dc_slave | 4 -- .../tests/80_docker/53_missing_dockerimage | 3 - .../test/ucs-test/tests/80_docker/54_app_preinst | 2 +- .../test/ucs-test/tests/80_docker/55_app_modproxy | 3 - .../test/ucs-test/tests/80_docker/56_app_nscd_stop | 2 - .../tests/80_docker/57_app_without_package | 2 - .../ucs-test/tests/80_docker/58_app_uninstallation | 6 +- .../tests/80_docker/59_app_center_signature | 4 +- .../tests/80_docker/61_app_updater_identify | 7 +-- .../tests/80_docker/62_app_update_available | 7 +-- .../tests/80_docker/64_app_container_upgrade | 5 -- .../65_app_container_upgrade_dockerallowedimage | 5 -- .../test/ucs-test/tests/80_docker/70_app_scaling | 14 ++--- .../tests/80_docker/75_app_ports_exclusive | 6 +- .../ucs-test/tests/80_docker/76_app_ports_redirect | 6 +- .../80_docker/77_app_ports_conflicts_exclusive | 2 - .../80_docker/78_app_ports_conflicts_redirect | 2 - .../tests/80_docker/79_app_ports_already_used | 15 +++-- .../tests/80_docker/80_docker_pull_via_proxy_http | 7 ++- .../tests/80_docker/create_appcenter_json.py | 44 +++++++++------ .../test/ucs-test/tests/80_docker/dockertest.py | 65 +++++++++++++++++----- .../ucs-test/univention/testing/debian_package.py | 2 +- 25 files changed, 110 insertions(+), 112 deletions(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini index 0e2425e..002607f 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini @@ -8,8 +8,6 @@ from dockertest import * if __name__ == '__main__': - docker_login() docker_pull('ucs-appbox-amd64:4.1-0') - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 index b8f775c..2dbc1a4 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 @@ -10,7 +10,6 @@ from univention.testing.utils import get_ldap_connection if __name__ == '__main__': - with Appcenter() as appcenter: appcenter.add_ucs_version_to_appcenter('4.0') @@ -21,7 +20,6 @@ if __name__ == '__main__': app.ucs_version = '4.0' app.add_to_local_appcenter() - # Since we are installing on a 4.1, a 4.1 ini entry is needed app = App(name=app_name, version='1', build_package=False) app.set_ini_parameter(DockerImage='docker.software-univention.de/ucs-appbox-amd64:4.0-3', @@ -38,7 +36,6 @@ if __name__ == '__main__': app.add_to_local_appcenter() try: - appcenter.update() app.install() @@ -48,8 +45,6 @@ if __name__ == '__main__': lo = get_ldap_connection() print lo.searchDn(filter='(&(cn=%s-*)(objectClass=univentionMemberServer))' % app_name, unique=True, required=True) - finally: app.uninstall() app.remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install index 1065f34..fb2c3b0 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install @@ -9,7 +9,6 @@ from dockertest import * from univention.testing.utils import get_ldap_connection if __name__ == '__main__': - with Appcenter() as appcenter: app_name = get_app_name() app_version = get_app_version() @@ -31,4 +30,3 @@ if __name__ == '__main__': finally: app.uninstall() app.remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave index fdc2f0b..a9e0b18 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave @@ -16,7 +16,6 @@ import ldap import time if __name__ == '__main__': - with Appcenter() as appcenter: app_name = get_app_name() app_version = get_app_version() @@ -45,10 +44,7 @@ univention-install --yes --no-install-recommends univention-server-slave univent print 'LDAP connection failed. Wait for ten seconds and try again.' time.sleep(60) lo = get_ldap_connection() - print lo.searchDn(filter='(&(cn=%s-*)(objectClass=univentionDomainController)(univentionServerRole=slave)(!(aRecord=*)))' % app_name, unique=True, required=True) - finally: app.uninstall() app.remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage index 2bf380a..080dc46 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage @@ -10,7 +10,6 @@ from univention.testing.utils import fail from univention.testing.internal import package_installed if __name__ == '__main__': - with Appcenter() as appcenter: app_name = get_app_name() app_version = get_app_version() @@ -29,8 +28,6 @@ if __name__ == '__main__': # The package must be installed locally if not package_installed(app.package_name): fail('The package %s is not installed locally.' % app.package_name) - finally: app.uninstall() app.remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst index ea316b0..44af031 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst @@ -7,7 +7,7 @@ from dockertest import * - + def create_app(fail_in_preinst): app_name = get_app_name() app_version = get_app_version() diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy index d2341dc..7ec2c24 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy @@ -8,7 +8,6 @@ from dockertest import * if __name__ == '__main__': - with Appcenter() as appcenter: app_name = get_app_name() app_version = get_app_version() @@ -31,9 +30,7 @@ if __name__ == '__main__': app.install() app.verify() - app.verify_basic_modproxy_settings() - finally: app.uninstall() app.remove() diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop index b0400fc..cd473dc 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop @@ -10,7 +10,6 @@ import subprocess import time if __name__ == '__main__': - nscd_stopped = False with Appcenter() as appcenter: @@ -40,7 +39,6 @@ if __name__ == '__main__': print ncs_container_pid_new if ncs_container_pid_old != ncs_container_pid_new: fail('nscd pid in container have been changed. old: [%s], new: [%s]' % (ncs_container_pid_old, ncs_container_pid_new)) - finally: if nscd_stopped: subprocess.call('/etc/init.d/nscd start', shell=True) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package index 5ada8c7..794b5be 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package @@ -9,7 +9,6 @@ from dockertest import * from univention.testing.utils import get_ldap_connection if __name__ == '__main__': - with Appcenter() as appcenter: app_name = get_app_name() app_version = get_app_version() @@ -40,4 +39,3 @@ if __name__ == '__main__': finally: app.uninstall() app.remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation index b8743fa..ace16ab 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation @@ -10,12 +10,13 @@ from univention.testing.utils import fail, get_ldap_connection import os import subprocess + def fail_if_file_exists(f): if os.path.exists(f): fail('%s still exists' % f) -if __name__ == '__main__': +if __name__ == '__main__': with Appcenter() as appcenter: app_name = get_app_name() app_version = get_app_version() @@ -42,7 +43,6 @@ echo "Test 123 Conf" >/var/lib/univention-appcenter/apps/%(app_name)s/conf/test1 lo = get_ldap_connection() print lo.searchDn(filter='(&(cn=%s-*)(objectClass=univentionMemberServer)(!(aRecord=*))(!(macAddress=*)))' % app_name, unique=True, required=True) - finally: app.uninstall() app.remove() @@ -79,7 +79,7 @@ echo "Test 123 Conf" >/var/lib/univention-appcenter/apps/%(app_name)s/conf/test1 fail('The LDAP object has not been removed: %s' % res) # Check for the backup container - res = subprocess.call('docker images | grep appcenter-backup-%s' % app.app_name, shell=True) + res = subprocess.call('docker images | grep appcenter-backup-%s' % app.app_name, shell=True) if res != 0: subprocess.call('docker images' % app.app_name, shell=True) fail('Backup container appcenter-backup-%s was not found' % app.app_name) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature index e714a09..73574d5 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature @@ -35,7 +35,7 @@ class SyncedAppcenter(Appcenter): d = os.path.dirname('/var/www/%s' % f) if not os.path.exists(d): os.makedirs(d) - + call('wget -O /var/www/%s %s/%s' % (f, self.upstream_appcenter, f), shell=True) def download_index_json(self): @@ -43,7 +43,7 @@ class SyncedAppcenter(Appcenter): def download_index_json_gpg(self): self.download('meta-inf/%s/index.json.gz.gpg' % self.vv) - + def remove_from_cache(self, f): if os.path.exists(os.path.join('/var/cache/univention-appcenter/', f)): os.remove(os.path.join('/var/cache/univention-appcenter/', f)) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify index d8d2935..3a97bb4 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify @@ -7,10 +7,11 @@ from dockertest import * -class UCSTest_DockerApp_Identify(UCSTest_Docker_Exception): pass +class UCSTest_DockerApp_Identify(UCSTest_Docker_Exception): + pass + if __name__ == '__main__': - with Appcenter() as appcenter: app_name = get_app_name() app_version = get_app_version() @@ -31,8 +32,6 @@ if __name__ == '__main__': print 'Identify: %s' % identify if identify.strip() != 'Docker App': raise UCSTest_DockerApp_Identify() - finally: app.uninstall() app.remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available index 03615ef..fbe6a09 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available @@ -28,7 +28,6 @@ def copy_package_to_appcenter(ucs_version, app_directory, package_name): ''' % {'version': ucs_version, 'app': app_directory}, shell=True) if __name__ == '__main__': - with Appcenter() as appcenter: ucr = ConfigRegistry() @@ -36,7 +35,7 @@ if __name__ == '__main__': app_name = get_app_name() package_name = get_app_name() - + app = App(name=app_name, version='1', package_name=package_name) app.set_ini_parameter(DockerImage='docker.software-univention.de/ucs-appbox-amd64:4.1-0') @@ -47,9 +46,7 @@ if __name__ == '__main__': test_package_v1.build() copy_package_to_appcenter(ucr['version/version'], app.app_directory, test_package_v1.get_binary_name()) - try: - appcenter.update() app.install() @@ -78,8 +75,6 @@ if __name__ == '__main__': res = app.execute_command_in_container('/usr/share/univention-docker-container-mode/update_available') if res != 'release: 4.1-0\n': fail('update_available returned [%s] instead of [release: 4.1-0\n]' % res) - finally: app.uninstall() app.remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade index 50ad822..6a72726 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade @@ -11,7 +11,6 @@ from univention.config_registry import ConfigRegistry if __name__ == '__main__': - with Appcenter() as appcenter: appcenter.add_ucs_version_to_appcenter('4.0') @@ -24,7 +23,6 @@ if __name__ == '__main__': app.add_to_local_appcenter() app_directory_suffix = app.app_directory_suffix - # Since we are installing on a 4.1, a 4.1 ini entry is needed app = App(name=app_name, version='1', package_name=package_name, build_package=False) app.set_ini_parameter(DockerImage='docker.software-univention.de/ucs-appbox-amd64:4.0-3', @@ -41,7 +39,6 @@ if __name__ == '__main__': app.add_to_local_appcenter() try: - appcenter.update() app.install() @@ -111,8 +108,6 @@ if __name__ == '__main__': fail('UCR variable test1 differes') if test_secret != test_secret_new: fail('/etc/test.secret link has been changed') - finally: app.uninstall() app.remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage index a5635e7..f7b2007 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage @@ -13,7 +13,6 @@ from univention.config_registry import ConfigRegistry if __name__ == '__main__': - with Appcenter() as appcenter: appcenter.add_ucs_version_to_appcenter('4.0') @@ -26,7 +25,6 @@ if __name__ == '__main__': app.add_to_local_appcenter() app_directory_suffix = app.app_directory_suffix - # Since we are installing on a 4.1, a 4.1 ini entry is needed app = App(name=app_name, version='1', package_name=package_name, build_package=False) app.set_ini_parameter(DockerImage='docker.software-univention.de/ucs-appbox-amd64:4.0-3', @@ -41,7 +39,6 @@ if __name__ == '__main__': app.add_to_local_appcenter() try: - appcenter.update() app.install() @@ -84,8 +81,6 @@ if __name__ == '__main__': print 'Container UUID: %s' % container_uuid_new if container_uuid != container_uuid_new: fail('The container UUID has been changed.') - finally: app.uninstall() app.remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling index 403d041..3c28cfb 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling @@ -8,15 +8,14 @@ from dockertest import * -DOCKER_APP_COUNT=20 +DOCKER_APP_COUNT = 20 if __name__ == '__main__': - with Appcenter() as appcenter: apps = [] try: - for i in range(0,DOCKER_APP_COUNT): + for i in range(0, DOCKER_APP_COUNT): app = App(name=get_app_name(), version=get_app_version()) app.set_ini_parameter(DockerImage='docker.software-univention.de/ucs-appbox-amd64:4.1-0', WebInterface='/%s' % app.app_name, @@ -30,18 +29,15 @@ if __name__ == '__main__': apps.append(app) - appcenter.update() - for i in range(0,DOCKER_APP_COUNT): + for i in range(0, DOCKER_APP_COUNT): apps[i].install() - for i in range(0,DOCKER_APP_COUNT): + for i in range(0, DOCKER_APP_COUNT): apps[i].verify() apps[i].verify_basic_modproxy_settings() - finally: - for i in range(0,len(apps)): + for i in range(0, len(apps)): apps[i].uninstall() apps[i].remove() - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive index 9420594..5b5978e 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive @@ -14,9 +14,7 @@ import pytest import socket if __name__ == '__main__': - with Appcenter() as appcenter: - app_name = get_app_name() app_version = get_app_version() app = App(name=app_name, version=app_version, build_package=False) @@ -43,7 +41,7 @@ if __name__ == '__main__': univention-app register "%(app_name)s" --component app_packages="$(univention-app get "%(app_name)s" default_packages --values-only --shell)" univention-install -y $app_packages - ''' % {'app_name': app_name}) + ''' % {'app_name': app_name}) app.add_to_local_appcenter() appcenter.update() app.install() @@ -54,7 +52,7 @@ if __name__ == '__main__': # restart firewall and check again restart_firewall() - + # check ports are open for port in ports: is_port_open(port) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect index 1c8f6bb..b6fb73e 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect @@ -14,9 +14,7 @@ import pytest import socket if __name__ == '__main__': - with Appcenter() as appcenter: - app_name = get_app_name() app_version = get_app_version() app = App(name=app_name, version=app_version, build_package=False) @@ -44,7 +42,7 @@ if __name__ == '__main__': univention-app register "%(app_name)s" --component app_packages="$(univention-app get "%(app_name)s" default_packages --values-only --shell)" univention-install -y $app_packages - ''' % {'app_name': app_name}) + ''' % {'app_name': app_name}) app.add_to_local_appcenter() appcenter.update() app.install() @@ -56,7 +54,7 @@ if __name__ == '__main__': # restart firewall and check again restart_firewall() - + # check ports are open for port in ports: host_port, container_port = port.split(':') diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive index fc04762..2c0a8b3 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive @@ -14,9 +14,7 @@ import pytest import time if __name__ == '__main__': - with Appcenter() as appcenter: - version = get_app_version() image = 'docker.software-univention.de/ucs-appbox-amd64:4.1-0' diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect index 06312d2..6cfb268 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect @@ -14,9 +14,7 @@ import pytest import time if __name__ == '__main__': - with Appcenter() as appcenter: - version = get_app_version() image = 'docker.software-univention.de/ucs-appbox-amd64:4.1-0' diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used index 7a2f4d5..8c0fbe3 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used @@ -13,7 +13,7 @@ import sys def _open_port(port): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: - s.bind(('', port)) + s.bind(('', port)) except socket.error as msg: print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1] return None @@ -23,17 +23,16 @@ def _open_port(port): if __name__ == '__main__': - sockets = [] - for i in range(40000,40100): + for i in range(40000, 40100): sockets.append(_open_port(i)) with Appcenter() as appcenter: app_name = get_app_name() app_version = get_app_version() - + app = App(name=app_name, version=app_version) - + try: app.set_ini_parameter( DockerImage='docker.software-univention.de/ucs-appbox-amd64:4.1-0', WebInterface='/%s' % app.app_name, @@ -44,11 +43,11 @@ if __name__ == '__main__': ) app.create_basic_modproxy_settings() app.add_to_local_appcenter() - + appcenter.update() - + app.install() - + app.verify() app.verify_basic_modproxy_settings() diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/80_docker_pull_via_proxy_http b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/80_docker_pull_via_proxy_http index 157f311..8e0fdee 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/80_docker_pull_via_proxy_http +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/80_docker_pull_via_proxy_http @@ -13,6 +13,7 @@ from univention.testing.utils import fail from dockertest import docker_login, pull_docker_image, docker_image_is_present from dockertest import remove_docker_image, restart_docker + def deb_package_is_installed(pkgname): cache = apt.Cache() if cache[pkgname].is_installed: @@ -20,11 +21,13 @@ def deb_package_is_installed(pkgname): else: return False + def deb_install_package(pkgname): cmd = ['univention-install', '-y', pkgname] p = subprocess.Popen(cmd, close_fds=True) p.wait() + def deb_uninstall_package(pkgname): cmd = ['apt-get', 'purge', '-y', pkgname] p = subprocess.Popen(cmd, close_fds=True) @@ -34,6 +37,7 @@ def deb_uninstall_package(pkgname): p = subprocess.Popen(cmd, close_fds=True) p.wait() + class TestCase: def __init__(self): self.ucr = UCSTestConfigRegistry() @@ -41,7 +45,7 @@ class TestCase: self.imgname = 'docker.software-univention.de/ucs-appbox-amd64:4.1-0' - required_pkgname = 'univention-squid' + required_pkgname = 'univention-squid' if not deb_package_is_installed(required_pkgname): deb_install_package(required_pkgname) self.remove_pkgname = required_pkgname @@ -82,6 +86,5 @@ class TestCase: if __name__ == '__main__': - with TestCase() as tc: tc.run() diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/create_appcenter_json.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/create_appcenter_json.py index 509b3e4..024d478 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/create_appcenter_json.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/create_appcenter_json.py @@ -50,6 +50,7 @@ DOCKER_READ_USER_CRED = { 'password': 'readonly', } + class FileInfo(object): def __init__(self, app, name, url, filename): self.name = name @@ -59,12 +60,14 @@ class FileInfo(object): self.sha256 = sha256sum(filename) self.archive_filename = '%s.%s' % (app.name, name) + class DockerImageInfo(object): def __init__(self, name, url, content): self.name = name self.url = url self.sha256 = sha256(content).hexdigest() + class App(object): def __init__(self, name, ucs_version, meta_inf_dir, components_dir, server): self.name = name @@ -198,7 +201,7 @@ class App(object): index = {} for file_info in self.important_files(): index[file_info.name] = { - 'url' : file_info.url, + 'url': file_info.url, } for hash_type in ('md5', 'sha256'): try: @@ -208,42 +211,52 @@ class App(object): pass for docker_image_info in self.docker_images(): index['ini'][docker_image_info.name] = { - 'url' : docker_image_info.url, - 'sha256' : docker_image_info.sha256, + 'url': docker_image_info.url, + 'sha256': docker_image_info.sha256, } return index + def check_ini_file(filename): name, ext = os.path.splitext(os.path.basename(filename)) if ext == '.ini': return name + def md5sum(filename): m = md5() with open(filename, 'r') as f: m.update(f.read()) return m.hexdigest() + def sha256sum(filename): m = sha256() with open(filename, 'r') as f: m.update(f.read()) return m.hexdigest() + if __name__ == '__main__': parser = OptionParser() - parser.add_option("-u", "--ucs-version", dest="version", default="3.1", - help="use UCS version VERSION (e.g. (and default) %default)", metavar="VERSION") - parser.add_option("-d", "--directory", dest="directory", default=".", - help="root directory where meta-inf and univention-repository lie", metavar="DIR") - parser.add_option("-o", "--output", dest="output", default=None, - help="write output to OUTPUTFILE. Defaults to stdout. If specified and not ending with .gz, .gz is added", metavar="OUTPUTFILE") - parser.add_option("-t", "--tar", dest="archive", default=None, - help="additionally add all files to tar archive TARFILE (not compressed)", metavar="TARFILE") - parser.add_option("-a", "--ask", action="store_true", dest="ask", default=False, - help="Diff between existing OUTPUTFILE and buffer. Overwrites if changes are confirmed (interactive! ... if any diff)") - parser.add_option("-s", "--server", dest="appcenter", default="https://appcenter.software-univention.de/", - help="external Univention App Center Server (defaults to %default. Another possibility may be https://appcenter-test.software-univention.de/ or http://appcenter.knut.univention.de/)", metavar="APPCENTER") + parser.add_option( + "-u", "--ucs-version", dest="version", default="3.1", + help="use UCS version VERSION (e.g. (and default) %default)", metavar="VERSION") + parser.add_option( + "-d", "--directory", dest="directory", default=".", + help="root directory where meta-inf and univention-repository lie", metavar="DIR") + parser.add_option( + "-o", "--output", dest="output", default=None, + help="write output to OUTPUTFILE. Defaults to stdout. If specified and not ending with .gz, .gz is added", metavar="OUTPUTFILE") + parser.add_option( + "-t", "--tar", dest="archive", default=None, + help="additionally add all files to tar archive TARFILE (not compressed)", metavar="TARFILE") + parser.add_option( + "-a", "--ask", action="store_true", dest="ask", default=False, + help="Diff between existing OUTPUTFILE and buffer. Overwrites if changes are confirmed (interactive! ... if any diff)") + parser.add_option( + "-s", "--server", dest="appcenter", default="https://appcenter.software-univention.de/", + help="external Univention App Center Server (defaults to %default. Another possibility may be https://appcenter-test.software-univention.de/ or http://appcenter.knut.univention.de/)", metavar="APPCENTER") (options, args) = parser.parse_args() root = options.directory @@ -294,4 +307,3 @@ if __name__ == '__main__': f.close() else: print out - diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py index 71624ce..52a266d 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py @@ -39,17 +39,49 @@ import subprocess import urllib2 -class UCSTest_Docker_Exception(Exception): pass -class UCSTest_Docker_LoginFailed(Exception): pass -class UCSTest_Docker_PullFailed(Exception): pass -class AppcenterMetainfAlreadyExists(Exception): pass -class AppcenterRepositoryAlreadyExists(Exception): pass -class UCSTest_DockerApp_InstallationFailed(Exception): pass -class UCSTest_DockerApp_UpdateFailed(Exception): pass -class UCSTest_DockerApp_UpgradeFailed(Exception): pass -class UCSTest_DockerApp_VerifyFailed(Exception): pass -class UCSTest_DockerApp_RemoveFailed(Exception): pass -class UCSTest_DockerApp_ModProxyFailed(Exception): pass + +class UCSTest_Docker_Exception(Exception): + pass + + +class UCSTest_Docker_LoginFailed(Exception): + pass + + +class UCSTest_Docker_PullFailed(Exception): + pass + + +class AppcenterMetainfAlreadyExists(Exception): + pass + + +class AppcenterRepositoryAlreadyExists(Exception): + pass + + +class UCSTest_DockerApp_InstallationFailed(Exception): + pass + + +class UCSTest_DockerApp_UpdateFailed(Exception): + pass + + +class UCSTest_DockerApp_UpgradeFailed(Exception): + pass + + +class UCSTest_DockerApp_VerifyFailed(Exception): + pass + + +class UCSTest_DockerApp_RemoveFailed(Exception): + pass + + +class UCSTest_DockerApp_ModProxyFailed(Exception): + pass def docker_login(server='docker.software-univention.de'): @@ -63,6 +95,7 @@ def docker_pull(image, server='docker.software-univention.de'): if ret != 0: raise UCSTest_Docker_PullFailed() + def docker_image_is_present(imgname): cmd = ['docker', 'inspect', imgname] with open('/dev/null', 'w') as devnull: @@ -70,24 +103,28 @@ def docker_image_is_present(imgname): p.wait() return p.returncode == 0 + def remove_docker_image(imgname): cmd = ['docker', 'rmi', imgname] p = subprocess.Popen(cmd, close_fds=True) p.wait() return p.returncode == 0 + def pull_docker_image(imgname): cmd = ['docker', 'pull', imgname] p = subprocess.Popen(cmd, close_fds=True) p.wait() return p.returncode == 0 + def restart_docker(): cmd = ['invoke-rc.d', 'docker', 'restart'] p = subprocess.Popen(cmd, close_fds=True) p.wait() return p.returncode == 0 + def get_app_name(): """ returns a valid app name """ return random_name() @@ -114,7 +151,7 @@ class App: else: self.package_name = get_app_name() - self.package_version = '%s.%s' % (version,get_app_version()) + self.package_version = '%s.%s' % (version, get_app_version()) self.ucr = ConfigRegistry() self.ucr.load() @@ -288,8 +325,6 @@ echo "TEST-%(app_name)s" >>/var/www/%(app_name)s/index.txt raise UCSTest_DockerApp_ModProxyFailed(Exception) - - class Appcenter: def __init__(self, version=None): self.meta_inf_created = False @@ -311,7 +346,6 @@ class Appcenter: self.add_ucs_version_to_appcenter(version) def add_ucs_version_to_appcenter(self, version): - if not os.path.exists('/var/www/meta-inf'): os.makedirs('/var/www/meta-inf', 0755) self.meta_inf_created = True @@ -368,6 +402,7 @@ Virtualization=Virtualisierung''') print 'Cleanup after exception: %s %s' % (exc_type, exc_value) self.cleanup() + def restore_data_script_4_1(): return '''#!/usr/bin/python2.7 from optparse import OptionParser diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py index f34ff8e..baeee73 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py @@ -185,6 +185,7 @@ uninstall/* usr/lib/univention-uninstall/ ''' self.create_debian_file_from_buffer('install', install) + if __name__ == '__main__': deb = DebianPackage('testdeb') share_file = '''# testdeb @@ -197,4 +198,3 @@ if __name__ == '__main__': deb.install() deb.uninstall() deb.remove() - -- 2.1.4 From 135a92afba1bf13b39efce407763c1164f9a58a1 Mon Sep 17 00:00:00 2001 Message-Id: <135a92afba1bf13b39efce407763c1164f9a58a1.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 07:26:18 +0100 Subject: [PATCH 02/14] Bug #40338 test: Fix dependencies for docker Organization: Univention GmbH, Bremen, Germany Move dependency on docker.io to package control file. Add dependency on build-essential as it is required to build the dummy Debian package. --- branches/ucs-4.1/ucs-4.1-0/test/ucs-test/debian/control | 2 ++ .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 | 2 -- branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage | 2 -- branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst | 2 -- .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy | 2 -- .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade | 2 -- .../tests/80_docker/65_app_container_upgrade_dockerallowedimage | 2 -- branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect | 2 -- .../test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive | 2 -- .../test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect | 2 -- .../ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used | 2 -- 22 files changed, 2 insertions(+), 42 deletions(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/debian/control b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/debian/control index 95ecd0c..e44361c 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/debian/control +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/debian/control @@ -523,6 +523,8 @@ Architecture: all Depends: ucs-test-libs (= ${source:Version}), ${misc:Depends}, python-pytest, + docker.io, + build-essential, Recommends: ucs-test-framework Provides: ucs-test-module Description: Test scripts to test the Docker integration diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini index 002607f..a1d7033 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini @@ -2,8 +2,6 @@ ## desc: Pull appbox docker image ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 index 2dbc1a4..34e7f40 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 @@ -2,8 +2,6 @@ ## desc: Create and install a simple UCS 4.0-3 docker app ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install index fb2c3b0..a8f8819 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install @@ -2,8 +2,6 @@ ## desc: Create and install a simple docker app ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave index a9e0b18..2635c2e 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave @@ -2,8 +2,6 @@ ## desc: Create and install a simple DC Slave docker app ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io ## versions: ## 4.1-0: skip ## bugs: diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage index 080dc46..5e329ae 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage @@ -2,8 +2,6 @@ ## desc: Create and install a simple docker app without the DockerImage parameter ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import fail diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst index 44af031..d1736ef 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst @@ -2,8 +2,6 @@ ## desc: Check the preinst script ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy index 7ec2c24..7ef1852 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy @@ -2,8 +2,6 @@ ## desc: Check Docker App mod_proxy configuration ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop index cd473dc..3942a64 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop @@ -2,8 +2,6 @@ ## desc: Check if a nscd stop also kills the container nscd processes ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * import subprocess diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package index 794b5be..6308a72 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package @@ -2,8 +2,6 @@ ## desc: Create and install a simple docker app without a Debian package (plain container app) ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation index ace16ab..299562b 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation @@ -2,8 +2,6 @@ ## desc: Test the Docker App uninstallation ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import fail, get_ldap_connection diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature index 73574d5..a7633e7 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature @@ -2,8 +2,6 @@ ## desc: Verify the signature implementation ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io import os from dockertest import * diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify index 3a97bb4..51f07ad 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify @@ -2,8 +2,6 @@ ## desc: Check updater/identify in a new Docker App ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available index fbe6a09..095eee9 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available @@ -4,8 +4,6 @@ ## exposure: dangerous ## versions: ## 4.1-0: skip -## packages: -## - docker.io from dockertest import * from univention.testing.debian_package import DebianPackage diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade index 6a72726..544a6da 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade @@ -2,8 +2,6 @@ ## desc: Test the container upgrade without a re-join ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection, fail diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage index f7b2007..2cce0dc 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage @@ -4,8 +4,6 @@ ## exposure: dangerous ## versions: ## 4.1-0: skip -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection,fail diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling index 3c28cfb..b3e32ce 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling @@ -3,8 +3,6 @@ ## tags: [WIP,docker] ## timeout: 7200 ## exposure: dangerous -## packages: -## - docker.io from dockertest import * diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive index 5b5978e..b1c5955 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive @@ -2,8 +2,6 @@ ## desc: Create and install a simple docker app and check ports exclusive ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect index b6fb73e..713b0d2 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect @@ -2,8 +2,6 @@ ## desc: Create and install a simple docker app and check ports redirect ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive index 2c0a8b3..51dc5c8 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive @@ -2,8 +2,6 @@ ## desc: Create and install a simple docker app and check ports exclusive constraints ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect index 6cfb268..b77e1d5 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect @@ -2,8 +2,6 @@ ## desc: Create and install a simple docker app and check ports redirection constraints ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used index 8c0fbe3..1750798 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used @@ -2,8 +2,6 @@ ## desc: Check the App installation if the next free port is already used ## tags: [docker] ## exposure: dangerous -## packages: -## - docker.io from dockertest import * from univention.testing.utils import get_ldap_connection -- 2.1.4 From 158054422584545b962038c24ccd0746b8066543 Mon Sep 17 00:00:00 2001 Message-Id: <158054422584545b962038c24ccd0746b8066543.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 08:32:12 +0100 Subject: [PATCH 03/14] Bug #40338 test: Remove useless statement Organization: Univention GmbH, Bremen, Germany --- branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py index 52a266d..5caca00 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py @@ -187,7 +187,6 @@ class App: def set_ini_parameter(self, **kwargs): for key, value in kwargs.iteritems(): self.ini[key] = value - pass def add_to_local_appcenter(self): self._dump_ini() -- 2.1.4 From 365aac2f00df5614b21ee73015a3a4fd5b5e3c44 Mon Sep 17 00:00:00 2001 Message-Id: <365aac2f00df5614b21ee73015a3a4fd5b5e3c44.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 07:40:29 +0100 Subject: [PATCH 04/14] Bug #40338 test: Move content to external files Organization: Univention GmbH, Bremen, Germany Extract file content from dockertest.py to external files. --- .../test/ucs-test/tests/80_docker/categories.ini | 8 + .../test/ucs-test/tests/80_docker/dockertest.py | 252 +-------------------- .../test/ucs-test/tests/80_docker/dummy.svg | 40 ++++ .../tests/80_docker/restore_data_script_4_1.py | 98 ++++++++ .../test/ucs-test/tests/80_docker/setup.sh | 11 + .../tests/80_docker/store_data_script_4_1.py | 91 ++++++++ 6 files changed, 257 insertions(+), 243 deletions(-) create mode 100644 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/categories.ini create mode 100644 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dummy.svg create mode 100755 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/restore_data_script_4_1.py create mode 100644 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/setup.sh create mode 100755 branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/store_data_script_4_1.py diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/categories.ini b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/categories.ini new file mode 100644 index 0000000..99343b2 --- /dev/null +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/categories.ini @@ -0,0 +1,8 @@ +[de] +Administration=Administration +Business=Business +Collaboration=Collaboration +Education=Schule +System services=Systemdienste +UCS components=UCS-Komponenten +Virtualization=Virtualisierung diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py index 5caca00..0308cbd 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py @@ -297,17 +297,8 @@ class App: ''' % {'version': self.ucs_version, 'app': self.app_directory}, shell=True) def create_basic_modproxy_settings(self): - self.add_script(setup='''#!/bin/bash -set -x -e -eval "$(ucr shell)" -if [ "$version_version" = 4.0 ]; then - ucr set repository/online/server="$(echo $repository_online_server | sed -e 's|.*//\(.*\)|\\1|')" -fi -univention-install --yes univention-apache -mkdir /var/www/%(app_name)s -echo "TEST-%(app_name)s" >>/var/www/%(app_name)s/index.txt -/usr/share/univention-docker-container-mode/setup "$@" -''' % {'app_name': self.app_name}) + setup = open(os.path.join(os.path.dirname(__file__), 'setup.sh'), 'r').read() + self.add_script(setup=setup % {'app_name': self.app_name}) def verify_basic_modproxy_settings(self): fqdn = '%s.%s' % (self.ucr['hostname'], self.ucr['domainname']) @@ -357,15 +348,9 @@ class Appcenter: os.makedirs('/var/www/meta-inf/%s' % version) if not os.path.exists('/var/www/meta-inf/categories.ini'): + text = open(os.path.join(os.path.dirname(__file__), 'categories.ini'), 'r').read() f = open('/var/www/meta-inf/categories.ini', 'w') - f.write('''[de] -Administration=Administration -Business=Business -Collaboration=Collaboration -Education=Schule -System services=Systemdienste -UCS components=UCS-Komponenten -Virtualization=Virtualisierung''') + f.write(test) f.close() f = open('/var/www/meta-inf/rating.ini', 'w') f.write('# rating stuff\n') @@ -403,231 +388,12 @@ Virtualization=Virtualisierung''') def restore_data_script_4_1(): - return '''#!/usr/bin/python2.7 -from optparse import OptionParser -import os -import shutil -import string -import univention.config_registry -import traceback - -BLACKLIST_UCR_VARIABLES = [ - 'version/version', - 'version/erratalevel', - 'version/patchlevel', - 'version/releasename', -] - - -# Helper function to copy all meta data of a file or directory -def copy_permissions(src, dest): - s_stat = os.stat(src) - os.chown(dest, s_stat.st_uid, s_stat.st_gid) - shutil.copymode(src, dest) - shutil.copystat(src, dest) - d_stat = os.stat(dest) - - -def restore_files(source_dir): - if not os.path.exists(source_dir): - return - for (path, dirs, files) in os.walk(source_dir): - for d in dirs: - r_path = string.replace(path, source_dir, '/', 1) - dest = os.path.join(r_path, d) - if not os.path.exists(dest): - os.makedirs(dest) - src = os.path.join(path, d) - copy_permissions(src, dest) - for i in files: - src = os.path.join(path, i) - dest = string.replace(src, source_dir, '', 1) - if os.path.islink(src): - linkto = os.readlink(src) - if os.path.exists(dest) or os.path.islink(dest): - print 'rm %s' % dest - os.remove(dest) - print 'ln -sf %s %s' % (linkto, dest) - os.symlink(linkto, dest) - else: - print 'cp %s %s' % (src, dest) - shutil.copy(src, dest) - copy_permissions(src, dest) - - -def restore_ucr_layer(ucr_file, options): - if not os.path.exists(ucr_file): - return - f = open(ucr_file, "r") - vv = [] - for v in f.readlines(): - v = v.strip() - if not v or v.startswith('#'): - continue - key, value = v.split(':', 1) - if key not in BLACKLIST_UCR_VARIABLES: - vv.append('%s=%s' % (key, value)) - if vv: - print vv - univention.config_registry.handler_set(vv, opts=options) - -if __name__ == '__main__': - parser = OptionParser('%prog [options]') - parser.add_option('--app', dest='app', help='App ID') - parser.add_option('--app-version', dest='app_version', help='Version of App') - parser.add_option('--error-file', dest='error_file', help='Name of Error File') - opts, args = parser.parse_args() - - conf_dir = '/var/lib/univention-appcenter/apps/%s/conf/' % opts.app - source_dir = '/var/lib/univention-appcenter/apps/%s/conf/files' % opts.app - - try: - restore_files(source_dir) - - print '** Restore forced UCR layer:' - restore_ucr_layer(os.path.join(conf_dir, 'base-forced.conf'), {'force': True}) - print '** Restore ldap UCR layer' - restore_ucr_layer(os.path.join(conf_dir, 'base-ldap.conf'), {'ldap-policy': True}) - print '** Restore normal UCR layer:' - restore_ucr_layer(os.path.join(conf_dir, 'base.conf'), {}) - except: - traceback.print_exc() - if opts.error_file: - error_file = open(opts.error_file, 'a+') - traceback.print_exc(file=error_file) - error_file.close() - raise -''' + return open(os.path.join(os.path.dirname(__file__), 'restore_data_script_4_1.py'), 'r').read() + def store_data_script_4_1(): - return '''#!/usr/bin/python2.7 -from optparse import OptionParser -import glob -import os -import shutil -import string -import traceback - - -# Helper function to copy all meta data of a file or directory -def copy_permissions(src, dest): - s_stat = os.stat(src) - os.chown(dest, s_stat.st_uid, s_stat.st_gid) - shutil.copymode(src, dest) - shutil.copystat(src, dest) - d_stat = os.stat(dest) - - -# Helper function to copy the files and directory -def copy_to_persistent_storage(src, dest): - l_src = string.split(src, '/') - # Ignore first empty entry - if l_src[0] == '': - l_src = l_src[1:] - for j in range(0, len(l_src)): - s = os.path.join('/', string.join(l_src[0:j + 1], '/')) - d = os.path.join(dest, string.join(l_src[0:j + 1], '/')) - if os.path.isdir(s): - if not os.path.exists(d): - os.makedirs(d) - copy_permissions(s, d) - elif os.path.islink(s): - linkto = os.readlink(s) - if os.path.exists(d) or os.path.islink(d): - print 'rm %s' % d - os.remove(d) - print 'ln -sf %s %s' % (linkto, d) - os.symlink(linkto, d) - else: - print 'cp %s %s' % (s, d) - shutil.copy(s, d) - copy_permissions(s, d) - - -def copy_files(src, dest): - for f in glob.glob(src): - copy_to_persistent_storage(f, dest) - - -def copy_recursive(src, dest): - if not os.path.exists(src): - return - copy_to_persistent_storage(src, dest) - for root, dirs, files in os.walk(src): - for f in files: - fullpath = os.path.join(root, f) - copy_to_persistent_storage(fullpath, dest) - -if __name__ == '__main__': - parser = OptionParser('%prog [options]') - parser.add_option('--app', dest='app', help='App ID') - parser.add_option('--app-version', dest='app_version', help='Version of App') - parser.add_option('--error-file', dest='error_file', help='Name of Error File') - opts, args = parser.parse_args() - - dest = '/var/lib/univention-appcenter/apps/%s/conf/' % opts.app - - # The files and directories below the files directory are restored - # automatically after the new container has been started - store = '/var/lib/univention-appcenter/apps/%s/conf/files' % opts.app - - try: - for f in glob.glob('/etc/univention/base*conf'): - print 'cp %s %s' % (f, dest) - shutil.copy(f, dest) - copy_files('/etc/*.secret', store) - copy_recursive('/etc/univention/ssl', store) - copy_recursive('/var/univention-join', store) - copy_recursive('/var/lib/univention-ldap/', store) - copy_recursive('/var/lib/univention-directory-listener/', store) - copy_recursive('/etc/univention/connector', store) - except: - traceback.print_exc() - if opts.error_file: - error_file = open(opts.error_file, 'a+') - traceback.print_exc(file=error_file) - error_file.close() - raise -''' + return open(os.path.join(os.path.dirname(__file__), 'store_data_script_4_1.py'), 'r').read() + def get_dummy_svg(): - return ''' - - - - - - - - image/svg+xml - - - - - - - - - - -''' + return open(os.path.join(os.path.dirname(__file__), 'dummy.svg'), 'r').read() diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dummy.svg b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dummy.svg new file mode 100644 index 0000000..3406494 --- /dev/null +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dummy.svg @@ -0,0 +1,40 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/restore_data_script_4_1.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/restore_data_script_4_1.py new file mode 100755 index 0000000..01db4b3 --- /dev/null +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/restore_data_script_4_1.py @@ -0,0 +1,98 @@ +#!/usr/bin/python2.7 +from optparse import OptionParser +import os +import shutil +import string +import univention.config_registry +import traceback + +BLACKLIST_UCR_VARIABLES = [ + 'version/version', + 'version/erratalevel', + 'version/patchlevel', + 'version/releasename', +] + + +# Helper function to copy all meta data of a file or directory +def copy_permissions(src, dest): + s_stat = os.stat(src) + os.chown(dest, s_stat.st_uid, s_stat.st_gid) + shutil.copymode(src, dest) + shutil.copystat(src, dest) + + +def restore_files(source_dir): + if not os.path.exists(source_dir): + return + for (path, dirs, files) in os.walk(source_dir): + for d in dirs: + r_path = string.replace(path, source_dir, '/', 1) + dest = os.path.join(r_path, d) + if not os.path.exists(dest): + os.makedirs(dest) + src = os.path.join(path, d) + copy_permissions(src, dest) + for i in files: + src = os.path.join(path, i) + dest = string.replace(src, source_dir, '', 1) + if os.path.islink(src): + linkto = os.readlink(src) + if os.path.exists(dest) or os.path.islink(dest): + print 'rm %s' % dest + os.remove(dest) + print 'ln -sf %s %s' % (linkto, dest) + os.symlink(linkto, dest) + else: + print 'cp %s %s' % (src, dest) + shutil.copy(src, dest) + copy_permissions(src, dest) + + +def restore_ucr_layer(ucr_file, options): + if not os.path.exists(ucr_file): + return + f = open(ucr_file, "r") + vv = [] + for v in f.readlines(): + v = v.strip() + if not v or v.startswith('#'): + continue + key, value = v.split(':', 1) + if key not in BLACKLIST_UCR_VARIABLES: + vv.append('%s=%s' % (key, value)) + if vv: + print vv + univention.config_registry.handler_set(vv, opts=options) + + +def main(): + parser = OptionParser('%prog [options]') + parser.add_option('--app', dest='app', help='App ID') + parser.add_option('--app-version', dest='app_version', help='Version of App') + parser.add_option('--error-file', dest='error_file', help='Name of Error File') + opts, args = parser.parse_args() + + conf_dir = '/var/lib/univention-appcenter/apps/%s/conf/' % opts.app + source_dir = '/var/lib/univention-appcenter/apps/%s/conf/files' % opts.app + + try: + restore_files(source_dir) + + print '** Restore forced UCR layer:' + restore_ucr_layer(os.path.join(conf_dir, 'base-forced.conf'), {'force': True}) + print '** Restore ldap UCR layer' + restore_ucr_layer(os.path.join(conf_dir, 'base-ldap.conf'), {'ldap-policy': True}) + print '** Restore normal UCR layer:' + restore_ucr_layer(os.path.join(conf_dir, 'base.conf'), {}) + except: + traceback.print_exc() + if opts.error_file: + error_file = open(opts.error_file, 'a+') + traceback.print_exc(file=error_file) + error_file.close() + raise + + +if __name__ == '__main__': + main() diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/setup.sh b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/setup.sh new file mode 100644 index 0000000..14b2031 --- /dev/null +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/setup.sh @@ -0,0 +1,11 @@ +#!/bin/bash +eval "$(ucr shell)" +set -x -e +if [ "$version_version" = 4.0 ]; then + repo=${repository_online_server#*://} + ucr set repository/online/server="${repo%%/*}" +fi +univention-install --yes univention-apache +mkdir "/var/www/%(app_name)s" +echo "TEST-%(app_name)s" >>"/var/www/%(app_name)s/index.txt" +/usr/share/univention-docker-container-mode/setup "$@" diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/store_data_script_4_1.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/store_data_script_4_1.py new file mode 100755 index 0000000..8a21b2b --- /dev/null +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/store_data_script_4_1.py @@ -0,0 +1,91 @@ +#!/usr/bin/python2.7 +from optparse import OptionParser +import glob +import os +import shutil +import traceback + + +# Helper function to copy all meta data of a file or directory +def copy_permissions(src, dest): + s_stat = os.stat(src) + os.chown(dest, s_stat.st_uid, s_stat.st_gid) + shutil.copymode(src, dest) + shutil.copystat(src, dest) + + +# Helper function to copy the files and directory +def copy_to_persistent_storage(src, dest): + l_src = src.split('/') + # Ignore first empty entry + if l_src[0] == '': + l_src = l_src[1:] + for j in range(0, len(l_src)): + s = os.path.join('/', '/'.join(l_src[0:j + 1])) + d = os.path.join(dest, '/'.join(l_src[0:j + 1])) + if os.path.isdir(s): + if not os.path.exists(d): + os.makedirs(d) + copy_permissions(s, d) + elif os.path.islink(s): + linkto = os.readlink(s) + if os.path.exists(d) or os.path.islink(d): + print 'rm %s' % d + os.remove(d) + print 'ln -sf %s %s' % (linkto, d) + os.symlink(linkto, d) + else: + print 'cp %s %s' % (s, d) + shutil.copy(s, d) + copy_permissions(s, d) + + +def copy_files(src, dest): + for f in glob.glob(src): + copy_to_persistent_storage(f, dest) + + +def copy_recursive(src, dest): + if not os.path.exists(src): + return + copy_to_persistent_storage(src, dest) + for root, dirs, files in os.walk(src): + for f in files: + fullpath = os.path.join(root, f) + copy_to_persistent_storage(fullpath, dest) + + +def main(): + parser = OptionParser('%prog [options]') + parser.add_option('--app', dest='app', help='App ID') + parser.add_option('--app-version', dest='app_version', help='Version of App') + parser.add_option('--error-file', dest='error_file', help='Name of Error File') + opts, args = parser.parse_args() + + dest = '/var/lib/univention-appcenter/apps/%s/conf/' % opts.app + + # The files and directories below the files directory are restored + # automatically after the new container has been started + store = '/var/lib/univention-appcenter/apps/%s/conf/files' % opts.app + + try: + for f in glob.glob('/etc/univention/base*conf'): + print 'cp %s %s' % (f, dest) + shutil.copy(f, dest) + copy_files('/etc/*.secret', store) + copy_recursive('/etc/univention/ssl', store) + copy_recursive('/var/univention-join', store) + copy_recursive('/var/lib/univention-ldap/', store) + copy_recursive('/var/lib/univention-directory-listener/', store) + copy_recursive('/etc/univention/connector', store) + except: + traceback.print_exc() + if opts.error_file: + error_file = open(opts.error_file, 'a+') + traceback.print_exc(file=error_file) + error_file.close() + raise + + +if __name__ == '__main__': + main() -- 2.1.4 From 191b9fe5e1cf192d6d62324ceb29be867facda50 Mon Sep 17 00:00:00 2001 Message-Id: <191b9fe5e1cf192d6d62324ceb29be867facda50.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 08:29:41 +0100 Subject: [PATCH 05/14] Bug #40338 test: Allow file mode during creation Organization: Univention GmbH, Bremen, Germany debian/rules should be executable. Reduce redundant code by moving the chmod() into the common function. --- .../test/ucs-test/univention/testing/debian_package.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py index baeee73..9a7efd5 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py @@ -76,20 +76,20 @@ class DebianPackage(): deb_package = os.path.join(self._package_tempdir, deb_file) return deb_package - def __create_file_from_buffer(self, path, file_buffer): + def __create_file_from_buffer(self, path, file_buffer, mode=None): f = open(path, 'w') f.write(file_buffer) f.close() + if mode: + os.chmod(path, mode) def create_join_script_from_buffer(self, joinscript_name, joinscript_buffer): self.__join_file = os.path.join(self._package_path, joinscript_name) - self.__create_file_from_buffer(self.__join_file, joinscript_buffer) - os.chmod(self.__join_file, 0755) + self.__create_file_from_buffer(self.__join_file, joinscript_buffer, 0755) def create_unjoin_script_from_buffer(self, unjoinscript_name, unjoinscript_buffer): self.__unjoin_file = os.path.join(self._package_path, unjoinscript_name) - self.__create_file_from_buffer(self.__unjoin_file, unjoinscript_buffer) - os.chmod(self.__unjoin_file, 0755) + self.__create_file_from_buffer(self.__unjoin_file, unjoinscript_buffer, 0755) def create_usr_share_file_from_buffer(self, share_filename, schema_buffer): share_file = os.path.join(self._package_path, 'usr/share/%s' % self._package_name, share_filename) @@ -98,9 +98,9 @@ class DebianPackage(): os.makedirs(dirpath) self.__create_file_from_buffer(share_file, schema_buffer) - def create_debian_file_from_buffer(self, debian_filename, debian_buffer): + def create_debian_file_from_buffer(self, debian_filename, debian_buffer, mode=None): deb_file = os.path.join(self._package_debian_path, debian_filename) - self.__create_file_from_buffer(deb_file, debian_buffer) + self.__create_file_from_buffer(deb_file, debian_buffer, mode) def build(self): install = [] @@ -170,7 +170,7 @@ Description: UCS - Test package %: dh $@ ''' - self.create_debian_file_from_buffer('rules', rules) + self.create_debian_file_from_buffer('rules', rules, 0755) def _create_compat(self): compat = '''7 -- 2.1.4 From 4d2750569adc9fabca61b66c503883fef5bd4b36 Mon Sep 17 00:00:00 2001 Message-Id: <4d2750569adc9fabca61b66c503883fef5bd4b36.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 07:31:03 +0100 Subject: [PATCH 06/14] Bug #40338 test: imports Organization: Univention GmbH, Bremen, Germany Remove unused imports Add missing import of fail Change import to explicit import of symbols for lint. --- .../ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini | 2 +- .../ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 | 2 +- .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install | 2 +- .../ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave | 2 +- .../ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage | 2 +- .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst | 5 ++++- .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy | 2 +- .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop | 3 ++- .../ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package | 2 +- .../ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation | 2 +- .../ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature | 3 ++- .../ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify | 2 +- .../ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available | 5 ++++- .../ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade | 2 +- .../tests/80_docker/65_app_container_upgrade_dockerallowedimage | 4 ++-- .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling | 2 +- .../ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive | 3 +-- .../ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect | 3 +-- .../test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive | 4 +--- .../test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect | 4 +--- .../test/ucs-test/tests/80_docker/79_app_ports_already_used | 3 +-- 21 files changed, 30 insertions(+), 29 deletions(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini index a1d7033..4f4fef2 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/10_pull_appbox_mini @@ -3,7 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (docker_login, docker_pull) if __name__ == '__main__': docker_login() diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 index 34e7f40..0ab9929 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/40_app_install_4_0-3 @@ -3,7 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, App, store_data_script_4_1) from univention.testing.utils import get_ldap_connection diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install index a8f8819..0996898 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/51_app_install @@ -3,7 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App) from univention.testing.utils import get_ldap_connection if __name__ == '__main__': diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave index 2635c2e..79cc84a 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave @@ -8,7 +8,7 @@ ## - 39792 ## - 39801 -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App) from univention.testing.utils import get_ldap_connection import ldap import time diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage index 5e329ae..1ae8b3a 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/53_missing_dockerimage @@ -3,7 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App) from univention.testing.utils import fail from univention.testing.internal import package_installed diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst index d1736ef..7f3f993 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/54_app_preinst @@ -3,7 +3,10 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import ( + Appcenter, get_app_name, get_app_version, App, + UCSTest_DockerApp_VerifyFailed, UCSTest_DockerApp_InstallationFailed, +) def create_app(fail_in_preinst): diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy index 7ef1852..c44227a 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/55_app_modproxy @@ -3,7 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App) if __name__ == '__main__': with Appcenter() as appcenter: diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop index 3942a64..97e7ba6 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop @@ -3,9 +3,10 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App) import subprocess import time +from univention.testing.utils import fail if __name__ == '__main__': nscd_stopped = False diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package index 6308a72..95e43ef 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/57_app_without_package @@ -3,7 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App) from univention.testing.utils import get_ldap_connection if __name__ == '__main__': diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation index 299562b..51c439e 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation @@ -3,7 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App) from univention.testing.utils import fail, get_ldap_connection import os import subprocess diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature index a7633e7..806c72a 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature @@ -4,7 +4,8 @@ ## exposure: dangerous import os -from dockertest import * +from dockertest import Appcenter +from univention.config_registry import handler_set from subprocess import call from univention.testing.utils import fail diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify index 51f07ad..37e8b8b 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/61_app_updater_identify @@ -3,7 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App, UCSTest_Docker_Exception) class UCSTest_DockerApp_Identify(UCSTest_Docker_Exception): pass diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available index 095eee9..0dbe022 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available @@ -5,10 +5,13 @@ ## versions: ## 4.1-0: skip -from dockertest import * +from dockertest import (Appcenter, get_app_name, App) from univention.testing.debian_package import DebianPackage from univention.testing.utils import get_ldap_connection, fail from univention.config_registry import ConfigRegistry +import os +import shutil +import subprocess def copy_package_to_appcenter(ucs_version, app_directory, package_name): target = os.path.join('/var/www/univention-repository/%s/maintained/component' % ucs_version, '%s/all' % app_directory) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade index 544a6da..bec11b9 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/64_app_container_upgrade @@ -3,7 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, App, store_data_script_4_1) from univention.testing.utils import get_ldap_connection, fail from univention.config_registry import ConfigRegistry diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage index 2cce0dc..ded399d 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/65_app_container_upgrade_dockerallowedimage @@ -5,8 +5,8 @@ ## versions: ## 4.1-0: skip -from dockertest import * -from univention.testing.utils import get_ldap_connection,fail +from dockertest import (Appcenter, get_app_name, App) +from univention.testing.utils import get_ldap_connection, fail from univention.config_registry import ConfigRegistry diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling index b3e32ce..4eed4a8 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/70_app_scaling @@ -4,7 +4,7 @@ ## timeout: 7200 ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App) DOCKER_APP_COUNT = 20 diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive index b1c5955..db4d405 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/75_app_ports_exclusive @@ -3,8 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * -from univention.testing.utils import get_ldap_connection +from dockertest import (Appcenter, get_app_name, get_app_version, App) from univention.testing.utils import is_port_open from univention.testing.utils import restart_firewall diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect index 713b0d2..b07658d 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/76_app_ports_redirect @@ -3,8 +3,7 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * -from univention.testing.utils import get_ldap_connection +from dockertest import (Appcenter, get_app_name, get_app_version, App) from univention.testing.utils import is_port_open from univention.testing.utils import restart_firewall diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive index 51dc5c8..fcd492a 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/77_app_ports_conflicts_exclusive @@ -3,13 +3,11 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * -from univention.testing.utils import get_ldap_connection +from dockertest import (Appcenter, get_app_version, App, UCSTest_DockerApp_InstallationFailed) from univention.testing.utils import is_port_open import socket import pytest -import time if __name__ == '__main__': with Appcenter() as appcenter: diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect index b77e1d5..e749518 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/78_app_ports_conflicts_redirect @@ -3,13 +3,11 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * -from univention.testing.utils import get_ldap_connection +from dockertest import (Appcenter, get_app_version, App, UCSTest_DockerApp_InstallationFailed) from univention.testing.utils import is_port_open import socket import pytest -import time if __name__ == '__main__': with Appcenter() as appcenter: diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used index 1750798..bd6f739 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/79_app_ports_already_used @@ -3,10 +3,9 @@ ## tags: [docker] ## exposure: dangerous -from dockertest import * +from dockertest import (Appcenter, get_app_name, get_app_version, App) from univention.testing.utils import get_ldap_connection import socket -import sys def _open_port(port): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -- 2.1.4 From 38b0490e0139fd894108b4953f79b5edbd5b6791 Mon Sep 17 00:00:00 2001 Message-Id: <38b0490e0139fd894108b4953f79b5edbd5b6791.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 07:32:25 +0100 Subject: [PATCH 07/14] Bug #40338 test: Fix exception Organization: Univention GmbH, Bremen, Germany Don't initiate instance in "except" clause. --- .../ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave index 79cc84a..fe3c628 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave @@ -38,7 +38,7 @@ univention-install --yes --no-install-recommends univention-server-slave univent try: lo = get_ldap_connection() - except ldap.SERVER_DOWN(): + except ldap.SERVER_DOWN: print 'LDAP connection failed. Wait for ten seconds and try again.' time.sleep(60) lo = get_ldap_connection() -- 2.1.4 From 6a4e9742bcbbf17546734ab06b7beca0c4c719b2 Mon Sep 17 00:00:00 2001 Message-Id: <6a4e9742bcbbf17546734ab06b7beca0c4c719b2.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 07:33:11 +0100 Subject: [PATCH 08/14] Bug #40338 test: Fix error message Organization: Univention GmbH, Bremen, Germany 10 -> 60 s --- .../ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave index fe3c628..18a41a8 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/52_app_install_dc_slave @@ -39,7 +39,7 @@ univention-install --yes --no-install-recommends univention-server-slave univent try: lo = get_ldap_connection() except ldap.SERVER_DOWN: - print 'LDAP connection failed. Wait for ten seconds and try again.' + print 'LDAP connection failed. Wait for 60 seconds and try again.' time.sleep(60) lo = get_ldap_connection() print lo.searchDn(filter='(&(cn=%s-*)(objectClass=univentionDomainController)(univentionServerRole=slave)(!(aRecord=*)))' % app_name, unique=True, required=True) -- 2.1.4 From 84eb0c61cabf9b60247a65f00fb3dcedaeb34e90 Mon Sep 17 00:00:00 2001 Message-Id: <84eb0c61cabf9b60247a65f00fb3dcedaeb34e90.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 07:36:24 +0100 Subject: [PATCH 09/14] Bug #40338 test: shell=False Organization: Univention GmbH, Bremen, Germany Remove intermediate shell to fix quoting problems. Fix bug by removing 'app.app_name' from non-format string. --- .../test/ucs-test/tests/80_docker/56_app_nscd_stop | 4 +- .../ucs-test/tests/80_docker/58_app_uninstallation | 2 +- .../tests/80_docker/59_app_center_signature | 16 +++--- .../tests/80_docker/62_app_update_available | 9 ++-- .../test/ucs-test/tests/80_docker/dockertest.py | 62 +++++++++++++++++----- 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop index 97e7ba6..f8c641b 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/56_app_nscd_stop @@ -31,7 +31,7 @@ if __name__ == '__main__': ncs_container_pid_old = app.execute_command_in_container('pidof nscd') print ncs_container_pid_old - subprocess.call('/etc/init.d/nscd stop', shell=True) + subprocess.call(('/etc/init.d/nscd', 'stop')) nscd_stopped = True time.sleep(3) ncs_container_pid_new = app.execute_command_in_container('pidof nscd') @@ -40,6 +40,6 @@ if __name__ == '__main__': fail('nscd pid in container have been changed. old: [%s], new: [%s]' % (ncs_container_pid_old, ncs_container_pid_new)) finally: if nscd_stopped: - subprocess.call('/etc/init.d/nscd start', shell=True) + subprocess.call(('/etc/init.d/nscd', 'start')) app.uninstall() app.remove() diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation index 51c439e..bcbceef 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/58_app_uninstallation @@ -79,5 +79,5 @@ echo "Test 123 Conf" >/var/lib/univention-appcenter/apps/%(app_name)s/conf/test1 # Check for the backup container res = subprocess.call('docker images | grep appcenter-backup-%s' % app.app_name, shell=True) if res != 0: - subprocess.call('docker images' % app.app_name, shell=True) + subprocess.call(('docker', 'images')) fail('Backup container appcenter-backup-%s was not found' % app.app_name) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature index 806c72a..6789347 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature @@ -22,7 +22,7 @@ class SyncedAppcenter(Appcenter): handler_set([ 'repository/app_center/server=%s' % (self.upstream_appcenter) ]) - call('univention-app update', shell=True) + call(('univention-app', 'update')) handler_set([ 'repository/app_center/server=%s.%s' % (self.ucr['hostname'], self.ucr['domainname']) ]) @@ -35,7 +35,7 @@ class SyncedAppcenter(Appcenter): if not os.path.exists(d): os.makedirs(d) - call('wget -O /var/www/%s %s/%s' % (f, self.upstream_appcenter, f), shell=True) + call(('wget', '-O', '/var/www/%s' % f, '%s/%s' % (self.upstream_appcenter, f)) def download_index_json(self): self.download('meta-inf/%s/index.json.gz' % self.vv) @@ -52,7 +52,7 @@ class SyncedAppcenter(Appcenter): def test_index_without_gpg(self): self.download_index_json() - res = call('univention-app update', shell=True) + res = call(('univention-app', 'update')) if res == 0: fail('_test_index_without_gpg failed') print '### _test_index_without_gpg passed' @@ -60,7 +60,7 @@ class SyncedAppcenter(Appcenter): def test_index_with_gpg(self): self.download_index_json() self.download_index_json_gpg() - res = call('univention-app update', shell=True) + res = call(('univention-app', 'update')) if res != 0: fail('_test_index_with_gpg failed') print '### _test_index_with_gpg passed' @@ -70,7 +70,7 @@ class SyncedAppcenter(Appcenter): self.download_index_json_gpg() f = '/var/www/meta-inf/%s/index.json' % self.vv call('gunzip %(f)s.gz; echo "foo" >>%(f)s; gzip %(f)s' % {'f':f}, shell=True) - res = call('univention-app update', shell=True) + res = call(('univention-app', 'update')) if res == 0: fail('_test_modify_index failed') print '### _test_modify_index passed' @@ -81,9 +81,9 @@ class SyncedAppcenter(Appcenter): self.remove_from_cache('dudle-docker.ini') self.download('meta-inf/%s/dudle-docker/dudle-docker.ini' % self.vv) call('echo "## SIGNATURE TEST ###" >>/var/www/meta-inf/%s/dudle-docker/dudle-docker.ini' % self.vv, shell=True) - res = call('univention-app update', shell=True) + res = call(('univention-app', 'update')) # dudle-docker must have been removed - res = call('univention-app get dudle-docker name', shell=True) + res = call(('univention-app', 'get', 'dudle-docker', 'name')) if res == 0: fail('_test_modify_ini failed') print '### _test_modify_ini passed' @@ -94,7 +94,7 @@ class SyncedAppcenter(Appcenter): self.remove_from_cache('owncloud8-docker_20150917.inst') self.download('univention-repository/%s/maintained/component/owncloud8-docker_20150917/inst' % self.vv) call('echo "## SIGNATURE TEST ###" >>/var/www/univention-repository/%s/maintained/component/owncloud8-docker_20150917/inst' % self.vv, shell=True) - res = call('univention-app update', shell=True) + res = call(('univention-app', 'update')) # Check only if the file was removed from th local cache if self.file_exists_in_cache('owncloud8-docker_20150917.inst'): fail('_test_modify_inst failed') diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available index 0dbe022..4e520ff 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/62_app_update_available @@ -17,16 +17,13 @@ def copy_package_to_appcenter(ucs_version, app_directory, package_name): target = os.path.join('/var/www/univention-repository/%s/maintained/component' % ucs_version, '%s/all' % app_directory) print 'cp %s %s' % (package_name, target) shutil.copy(package_name, target) - print ''' + cmd = ''' cd /var/www/univention-repository/%(version)s/maintained/component; apt-ftparchive packages %(app)s/all >%(app)s/all/Packages; gzip -c %(app)s/all/Packages >%(app)s/all/Packages.gz ''' % {'version': ucs_version, 'app': app_directory} - subprocess.call(''' - cd /var/www/univention-repository/%(version)s/maintained/component; - apt-ftparchive packages %(app)s/all >%(app)s/all/Packages; - gzip -c %(app)s/all/Packages >%(app)s/all/Packages.gz - ''' % {'version': ucs_version, 'app': app_directory}, shell=True) + print cmd + subprocess.call(cmd, shell=True) if __name__ == '__main__': with Appcenter() as appcenter: diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py index 0308cbd..f7fb999 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py @@ -85,7 +85,14 @@ class UCSTest_DockerApp_ModProxyFailed(Exception): def docker_login(server='docker.software-univention.de'): - ret = subprocess.call(['docker', 'login', '-e', 'foo@bar', '-u', 'ucs', '-p', 'readonly', server]) + ret = subprocess.call(( + 'docker', + 'login', + '-e', 'foo@bar', + '-u', 'ucs', + '-p', 'readonly', + server, + )) if ret != 0: raise UCSTest_Docker_LoginFailed() @@ -201,10 +208,15 @@ class App: def install(self): self._update() admin_user = self.ucr.get('tests/domainadmin/account').split(',')[0][len('uid='):] - # ret = subprocess.call('univention-app install --noninteractive --do-not-revert --username=%s --pwdfile=%s %s' % - cmd = 'univention-app install --noninteractive --username=%s --pwdfile=%s %s' % (admin_user, self.ucr.get('tests/domainadmin/pwdfile'), self.app_name) + cmd = ( + 'univention-app', 'install', + '--noninteractive', + '--username=%s' % admin_user, + '--pwdfile=%s' % self.ucr.get('tests/domainadmin/pwdfile'), + self.app_name, + ) print cmd - ret = subprocess.call(cmd, shell=True) + ret = subprocess.call(cmd) if ret != 0: raise UCSTest_DockerApp_InstallationFailed() @@ -220,8 +232,13 @@ class App: def upgrade(self): self._update() - ret = subprocess.call('univention-app upgrade --noninteractive --username=%s --pwdfile=%s %s' % - (self.admin_user, self.admin_pwdfile, self.app_name), shell=True) + ret = subprocess.call(( + 'univention-app', 'upgrade', + '--noninteractive', + '--username=%s' % self.admin_user, + '--pwdfile=%s' % self.admin_pwdfile, + self.app_name, + )) if ret != 0: raise UCSTest_DockerApp_UpgradeFailed() self.ucr.load() @@ -229,25 +246,38 @@ class App: self.installed = True def verify(self, joined=True): - ret = subprocess.call('univention-app status %s' % (self.app_name), shell=True) + ret = subprocess.call(('univention-app', 'status', self.app_name)) if ret != 0: raise UCSTest_DockerApp_VerifyFailed() if joined: - ret = subprocess.call('docker exec %s univention-check-join-status' % self.container_id, stderr=subprocess.STDOUT, shell=True) + ret = subprocess.call(( + 'docker', + 'exec', self.container_id, + 'univention-check-join-status', + ), stderr=subprocess.STDOUT) if ret != 0: raise UCSTest_DockerApp_VerifyFailed() def uninstall(self): if self.installed: - ret = subprocess.call('univention-app remove --noninteractive --username=%s --pwdfile=%s %s' % - (self.admin_user, self.admin_pwdfile, self.app_name), shell=True) + ret = subprocess.call(( + 'univention-app', 'remove', + '--noninteractive', + '--username=%s' % self.admin_user, + '--pwdfile=%s' % self.admin_pwdfile, + self.app_name, + )) if ret != 0: raise UCSTest_DockerApp_RemoveFailed() def execute_command_in_container(self, cmd): print 'Execute: %s' % cmd - return subprocess.check_output('docker exec %s %s' % (self.container_id, cmd), stderr=subprocess.STDOUT, shell=True) + return subprocess.check_output(( + 'docker', + 'exec', self.container_id, + '/bin/bash', '-c', cmd, + ), stderr=subprocess.STDOUT) def remove(self): if self.package: @@ -368,8 +398,14 @@ class Appcenter: if not os.path.isdir(directory): continue print 'create_appcenter_json.py for %s' % vv - subprocess.call('create_appcenter_json.py -u %(version)s -d /var/www -o /var/www/meta-inf/%(version)s/index.json.gz -s http://%(fqdn)s' % - {'version': vv, 'fqdn': '%s.%s' % (self.ucr['hostname'], self.ucr['domainname'])}, shell=True) + var = {'version': vv, 'fqdn': '%s.%s' % (self.ucr['hostname'], self.ucr['domainname'])}, shell=True) + subprocess.call(( + 'create_appcenter_json.py', + '-u', vv, + '-d', '/var/www', + '-o', '/var/www/meta-inf/%(version)s/index.json.gz' % var, + '-s', 'http://%(fqdn)s' % var, + )) def cleanup(self): if self.meta_inf_created: -- 2.1.4 From cef3664f2dde6d5ac69f3ee791c6ac836f49f7f7 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 07:41:34 +0100 Subject: [PATCH 10/14] Bug #40338 test: Check return value Organization: Univention GmbH, Bremen, Germany Printe message if command fails. --- .../ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature | 2 ++ 1 file changed, 2 insertions(+) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature index 6789347..a8d5d4b 100755 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/59_app_center_signature @@ -95,6 +95,8 @@ class SyncedAppcenter(Appcenter): self.download('univention-repository/%s/maintained/component/owncloud8-docker_20150917/inst' % self.vv) call('echo "## SIGNATURE TEST ###" >>/var/www/univention-repository/%s/maintained/component/owncloud8-docker_20150917/inst' % self.vv, shell=True) res = call(('univention-app', 'update')) + if res == 0: + print 'update failed: %d' % res # Check only if the file was removed from th local cache if self.file_exists_in_cache('owncloud8-docker_20150917.inst'): fail('_test_modify_inst failed') -- 2.1.4 From 0710e2d70b0f93359b868b5f7c58a32d2aea8f96 Mon Sep 17 00:00:00 2001 Message-Id: <0710e2d70b0f93359b868b5f7c58a32d2aea8f96.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 07:46:19 +0100 Subject: [PATCH 11/14] Bug #40338 test: Use constant for directory names Organization: Univention GmbH, Bremen, Germany --- .../test/ucs-test/tests/80_docker/dockertest.py | 68 +++++++++++++--------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py index f7fb999..1f0adb7 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py @@ -38,6 +38,8 @@ import shutil import subprocess import urllib2 +META_INF = '/var/www/meta-inf' +REPO_DIR = '/var/www/univention-repository' class UCSTest_Docker_Exception(Exception): @@ -284,10 +286,11 @@ class App: self.package.remove() def _dump_ini(self): - if not os.path.exists('/var/www/meta-inf/%s' % self.ucs_version): - os.makedirs('/var/www/meta-inf/%s' % self.ucs_version) + path = os.path.join(META_INF, self.ucs_version) + if not os.path.exists(path): + os.makedirs(path) - target = os.path.join('/var/www/meta-inf/%s' % self.ucs_version, '%s.ini' % self.app_directory) + target = os.path.join(path, '%s.ini' % self.app_directory) f = open(target, 'w') print 'Write ini file: %s' % target f.write('[Application]\n') @@ -297,16 +300,22 @@ class App: print '%s: %s' % (key, self.ini[key]) print f.close() - svg = os.path.join('/var/www/meta-inf/%s' % self.ucs_version, self.ini.get('Logo')) + svg = os.path.join(path, self.ini.get('Logo')) f = open(svg, 'w') f.write(get_dummy_svg()) f.close() def _dump_scripts(self): + comp_path = os.path.join( + REPO_DIR, + self.ucs_version, + 'maintained/component', + self.app_directory, + ) + if not os.path.exists(comp_path): + os.makedirs(comp_path) + for script in self.scripts.keys(): - comp_path = os.path.join('/var/www/univention-repository/%s/maintained/component' % self.ucs_version, '%s' % self.app_directory) - if not os.path.exists(comp_path): - os.makedirs(comp_path) target = os.path.join(comp_path, script) print 'Create %s' % target @@ -317,7 +326,13 @@ class App: f.close() def _copy_package(self): - target = os.path.join('/var/www/univention-repository/%s/maintained/component' % self.ucs_version, '%s/all' % self.app_directory) + target = os.path.join( + REPO_DIR, + self.ucs_version, + 'maintained/component', + self.app_directory, + 'all', + ) os.makedirs(target) shutil.copy(self.package.get_binary_name(), target) subprocess.call(''' @@ -353,11 +368,11 @@ class Appcenter: self.ucr = UCSTestConfigRegistry() self.ucr.load() - if os.path.exists('/var/www/meta-inf'): - print 'ERROR: /var/www/meta-inf already exists' + if os.path.exists(META_INF): + print 'ERROR: %s already exists' % META_INF raise AppcenterMetainfAlreadyExists() - if os.path.exists('/var/www/univention-repository'): - print 'ERROR: /var/www/univention-repository already exists' + if os.path.exists(REPO_DIR): + print 'ERROR: %s already exists' % REPO_DIR raise AppcenterRepositoryAlreadyExists() if not version: @@ -366,23 +381,24 @@ class Appcenter: self.add_ucs_version_to_appcenter(version) def add_ucs_version_to_appcenter(self, version): - if not os.path.exists('/var/www/meta-inf'): - os.makedirs('/var/www/meta-inf', 0755) + if not os.path.exists(META_INF): + os.makedirs(META_INF, 0755) self.meta_inf_created = True - if not os.path.exists('/var/www/univention-repository'): - os.makedirs('/var/www/univention-repository', 0755) + if not os.path.exists(REPO_DIR): + os.makedirs(REPO_DIR, 0755) self.univention_repository_created = True - os.makedirs('/var/www/univention-repository/%s/maintained/component' % version) - os.makedirs('/var/www/meta-inf/%s' % version) + os.makedirs(os.path.join(REPO_DIR, version, 'maintained/component')) + os.makedirs(os.path.join(META_INF, version)) - if not os.path.exists('/var/www/meta-inf/categories.ini'): + path = os.path.join(META_INF, 'categories.ini') + if not os.path.exists(path): text = open(os.path.join(os.path.dirname(__file__), 'categories.ini'), 'r').read() - f = open('/var/www/meta-inf/categories.ini', 'w') + f = open(path, 'w') f.write(test) f.close() - f = open('/var/www/meta-inf/rating.ini', 'w') + f = open(os.path.join(META_INF, 'rating.ini'), 'w') f.write('# rating stuff\n') f.close() @@ -393,8 +409,8 @@ class Appcenter: ]) def update(self): - for vv in os.listdir('/var/www/meta-inf/'): - directory = os.path.join('/var/www/meta-inf/', vv) + for vv in os.listdir(META_INF): + directory = os.path.join(META_INF, vv) if not os.path.isdir(directory): continue print 'create_appcenter_json.py for %s' % vv @@ -403,15 +419,15 @@ class Appcenter: 'create_appcenter_json.py', '-u', vv, '-d', '/var/www', - '-o', '/var/www/meta-inf/%(version)s/index.json.gz' % var, + '-o', os.path.join(META_INF, vv, 'index.json.gz'), '-s', 'http://%(fqdn)s' % var, )) def cleanup(self): if self.meta_inf_created: - shutil.rmtree('/var/www/meta-inf') + shutil.rmtree(META_INF) if self.univention_repository_created: - shutil.rmtree('/var/www/univention-repository') + shutil.rmtree(REPO_DIR) self.ucr.revert_to_original_registry() def __enter__(self): -- 2.1.4 From 1a4bd690a3b2225f27b671fedf23ccf30f631020 Mon Sep 17 00:00:00 2001 Message-Id: <1a4bd690a3b2225f27b671fedf23ccf30f631020.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 08:34:10 +0100 Subject: [PATCH 12/14] Bug #40338 test: Convert open() to context Organization: Univention GmbH, Bremen, Germany --- .../test/ucs-test/tests/80_docker/dockertest.py | 37 ++++++++++------------ .../ucs-test/univention/testing/debian_package.py | 5 ++- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py index 1f0adb7..0771916 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py @@ -291,19 +291,17 @@ class App: os.makedirs(path) target = os.path.join(path, '%s.ini' % self.app_directory) - f = open(target, 'w') - print 'Write ini file: %s' % target - f.write('[Application]\n') - print '[Application]' - for key in self.ini.keys(): - f.write('%s: %s\n' % (key, self.ini[key])) - print '%s: %s' % (key, self.ini[key]) - print - f.close() + with open(target, 'w') as f: + print 'Write ini file: %s' % target + f.write('[Application]\n') + print '[Application]' + for key in self.ini.keys(): + f.write('%s: %s\n' % (key, self.ini[key])) + print '%s: %s' % (key, self.ini[key]) + print svg = os.path.join(path, self.ini.get('Logo')) - f = open(svg, 'w') - f.write(get_dummy_svg()) - f.close() + with open(svg, 'w') as f: + f.write(get_dummy_svg()) def _dump_scripts(self): comp_path = os.path.join( @@ -321,9 +319,8 @@ class App: print 'Create %s' % target print self.scripts[script] - f = open(target, 'w') - f.write(self.scripts[script]) - f.close() + with open(target, 'w') as f: + f.write(self.scripts[script]) def _copy_package(self): target = os.path.join( @@ -395,12 +392,10 @@ class Appcenter: path = os.path.join(META_INF, 'categories.ini') if not os.path.exists(path): text = open(os.path.join(os.path.dirname(__file__), 'categories.ini'), 'r').read() - f = open(path, 'w') - f.write(test) - f.close() - f = open(os.path.join(META_INF, 'rating.ini'), 'w') - f.write('# rating stuff\n') - f.close() + with open(path, 'w') as f: + f.write(text) + with open(os.path.join(META_INF, 'rating.ini'), 'w') as f: + f.write('# rating stuff\n') handler_set([ 'update/secure_apt=no', diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py index 9a7efd5..7b30985 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/univention/testing/debian_package.py @@ -77,9 +77,8 @@ class DebianPackage(): return deb_package def __create_file_from_buffer(self, path, file_buffer, mode=None): - f = open(path, 'w') - f.write(file_buffer) - f.close() + with open(path, 'w') as f: + f.write(file_buffer) if mode: os.chmod(path, mode) -- 2.1.4 From c47584a8e2157ba89470b301635799aeb590e1ec Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 08:34:40 +0100 Subject: [PATCH 13/14] Bug #40338 test: Use .iteritems() Organization: Univention GmbH, Bremen, Germany --- .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py index 0771916..f1e568b 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py @@ -313,14 +313,14 @@ class App: if not os.path.exists(comp_path): os.makedirs(comp_path) - for script in self.scripts.keys(): - target = os.path.join(comp_path, script) + for name, script in self.scripts.iteritems(): + target = os.path.join(comp_path, name) print 'Create %s' % target - print self.scripts[script] + print script with open(target, 'w') as f: - f.write(self.scripts[script]) + f.write(script) def _copy_package(self): target = os.path.join( -- 2.1.4 From 8597528890d2f85112c555541fa0566593a8e5a9 Mon Sep 17 00:00:00 2001 Message-Id: <8597528890d2f85112c555541fa0566593a8e5a9.1453276049.git.hahn@univention.de> In-Reply-To: References: From: Philipp Hahn Date: Tue, 19 Jan 2016 08:35:34 +0100 Subject: [PATCH 14/14] Bug #40338 test: "%()s" % ucr Organization: Univention GmbH, Bremen, Germany Pass ucr to directly to format strings --- .../ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py index f1e568b..01ac1a1 100644 --- a/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py +++ b/branches/ucs-4.1/ucs-4.1-0/test/ucs-test/tests/80_docker/dockertest.py @@ -343,7 +343,7 @@ class App: self.add_script(setup=setup % {'app_name': self.app_name}) def verify_basic_modproxy_settings(self): - fqdn = '%s.%s' % (self.ucr['hostname'], self.ucr['domainname']) + fqdn = '%(hostname)s.%(domainname)s' % self.ucr test_string = 'TEST-%s\n' % self.app_name response = urllib2.urlopen('http://%s/%s/index.txt' % (fqdn, self.app_name)) @@ -400,7 +400,7 @@ class Appcenter: handler_set([ 'update/secure_apt=no', 'appcenter/index/verify=false', - 'repository/app_center/server=%s.%s' % (self.ucr['hostname'], self.ucr['domainname']) + 'repository/app_center/server=%(hostname)s.%(domainname)s' % self.ucr ]) def update(self): @@ -409,13 +409,12 @@ class Appcenter: if not os.path.isdir(directory): continue print 'create_appcenter_json.py for %s' % vv - var = {'version': vv, 'fqdn': '%s.%s' % (self.ucr['hostname'], self.ucr['domainname'])}, shell=True) subprocess.call(( 'create_appcenter_json.py', '-u', vv, '-d', '/var/www', '-o', os.path.join(META_INF, vv, 'index.json.gz'), - '-s', 'http://%(fqdn)s' % var, + '-s', 'http://%(hostname)s.%(domainname)s' % self.ucr, )) def cleanup(self): -- 2.1.4