def juju_wait_finished(max_wait=5400): """Use juju-wait from local utils path to block until all service units quiesce and satisfy workload status ready state.""" log = logging.getLogger() log.setLevel(logging.DEBUG) logging.info('Calling juju-wait') juju_wait.wait(log, wait_for_workload=True, max_wait=max_wait) logging.debug('End of juju-wait')
def deploy(bundle, model, wait=True): """Run all steps to complete deployment :param bundle: Path to bundle file :type bundle: str :param model: Name of model to deploy bundle in :type model: str :param wait: Whether to wait until deployment completes :type model: bool """ deploy_bundle(bundle, model) if wait: logging.info("Waiting for environment to settle") juju_wait.wait()
def configure_gateway_ext_port(novaclient, neutronclient, dvr_mode=None, net_id=None): """Configure the neturong-gateway external port :param novaclient: Authenticated novaclient :type novaclient: novaclient.Client object :param neutronclient: Authenticated neutronclient :type neutronclient: neutronclient.Client object :param dvr_mode: Using DVR mode or not :type dvr_mode: boolean :param net_id: Network ID :type net_id: string :returns: Nothing: This fucntion is executed for its sideffect :rtype: None """ if dvr_mode: uuids = get_ovs_uuids() else: uuids = get_gateway_uuids() deprecated_extnet_mode = deprecated_external_networking(dvr_mode) config_key = 'data-port' if deprecated_extnet_mode: config_key = 'ext-port' if not net_id: net_id = get_admin_net(neutronclient)['id'] for uuid in uuids: server = novaclient.servers.get(uuid) ext_port_name = "{}_ext-port".format(server.name) for port in neutronclient.list_ports(device_id=server.id)['ports']: if port['name'] == ext_port_name: logging.warning('Neutron Gateway already has additional port') break else: logging.info('Attaching additional port to instance, ' 'connected to net id: {}'.format(net_id)) body_value = { "port": { "admin_state_up": True, "name": ext_port_name, "network_id": net_id, "port_security_enabled": False, } } port = neutronclient.create_port(body=body_value) server.interface_attach(port_id=port['port']['id'], net_id=None, fixed_ip=None) ext_br_macs = [] for port in neutronclient.list_ports(network_id=net_id)['ports']: if 'ext-port' in port['name']: if deprecated_extnet_mode: ext_br_macs.append(port['mac_address']) else: ext_br_macs.append('br-ex:{}'.format(port['mac_address'])) ext_br_macs.sort() ext_br_macs_str = ' '.join(ext_br_macs) if dvr_mode: application_name = 'neutron-openvswitch' else: application_name = 'neutron-gateway' if ext_br_macs: logging.info('Setting {} on {} external port to {}'.format( config_key, application_name, ext_br_macs_str)) current_data_port = get_application_config_option( application_name, config_key) if current_data_port == ext_br_macs_str: logging.info('Config already set to value') return model.set_application_config( lifecycle_utils.get_juju_model(), application_name, configuration={config_key: ext_br_macs_str}) juju_wait.wait(wait_for_workload=True)
def _pre_deploy_remote_compute(self): """Add a simulated remote machine ahead of the actual deployment. This is done outside of Amulet because Amulet only supports one deploy call, and the public-address of the remote-compute is needed as a charm config option on the nova-compute-proxy charm. In a production scenario, the remote compute machine is up and running before the control plane is deployed. This simulates that.""" # Deploy simulated remote-compute host if not already deployed cmd = ['juju', 'status', 'remote-compute'] compute_deployed = 'remote-compute' in \ subprocess.check_output(cmd).decode('UTF-8') if not compute_deployed: u.log.debug('Pre-deploying a simulated remote-compute unit') cmd = ['juju', 'deploy', 'cs:ubuntu', 'remote-compute'] subprocess.check_call(cmd) u.log.debug('Using juju_wait to wait for remote-compute ' 'deployment') juju_wait.wait(max_wait=900) self.remote_compute = (self._get_status()['applications'] ['remote-compute']['units'].keys()[0]) u.log.debug('Simulated remote compute: ' '{}'.format(self.remote_compute)) # Discover IP address of remote-compute unit cmd = [ 'juju', 'run', '--application', 'remote-compute', 'unit-get public-address' ] self.compute_addr = ( subprocess.check_output(cmd).decode('UTF-8').strip()) u.log.debug('Simulated remote compute address: ' '{}'.format(self.compute_addr)) # Remove local test keys if they exist key_files = ['id_rsa_tmp', 'id_rsa_tmp.pub'] for key_file in key_files: key_file_path = os.path.join('files', key_file) if os.path.exists(key_file_path): u.log.debug('Removing file: {}'.format(key_file_path)) os.remove(key_file_path) # Create a new local test key u.log.debug('Generating new test ssh keys') cmd = [ 'ssh-keygen', '-t', 'rsa', '-b', '4096', '-C', 'demo@local', '-f', 'files/id_rsa_tmp', '-q', '-N', '' ] subprocess.check_call(cmd) for key_file in key_files: key_file_path = os.path.join('files', key_file) if not os.path.exists(key_file_path): raise with open('files/id_rsa_tmp', 'r') as key_file: self.ssh_key = key_file.read() # Copy new local test pub key into remote-compute and # add it to the authorized_hosts. u.log.debug('Copying pub key into simulated remote-compute host') src_file = os.path.join('files', 'id_rsa_tmp.pub') dst_file = os.path.join(os.sep, 'home', 'ubuntu', 'id_rsa_tmp.pub') auth_file = os.path.join(os.sep, 'home', 'ubuntu', '.ssh', 'authorized_keys') cmd = [ 'juju', 'scp', src_file, '{}:{}'.format(self.remote_compute, dst_file) ] subprocess.check_call(cmd) u.log.debug('Adding pub key to authorized_hosts on the simulated ' 'remote-compute host') cmd = [ 'juju', 'ssh', '{}'.format(self.remote_compute), 'cat {} >> {}'.format(dst_file, auth_file) ] subprocess.check_call(cmd) u.log.debug('Installing and enabling yum on remote compute host') cmd = [ 'juju', 'ssh', '{}'.format(self.remote_compute), 'sudo apt-get install yum yum-utils -y' ] subprocess.check_call(cmd) cmd = [ 'juju', 'ssh', '{}'.format(self.remote_compute), 'sudo yum-config-manager --enable' ] subprocess.check_call(cmd) u.log.debug('Remote compute host deploy and prep complete')