def main(argv):
    parser = argparse.ArgumentParser()
    default_machines = ["precise:m1.small:1", "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'))
    logging.basicConfig(level=logging.INFO)
    overcloud_novarc = mojo_utils.get_overcloud_auth()
    novac = mojo_os_utils.get_nova_client(overcloud_novarc)
    priv_key = mojo_os_utils.create_keypair(novac, 'mojo')
    mojo_os_utils.add_secgroup_rules(novac)
    for instanceset in machines:
        image_name, flavor_name, count = instanceset.split(":")
        mojo_os_utils.boot_and_test(novac,
                                    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)
def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument("application", default="ceph-mon", nargs="*")
    parser.add_argument("units", default=[0, 1], nargs="*")
    options = parser.parse_args()
    application = mojo_utils.parse_mojo_arg(options,
                                            'application',
                                            multiargs=False)
    units = mojo_utils.parse_mojo_arg(options, 'units', multiargs=True)

    mojo_utils.remote_run('{}/{}'.format(application, units[-1]),
                          'ceph osd pool create rbd 128')
    # Check
    mojo_utils.remote_run('{}/{}'.format(application, units[0]),
                          'echo 123456789 > /tmp/input.txt')
    mojo_utils.remote_run('{}/{}'.format(application, units[0]),
                          'rados put -p rbd test_input /tmp/input.txt')

    # Check
    output = mojo_utils.remote_run('{}/{}'.format(application, units[-1]),
                                   'rados get -p rbd test_input /dev/stdout')

    # Cleanup
    mojo_utils.remote_run('{}/{}'.format(application, units[-1]),
                          'rados rm -p rbd test_input')
    if output[0].strip() != "123456789":
        sys.exit(1)
Exemple #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)
def main(argv):
    logging.basicConfig(level=logging.INFO)
    parser = argparse.ArgumentParser()
    parser.add_argument("--service")
    parser.add_argument("--resource")
    options = parser.parse_args()
    service = mojo_utils.parse_mojo_arg(options, 'service')
    resource = mojo_utils.parse_mojo_arg(options, 'resource')
    xenial = distro_info.UbuntuDistroInfo().all.index('xenial')
    series = os.environ.get('MOJO_SERIES')
    mojo_env = distro_info.UbuntuDistroInfo().all.index(series)
    if mojo_env >= xenial:
        resource = resource.replace('eth0', 'ens2')
    mojo_os_utils.delete_crm_leader(service, resource)
def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument("--service")
    parser.add_argument("--kv")
    parser.add_argument("--wait")
    options = parser.parse_args()
    service = mojo_utils.parse_mojo_arg(options, 'service')
    kv = mojo_utils.parse_mojo_arg(options, 'kv')
    wait = mojo_utils.parse_mojo_arg(options, 'wait')
    print("Wait: {}".format(wait))
    if wait is not None:
        wait = wait == 'True'
    print("Service: {}".format(service))
    print("Option: {}".format(kv))
    print("Wait: {}".format(wait))
    mojo_utils.juju_set(service, kv, wait=wait)
Exemple #6
0
def main(argv):
    logging.basicConfig(level=logging.INFO)
    parser = argparse.ArgumentParser()
    parser.add_argument("services", nargs="*")
    options = parser.parse_args()
    services = mojo_utils.parse_mojo_arg(options, 'services', multiargs=True)
    for service in services:
        mojo_utils.upgrade_service(service)
Exemple #7
0
def main(argv):
    logging.basicConfig(level=logging.INFO)
    parser = argparse.ArgumentParser()
    parser.add_argument("units", nargs="*")
    options = parser.parse_args()
    unit_args = mojo_utils.parse_mojo_arg(options, 'units', multiargs=True)
    for unitreq in unit_args:
        service, count = unitreq.split(":")
        mojo_utils.add_unit(service, unit_num=count)
def main(argv):
    logging.basicConfig(level=logging.INFO)
    parser = argparse.ArgumentParser()
    parser.add_argument("application", nargs="*")
    options = parser.parse_args()
    unit_args = mojo_utils.parse_mojo_arg(
        options,
        'application', multiargs=True)
    for application in unit_args:
        mojo_utils.delete_application(application)
Exemple #9
0
def main(argv):
    logging.basicConfig(level=logging.INFO)
    parser = argparse.ArgumentParser()
    parser.add_argument("router", nargs="?")
    options = parser.parse_args()
    router_name = mojo_utils.parse_mojo_arg(options, 'router')
    overcloud_novarc = mojo_utils.get_overcloud_auth()
    neutron_client = mojo_os_utils.get_neutron_client(overcloud_novarc)
    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)
Exemple #10
0
def main(argv):
    mojo_utils.setup_logging()
    parser = argparse.ArgumentParser()
    parser.add_argument('net_topology',
                        help='network topology type, default is GRE',
                        default='gre',
                        nargs='?')
    parser.add_argument('--ignore_env_vars',
                        '-i',
                        help='do not override using environment variables',
                        action='store_true',
                        default=False)
    options = parser.parse_args()
    net_topology = mojo_utils.parse_mojo_arg(options, 'net_topology')
    ignore_env_vars = mojo_utils.parse_mojo_arg(options, 'ignore_env_vars')
    logging.info('Setting up %s network' % (net_topology))
    net_info = mojo_utils.get_net_info(net_topology, ignore_env_vars)

    # Handle network for Openstack-on-Openstack scenarios
    if mojo_utils.get_provider_type() == 'openstack':
        logging.info('Configuring network for OpenStack undercloud/provider')
        session = mojo_os_utils.get_keystone_session(
            mojo_utils.get_undercloud_auth())
        novac = mojo_os_utils.get_nova_session_client(session)
        neutronc = mojo_os_utils.get_neutron_session_client(session)

        # Add an interface to the neutron-gateway units and tell juju to use it
        # as the external port.
        if 'net_id' in net_info.keys():
            net_id = net_info['net_id']
        else:
            net_id = None

        mojo_os_utils.configure_gateway_ext_port(novac,
                                                 neutronc,
                                                 dvr_mode=net_info.get(
                                                     'dvr_enabled', False),
                                                 net_id=net_id)

    setup_sdn(net_topology, net_info)
Exemple #11
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()
def main(argv):
    logging.basicConfig(level=logging.INFO)
    parser = argparse.ArgumentParser()
    parser.add_argument("term_method", default='juju', nargs='?')
    options = parser.parse_args()
    term_method = mojo_utils.parse_mojo_arg(options, 'term_method')
    services = mojo_utils.get_principle_services()
    for svc in services:
        doomed_service = services.pop(0)
        if mojo_utils.is_crm_clustered(doomed_service):
            mojo_os_utils.delete_crm_leader(doomed_service, method=term_method)
        else:
            mojo_utils.delete_oldest(doomed_service, method=term_method)
        mojo_utils.juju_check_hooks_complete()
        mojo_utils.juju_status_check_and_wait()
        mojo_utils.add_unit(svc, unit_num=1)
        mojo_utils.juju_check_hooks_complete()
        mojo_utils.juju_status_check_and_wait()
Exemple #13
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))
Exemple #14
0
def main(argv):
    logging.basicConfig(level=logging.INFO)
    parser = argparse.ArgumentParser()
    parser.add_argument("units", nargs="*")
    options = parser.parse_args()
    unit_args = mojo_utils.parse_mojo_arg(options, 'units', multiargs=True)
    for unitreq in unit_args:
        if ':' in unitreq:
            service, unitcount = unitreq.split(':')
            units = mojo_utils.get_juju_units(service=service)
            i = 0
            for unit in units:
                if i >= int(unitcount):
                    break
                mojo_utils.delete_unit(unit)
                i = i + 1
        elif '/' in unitreq:
            units = mojo_utils.get_juju_units(service=unitreq.split('/')[0])
            if unitreq in units:
                mojo_utils.delete_unit(unitreq)
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)
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)