예제 #1
0
def get_cloud_configs(cloud=None):
    """Get cloud configuration from local clouds.yaml.

    libjuju does not yet have cloud information implemented.
    Use libjuju as soon as possible.

    :param cloud: Name of specific cloud
    :type remote_cmd: string
    :returns: Dictionary of cloud configuration
    :rtype: dict
    """
    home = str(Path.home())
    cloud_config = os.path.join(home, ".local", "share", "juju", "clouds.yaml")
    if cloud:
        return generic_utils.get_yaml_config(cloud_config)["clouds"].get(cloud)
    else:
        return generic_utils.get_yaml_config(cloud_config)
예제 #2
0
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')
    series = os.environ.get("MOJO_SERIES")
    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')
        if series == "xenial":
            logging.info(
                "Concluding tests as rebooting a xenial guest can cause "
                "network interfaces to be renamed which breaks the "
                "gateway")
            return
    def test_get_yaml_config(self):
        self.patch("builtins.open",
                   new_callable=mock.mock_open(),
                   name="_open")
        _yaml = "data: somedata"
        _yaml_dict = {"data": "somedata"}
        _filename = "filename"
        _fileobj = mock.MagicMock()
        _fileobj.read.return_value = _yaml
        self._open.return_value = _fileobj

        self.assertEqual(generic_utils.get_yaml_config(_filename), _yaml_dict)
        self._open.assert_called_once_with(_filename, "r")
예제 #4
0
def main(argv):
    # Tempest expects an admin project in the admin domain that the admin user
    # has admin role on so make sure that exists (pre-17.02)
    keystone_v3_domain_setup()

    results_file = mojo_utils.get_mojo_file('tempest_expected_results.yaml')
    expected_results = generic_utils.get_yaml_config(results_file)['smoke']
    action = model.run_action_on_leader('tempest',
                                        'run-tempest',
                                        action_params={})
    logging.debug(action.message)
    actual_results = action.data['results']

    result_matrix = {
        'failed': {
            'on_more': raise_tempest_fail,
            'on_less': report_success
        },
        'skipped': {
            'on_more': warn,
            'on_less': report_success
        },
        'expected-fail': {
            'on_more': raise_tempest_fail,
            'on_less': report_success
        },
        'unexpected-success': {
            'on_more': report_success,
            'on_less': warn
        },
        'passed': {
            'on_more': report_success,
            'on_less': raise_tempest_fail
        }
    }

    for result_type, expected in expected_results.items():
        actual = actual_results[result_type]
        msg = "Number of tests {} was {} expected {}".format(
            result_type, actual, expected)
        if int(actual) > expected:
            result_matrix[result_type]['on_more'](msg)
        elif int(actual) == expected:
            report_success(msg)
        else:
            result_matrix[result_type]['on_less'](msg)
예제 #5
0
def boot_and_test(nova_client,
                  neutron_client,
                  image_name,
                  flavor_name,
                  number,
                  privkey,
                  active_wait=600,
                  cloudinit_wait=600,
                  ping_wait=600,
                  boot_from_volume=False):
    image_file = mojo_utils.get_mojo_file('images.yaml')
    image_config = generic_utils.get_yaml_config(image_file)
    for counter in range(int(number)):
        logging.info("Launching instance")
        instance = boot_instance(
            nova_client,
            neutron_client,
            image_name=image_name,
            flavor_name=flavor_name,
            key_name='mojo',
            boot_from_volume=boot_from_volume,
        )
        logging.info("Launched {}".format(instance))
        wait_for_boot(nova_client, instance.name,
                      image_config[image_name]['bootstring'], active_wait,
                      cloudinit_wait)
        ip = assign_floating_ip(nova_client, neutron_client, instance.name)
        wait_for_ping(ip, ping_wait)
        if not wait_for_ping(ip, ping_wait):
            raise Exception('Ping of %s failed' % (ip))
        ssh_test_args = {
            'username': image_config[image_name]['username'],
            'ip': ip,
            'vm_name': instance.name,
        }
        if image_config[image_name]['auth_type'] == 'password':
            ssh_test_args['password'] = image_config[image_name]['password']
        elif image_config[image_name]['auth_type'] == 'privkey':
            ssh_test_args['privkey'] = privkey
        if not ssh_test(**ssh_test_args):
            raise Exception('SSH failed to instance at %s' % (ip))