def setup_ceph_proxy():
    """
    Configure ceph proxy with ceph metadata.

    Fetches admin_keyring and FSID from ceph-mon and
    uses those to configure ceph-proxy.
    """
    raw_admin_keyring = model.run_on_leader(
        "ceph-mon", 'cat /etc/ceph/ceph.client.admin.keyring')["Stdout"]
    admin_keyring = [
        line for line in raw_admin_keyring.split("\n") if "key" in line
    ][0].split(' = ')[-1].rstrip()
    fsid = model.run_on_leader("ceph-mon", "leader-get fsid")["Stdout"]
    cluster_ips = model.get_app_ips("ceph-mon")

    proxy_config = {
        'auth-supported': 'cephx',
        'admin-key': admin_keyring,
        'fsid': fsid,
        'monitor-hosts': ' '.join(cluster_ips)
    }

    logging.debug('Config: {}'.format(proxy_config))

    model.set_application_config("ceph-proxy", proxy_config)
Exemple #2
0
    def test_cephfs_share(self):
        """Test that CephFS shares can be accessed on two instances.

        1. Spawn two servers
        2. mount it on both
        3. write a file on one
        4. read it on the other
        5. profit
        """
        keyring = model.run_on_leader(
            'ceph-mon', 'cat /etc/ceph/ceph.client.admin.keyring')['Stdout']
        conf = model.run_on_leader('ceph-mon',
                                   'cat /etc/ceph/ceph.conf')['Stdout']
        # Spawn Servers
        instance_1, instance_2 = self.launch_guests(
            userdata=self.INSTANCE_USERDATA.format(_indent(conf, 8),
                                                   _indent(keyring, 8)))

        # Write a file on instance_1
        def verify_setup(stdin, stdout, stderr):
            status = stdout.channel.recv_exit_status()
            self.assertEqual(status, 0)

        fip_1 = neutron_tests.floating_ips_from_instance(instance_1)[0]
        fip_2 = neutron_tests.floating_ips_from_instance(instance_2)[0]
        username = guest.boot_tests['bionic']['username']
        password = guest.boot_tests['bionic'].get('password')
        privkey = openstack_utils.get_private_key(nova_utils.KEYPAIR_NAME)

        for attempt in Retrying(stop=stop_after_attempt(3),
                                wait=wait_exponential(multiplier=1,
                                                      min=2,
                                                      max=10)):
            with attempt:
                openstack_utils.ssh_command(
                    username,
                    fip_1,
                    'instance-1', 'sudo mount -a && '
                    'echo "test" | sudo tee /mnt/cephfs/test',
                    password=password,
                    privkey=privkey,
                    verify=verify_setup)

        def verify(stdin, stdout, stderr):
            status = stdout.channel.recv_exit_status()
            self.assertEqual(status, 0)
            out = ""
            for line in iter(stdout.readline, ""):
                out += line
            self.assertEqual(out, "test\n")

        openstack_utils.ssh_command(username,
                                    fip_2,
                                    'instance-2', 'sudo mount -a && '
                                    'sudo cat /mnt/cephfs/test',
                                    password=password,
                                    privkey=privkey,
                                    verify=verify)
Exemple #3
0
def get_ceph_pool_details(query_leader=True, unit_name=None, model_name=None):
    """Get ceph pool details.

    Return a list of ceph pools details dicts.

    :param query_leader: Whether to query the leader for pool details.
    :type query_leader: bool
    :param unit_name: Name of unit to get the pools on if query_leader is False
    :type unit_name: string
    :param model_name: Name of model to operate in
    :type model_name: str
    :returns: Dict of ceph pools
    :rtype: List[Dict,]
    :raise: zaza_model.CommandRunFailed
    """
    cmd = 'sudo ceph osd pool ls detail -f json'
    if query_leader and unit_name:
        raise ValueError("Cannot set query_leader and unit_name")
    if query_leader:
        result = zaza_model.run_on_leader(
            'ceph-mon',
            cmd,
            model_name=model_name)
    else:
        result = zaza_model.run_on_unit(
            unit_name,
            cmd,
            model_name=model_name)
    if int(result.get('Code')) != 0:
        raise zaza_model.CommandRunFailed(cmd, result)
    return json.loads(result.get('Stdout'))
    def test_ceph_health(self):
        """Make sure ceph-proxy can communicate with ceph."""
        logging.info('Wait for idle/ready status...')
        zaza_model.wait_for_application_states()

        self.assertEqual(
            zaza_model.run_on_leader("ceph-proxy", "sudo ceph health")["Code"],
            "0")
Exemple #5
0
 def test_run_on_leader(self):
     self.patch_object(model, 'get_juju_model', return_value='mname')
     expected = {'Code': '0', 'Stderr': '', 'Stdout': 'RESULT'}
     self.cmd = cmd = 'somecommand someargument'
     self.patch_object(model, 'Model')
     self.Model.return_value = self.Model_mock
     self.assertEqual(model.run_on_leader('app', cmd), expected)
     self.unit2.run.assert_called_once_with(cmd, timeout=None)
Exemple #6
0
def setup_ceph_proxy():
    raw_admin_keyring = model.run_on_leader(
        "ceph-mon", 'cat /etc/ceph/ceph.client.admin.keyring')["Stdout"]
    admin_keyring = raw_admin_keyring.split(' = ')[-1].rstrip()
    fsid = model.run_on_leader("ceph-mon", "leader-get fsid")["Stdout"]
    cluster_ips = model.get_app_ips("ceph-mon")

    proxy_config = {
        'auth-supported': 'cephx',
        'admin-key': admin_keyring,
        'fsid': fsid,
        'monitor-hosts': ' '.join(cluster_ips)
    }

    logging.debug('Config: {}'.format(proxy_config))

    model.set_application_config("ceph-proxy", proxy_config)
Exemple #7
0
def configure_external_s3_backend():
    """Set up Ceph-radosgw as an external S3 backend for Glance."""
    logging.info("Creating a test S3 user and credentials for Glance")
    username, displayname = "zaza-glance-test", "Zaza Glance Test User"
    cmd = "radosgw-admin user create --uid='{}' --display-name='{}'".format(
        username, displayname)
    results = model.run_on_leader("ceph-mon", cmd)
    stdout = json.loads(results["stdout"])
    keys = stdout["keys"][0]
    access_key, secret_key = keys["access_key"], keys["secret_key"]

    logging.info("Getting S3 endpoint URL of Radosgw from Keystone")
    keystone_auth = openstack_utils.get_overcloud_auth()
    keystone_client = openstack_utils.get_keystone_client(keystone_auth)
    endpoint_url = keystone_client.session.get_endpoint(
        service_type="s3",
        interface="public",
        region="RegionOne",
    )

    logging.info("Creating a test S3 bucket for Glance")
    bucket_name = "zaza-glance-s3-test"
    s3_client = boto3.client(
        "s3",
        endpoint_url=endpoint_url,
        aws_access_key_id=access_key,
        aws_secret_access_key=secret_key,
    )
    s3_client.create_bucket(Bucket=bucket_name)

    logging.info("Updating Glance configs with S3 endpoint information")
    model.set_application_config(
        "glance",
        {
            "s3-store-host": endpoint_url,
            "s3-store-access-key": access_key,
            "s3-store-secret-key": secret_key,
            "s3-store-bucket": bucket_name,
        },
    )
    model.wait_for_agent_status()

    logging.info("Waiting for units to reach target states")
    model.wait_for_application_states(
        states={
            "glance": {
                "workload-status": "active",
                "workload-status-message": "Unit is ready",
            }
        })
    model.block_until_all_units_idle()
Exemple #8
0
def leader_get(application, key=''):
    """Get leader settings from leader unit of named application.

    :param application: Application to get leader settings from.
    :type application: str
    :returns: dict with leader settings
    :rtype: dict
    :raises: model.CommandRunFailed
    """
    cmd = 'leader-get --format=yaml {}'.format(key)
    result = model.run_on_leader(application, cmd)
    if result and int(result.get('Code')) == 0:
        return yaml.safe_load(result.get('Stdout'))
    else:
        raise model.CommandRunFailed(cmd, result)
Exemple #9
0
def leader_get(application, key='', model_name=None):
    """Get leader settings from leader unit of named application.

    :param application: Application to get leader settings from.
    :type application: str
    :param key: Key option requested
    :type key: string
    :param model_name: Name of model to query.
    :type model_name: str
    :returns: dict with leader settings
    :rtype: dict
    :raises: model.CommandRunFailed
    """
    cmd = 'leader-get --format=yaml {}'.format(key)
    result = model.run_on_leader(application, cmd, model_name=model_name)
    if result and int(result.get('Code')) == 0:
        return yaml.safe_load(result.get('Stdout'))
    else:
        raise model.CommandRunFailed(cmd, result)
 def test_schema_registry_deployment(self):
     first_unit = model.get_units('confluent-schema-registry')[0]
     result = model.run_on_leader('ubuntu', 'lsb_release -cs')
     self.assertEqual(result['Code'], '0')
     self.assertEqual(result['Stdout'].strip(), first_unit.series)
 def test_kafka_deployment(self):
     first_unit = model.get_units('kafka')[0]
     result = model.run_on_leader('ubuntu', 'lsb_release -cs')
     self.assertEqual(result['Code'], '0')
     self.assertEqual(result['Stdout'].strip(), first_unit.series)
Exemple #12
0
 def test_ceph_health(self):
     """Make sure ceph-proxy can communicate with ceph."""
     self.assertEqual(
         zaza_model.run_on_leader("ceph-proxy", "sudo ceph health")["Code"],
         "0")