Exemplo n.º 1
0
    def get_client_and_attempt_operation(self, ip):
        """Attempt to list users on the openstack-dashboard service.

        This is slightly complicated in that the client is actually a web-site.
        Thus, the test has to login first and then attempt the operation.  This
        makes the test a little more complicated.

        :param ip: the IP address to get the session against.
        :type ip: str
        :raises: PolicydOperationFailedException if operation fails.
        """
        unit = zaza_model.get_unit_from_name(
            zaza_model.get_lead_unit_name(self.application_name))
        logging.info("Dashboard is at {}".format(
            zaza_model.get_unit_public_address(unit)))
        overcloud_auth = openstack_utils.get_overcloud_auth()
        password = overcloud_auth['OS_PASSWORD']
        logging.info("admin password is {}".format(password))
        # try to get the url which will either pass or fail with a 403
        domain = 'admin_domain'
        username = '******'
        client, response = _login(self.get_horizon_url(),
                                  domain,
                                  username,
                                  password,
                                  cafile=self.cacert)
        # now attempt to get the domains page
        _url = self.url.format(zaza_model.get_unit_public_address(unit))
        logging.info("URL is {}".format(_url))
        result = client.get(_url)
        if result.status_code == 403:
            raise policyd.PolicydOperationFailedException("Not authenticated")
Exemplo n.º 2
0
    def _ceph_to_ceph_osd_relation(self, remote_unit_name):
        """Verify the cephX to ceph-osd relation data.

        Helper function to test the relation.
        """
        logging.info('Checking {}:ceph-osd mon relation data...'.
                     format(remote_unit_name))
        unit_name = 'ceph-osd/0'
        relation_name = 'osd'
        remote_unit = zaza_model.get_unit_from_name(remote_unit_name)
        remote_ip = zaza_model.get_unit_public_address(remote_unit)
        cmd = 'leader-get fsid'
        result = zaza_model.run_on_unit(remote_unit_name, cmd)
        fsid = result.get('Stdout').strip()
        expected = {
            'private-address': remote_ip,
            'ceph-public-address': remote_ip,
            'fsid': fsid,
        }
        relation = juju_utils.get_relation_from_unit(
            unit_name,
            remote_unit_name,
            relation_name
        )
        for e_key, e_value in expected.items():
            a_value = relation[e_key]
            self.assertEqual(e_value, a_value)
        self.assertTrue(relation['osd_bootstrap_key'] is not None)
Exemplo n.º 3
0
    def test_200_haproxy_stats_config(self):
        """Verify that the HAProxy stats are properly setup."""
        logging.info('Checking dashboard HAProxy settings...')
        unit = zaza_model.get_unit_from_name(
            zaza_model.get_lead_unit_name(self.application_name))
        logging.debug("... dashboard_ip is:{}".format(
            zaza_model.get_unit_public_address(unit)))
        conf = '/etc/haproxy/haproxy.cfg'
        port = '8888'
        set_alternate = {
            'haproxy-expose-stats': 'True',
        }

        request = urllib.request.Request('http://{}:{}'.format(
            zaza_model.get_unit_public_address(unit), port))

        output = str(generic_utils.get_file_contents(unit, conf))

        password = None
        for line in output.split('\n'):
            if "stats auth" in line:
                password = line.split(':')[1]
                break
        else:
            raise ValueError("'stats auth' not found in output'")
        base64string = base64.b64encode(
            bytes('{}:{}'.format('admin', password), 'ascii'))
        request.add_header("Authorization",
                           "Basic {}".format(base64string.decode('utf-8')))

        # Expect default config to not be available externally.
        expected = 'bind 127.0.0.1:{}'.format(port)
        self.assertIn(expected, output)
        with self.assertRaises(urllib.error.URLError):
            _do_request(request)

        zaza_model.set_application_config(self.application_name, set_alternate)
        zaza_model.block_until_all_units_idle(model_name=self.model_name)

        # Once exposed, expect HAProxy stats to be available externally
        output = str(generic_utils.get_file_contents(unit, conf))
        expected = 'bind 0.0.0.0:{}'.format(port)
        html = _do_request(request).read().decode(encoding='utf-8')
        self.assertIn(expected, output)
        self.assertIn('Statistics Report for HAProxy', html,
                      "HAProxy stats check failed")
Exemplo n.º 4
0
 def test_prometheus_metrics(self):
     """Validate that Prometheus has Ceph metrics."""
     try:
         zaza_model.get_application('prometheus2')
     except KeyError:
         raise unittest.SkipTest('Prometheus not present, skipping test')
     unit = zaza_model.get_unit_from_name(
         zaza_model.get_lead_unit_name('prometheus2'))
     self.assertEqual(
         '3',
         _get_mon_count_from_prometheus(
             zaza_model.get_unit_public_address(unit)))
Exemplo n.º 5
0
 def test_ceph_osd_ceph_relation_address(self):
     """Verify the ceph-osd to ceph relation data."""
     logging.info('Checking ceph-osd:ceph-mon relation data...')
     unit_name = 'ceph-osd/0'
     remote_unit_name = 'ceph-mon/0'
     relation_name = 'osd'
     remote_unit = zaza_model.get_unit_from_name(remote_unit_name)
     remote_ip = zaza_model.get_unit_public_address(remote_unit)
     relation = juju_utils.get_relation_from_unit(unit_name,
                                                  remote_unit_name,
                                                  relation_name)
     # Get private-address in relation
     rel_private_ip = relation.get('private-address')
     # The private address in relation should match ceph-mon/0 address
     self.assertEqual(rel_private_ip, remote_ip)
Exemplo n.º 6
0
def port_knock_units(units, port=22, expect_success=True):
    """Check if specific port is open on units.

    Open a TCP socket to check for a listening sevice on each listed juju unit.
    :param units: list of unit pointers
    :param port: TCP port number, default to 22
    :param timeout: Connect timeout, default to 15 seconds
    :expect_success: True by default, set False to invert logic
    :returns: None if successful, Failure message otherwise
    """
    for u in units:
        host = model.get_unit_public_address(u)
        connected = is_port_open(port, host)
        if not connected and expect_success:
            return 'Socket connect failed.'
        elif connected and not expect_success:
            return 'Socket connected unexpectedly.'
Exemplo n.º 7
0
    def get_base_url(self):
        """Return the base url for http(s) requests.

        :returns: URL
        :rtype: str
        """
        vip = (zaza_model.get_application_config(
            self.application_name).get("vip").get("value"))
        if vip:
            ip = vip
        else:
            unit = zaza_model.get_unit_from_name(
                zaza_model.get_lead_unit_name(self.application_name))
            ip = zaza_model.get_unit_public_address(unit)

        logging.debug("Dashboard ip is:{}".format(ip))
        scheme = 'http'
        if self.use_https:
            scheme = 'https'
        url = '{}://{}'.format(scheme, ip)
        return url
Exemplo n.º 8
0
def get_application_ip(application, model_name=None):
    """Get the application's IP address.

    :param application: Application name
    :type application: str
    :param model_name: Name of model to query.
    :type model_name: str
    :returns: Application's IP address
    :rtype: str
    """
    try:
        app_config = model.get_application_config(application,
                                                  model_name=model_name)
    except KeyError:
        return ''
    vip = app_config.get("vip", {}).get("value")
    if vip:
        ip = vip
    else:
        unit = model.get_units(application, model_name=model_name)[0]
        ip = model.get_unit_public_address(unit)
    return ip