def main(argv):
    mojo_utils.setup_logging()
    overcloud_novarc = mojo_utils.get_overcloud_auth()
    user_config = mojo_utils.get_mojo_config('keystone_users.yaml')
    os_version = mojo_os_utils.get_current_os_versions('keystone')['keystone']
    # Keystone policy.json shipped the charm with liberty requires a domain
    # scoped token. Bug #1649106
    if os_version == 'liberty':
        scope = 'DOMAIN'
    else:
        scope = 'PROJECT'
    keystone_session = mojo_os_utils.get_keystone_session(overcloud_novarc,
                                                          scope=scope)
    keystone_client = (
        mojo_os_utils.get_keystone_session_client(keystone_session))
    if overcloud_novarc.get('API_VERSION', 2) == 2:
        projects = [user['project'] for user in user_config]
        mojo_os_utils.project_create(keystone_client, projects)
        mojo_os_utils.user_create_v2(keystone_client, user_config)
        # TODO validate this works without adding roles
        # mojo_os_utils.add_users_to_roles(keystone_client, user_config)
    else:
        for user in user_config:
            mojo_os_utils.domain_create(keystone_client, [user['domain']])
            mojo_os_utils.project_create(keystone_client, [user['project']],
                                         user['domain'])
    mojo_os_utils.user_create_v3(keystone_client, user_config)
示例#2
0
def main(argv):
    logging.basicConfig(level=logging.INFO)
    logging.getLogger("urllib3").setLevel(logging.WARNING)
    # Keystone policy.json shipped the charm with liberty requires a domain
    # scoped token. Bug #1649106
    os_version = mojo_os_utils.get_current_os_versions('keystone')['keystone']
    if os_version == 'liberty':
        scope = 'DOMAIN'
    else:
        scope = 'PROJECT'
    undercloud_novarc = mojo_utils.get_undercloud_auth()
    keystone_session_uc = mojo_os_utils.get_keystone_session(undercloud_novarc,
                                                             scope=scope)
    under_novac = mojo_os_utils.get_nova_session_client(keystone_session_uc)

    overcloud_novarc = mojo_utils.get_overcloud_auth()
    keystone_session_oc = mojo_os_utils.get_keystone_session(overcloud_novarc,
                                                             scope=scope)
    clients = {
        'neutron':
        mojo_os_utils.get_neutron_session_client(keystone_session_oc),
        'nova': mojo_os_utils.get_nova_session_client(keystone_session_oc),
        'glance': mojo_os_utils.get_glance_session_client(keystone_session_oc),
    }
    image_config = mojo_utils.get_mojo_config('images.yaml')
    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')
示例#3
0
def main(argv):
    mojo_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 = mojo_utils.parse_mojo_arg(options, 'machines', multiargs=True)
    active_wait = int(mojo_utils.parse_mojo_arg(options, 'active_wait'))
    cloudinit_wait = int(mojo_utils.parse_mojo_arg(options, 'cloudinit_wait'))
    ping_wait = int(mojo_utils.parse_mojo_arg(options, 'ping_wait'))
    overcloud_novarc = mojo_utils.get_overcloud_auth()
    keystone_session = mojo_os_utils.get_keystone_session(overcloud_novarc,
                                                          scope='PROJECT')
    os_version = mojo_os_utils.get_current_os_versions('keystone')['keystone']
    # Keystone policy.json shipped the charm with liberty requires a domain
    # scoped token. Bug #1649106
    if os_version == 'liberty':
        project_query_session = mojo_os_utils.get_keystone_session(
            overcloud_novarc, scope='DOMAIN')
    else:
        project_query_session = keystone_session
    keystonec = mojo_os_utils.get_keystone_session_client(
        project_query_session)
    domain = overcloud_novarc.get('OS_PROJECT_DOMAIN_NAME')
    project_id = mojo_os_utils.get_project_id(
        keystonec,
        'admin',
        api_version=overcloud_novarc['API_VERSION'],
        domain_name=domain)
    novac = mojo_os_utils.get_nova_session_client(keystone_session)
    neutronc = mojo_os_utils.get_neutron_session_client(keystone_session)

    init_flavors(novac)

    priv_key = mojo_os_utils.create_keypair(novac, 'mojo')
    mojo_os_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(":")
        mojo_os_utils.boot_and_test(novac,
                                    neutronc,
                                    image_name=image_name,
                                    flavor_name=flavor_name,
                                    number=int(count),
                                    privkey=priv_key,
                                    active_wait=active_wait,
                                    cloudinit_wait=cloudinit_wait,
                                    ping_wait=ping_wait)
示例#4
0
def main(argv):
    mojo_utils.setup_logging()
    # Setup client
    overcloud_novarc = mojo_utils.get_overcloud_auth()
    keystone_session = mojo_os_utils.get_keystone_session(overcloud_novarc,
                                                          scope='PROJECT')
    client = mojo_os_utils.get_designate_session_client(keystone_session)
    os_version = mojo_os_utils.get_current_os_versions('keystone')['keystone']

    if os_version >= 'queens':
        designate_api_version = 2
        zone = mojo_os_utils.create_or_return_zone(client, TEST_DOMAIN,
                                                   TEST_DOMAIN_EMAIL)
        rs = mojo_os_utils.create_or_return_recordset(
            client, zone['id'], 'www', 'A', [TEST_RECORD[TEST_WWW_RECORD]])
    else:
        designate_api_version = 1

        # Create test domain and record in test domain
        domain = mojo_os_utils.create_designate_dns_domain(
            client, TEST_DOMAIN, TEST_DOMAIN_EMAIL)
        record = mojo_os_utils.create_designate_dns_record(
            client, domain.id, TEST_WWW_RECORD, "A",
            TEST_RECORD[TEST_WWW_RECORD])

    # Test record is in bind and designate
    mojo_os_utils.check_dns_entry(client,
                                  TEST_RECORD[TEST_WWW_RECORD],
                                  TEST_DOMAIN,
                                  record_name=TEST_WWW_RECORD,
                                  designate_api=designate_api_version)

    mojo_utils.add_unit('designate-bind')

    mojo_os_utils.check_dns_entry(client,
                                  TEST_RECORD[TEST_WWW_RECORD],
                                  TEST_DOMAIN,
                                  record_name=TEST_WWW_RECORD,
                                  designate_api=designate_api_version)

    mojo_utils.delete_oldest('designate-bind')

    mojo_os_utils.check_dns_entry(client,
                                  TEST_RECORD[TEST_WWW_RECORD],
                                  TEST_DOMAIN,
                                  record_name=TEST_WWW_RECORD,
                                  designate_api=designate_api_version)
示例#5
0
def main(argv):
    logging.basicConfig(level=logging.INFO)
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--target_release",
        default='auto', help="Openstack release name to upgrade to or 'auto' "
                             "to have script upgrade based on the lowest value"
                             "across all services")
    options = parser.parse_args()
    target_release = mojo_utils.parse_mojo_arg(options, 'target_release')
    principle_services = mojo_utils.get_principle_services()
    current_versions = mojo_os_utils.get_current_os_versions(
        principle_services)
    if target_release == 'auto':
        # If in auto mode find the lowest value openstack release across all
        # services and make sure all servcies are upgraded to one release
        # higher than the lowest
        lowest_release = mojo_os_utils.get_lowest_os_version(current_versions)
        target_release = mojo_os_utils.next_release(lowest_release)[1]
    # Get a list of services that need upgrading
    needs_upgrade = get_upgrade_targets(target_release, current_versions)
    for service in mojo_os_utils.UPGRADE_SERVICES:
        if service['name'] not in principle_services:
            continue
        if service['name'] not in needs_upgrade:
            logging.info('Not upgrading {} it is at {} or higher'.format(
                service['name'],
                target_release)
            )
            continue
        logging.info('Upgrading {} to {}'.format(service['name'],
                                                 target_release))
        ubuntu_version = mojo_utils.get_ubuntu_version(service['name'])
        option = "{}=cloud:{}-{}/proposed".format(
            service['type']['origin_setting'],
            ubuntu_version, target_release
        )
        mojo_utils.juju_set(service['name'], option, wait=False)
        # NOTE: For liberty->mitaka upgrade ceilometer-agent gets stuck at
        # 'Services not running that should be: memcached' after nova-compute
        # upgrade, and test would wait forever. Therefore we upgrade
        # ceilometer-agent immediately after nova-compute.
        if service['name'] == 'nova-compute':
            mojo_utils.juju_set('ceilometer-agent', option, wait=False)
        mojo_utils.juju_wait_finished()
示例#6
0
def main(argv):
    mojo_utils.setup_logging()
    parser = argparse.ArgumentParser()
    parser.add_argument('--peer-application', '-a',
                        help='BGP Peer application name. Default: quagga',
                        default='quagga')
    options = parser.parse_args()

    peer_application_name = mojo_utils.parse_mojo_arg(options,
                                                      'peer_application')
    overcloud_novarc = mojo_utils.get_overcloud_auth()
    os_version = mojo_os_utils.get_current_os_versions('keystone')['keystone']
    # Keystone policy.json shipped the charm with liberty requires a domain
    # scoped token. Bug #1649106
    if os_version == 'liberty':
        scope = 'DOMAIN'
    else:
        scope = 'PROJECT'
    keystone_session = mojo_os_utils.get_keystone_session(overcloud_novarc,
                                                          scope=scope)
    neutronc = mojo_os_utils.get_neutron_session_client(keystone_session)

    # Run show ip route on BGP peer
    peer_unit = mojo_utils.get_juju_units(service=peer_application_name)[0]
    logging.info("Checking routes on BGP peer {}".format(peer_unit))
    routes = mojo_utils.remote_run(peer_unit,
                                   remote_cmd="vtysh -c 'show ip route'")[0]
    logging.debug(routes)

    # Check for expected advertised routes
    private_cidr = neutronc.list_subnets(
        name='private_subnet')['subnets'][0]['cidr']
    floating_ip_cidr = "{}/32".format(
        neutronc.list_floatingips()['floatingips'][0]['floating_ip_address'])
    assert private_cidr in routes, ("Private subnet CIDR, {}, not advertised "
                                    "to BGP peer".format(private_cidr))
    logging.info("Private subnet CIDR, {}, found in routing table"
                 .format(private_cidr))
    assert floating_ip_cidr in routes, ("Floating IP, {}, not advertised "
                                        "to BGP peer".format(floating_ip_cidr))
    logging.info("Floating IP CIDR, {}, found in routing table"
                 .format(floating_ip_cidr))
def main(argv):
    mojo_utils.setup_logging()
    parser = argparse.ArgumentParser()
    parser.add_argument('--peer-application',
                        '-a',
                        help='BGP peer application name. Default: quagga',
                        default='quagga')

    options = parser.parse_args()
    peer_application_name = mojo_utils.parse_mojo_arg(options,
                                                      'peer_application')

    overcloud_novarc = mojo_utils.get_overcloud_auth()
    os_version = mojo_os_utils.get_current_os_versions('keystone')['keystone']
    # Keystone policy.json shipped the charm with liberty requires a domain
    # scoped token. Bug #1649106
    if os_version == 'liberty':
        scope = 'DOMAIN'
    else:
        scope = 'PROJECT'
    keystone_session = mojo_os_utils.get_keystone_session(overcloud_novarc,
                                                          scope=scope)
    neutronc = mojo_os_utils.get_neutron_session_client(keystone_session)

    logging.info("Setting up BGP speaker")
    bgp_speaker = mojo_os_utils.create_bgp_speaker(neutronc, local_as=12345)

    logging.info("Advertising BGP routes")
    # Add networks to bgp speaker
    mojo_os_utils.add_network_to_bgp_speaker(neutronc, bgp_speaker, 'ext_net')
    mojo_os_utils.add_network_to_bgp_speaker(neutronc, bgp_speaker, 'private')
    logging.debug("Advertised routes: {}".format(
        neutronc.list_route_advertised_from_bgp_speaker(bgp_speaker['id'])))

    # Create peer
    logging.info("Setting up BGP peer")
    bgp_peer = mojo_os_utils.create_bgp_peer(neutronc,
                                             peer_application_name,
                                             remote_as=10000)
    # Add peer to bgp speaker
    mojo_os_utils.add_peer_to_bgp_speaker(neutronc, bgp_speaker, bgp_peer)
示例#8
0
def setup_sdn(net_topology, net_info):
    overcloud_novarc = mojo_utils.get_overcloud_auth()
    os_version = mojo_os_utils.get_current_os_versions('keystone')['keystone']
    # Keystone policy.json shipped the charm with liberty requires a domain
    # scoped token. Bug #1649106
    if os_version == 'liberty':
        scope = 'DOMAIN'
    else:
        scope = 'PROJECT'
    keystone_session = mojo_os_utils.get_keystone_session(overcloud_novarc,
                                                          scope=scope)
    keystonec = mojo_os_utils.get_keystone_session_client(keystone_session)
    neutronc = mojo_os_utils.get_neutron_session_client(keystone_session)
    # Resolve the project name from the overcloud novarc into a project id
    project_id = mojo_os_utils.get_project_id(
        keystonec, 'admin', api_version=overcloud_novarc['API_VERSION'])
    # Network Setup
    subnetpools = False
    if net_info.get('subnetpool_prefix'):
        subnetpools = True
    # Create the external network
    ext_network = mojo_os_utils.create_external_network(
        neutronc, project_id, net_info.get('dvr_enabled', False),
        net_info['external_net_name'])
    mojo_os_utils.create_external_subnet(neutronc, project_id, ext_network,
                                         net_info['default_gateway'],
                                         net_info['external_net_cidr'],
                                         net_info['start_floating_ip'],
                                         net_info['end_floating_ip'],
                                         net_info['external_subnet_name'])
    # Should this be --enable_snat = False
    provider_router = (mojo_os_utils.create_provider_router(
        neutronc, project_id))
    mojo_os_utils.plug_extnet_into_router(neutronc, provider_router,
                                          ext_network)
    ip_version = net_info.get('ip_version') or 4
    subnetpool = None
    if subnetpools:
        address_scope = mojo_os_utils.create_address_scope(
            neutronc,
            project_id,
            net_info.get('address_scope'),
            ip_version=ip_version)
        subnetpool = mojo_os_utils.create_subnetpool(
            neutronc, project_id, net_info.get('subnetpool_name'),
            net_info.get('subnetpool_prefix'), address_scope)
    project_network = mojo_os_utils.create_project_network(
        neutronc,
        project_id,
        shared=False,
        network_type=net_info['network_type'])
    project_subnet = mojo_os_utils.create_project_subnet(
        neutronc,
        project_id,
        project_network,
        net_info.get('private_net_cidr'),
        subnetpool=subnetpool,
        ip_version=ip_version)
    mojo_os_utils.update_subnet_dns(neutronc, project_subnet,
                                    net_info['external_dns'])
    mojo_os_utils.plug_subnet_into_router(neutronc, net_info['router_name'],
                                          project_network, project_subnet)
def main(argv):
    mojo_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 = mojo_utils.parse_mojo_arg(options, 'bind_service')
    resolver = mojo_utils.parse_mojo_arg(options, 'resolver')
    bind_unit = mojo_utils.get_juju_units(service=bind_service_name)[0]
    if not resolver:
        resolver = mojo_utils.get_juju_unit_ip(bind_unit)
    domain_name = mojo_utils.parse_mojo_arg(options, 'domain_name')
    email = mojo_utils.parse_mojo_arg(options, 'email')
    nameserver = 'ns1.{}'.format(domain_name)

    logging.info('Setting up designate {} {}'.format(nameserver, resolver))

    overcloud_novarc = mojo_utils.get_overcloud_auth()
    os_version = mojo_os_utils.get_current_os_versions('keystone')['keystone']
    # Keystone policy.json shipped the charm with liberty requires a domain
    # scoped token. Bug #1649106
    if os_version == 'liberty':
        scope = 'DOMAIN'
    else:
        scope = 'PROJECT'
    keystone_session = mojo_os_utils.get_keystone_session(overcloud_novarc,
                                                          scope=scope)
    neutronc = mojo_os_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)
        rs = 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 = mojo_os_utils.get_net_uuid(neutronc, 'private')
    mojo_os_utils.update_network_dns(neutronc, net_uuid, domain_name)