示例#1
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 = remote_unit.public_address
        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 = zaza_juju.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)
示例#2
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(unit.public_address))
        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
        overcloud_auth = openstack_utils.get_overcloud_auth()
        domain = 'admin_domain',
        username = '******',
        password = overcloud_auth['OS_PASSWORD'],
        client, response = _login(self.get_horizon_url(), domain, username,
                                  password)
        # now attempt to get the domains page
        _url = self.url.format(unit.public_address)
        result = client.get(_url)
        if result.status_code == 403:
            raise policyd.PolicydOperationFailedException("Not authenticated")
示例#3
0
    def test_404_connection(self):
        """Verify the apache status module gets disabled when hardening apache.

        Ported from amulet tests.
        """
        logging.info('Checking apache mod_status gets disabled.')

        unit = zaza_model.get_unit_from_name(
            zaza_model.get_lead_unit_name(self.application_name))
        logging.debug("... dashboard_ip is: {}".format(unit.public_address))

        logging.debug('Maybe enabling hardening for apache...')
        _app_config = zaza_model.get_application_config(self.application_name)
        logging.info(_app_config['harden'])

        request = urllib.request.Request('http://{}/server-status'.format(
            unit.public_address))
        with self.config_change(
            {'harden': _app_config['harden'].get('value', '')},
            {'harden': 'apache'}):
            try:
                _do_request(request)
            except urllib.request.HTTPError as e:
                # test failed if it didn't return 404
                msg = "Apache mod_status check failed."
                self.assertEqual(e.code, 404, msg)
        logging.info('OK')
示例#4
0
    def test_get_unit_from_name(self):
        self.patch_object(model, 'get_juju_model', return_value='mname')
        self.patch_object(model, 'Model')
        self.Model.return_value = self.Model_mock
        # Normal case
        self.assertEqual(
            model.get_unit_from_name('app/4', model_name='mname'),
            self.unit2)

        # Normal case with Model()
        self.assertEqual(
            model.get_unit_from_name('app/4', self.mymodel),
            self.unit2)

        # Normal case, using default
        self.assertEqual(
            model.get_unit_from_name('app/4'),
            self.unit2)

        # Unit does not exist
        with self.assertRaises(model.UnitNotFound):
            model.get_unit_from_name('app/10', model_name='mname')

        # Application does not exist
        with self.assertRaises(model.UnitNotFound):
            model.get_unit_from_name('bad_name', model_name='mname')
示例#5
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(unit.public_address))
示例#6
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 = remote_unit.public_address
     relation = zaza_juju.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)
示例#7
0
    def test_401_authenticate(self):
        """Validate that authentication succeeds for client log in."""
        logging.info('Checking authentication through dashboard...')

        unit = zaza_model.get_unit_from_name(
            zaza_model.get_lead_unit_name(self.application_name))
        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
        overcloud_auth = openstack_utils.get_overcloud_auth()
        domain = 'admin_domain',
        username = '******',
        password = overcloud_auth['OS_PASSWORD'],
        _login(unit.public_address, domain, username, password)
        logging.info('OK')
示例#8
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")
示例#9
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 = unit.public_address

        logging.debug("Dashboard ip is:{}".format(ip))
        scheme = 'http'
        if self.use_https:
            scheme = 'https'
        url = '{}://{}'.format(scheme, ip)
        return url
示例#10
0
def systemctl(unit, service, command="restart"):
    """Run systemctl command on a unit.

    :param unit: Unit object or unit name
    :type unit: Union[Unit,string]
    :param service: Name of service to act on
    :type service: string
    :param command: Name of command. i.e. start, stop, restart
    :type command: string
    :raises: AssertionError if the command is unsuccessful
    :returns: None if successful
    """
    cmd = "/bin/systemctl {} {}".format(command, service)

    # Check if this is a unit object or string name of a unit
    try:
        unit.entity_id
    except AttributeError:
        unit = model.get_unit_from_name(unit)

    result = model.run_on_unit(unit.entity_id, cmd)
    assert int(result['Code']) == 0, ("{} of {} on {} failed".format(
        command, service, unit.entity_id))
示例#11
0
    def test_400_connection(self):
        """Test that dashboard responds to http request.

        Ported from amulet tests.
        """
        logging.info('Checking dashboard http response...')

        unit = zaza_model.get_unit_from_name(
            zaza_model.get_lead_unit_name(self.application_name))
        logging.debug("... dashboard_ip is:{}".format(unit.public_address))

        request = urllib.request.Request('http://{}/horizon'.format(
            unit.public_address))
        try:
            logging.info("... trying to fetch the page")
            html = _do_request(request)
            logging.info("... fetched page")
        except Exception as e:
            logging.info("... exception raised was {}".format(str(e)))
            raise
        return html.read().decode('utf-8')
        self.assertIn('OpenStack Dashboard', html,
                      "Dashboard frontpage check failed")
示例#12
0
 def test_get_unit_from_name(self):
     self.assertEqual(model.get_unit_from_name('app/4', self.mymodel),
                      self.unit2)