def test_create_loadbalancer(self): """Create load balancer.""" keystone_session = openstack_utils.get_overcloud_keystone_session() neutron_client = openstack_utils.get_neutron_session_client( keystone_session) resp = neutron_client.list_networks(name='private') subnet_id = resp['networks'][0]['subnets'][0] octavia_client = openstack_utils.get_octavia_session_client( keystone_session) result = octavia_client.load_balancer_create( json={ 'loadbalancer': { 'description': 'Created by Zaza', 'admin_state_up': True, 'vip_subnet_id': subnet_id, 'name': 'zaza-lb-0', } }) lb_id = result['loadbalancer']['id'] @tenacity.retry(wait=tenacity.wait_fixed(1), reraise=True, stop=tenacity.stop_after_delay(900)) def wait_for_loadbalancer(octavia_client, load_balancer_id): resp = octavia_client.load_balancer_show(load_balancer_id) if resp['provisioning_status'] != 'ACTIVE': raise Exception('load balancer has not reached expected ' 'status: {}'.format(resp)) return resp logging.info('Awaiting loadbalancer to reach provisioning_status ' '"ACTIVE"') resp = wait_for_loadbalancer(octavia_client, lb_id) logging.info(resp)
def setup_gateway_ext_port(network_config, keystone_session=None): """Perform setup external port on Neutron Gateway. For OpenStack on OpenStack scenarios. :param network_config: Network configuration dictionary :type network_config: dict :param keystone_session: Keystone session object for undercloud :type keystone_session: keystoneauth1.session.Session object :returns: None :rtype: None """ # If a session has not been provided, acquire one if not keystone_session: keystone_session = openstack_utils.get_undercloud_keystone_session() # Get authenticated clients nova_client = openstack_utils.get_nova_session_client(keystone_session) neutron_client = openstack_utils.get_neutron_session_client( keystone_session) # Add an interface to the neutron-gateway units and tell juju to use it # as the external port. if "net_id" in network_config.keys(): net_id = network_config["net_id"] else: net_id = None logging.info("Configuring network for OpenStack undercloud/provider") openstack_utils.configure_gateway_ext_port(nova_client, neutron_client, dvr_mode=network_config.get( "dvr_enabled", False), net_id=net_id)
def __init__(self, prov_net_id=None): try: cacert = os.path.join(os.environ.get('MOJO_LOCAL_DIR'), 'cacert.pem') os.stat(cacert) except FileNotFoundError: cacert = None keystone_session = openstack_utils.get_undercloud_keystone_session( verify=cacert) neutronc = openstack_utils.get_neutron_session_client(keystone_session) if prov_net_id: net = neutronc.list_networks(id=prov_net_id)['networks'][0] else: net = openstack_utils.get_admin_net(neutronc) subnet_id = net['subnets'][0] subnet = neutronc.list_subnets(id=subnet_id)['subnets'][0] allocation_pools = subnet['allocation_pools'] self.cidr = subnet['cidr'] self.highest_assigned = netaddr.IPAddress(allocation_pools[0]['end']) # XXX look away now, nothing to see here, move along. # If there is less than 30 free ips in the network after the top # dhcp ip then eat into the top of the dhcp range available_ips = [] for element in list(netaddr.IPNetwork(self.cidr)): if element == netaddr.IPAddress(self.highest_assigned) or \ available_ips: available_ips.append(element) if len(available_ips) < 30: self.highest_assigned = self.highest_assigned - 30
def setUpClass(cls): """Run class setup for running glance tests.""" cls.keystone_session = openstack_utils.get_overcloud_keystone_session() cls.model_name = model.get_juju_model() cls.nova_client = openstack_utils.get_nova_session_client( cls.keystone_session) cls.neutron_client = openstack_utils.get_neutron_session_client( cls.keystone_session)
def test_bgp_routes(peer_application_name="quagga", keystone_session=None): """Test BGP routes. :param peer_application_name: String name of BGP peer application :type peer_application_name: string :param keystone_session: Keystone session object for overcloud :type keystone_session: keystoneauth1.session.Session object :raises: AssertionError if expected BGP routes are not found :returns: None :rtype: None """ # If a session has not been provided, acquire one if not keystone_session: keystone_session = openstack_utils.get_overcloud_keystone_session() # Get authenticated clients neutron_client = openstack_utils.get_neutron_session_client( keystone_session) # Get the peer unit peer_unit = model.get_units(peer_application_name)[0].entity_id # Get expected advertised routes private_cidr = neutron_client.list_subnets( name="private_subnet")["subnets"][0]["cidr"] floating_ip_cidr = "{}/32".format( neutron_client.list_floatingips()["floatingips"][0] ["floating_ip_address"]) # This test may run immediately after configuration. It may take time for # routes to propogate via BGP. Do a binary backoff. @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1, max=60), reraise=True, stop=tenacity.stop_after_attempt(8)) def _assert_cidr_in_peer_routing_table(peer_unit, cidr): logging.debug("Checking for {} on BGP peer {}".format(cidr, peer_unit)) # Run show ip route bgp on BGP peer routes = juju_utils.remote_run( peer_unit, remote_cmd='vtysh -c "show ip route bgp"') logging.debug(routes) assert cidr in routes, ( "CIDR, {}, not found in BGP peer's routing table".format(cidr)) _assert_cidr_in_peer_routing_table(peer_unit, private_cidr) logging.info( "Private subnet CIDR, {}, found in routing table".format(private_cidr)) _assert_cidr_in_peer_routing_table(peer_unit, floating_ip_cidr) logging.info("Floating IP CIDR, {}, found in routing table".format( floating_ip_cidr))
def main(argv): cli_utils.setup_logging() logging.getLogger("urllib3").setLevel(logging.WARNING) keystone_session_uc = openstack_utils.get_undercloud_keystone_session() under_novac = openstack_utils.get_nova_session_client(keystone_session_uc) keystone_session_oc = openstack_utils.get_overcloud_keystone_session() clients = { 'neutron': openstack_utils.get_neutron_session_client(keystone_session_oc), 'nova': openstack_utils.get_nova_session_client(keystone_session_oc), 'glance': mojo_os_utils.get_glance_session_client(keystone_session_oc), } image_file = mojo_utils.get_mojo_file('images.yaml') image_config = generic_utils.get_yaml_config(image_file) image_password = image_config['cirros']['password'] # Look for existing Cirros guest server, ip = get_cirros_server(clients, image_password) router = (clients['neutron'].list_routers( name='provider-router')['routers'][0]) l3_agents = clients['neutron'].list_l3_agent_hosting_routers( router=router['id'])['agents'] logging.info('Checking there are multiple L3 agents running tenant router') if len(l3_agents) != 2: raise Exception('Unexpected number of l3 agents') for agent in l3_agents: gateway_hostname = agent['host'] gateway_server = under_novac.servers.find(name=gateway_hostname) logging.info('Shutting down neutron gateway {} ({})'.format( gateway_hostname, gateway_server.id)) gateway_server.stop() if not check_server_state( under_novac, 'SHUTOFF', server_name=gateway_hostname): raise Exception('Server failed to reach SHUTOFF state') logging.info('Neutron gateway %s has shutdown' % (gateway_hostname)) logging.info('Checking connectivity to cirros guest') if not mojo_os_utils.wait_for_ping(ip, 90): raise Exception('Cirros guest not responding to ping') if not mojo_os_utils.ssh_test( 'cirros', ip, server.name, password=image_password): raise Exception('Cirros guest issh connection failed') logging.info('Starting neutron gateway: ' + gateway_hostname) gateway_server.start() if not check_server_state( under_novac, 'ACTIVE', server_name=gateway_hostname): raise Exception('Server failed to reach SHUTOFF state') if not check_neutron_agent_states(clients['neutron'], gateway_hostname): raise Exception('Server agents failed to reach active state')
def test_tunnel_datapath(self): """From ports list, connect to unit in one end, ping other end(s).""" keystone_session = openstack_utils.get_overcloud_keystone_session() neutron_client = openstack_utils.get_neutron_session_client( keystone_session) resp = neutron_client.list_ports() ports = resp['ports'] host_port = {} for port in ports: if (port['device_owner'].startswith('network:') or port['device_owner'].startswith('compute:')): continue host_port[port['binding:host_id']] = port for unit in zaza.model.get_units('neutron-openvswitch'): result = zaza.model.run_on_unit(unit.entity_id, 'hostname') hostname = result['Stdout'].rstrip() if hostname not in host_port: # no port bound to this host, skip continue # get interface name from unit OVS data ovs_interface = json.loads( zaza.model.run_on_unit( unit.entity_id, 'ovs-vsctl -f json find Interface ' 'external_ids:iface-id={}'.format( host_port[hostname]['id']))['Stdout']) for (idx, heading) in enumerate(ovs_interface['headings']): if heading == 'name': break else: raise Exception('Unable to find interface name from OVS') interface_name = ovs_interface['data'][0][idx] ip_unit = zaza.model.run_on_unit( unit.entity_id, 'ip addr show dev {}'.format(interface_name)) for other_host in (set(host_port) - set([hostname])): for ip_info in host_port[other_host]['fixed_ips']: logging.info('Local IP info: "{}"'.format(ip_unit)) logging.info('PING "{}" --> "{}"...'.format( hostname, other_host)) result = zaza.model.run_on_unit( unit.entity_id, 'ping -c 3 {}'.format(ip_info['ip_address'])) logging.info(result['Stdout']) if result['Code'] == '1': raise Exception('FAILED')
def main(argv): cli_utils.setup_logging() parser = argparse.ArgumentParser() parser.add_argument("router", nargs="?") options = parser.parse_args() router_name = cli_utils.parse_arg(options, 'router') try: cacert = os.path.join(os.environ.get('MOJO_LOCAL_DIR'), 'cacert.pem') os.stat(cacert) except FileNotFoundError: cacert = None keystone_session = openstack_utils.get_overcloud_keystone_session( verify=cacert) neutron_client = openstack_utils.get_neutron_session_client( keystone_session) router = neutron_client.list_routers(name=router_name)['routers'][0]['id'] l3_agent = neutron_client.list_l3_agent_hosting_routers(router=router) hosting_machine = l3_agent['agents'][0]['host'] mojo_utils.delete_machine(hosting_machine)
def main(): """Cleanup after test run.""" args = parse_args(sys.argv[1:]) keystone_session = openstack_utils.get_overcloud_keystone_session() nova_client = openstack_utils.get_nova_session_client(keystone_session) neutron_client = openstack_utils.get_neutron_session_client( keystone_session) instance = nova_client.servers.find(name=args.vm_name) logger.debug("Found vm {} with instance is {}".format( args.vm_name, instance.id)) wait(nova_client, instance.id, args.vm_name) ip = assign_ip(neutron_client, instance.id) logger.debug("Checking ping to {}".format(ip)) openstack_utils.ping_response(ip) logger.debug("Checking ssh to {}".format(ip)) openstack_utils.ssh_test(username='******', ip=ip, vm_name=args.vm_name, password=None, privkey=get_priv_key(args.key_file))
def overlay_network(): """Create network with subnets, add OVS port per unit. Useful for testing that the `neutron-openvswitch` charm configures the system, LXD profiles etc in such a way that the Neutron OpenvSwitch agent is able to perform the required OVS configuration. """ keystone_session = openstack_utils.get_overcloud_keystone_session() neutron_client = openstack_utils.get_neutron_session_client( keystone_session) resp = neutron_client.create_network( {'network': { 'name': 'zaza-neutron-openvswitch-network' }}) network = resp['network'] logging.info('created network {}'.format(pprint.pformat(network))) # make rfc4193 Unique Local IPv6 Unicast Addresses from network UUID rfc4193_addr = 'fc00' for n in [0, 4, 8]: rfc4193_addr += ':' + network['id'].split('-')[4][n:n + 4] rfc4193_addr += '::/64' resp = neutron_client.create_subnet({ 'subnets': [ { 'name': 'zaza-neutron-openvswitch-subnet', 'ip_version': 4, 'cidr': '10.42.42.0/24', 'network_id': network['id'], }, { 'name': 'zaza-neutron-openvswitch-subnetv6', 'ip_version': 6, 'ipv6_address_mode': 'slaac', 'ipv6_ra_mode': 'slaac', 'cidr': rfc4193_addr, 'network_id': network['id'], }, ], }) logging.info('created subnets {}'.format(pprint.pformat(resp['subnets']))) for unit in zaza.model.get_units('neutron-openvswitch'): result = zaza.model.run_on_unit(unit.entity_id, 'hostname') hostname = result['Stdout'].rstrip() logging.info('hostname: "{}"'.format(hostname)) resp = neutron_client.create_port({ 'port': { 'binding:host_id': hostname, 'device_owner': 'Zaza:neutron-openvswitch-test', 'name': hostname, 'network_id': network['id'], }, }) port = resp['port'] logging.info('created port {}'.format(pprint.pformat(port))) result = zaza.model.run_on_unit( unit.entity_id, 'ovs-vsctl -- --may-exist add-port br-int zaza0 ' '-- set Interface zaza0 type=internal ' '-- set Interface zaza0 external-ids:iface-status=active ' '-- set Interface zaza0 external-ids:attached-mac={} ' '-- set Interface zaza0 external-ids:iface-id={} ' '-- set Interface zaza0 external-ids:skip_cleanup=true '.format( port['mac_address'], port['id'])) logging.info('do ovs configuration {}'.format(pprint.pformat(result))) result = zaza.model.run_on_unit( unit.entity_id, 'ip link set dev zaza0 address {} up'.format(port['mac_address'])) logging.info('ip link {}'.format(pprint.pformat(result))) for ip_info in port['fixed_ips']: # NOTE(fnordahl) overly simplified but is sufficient for test if ':' in ip_info['ip_address']: bits = '64' else: bits = '24' result = zaza.model.run_on_unit( unit.entity_id, 'ip addr add {}/{} dev zaza0'.format(ip_info['ip_address'], bits)) logging.info('ip addr add {}'.format(pprint.pformat(result)))
def main(argv): cli_utils.setup_logging() parser = argparse.ArgumentParser() parser.add_argument('-r', '--resolver', help='Resolver address. ' 'Usually designate-bind address.', required=False) parser.add_argument('-d', '--domain_name', help='DNS Domain Name. ' 'Must end in a .', default='mojo.serverstack.') parser.add_argument('-e', '--email', help='Email address', default='*****@*****.**') parser.add_argument('-b', '--bind-service', help='Bind Service Name', default='designate-bind') options = parser.parse_args() bind_service_name = cli_utils.parse_arg(options, 'bind_service') resolver = cli_utils.parse_arg(options, 'resolver') bind_unit = mojo_utils.get_juju_units(bind_service_name)[0] if not resolver: resolver = mojo_utils.get_juju_unit_ip(bind_unit) domain_name = cli_utils.parse_arg(options, 'domain_name') email = cli_utils.parse_arg(options, 'email') nameserver = 'ns1.{}'.format(domain_name) logging.info('Setting up designate {} {}'.format(nameserver, resolver)) os_version = openstack_utils.get_current_os_versions( 'keystone')['keystone'] try: cacert = os.path.join(os.environ.get('MOJO_LOCAL_DIR'), 'cacert.pem') os.stat(cacert) except FileNotFoundError: cacert = None keystone_session = openstack_utils.get_overcloud_keystone_session( verify=cacert) neutronc = openstack_utils.get_neutron_session_client(keystone_session) if os_version >= 'queens': designatec = mojo_os_utils.get_designate_session_client( keystone_session, client_version='2') zone = mojo_os_utils.create_or_return_zone(designatec, domain_name, email) mojo_os_utils.create_or_return_recordset(designatec, zone['id'], 'www', 'A', [resolver]) else: designatec = mojo_os_utils.get_designate_session_client( keystone_session, client_version='1') if not mojo_os_utils.get_designate_server_id(designatec, nameserver): logging.info('Creating server {}'.format(nameserver)) server = Server(name=nameserver) server_id = designatec.servers.create(server) assert (server_id is not None) else: logging.info('{} server already exists.'.format(nameserver)) domain_id = mojo_os_utils.get_designate_domain_id( designatec, domain_name) if not domain_id: logging.info('Creating domain {}'.format(domain_name)) domain = Domain(name=domain_name, email=email) domain_id = designatec.domains.create(domain) assert (domain_id is not None) else: logging.info('{} domain already exists.'.format(domain_name)) if not mojo_os_utils.get_designate_record_id(designatec, domain_id, nameserver): logging.info('Creating NS record {}'.format(nameserver)) ns_record = Record(name=nameserver, type="A", data=resolver) record_id = designatec.records.create(domain_id, ns_record) assert (record_id is not None) else: logging.info('{} record already exists.'.format(nameserver)) logging.info('Update network to use domain {}'.format(domain_name)) net_uuid = openstack_utils.get_net_uuid(neutronc, 'private') mojo_os_utils.update_network_dns(neutronc, net_uuid, domain_name)
def main(argv): cli_utils.setup_logging() parser = argparse.ArgumentParser() default_machines = ["cirros:m1.tiny:1"] parser.add_argument("machines", default=default_machines, nargs="*") parser.add_argument("--active_wait", default=180) parser.add_argument("--cloudinit_wait", default=180) parser.add_argument("--ping_wait", default=180) options = parser.parse_args() machines = cli_utils.parse_arg(options, 'machines', multiargs=True) active_wait = int(cli_utils.parse_arg(options, 'active_wait')) cloudinit_wait = int(cli_utils.parse_arg(options, 'cloudinit_wait')) ping_wait = int(cli_utils.parse_arg(options, 'ping_wait')) overcloud_novarc = openstack_utils.get_overcloud_auth() try: cacert = os.path.join(os.environ.get('MOJO_LOCAL_DIR'), 'cacert.pem') os.stat(cacert) except FileNotFoundError: cacert = None keystone_session = openstack_utils.get_overcloud_keystone_session( verify=cacert) keystonec = openstack_utils.get_keystone_session_client(keystone_session) domain = overcloud_novarc.get('OS_PROJECT_DOMAIN_NAME') project_id = openstack_utils.get_project_id( keystonec, 'admin', api_version=overcloud_novarc['API_VERSION'], domain_name=domain) novac = openstack_utils.get_nova_session_client(keystone_session) neutronc = openstack_utils.get_neutron_session_client(keystone_session) init_flavors(novac) priv_key = mojo_os_utils.create_keypair(novac, 'mojo') openstack_utils.add_neutron_secgroup_rules(neutronc, project_id) for server in novac.servers.list(): novac.servers.delete(server.id) for instanceset in machines: image_name, flavor_name, count = instanceset.split(":") # when instance count allows boot instances off both regular instance # storage and volume storage # # account for count=1 and odd numbers # NOTE(fnordahl) temporarilly disable test while tests settle # regular_boot_count = int(int(count) / 2) + (int(count) % 2) # volume_boot_count = int(int(count) / 2) regular_boot_count = int(count) volume_boot_count = 0 mojo_os_utils.boot_and_test( novac, neutronc, image_name=image_name, flavor_name=flavor_name, number=regular_boot_count, privkey=priv_key, active_wait=active_wait, cloudinit_wait=cloudinit_wait, ping_wait=ping_wait, ) mojo_os_utils.boot_and_test( novac, neutronc, image_name=image_name, flavor_name=flavor_name, number=volume_boot_count, privkey=priv_key, active_wait=active_wait, cloudinit_wait=cloudinit_wait, ping_wait=ping_wait, boot_from_volume=True, )
def setup_bgp_speaker(peer_application_name, keystone_session=None): """Perform BGP Speaker setup. :param peer_application_name: String name of BGP peer application :type peer_application_name: string :param keystone_session: Keystone session object for overcloud :type keystone_session: keystoneauth1.session.Session object :returns: None :rtype: None """ # Get ASNs from deployment dr_relation = juju_utils.get_relation_from_unit( 'neutron-dynamic-routing', peer_application_name, 'bgpclient') peer_asn = dr_relation.get('asn') logging.debug('peer ASn: "{}"'.format(peer_asn)) peer_relation = juju_utils.get_relation_from_unit( peer_application_name, 'neutron-dynamic-routing', 'bgp-speaker') dr_asn = peer_relation.get('asn') logging.debug('our ASn: "{}"'.format(dr_asn)) # If a session has not been provided, acquire one if not keystone_session: keystone_session = openstack_utils.get_overcloud_keystone_session() # Get authenticated clients neutron_client = openstack_utils.get_neutron_session_client( keystone_session) # Create BGP speaker logging.info("Setting up BGP speaker") bgp_speaker = openstack_utils.create_bgp_speaker( neutron_client, local_as=dr_asn) # Add networks to bgp speaker logging.info("Advertising BGP routes") openstack_utils.add_network_to_bgp_speaker( neutron_client, bgp_speaker, EXT_NET) openstack_utils.add_network_to_bgp_speaker( neutron_client, bgp_speaker, PRIVATE_NET) logging.debug("Advertised routes: {}" .format( neutron_client.list_route_advertised_from_bgp_speaker( bgp_speaker["id"]))) # Create peer logging.info("Setting up BGP peer") bgp_peer = openstack_utils.create_bgp_peer(neutron_client, peer_application_name, remote_as=peer_asn) # Add peer to bgp speaker logging.info("Adding BGP peer to BGP speaker") openstack_utils.add_peer_to_bgp_speaker( neutron_client, bgp_speaker, bgp_peer) # Create Floating IP to advertise logging.info("Creating floating IP to advertise") port = openstack_utils.create_port(neutron_client, FIP_TEST, PRIVATE_NET) floating_ip = openstack_utils.create_floating_ip(neutron_client, EXT_NET, port=port) logging.info( "Advertised floating IP: {}".format( floating_ip["floating_ip_address"])) # NOTE(fnordahl): As a workaround for LP: #1784083 remove BGP speaker from # dragent and add it back. logging.info( "Waiting for Neutron agent 'neutron-bgp-dragent' to appear...") keystone_session = openstack_utils.get_overcloud_keystone_session() neutron_client = openstack_utils.get_neutron_session_client( keystone_session) agents = openstack_utils.neutron_agent_appears(neutron_client, 'neutron-bgp-dragent') agent_id = None for agent in agents.get('agents', []): agent_id = agent.get('id', None) if agent_id is not None: break logging.info( 'Waiting for BGP speaker to appear on agent "{}"...'.format(agent_id)) bgp_speakers = openstack_utils.neutron_bgp_speaker_appears_on_agent( neutron_client, agent_id) logging.info( "Removing and adding back bgp-speakers to agent (LP: #1784083)...") while True: try: for bgp_speaker in bgp_speakers.get('bgp_speakers', []): bgp_speaker_id = bgp_speaker.get('id', None) logging.info('removing "{}" from "{}"' ''.format(bgp_speaker_id, agent_id)) neutron_client.remove_bgp_speaker_from_dragent( agent_id, bgp_speaker_id) except neutronclient.common.exceptions.NotFound as e: logging.info('Exception: "{}"'.format(e)) break neutron_client.add_bgp_speaker_to_dragent( agent_id, {'bgp_speaker_id': bgp_speaker_id})
def launch_instance(instance_key, use_boot_volume=False, vm_name=None, private_network_name=None, image_name=None, flavor_name=None, external_network_name=None, meta=None): """Launch an instance. :param instance_key: Key to collect associated config data with. :type instance_key: str :param use_boot_volume: Whether to boot guest from a shared volume. :type use_boot_volume: boolean :param vm_name: Name to give guest. :type vm_name: str :param private_network_name: Name of private network to attach guest to. :type private_network_name: str :param image_name: Image name to use with guest. :type image_name: str :param flavor_name: Flavor name to use with guest. :type flavor_name: str :param external_network_name: External network to create floating ip from for guest. :type external_network_name: str :param meta: A dict of arbitrary key/value metadata to store for this server. Both keys and values must be <=255 characters. :type meta: dict """ keystone_session = openstack_utils.get_overcloud_keystone_session() nova_client = openstack_utils.get_nova_session_client(keystone_session) neutron_client = openstack_utils.get_neutron_session_client( keystone_session) # Collect resource information. vm_name = vm_name or time.strftime("%Y%m%d%H%M%S") image_name = image_name or boot_tests[instance_key]['image_name'] image = nova_client.glance.find_image(image_name) flavor_name = flavor_name or boot_tests[instance_key]['flavor_name'] flavor = nova_client.flavors.find(name=flavor_name) private_network_name = private_network_name or "private" net = neutron_client.find_resource("network", private_network_name) nics = [{'net-id': net.get('id')}] meta = meta or {} external_network_name = external_network_name or "ext_net" if use_boot_volume: bdmv2 = [{ 'boot_index': '0', 'uuid': image.id, 'source_type': 'image', 'volume_size': flavor.disk, 'destination_type': 'volume', 'delete_on_termination': True}] image = None else: bdmv2 = None # Launch instance. logging.info('Launching instance {}'.format(vm_name)) instance = nova_client.servers.create( name=vm_name, image=image, block_device_mapping_v2=bdmv2, flavor=flavor, key_name=nova_utils.KEYPAIR_NAME, meta=meta, nics=nics) # Test Instance is ready. logging.info('Checking instance is active') openstack_utils.resource_reaches_status( nova_client.servers, instance.id, expected_status='ACTIVE', stop_after_attempt=16) logging.info('Checking cloud init is complete') openstack_utils.cloud_init_complete( nova_client, instance.id, boot_tests[instance_key]['bootstring']) port = openstack_utils.get_ports_from_device_id( neutron_client, instance.id)[0] logging.info('Assigning floating ip.') ip = openstack_utils.create_floating_ip( neutron_client, external_network_name, port=port)['floating_ip_address'] logging.info('Assigned floating IP {} to {}'.format(ip, vm_name)) openstack_utils.ping_response(ip) # Check ssh'ing to instance. logging.info('Testing ssh access.') openstack_utils.ssh_test( username=boot_tests[instance_key]['username'], ip=ip, vm_name=vm_name, password=boot_tests[instance_key].get('password'), privkey=openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME))
def setup_sdn(network_config, keystone_session=None): """Perform setup for Software Defined Network. :param network_config: Network configuration settings dictionary :type network_config: dict :param keystone_session: Keystone session object for overcloud :type keystone_session: keystoneauth1.session.Session object :returns: None :rtype: None """ # If a session has not been provided, acquire one if not keystone_session: keystone_session = openstack_utils.get_overcloud_keystone_session() # Get authenticated clients keystone_client = openstack_utils.get_keystone_session_client( keystone_session) neutron_client = openstack_utils.get_neutron_session_client( keystone_session) admin_domain = None if openstack_utils.get_keystone_api_version() > 2: admin_domain = "admin_domain" # Resolve the project name from the overcloud openrc into a project id project_id = openstack_utils.get_project_id( keystone_client, "admin", domain_name=admin_domain, ) # Network Setup subnetpools = False if network_config.get("subnetpool_prefix"): subnetpools = True logging.info("Configuring overcloud network") # Create the external network ext_network = openstack_utils.create_external_network( neutron_client, project_id, network_config.get("dvr_enabled", False), network_config["external_net_name"]) openstack_utils.create_external_subnet( neutron_client, project_id, ext_network, network_config["default_gateway"], network_config["external_net_cidr"], network_config["start_floating_ip"], network_config["end_floating_ip"], network_config["external_subnet_name"]) provider_router = (openstack_utils.create_provider_router( neutron_client, project_id)) openstack_utils.plug_extnet_into_router(neutron_client, provider_router, ext_network) ip_version = network_config.get("ip_version") or 4 subnetpool = None if subnetpools: address_scope = openstack_utils.create_address_scope( neutron_client, project_id, network_config.get("address_scope"), ip_version=ip_version) subnetpool = openstack_utils.create_subnetpool( neutron_client, project_id, network_config.get("subnetpool_name"), network_config.get("subnetpool_prefix"), address_scope) project_network = openstack_utils.create_project_network( neutron_client, project_id, shared=False, network_type=network_config["network_type"]) project_subnet = openstack_utils.create_project_subnet( neutron_client, project_id, project_network, network_config.get("private_net_cidr"), subnetpool=subnetpool, ip_version=ip_version) openstack_utils.update_subnet_dns(neutron_client, project_subnet, network_config["external_dns"]) openstack_utils.plug_subnet_into_router(neutron_client, network_config["router_name"], project_network, project_subnet) openstack_utils.add_neutron_secgroup_rules(neutron_client, project_id)