From 69eeb5a35db243d90e03248e4d84ad5e25ed08f1 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Wed, 18 Oct 2017 15:17:01 +0800 Subject: Skip recreate Daisy server VM if it exists in python Do not recreate daisy server if it exists. Reference to the bash code in patch [1]. [1] https://gerrit.opnfv.org/gerrit/#/c/40337/ Change-Id: If472c59ea180e550f358af4a3a9c7b42e575eddc Signed-off-by: Alex Yang --- deploy/daisy_server.py | 14 ++++++-------- deploy/deploy.py | 23 ++++++++++++++++++----- deploy/environment.py | 49 ++++++++++++++++++++++++++++++++----------------- 3 files changed, 56 insertions(+), 30 deletions(-) (limited to 'deploy') diff --git a/deploy/daisy_server.py b/deploy/daisy_server.py index a899ea2b..fccfbe8c 100644 --- a/deploy/daisy_server.py +++ b/deploy/daisy_server.py @@ -207,7 +207,11 @@ class DaisyServer(object): status = self.ssh_run('%s install' % path_join(self.remote_dir, 'opnfv.bin')) log_bar('Daisy installation completed ! status = %s' % status) - def prepare_configurations(self): + def prepare_configurations(self, deploy_file, net_file): + LI('Copy cluster configuration files to Daisy Server') + self.scp_put(deploy_file, path_join(self.remote_dir, self.deploy_file_name)) + self.scp_put(net_file, path_join(self.remote_dir, self.net_file_name)) + if self.adapter != 'libvirt': return LI('Prepare some configuration files') @@ -218,13 +222,7 @@ class DaisyServer(object): is_bare=1 if self.adapter == 'ipmi' else 0) self.ssh_run(cmd) - def prepare_cluster(self, deploy_file, net_file): - LI('Copy cluster configuration files to Daisy Server') - self.scp_put(deploy_file, path_join(self.remote_dir, self.deploy_file_name)) - self.scp_put(net_file, path_join(self.remote_dir, self.net_file_name)) - - self.prepare_configurations() - + def prepare_cluster(self): LI('Prepare cluster and PXE') cmd = "python {script} --dha {deploy_file} --network {net_file} --cluster \'yes\'".format( script=path_join(self.remote_dir, 'deploy/tempest.py'), diff --git a/deploy/deploy.py b/deploy/deploy.py index 245776fb..192b4ee4 100644 --- a/deploy/deploy.py +++ b/deploy/deploy.py @@ -181,16 +181,24 @@ class DaisyDeployment(object): return final_deploy_file, final_deploy_file_name def run(self): - self.daisy_env.delete_old_environment() + self.daisy_env.delete_old_environment(skip_daisy=self.skip_daisy) if self.cleanup_only: return - self.daisy_env.create_daisy_server() + + if self.skip_daisy: + self.daisy_env.connect_daisy_server(self.remote_dir, self.bin_file, + self.deploy_file_name, self.net_file_name) + else: + self.daisy_env.create_daisy_server() + self.daisy_env.connect_daisy_server(self.remote_dir, self.bin_file, + self.deploy_file_name, self.net_file_name) + self.daisy_env.install_daisy() + if self.daisy_only: log_bar('Create Daisy Server successfully !') return - self.daisy_env.install_daisy(self.remote_dir, self.bin_file, - self.deploy_file_name, self.net_file_name) - self.daisy_env.deploy(self.deploy_file, self.net_file) + + self.daisy_env.deploy(self.deploy_file, self.net_file, skip_preparation=self.skip_daisy) log_bar('Daisy deploy successfully !') @@ -214,6 +222,10 @@ def config_arg_parser(): default=path_join(WORKSPACE, 'opnfv.bin'), help='OPNFV Daisy BIN File') + parser.add_argument('-S', dest='skip_daisy', action='store_true', + default=False, + help='DO NOT install Daisy Server again') + parser.add_argument('-do', dest='daisy_only', action='store_true', default=False, help='Install Daisy Server only') @@ -273,6 +285,7 @@ def parse_arguments(): 'src_deploy_file': deploy_file, 'net_file': net_file, 'bin_file': args.bin_file, + 'skip_daisy': args.skip_daisy, 'daisy_only': args.daisy_only, 'cleanup_only': args.cleanup_only, 'remote_dir': args.remote_dir, diff --git a/deploy/environment.py b/deploy/environment.py index 24c1b4f7..2dd61d11 100644 --- a/deploy/environment.py +++ b/deploy/environment.py @@ -42,9 +42,11 @@ from utils import ( CREATE_QCOW2_PATH = path_join(WORKSPACE, 'tools') -VMDEPLOY_DAISY_SERVER_NET = path_join(WORKSPACE, 'templates/virtual_environment/networks/daisy.xml') -VMDEPLOY_TARGET_NODE_NET = path_join(WORKSPACE, 'templates/virtual_environment/networks/external.xml') -VMDEPLOY_TARGET_KEEPALIVED_NET = path_join(WORKSPACE, 'templates/virtual_environment/networks/keepalived.xml') +VIRT_NET_TEMPLATE_PATH = path_join(WORKSPACE, 'templates/virtual_environment/networks') +VMDEPLOY_DAISY_SERVER_NET = path_join(VIRT_NET_TEMPLATE_PATH, 'daisy.xml') +VMDEPLOY_TARGET_NODE_NET = path_join(VIRT_NET_TEMPLATE_PATH, 'external.xml') +VMDEPLOY_TARGET_KEEPALIVED_NET = path_join(VIRT_NET_TEMPLATE_PATH, 'keepalived.xml') + VMDEPLOY_DAISY_SERVER_VM = path_join(WORKSPACE, 'templates/virtual_environment/vms/daisy.xml') BMDEPLOY_DAISY_SERVER_VM = path_join(WORKSPACE, 'templates/physical_environment/vms/daisy.xml') @@ -52,7 +54,6 @@ BMDEPLOY_DAISY_SERVER_VM = path_join(WORKSPACE, 'templates/physical_environment/ ALL_IN_ONE_TEMPLATE = path_join(WORKSPACE, 'templates/virtual_environment/vms/all_in_one.xml') CONTROLLER_TEMPLATE = path_join(WORKSPACE, 'templates/virtual_environment/vms/controller.xml') COMPUTE_TEMPLATE = path_join(WORKSPACE, 'templates/virtual_environment/vms/computer.xml') -VIRT_NET_TEMPLATE_PATH = path_join(WORKSPACE, 'templates/virtual_environment/networks') class DaisyEnvironment(object): @@ -109,7 +110,7 @@ class DaisyEnvironmentBase(object): shutil.move(image, self.daisy_server_info['image']) LI('Daisy Server image is created %s' % self.daisy_server_info['image']) - def install_daisy(self, remote_dir, bin_file, deploy_file_name, net_file_name): + def connect_daisy_server(self, remote_dir, bin_file, deploy_file_name, net_file_name): self.server = DaisyServer(self.daisy_server_info['name'], self.daisy_server_info['address'], self.daisy_server_info['password'], @@ -120,14 +121,19 @@ class DaisyEnvironmentBase(object): deploy_file_name, net_file_name) self.server.connect() + + def install_daisy(self): self.server.install_daisy() class BareMetalEnvironment(DaisyEnvironmentBase): - def delete_old_environment(self): - LW('Begin to delete old environment !') - self.delete_daisy_server() - LW('Old environment cleanup finished !') + def delete_old_environment(self, skip_daisy=False): + if skip_daisy: + LI('Skip deletion of old daisy server VM') + else: + LW('Begin to delete old environment !') + self.delete_daisy_server() + LW('Old environment cleanup finished !') def create_daisy_server(self): self.create_daisy_server_image() @@ -157,8 +163,10 @@ class BareMetalEnvironment(DaisyEnvironmentBase): node['ipmi_pass'], boot_source=boot_dev) - def deploy(self, deploy_file, net_file): - self.server.prepare_cluster(deploy_file, net_file) + def deploy(self, deploy_file, net_file, skip_preparation=False): + if not skip_preparation: + self.server.prepare_configurations(deploy_file, net_file) + self.server.prepare_cluster() self.reboot_nodes(boot_dev='pxe') self.server.prepare_host_and_pxe() @@ -274,7 +282,7 @@ class VirtualEnvironment(DaisyEnvironmentBase): for host in self.deploy_struct['hosts']: delete_vm_and_disk(host['name']) - def delete_networks(self): + def delete_networks(self, skip_daisy=False): if 'virtNetTemplatePath' in self.deploy_struct: path = self.deploy_struct['virtNetTemplatePath'] else: @@ -284,19 +292,26 @@ class VirtualEnvironment(DaisyEnvironmentBase): LW('Cannot find the virtual network template path %s' % path) return for f in os.listdir(path): + if not (skip_daisy and f == 'daisy.xml'): f = path_join(path, f) if os.path.isfile(f): delete_virtual_network(f) - def delete_old_environment(self): + def delete_old_environment(self, skip_daisy=False): LW('Begin to delete old environment !') self.delete_nodes() - self.delete_daisy_server() - self.delete_networks() + + if skip_daisy: + LI('Skip deletion of old daisy server VM and network') + else: + self.delete_daisy_server() + self.delete_networks(skip_daisy=skip_daisy) LW('Old environment cleanup finished !') - def deploy(self, deploy_file, net_file): - self.server.prepare_cluster(deploy_file, net_file) + def deploy(self, deploy_file, net_file, skip_preparation=False): + if not skip_preparation: + self.server.prepare_configurations(deploy_file, net_file) + self.server.prepare_cluster() self.create_nodes() self.server.copy_new_deploy_config(self.deploy_struct) self.server.prepare_host_and_pxe() -- cgit 1.2.3-korg