add test for external cert config option for gnocchi

This commit is contained in:
camille.rodriguez
2020-08-17 17:32:22 -05:00
parent 2c18d0f471
commit 3343582ddd
4 changed files with 38 additions and 147 deletions

View File

@@ -16,12 +16,15 @@
"""Encapsulate Gnocchi testing."""
import base64
import boto3
import logging
import pprint
from gnocchiclient.v1 import client as gnocchi_client
import zaza.model as model
import zaza.openstack.charm_tests.test_utils as test_utils
import zaza.openstack.utilities as utilities
import zaza.openstack.utilities.openstack as openstack_utils
@@ -89,6 +92,41 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest):
# Create AWS compatible application credentials in Keystone
cls.ec2_creds = ks_client.ec2.create(user_id, project_id)
def test_upload_external_cert(self):
"""Verify that the external CA is uploaded correctly."""
logging.info('Changing value for trusted-external-ca-cert.')
ca_cert_option = 'trusted-external-ca-cert'
ppk, cert = utilities.cert.generate_cert('gnocchi_test.ci.local')
b64_cert = base64.b64encode(cert).decode()
config = {
ca_cert_option: b64_cert,
}
model.set_application_config(
'gnocchi',
config
)
model.block_until_all_units_idle()
def test_validate_cert_location(self):
"""Validate that the cert is correctly uploaded to the unit."""
cert_location = '/usr/local/share/ca-certificates'
cert_name = 'gnocchi-external.crt'
cmd = 'ls ' + cert_location + '/' + cert_name
logging.info("Validating that the file {} is created in \
{}".format(cert_name, cert_location))
result = model.run_on_unit('gnocchi/0', cmd)
self.assertEqual(result['Code'], '0')
def test_validate_update_ca_certificates(self):
"""Validate that /usr/sbin/update-ca-certificates ran successfully."""
linked_cert_location = '/etc/ssl/certs'
cert_name = 'gnocchi-external.pem'
cmd = 'ls ' + linked_cert_location + '/' + cert_name
logging.info("Validating that the link {} is created in \
{}".format(cert_name, linked_cert_location))
result = model.run_on_unit('gnocchi/0', cmd)
self.assertEqual(result['Code'], '0')
def test_s3_list_gnocchi_buckets(self):
"""Verify that the gnocchi buckets were created in the S3 backend."""
kwargs = {

View File

@@ -1,15 +0,0 @@
# Copyright 2020 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Collection of code for setting up and testing iscsi-connector charm."""

View File

@@ -1,60 +0,0 @@
# Copyright 2020 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Code for setting up iscsi-connector tests."""
import logging
import zaza.model
def basic_target_setup():
"""Run basic setup for iscsi guest."""
logging.info('Installing package tgt on ubuntu-target')
unit = zaza.model.get_units('ubuntu-target')[0]
setup_cmds = [
"apt install --yes tgt",
"systemctl start tgt",
"open-port 3260"]
for cmd in setup_cmds:
zaza.model.run_on_unit(
unit.entity_id,
cmd)
def configure_iscsi_target():
"""Configure the iscsi target."""
lun = 'iqn.2020-07.canonical.com:lun1'
backing_store = 'dev/vdb'
initiator_address = zaza.model.get_app_ips('ubuntu')[0]
username = 'iscsi-user'
password = 'password123'
username_in = 'iscsi-target'
password_in = 'secretpass'
write_file = (
"""echo -e '<target {}>\n\tbacking-store {}\n\tinitiator-address """
"""{}\n\tincominguser {} {}\n\toutgoinguser {} {}\n</target>' """
""" | sudo tee /etc/tgt/conf.d/iscsi.conf""".format(lun,
backing_store,
initiator_address,
username,
password,
username_in,
password_in)
)
logging.info('Writing target iscsi.conf')
zaza.model.run_on_unit('ubuntu-target/0', write_file)
# Restart tgt to load new config
restart_tgt = "systemctl restart tgt"
zaza.model.run_on_unit('ubuntu-target/0', restart_tgt)

View File

@@ -1,72 +0,0 @@
# Copyright 2020 Canonical Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Encapsulate iscsi-connector testing."""
import json
import logging
import zaza.model
import zaza.openstack.charm_tests.test_utils as test_utils
class ISCSIConnectorTest(test_utils.BaseCharmTest):
"""Class for iscsi-connector tests."""
@classmethod
def setUpClass(cls):
"""Run class setup for running glance tests."""
super(ISCSIConnectorTest, cls).setUpClass()
def configure_iscsi_connector(self):
"""Configure iscsi connector."""
iqn = 'iqn.2020-07.canonical.com:lun1'
unit_fqdn = self.get_unit_full_hostname('ubuntu')
target_ip = zaza.model.get_app_ips('ubuntu-target')[0]
initiator_dictionary = json.dumps({unit_fqdn: iqn})
conf = {
'initiator-dictionary': initiator_dictionary,
'target': target_ip,
'port': '3260',
'iscsi-node-session-auth-authmethod': 'CHAP',
'iscsi-node-session-auth-username': 'iscsi-user',
'iscsi-node-session-auth-password': 'password123',
'iscsi-node-session-auth-username-in': 'iscsi-target',
'iscsi-node-session-auth-password-in': 'secretpass',
}
zaza.model.set_application_config('iscsi-connector', conf)
def get_unit_full_hostname(self, unit_name):
"""Retrieve the full hostname of a unit."""
for unit in zaza.model.get_units(unit_name):
result = zaza.model.run_on_unit(unit.entity_id, 'hostname -f')
hostname = result['Stdout'].rstrip()
return hostname
def test_iscsi_connector(self):
"""Test iscsi configuration and wait for idle status."""
self.configure_iscsi_connector()
logging.info('Wait for idle/ready status...')
zaza.model.wait_for_application_states()
def test_validate_iscsi_session(self):
"""Validate that the iscsi session is active."""
unit = zaza.model.get_units('ubuntu')[0]
logging.info('Checking if iscsi session is active.')
run = zaza.model.run_on_unit(unit.entity_id, 'iscsiadm -m session')
logging.info("""iscsiadm -m session: Stdout: {}, Stderr: {}, """
"""Code: {}""".format(run['Stdout'],
run['Stderr'],
run['Code']))
assert run['Code'] == '0'