From 7523e5e232c5bce4e71404de78f4555d787d947f Mon Sep 17 00:00:00 2001 From: Artem Grechanichenko Date: Wed, 9 Dec 2015 23:19:12 +0200 Subject: [PATCH] Adding bootstrapping rebuilding to test_review_in_fuel_agent Adding gates_test/helpers/utils patch_bootstrap methods to rebuild centos and ubuntu bootstraps to use new code from fuel-agent review. Methods for CentOS bootstrap commented and unused. Change-Id: I8cc601dfa53f71b4e1d78814ce451ea9d98940e9 Closes-Bug: #1519880 --- gates_tests/helpers/utils.py | 178 +++++++++++++++--- .../tests/test_review_in_fuel_agent.py | 11 +- 2 files changed, 163 insertions(+), 26 deletions(-) diff --git a/gates_tests/helpers/utils.py b/gates_tests/helpers/utils.py index 9c9086ad6..b9308476f 100644 --- a/gates_tests/helpers/utils.py +++ b/gates_tests/helpers/utils.py @@ -44,21 +44,14 @@ def replace_fuel_agent_rpm(environment): old_package = \ environment.base_actions.execute_in_container( cmd, container, exit_code=0) - logger.info("Delete package {0}" - .format(old_package)) - - cmd = "rpm -e fuel-agent" - environment.base_actions.execute_in_container( - cmd, container, exit_code=0) - cmd = "ls -1 {0}|grep 'fuel-agent'".format(pack_path) new_package = \ environment.base_actions.execute_in_container( cmd, container).rstrip('.rpm') - logger.info("Install package {0}" - .format(new_package)) + logger.info("Updating package {0} with {1}" + .format(old_package, new_package)) - cmd = "yum localinstall -y {0}fuel-agent*.rpm".format( + cmd = "rpm -Uvh --oldpackage {0}fuel-agent*.rpm".format( pack_path) environment.base_actions.execute_in_container( cmd, container, exit_code=0) @@ -71,36 +64,173 @@ def replace_fuel_agent_rpm(environment): assert_equal(installed_package, new_package, "The new package {0} was not installed". format(new_package)) + + # Update fuel-agent on master node + cmd = "rpm -Uvh --oldpackage {0}fuel-agent*.rpm".format( + pack_path) + result = remote.execute(cmd) + assert_equal(result['exit_code'], 0, + ('Failed to update package {}').format(result)) + except Exception as e: logger.error("Could not upload package {e}".format(e=e)) raise -def replace_bootstrap(environment): +def patch_centos_bootstrap(environment): """Replaced initramfs.img in /var/www/nailgun/ with newly_builded from review environment - Environment Model object - self.env """ + logger.info("Update fuel-agent code and assemble new bootstrap") + if not settings.UPDATE_FUEL: + raise Exception("{} variable don't exist" + .format(settings.UPDATE_FUEL)) + try: + pack_path = '/var/www/nailgun/fuel-agent-review/' + with environment.d_env.get_admin_remote() as remote: + remote.upload(settings.UPDATE_FUEL_PATH.rstrip('/'), + pack_path) + # renew code in bootstrap + + # Step 1 - unpack bootstrap + bootstrap_var = "/var/initramfs" + bootstrap = "/var/www/nailgun/bootstrap" + cmd = ("mkdir {0};" + "cp /{1}/initramfs.img {0}/;" + "cd {0};" + "cat initramfs.img | gunzip | cpio -imudv;").format( + bootstrap_var, + bootstrap + ) + result = remote.execute(cmd) + assert_equal(result['exit_code'], 0, + ('Failed to add unpack bootstrap {}' + ).format(result)) + + # Step 2 - replace fuel-agent code in unpacked bootstrap + agent_path = "/usr/lib/python2.7/site-packages/fuel_agent" + image_rebuild = "{} | {} | {}".format( + "find . -xdev", + "cpio --create --format='newc'", + "gzip -9 > /var/initramfs.img.updated") + + cmd = ("rm -rf {0}/initramfs.img;" + "rsync -r {2}fuel-agent/fuel_agent/* {0}{1}/;" + "cd {0}/;" + "{3};" + ).format( + bootstrap_var, + agent_path, + pack_path, + image_rebuild) + + result = remote.execute(cmd) + assert_equal(result['exit_code'], 0, + ('Failed to rebuild bootstrap {}').format(result)) + except Exception as e: + logger.error("Could not upload package {e}".format(e=e)) + raise + + +def patch_and_assemble_ubuntu_bootstrap(environment): + """Replaced initramfs.img in /var/www/nailgun/ + with newly_builded from review + environment - Environment Model object - self.env + """ + logger.info("Update fuel-agent code and assemble new ubuntu bootstrap") + if not settings.UPDATE_FUEL: + raise Exception("{} variable don't exist" + .format(settings.UPDATE_FUEL)) + try: + pack_path = '/var/www/nailgun/fuel-agent-review/' + with environment.d_env.get_admin_remote() as remote: + remote.upload(settings.UPDATE_FUEL_PATH.rstrip('/'), + pack_path) + # renew code in bootstrap + + # Step 1 - install squashfs-tools + cmd = ("yum install -y squashfs-tools") + result = remote.execute(cmd) + assert_equal(result['exit_code'], 0, + ('Failed to install squashfs-tools {}' + ).format(result)) + + # Step 2 - unpack bootstrap + bootstrap = "/var/www/nailgun/bootstraps/active_bootstrap" + bootstrap_var = "/var/root.squashfs" + + cmd = ("unsquashfs -d /var/root.squashfs {}/root.squashfs" + ).format(bootstrap) + result = remote.execute(cmd) + assert_equal(result['exit_code'], 0, + ('Failed to add unpack bootstrap {}' + ).format(result)) + + # Step 3 - replace fuel-agent code in unpacked bootstrap + agent_path = "/usr/lib/python2.7/dist-packages/fuel_agent" + bootstrap_file = bootstrap + "/root.squashfs" + cmd = ("rsync -r {2}fuel-agent/fuel_agent/* {0}{1}/;" + "mv {3} /var/root.squashfs.old;" + ).format( + bootstrap_var, + agent_path, + pack_path, + bootstrap_file + ) + + result = remote.execute(cmd) + assert_equal(result['exit_code'], 0, + ('Failed to replace fuel-agent code {}' + ).format(result)) + + # Step 4 - assemble new bootstrap + compression = "-comp xz" + no_progress_bar = "-no-progress" + no_append = "-noappend" + image_rebuild = "mksquashfs {0} {1} {2} {3} {4}".format( + bootstrap_var, + bootstrap_file, + compression, + no_progress_bar, + no_append + ) + result = remote.execute(image_rebuild) + assert_equal(result['exit_code'], 0, + ('Failed to rebuild bootstrap {}' + ).format(result)) + + checkers.check_file_exists( + remote, + '{0}'.format(bootstrap_file)) + except Exception as e: + logger.error("Could not upload package {e}".format(e=e)) + raise + + +def replace_centos_bootstrap(environment): + """Replaced initramfs.img in /var/www/nailgun/ + with re-builded with review code + environment - Environment Model object - self.env + """ logger.info("Updating bootstrap") if not settings.UPDATE_FUEL: raise Exception("{} variable don't exist" .format(settings.UPDATE_FUEL)) try: - pack_path = '/var/www/nailgun/fuel-agent/' - with environment.d_env.get_admin_remote() as remote: - remote.upload(settings.UPDATE_FUEL_PATH.rstrip('/'), - pack_path) - logger.info("Assigning new bootstrap from {}" - .format(pack_path)) - bootstrap = "/var/www/nailgun/bootstrap" - cmd = ("rm {0}/initramfs.img;" - "cp {1}/initramfs.img.updated {0}/initramfs.img;" - "chmod +r {0}/initramfs.img;" - ).format(bootstrap, pack_path) + + rebuilded_bootstrap = '/var/initramfs.img.updated' with environment.d_env.get_admin_remote() as remote: checkers.check_file_exists( remote, - '{0}initramfs.img.updated'.format(pack_path)) + '{0}'.format(rebuilded_bootstrap)) + logger.info("Assigning new bootstrap from {}" + .format(rebuilded_bootstrap)) + bootstrap = "/var/www/nailgun/bootstrap" + cmd = ("mv {0}/initramfs.img /var/initramfs.img;" + "cp /var/initramfs.img.updated {0}/initramfs.img;" + "chmod +r {0}/initramfs.img;" + ).format(bootstrap) result = remote.execute(cmd) assert_equal(result['exit_code'], 0, ('Failed to assign bootstrap {}' @@ -110,7 +240,7 @@ def replace_bootstrap(environment): environment.base_actions.execute_in_container( cmd, container, exit_code=0) except Exception as e: - logger.error("Could not upload package {e}".format(e=e)) + logger.error("Could not update bootstrap {e}".format(e=e)) raise diff --git a/gates_tests/tests/test_review_in_fuel_agent.py b/gates_tests/tests/test_review_in_fuel_agent.py index cecf3a0b4..bb18af6e3 100644 --- a/gates_tests/tests/test_review_in_fuel_agent.py +++ b/gates_tests/tests/test_review_in_fuel_agent.py @@ -14,7 +14,9 @@ from proboscis import test -from gates_tests.helpers.utils import replace_bootstrap +# from gates_tests.helpers.utils import patch_centos_bootstrap +# from gates_tests.helpers.utils import replace_centos_bootstrap +from gates_tests.helpers.utils import patch_and_assemble_ubuntu_bootstrap from gates_tests.helpers.utils import replace_fuel_agent_rpm from fuelweb_test.helpers.decorators import log_snapshot_after_test @@ -59,7 +61,12 @@ class Gate(TestBasic): replace_fuel_agent_rpm(self.env) self.show_step(3) - replace_bootstrap(self.env) + # Uncomment when use CentOS bootstrap by default + # patch_centos_bootstrap(self.env) + # replace_centos_bootstrap(self.env) + + # Comment and disable when use CentOS bootstrap by default + patch_and_assemble_ubuntu_bootstrap(self.env) self.show_step(4) self.env.bootstrap_nodes(