From cf04bbfc7dec010bac9e08126d3b176594ea47ed Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Thu, 20 Aug 2020 11:02:07 -0500 Subject: [PATCH 1/6] move new test in separate class --- zaza/openstack/charm_tests/gnocchi/tests.py | 56 +++++++++++---------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index e3b9ae1..808f374 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -65,32 +65,8 @@ class GnocchiTest(test_utils.OpenStackBaseTest): logging.info("Testing pause and resume") -class GnocchiS3Test(test_utils.OpenStackBaseTest): - """Test Gnocchi for S3 storage backend.""" - - @classmethod - def setUpClass(cls): - """Run class setup for running tests.""" - super(GnocchiS3Test, cls).setUpClass() - - session = openstack_utils.get_overcloud_keystone_session() - ks_client = openstack_utils.get_keystone_session_client(session) - - # Get token data so we can glean our user_id and project_id - token_data = ks_client.tokens.get_token_data(session.get_token()) - project_id = token_data['token']['project']['id'] - user_id = token_data['token']['user']['id'] - - # Store URL to service providing S3 compatible API - for entry in token_data['token']['catalog']: - if entry['type'] == 's3': - for endpoint in entry['endpoints']: - if endpoint['interface'] == 'public': - cls.s3_region = endpoint['region'] - cls.s3_endpoint = endpoint['url'] - - # Create AWS compatible application credentials in Keystone - cls.ec2_creds = ks_client.ec2.create(user_id, project_id) +class GnocchiExternalCATest(test_utils.OpenStackBaseTest): + """Test Gnocchi for external root CA config option.""" def test_upload_external_cert(self): """Verify that the external CA is uploaded correctly.""" @@ -123,6 +99,34 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): result = model.run_on_unit('gnocchi/0', cmd) self.assertEqual(result['Code'], '0') + +class GnocchiS3Test(test_utils.OpenStackBaseTest): + """Test Gnocchi for S3 storage backend.""" + + @classmethod + def setUpClass(cls): + """Run class setup for running tests.""" + super(GnocchiS3Test, cls).setUpClass() + + session = openstack_utils.get_overcloud_keystone_session() + ks_client = openstack_utils.get_keystone_session_client(session) + + # Get token data so we can glean our user_id and project_id + token_data = ks_client.tokens.get_token_data(session.get_token()) + project_id = token_data['token']['project']['id'] + user_id = token_data['token']['user']['id'] + + # Store URL to service providing S3 compatible API + for entry in token_data['token']['catalog']: + if entry['type'] == 's3': + for endpoint in entry['endpoints']: + if endpoint['interface'] == 'public': + cls.s3_region = endpoint['region'] + cls.s3_endpoint = endpoint['url'] + + # Create AWS compatible application credentials in Keystone + cls.ec2_creds = ks_client.ec2.create(user_id, project_id) + def test_s3_list_gnocchi_buckets(self): """Verify that the gnocchi buckets were created in the S3 backend.""" kwargs = { From 6d0a59802bd676f4b8565bc005dc94c6cc97ed57 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Thu, 20 Aug 2020 11:35:38 -0500 Subject: [PATCH 2/6] fix merge conflict --- zaza/openstack/charm_tests/gnocchi/tests.py | 73 ++++++++++----------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 808f374..5147486 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -16,15 +16,12 @@ """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 @@ -65,41 +62,6 @@ class GnocchiTest(test_utils.OpenStackBaseTest): logging.info("Testing pause and resume") -class GnocchiExternalCATest(test_utils.OpenStackBaseTest): - """Test Gnocchi for external root CA config option.""" - - 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() - - 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') - - linked_cert_location = '/etc/ssl/certs' - linked_cert_name = 'gnocchi-external.pem' - cmd = 'ls ' + linked_cert_location + '/' + linked_cert_name - logging.info("Validating that the link {} is created in \ - {}".format(linked_cert_name, linked_cert_location)) - result = model.run_on_unit('gnocchi/0', cmd) - self.assertEqual(result['Code'], '0') - - class GnocchiS3Test(test_utils.OpenStackBaseTest): """Test Gnocchi for S3 storage backend.""" @@ -148,3 +110,38 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): break else: AssertionError('Bucket "{}" not found'.format(gnocchi_bkt)) + + +class GnocchiExternalCATest(test_utils.OpenStackBaseTest): + """Test Gnocchi for external root CA config option.""" + + 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() + + 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') + + linked_cert_location = '/etc/ssl/certs' + linked_cert_name = 'gnocchi-external.pem' + cmd = 'ls ' + linked_cert_location + '/' + linked_cert_name + logging.info("Validating that the link {} is created in \ + {}".format(linked_cert_name, linked_cert_location)) + result = model.run_on_unit('gnocchi/0', cmd) + self.assertEqual(result['Code'], '0') \ No newline at end of file From 1dc8ee4287f3d7237f4478f699deac216be707fc Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Thu, 20 Aug 2020 11:37:03 -0500 Subject: [PATCH 3/6] add imports --- zaza/openstack/charm_tests/gnocchi/tests.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 5147486..7bd4523 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -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 @@ -144,4 +147,4 @@ class GnocchiExternalCATest(test_utils.OpenStackBaseTest): logging.info("Validating that the link {} is created in \ {}".format(linked_cert_name, linked_cert_location)) result = model.run_on_unit('gnocchi/0', cmd) - self.assertEqual(result['Code'], '0') \ No newline at end of file + self.assertEqual(result['Code'], '0') From 28de49811e556c3963206929d30d4c5c686e2950 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Thu, 20 Aug 2020 13:47:12 -0500 Subject: [PATCH 4/6] test block function instead of ls --- zaza/openstack/charm_tests/gnocchi/tests.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 7bd4523..73c32a9 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -133,13 +133,15 @@ class GnocchiExternalCATest(test_utils.OpenStackBaseTest): ) model.block_until_all_units_idle() - 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') + # 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) + remote_file = '/usr/local/share/ca-certificates/gnocchi-external.crt' + result = model.block_until_file_ready('gnocchi', remote_file, b64_cert) + self.assertTrue(result) linked_cert_location = '/etc/ssl/certs' linked_cert_name = 'gnocchi-external.pem' From cece0d3096fff512303c23de10f611e1e27be768 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Thu, 20 Aug 2020 13:47:12 -0500 Subject: [PATCH 5/6] test block function instead of ls --- zaza/openstack/charm_tests/gnocchi/tests.py | 36 ++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 7bd4523..b099fa6 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -76,7 +76,7 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): session = openstack_utils.get_overcloud_keystone_session() ks_client = openstack_utils.get_keystone_session_client(session) - # Get token data so we can glean our user_id and project_id + # Get token data so we can clean our user_id and project_id token_data = ks_client.tokens.get_token_data(session.get_token()) project_id = token_data['token']['project']['id'] user_id = token_data['token']['user']['id'] @@ -133,18 +133,24 @@ class GnocchiExternalCATest(test_utils.OpenStackBaseTest): ) model.block_until_all_units_idle() - 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') + # 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) + remote_file = '/usr/local/share/ca-certificates/gnocchi-external.crt' + logging.info("Validating that {} is created.".format(remote_file)) + result = model.block_until_file_ready('gnocchi', remote_file, b64_cert) + self.assertTrue(result) - linked_cert_location = '/etc/ssl/certs' - linked_cert_name = 'gnocchi-external.pem' - cmd = 'ls ' + linked_cert_location + '/' + linked_cert_name - logging.info("Validating that the link {} is created in \ - {}".format(linked_cert_name, linked_cert_location)) - result = model.run_on_unit('gnocchi/0', cmd) - self.assertEqual(result['Code'], '0') + # linked_cert_location = '/etc/ssl/certs' + # linked_cert_name = 'gnocchi-external.pem' + # cmd = 'ls ' + linked_cert_location + '/' + linked_cert_name + # logging.info("Validating that the link {} is created in \ + # {}".format(linked_cert_name, linked_cert_location)) + # result = model.run_on_unit('gnocchi/0', cmd) + remote_linked_file = '/etc/ssl/certs/gnocchi-external.pem' + result = model.block_until_file_ready('gnocchi', remote_linked_file, b64_cert) + # self.assertEqual(result['Code'], '0') + self.assertTrue(result) From 6b822ee8ecec179ad5d888666d79f2decbc48172 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Thu, 20 Aug 2020 16:03:04 -0500 Subject: [PATCH 6/6] replace ls with file_has_contents --- zaza/openstack/charm_tests/gnocchi/tests.py | 28 ++++++--------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index b099fa6..ed4bac0 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -133,24 +133,12 @@ class GnocchiExternalCATest(test_utils.OpenStackBaseTest): ) model.block_until_all_units_idle() - # 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) - remote_file = '/usr/local/share/ca-certificates/gnocchi-external.crt' - logging.info("Validating that {} is created.".format(remote_file)) - result = model.block_until_file_ready('gnocchi', remote_file, b64_cert) - self.assertTrue(result) + files = [ + '/usr/local/share/ca-certificates/gnocchi-external.crt', + '/etc/ssl/certs/gnocchi-external.pem', + ] - # linked_cert_location = '/etc/ssl/certs' - # linked_cert_name = 'gnocchi-external.pem' - # cmd = 'ls ' + linked_cert_location + '/' + linked_cert_name - # logging.info("Validating that the link {} is created in \ - # {}".format(linked_cert_name, linked_cert_location)) - # result = model.run_on_unit('gnocchi/0', cmd) - remote_linked_file = '/etc/ssl/certs/gnocchi-external.pem' - result = model.block_until_file_ready('gnocchi', remote_linked_file, b64_cert) - # self.assertEqual(result['Code'], '0') - self.assertTrue(result) + for file in files: + logging.info("Validating that {} is created.".format(file)) + model.block_until_file_has_contents('gnocchi', file, 'CERTIFICATE') + logging.info("Found {} successfully.".format(file))