From 06ed9eecf02aaeeb4166d3b7b042e030beaa2f0b Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Tue, 16 Jun 2020 17:01:05 -0500 Subject: [PATCH 01/23] Add gnocchi s3 test --- zaza/openstack/charm_tests/gnocchi/tests.py | 42 ++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index f789cff..269851f 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -16,11 +16,14 @@ """Encapsulate Gnocchi testing.""" +import boto3 import logging - 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.openstack as openstack_utils +from zaza.openstack.charm_tests.swift.tests import S3APITest class GnocchiTest(test_utils.OpenStackBaseTest): @@ -58,3 +61,40 @@ class GnocchiTest(test_utils.OpenStackBaseTest): """ with self.pause_resume(self.services): logging.info("Testing pause and resume") + + +class GnocchiS3Test(test_utils.OpenStackBaseTest): + """Tests for S3 storage backend""" + + swift = S3APITest + kwargs = { + 'region_name': swift.s3_region, + 'aws_access_key_id': swift.ec2_creds.access, + 'aws_secret_access_key': swift.ec2_creds.secret, + 'endpoint_url': swift.s3_endpoint, + 'verify': swift.cacert, + } + + def update_gnocchi_config_for_s3(self): + """Update Gnocchi with the correct values for the S3 backend""" + logging.debug('Changing charm setting to connect to S3') + model.set_application_config( + 'gnocchi', + {'s3-endpoint-url': self.swift.s3_endpoint, + 's3-region-name': self.swift.s3_region, + 's3-access-key-id': self.swift.ec2_creds.access, + 's3-secret-access-key': self.swift.ec2_creds.secret}, + model_name=self.model_name + ) + logging.debug( + 'Waiting for units to execute config-changed hook') + model.wait_for_agent_status(model_name=self.model_name) + logging.debug( + 'Waiting for units to reach target states') + model.wait_for_application_states( + model_name=self.model_name, + states={'gnocchi': { + 'workload-status-': 'active', + 'workload-status-message': 'Unit is ready'}} + ) + model.block_until_all_units_idle() \ No newline at end of file From e66ef5ac6c039d2687326d669726c001766da65b Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Tue, 16 Jun 2020 17:38:59 -0500 Subject: [PATCH 02/23] Get S3 info --- zaza/openstack/charm_tests/gnocchi/tests.py | 50 +++++++++++++++------ 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 269851f..6148675 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -66,24 +66,48 @@ class GnocchiTest(test_utils.OpenStackBaseTest): class GnocchiS3Test(test_utils.OpenStackBaseTest): """Tests for S3 storage backend""" - swift = S3APITest - kwargs = { - 'region_name': swift.s3_region, - 'aws_access_key_id': swift.ec2_creds.access, - 'aws_secret_access_key': swift.ec2_creds.secret, - 'endpoint_url': swift.s3_endpoint, - 'verify': swift.cacert, - } + @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 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'] + + # 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) + + # kwargs = { + # 'region_name': swift.s3_region, + # 'aws_access_key_id': swift.ec2_creds.access, + # 'aws_secret_access_key': swift.ec2_creds.secret, + # 'endpoint_url': swift.s3_endpoint, + # 'verify': swift.cacert, + # } def update_gnocchi_config_for_s3(self): """Update Gnocchi with the correct values for the S3 backend""" + logging.debug('Changing charm setting to connect to S3') model.set_application_config( 'gnocchi', - {'s3-endpoint-url': self.swift.s3_endpoint, - 's3-region-name': self.swift.s3_region, - 's3-access-key-id': self.swift.ec2_creds.access, - 's3-secret-access-key': self.swift.ec2_creds.secret}, + {'s3-endpoint-url': self.s3_endpoint, + 's3-region-name': self.s3_region, + 's3-access-key-id': self.ec2_creds.access, + 's3-secret-access-key': self.ec2_creds.secret}, model_name=self.model_name ) logging.debug( @@ -97,4 +121,4 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): 'workload-status-': 'active', 'workload-status-message': 'Unit is ready'}} ) - model.block_until_all_units_idle() \ No newline at end of file + model.block_until_all_units_idle() From 0c33bcc4a1705cbf36a9f3d369749c38f1436ba0 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Wed, 17 Jun 2020 15:17:02 -0500 Subject: [PATCH 03/23] Gnocchi S3 Tests --- zaza/openstack/charm_tests/gnocchi/tests.py | 58 +++++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 6148675..2f1cb83 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -64,7 +64,7 @@ class GnocchiTest(test_utils.OpenStackBaseTest): class GnocchiS3Test(test_utils.OpenStackBaseTest): - """Tests for S3 storage backend""" + """Test object storage S3 API.""" @classmethod def setUpClass(cls): @@ -74,7 +74,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 clean our user_id and project_id + # 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'] @@ -90,18 +90,10 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): # Create AWS compatible application credentials in Keystone cls.ec2_creds = ks_client.ec2.create(user_id, project_id) - # kwargs = { - # 'region_name': swift.s3_region, - # 'aws_access_key_id': swift.ec2_creds.access, - # 'aws_secret_access_key': swift.ec2_creds.secret, - # 'endpoint_url': swift.s3_endpoint, - # 'verify': swift.cacert, - # } - - def update_gnocchi_config_for_s3(self): - """Update Gnocchi with the correct values for the S3 backend""" + def test_s3_connection_for_gnocchi(self): + """Use S3 API to list buckets.""" - logging.debug('Changing charm setting to connect to S3') + logging.info('Changing charm config to connect to swift S3 backend') model.set_application_config( 'gnocchi', {'s3-endpoint-url': self.s3_endpoint, @@ -110,15 +102,47 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): 's3-secret-access-key': self.ec2_creds.secret}, model_name=self.model_name ) - logging.debug( + logging.info( 'Waiting for units to execute config-changed hook') model.wait_for_agent_status(model_name=self.model_name) - logging.debug( + logging.info( 'Waiting for units to reach target states') model.wait_for_application_states( model_name=self.model_name, states={'gnocchi': { - 'workload-status-': 'active', - 'workload-status-message': 'Unit is ready'}} + 'workload-status-': 'active', + 'workload-status-message': 'Unit is ready' + }, + 'ceilometer': { + 'workload-status' : 'blocked', + 'workload-status-message': 'Run the ceilometer-upgrade action on the leader to initialize ceilometer and gnocchi' + } + } ) model.block_until_all_units_idle() + + def test_s3_list_gnocchi_buckets(self): + """Verify that the gnocchi buckets were created in the S3 backend """ + + kwargs = { + 'region_name': self.s3_region, + 'aws_access_key_id': self.ec2_creds.access, + 'aws_secret_access_key': self.ec2_creds.secret, + 'endpoint_url': self.s3_endpoint, + 'verify': self.cacert, + } + s3_client = boto3.client('s3', **kwargs) + s3 = boto3.resource('s3', **kwargs) + + bucket_names = ['gnocchi-measure', 'gnocchi-aggregates'] + # Validate their presence + bucket_list = s3_client.list_buckets() + logging.info(pprint.pformat(bucket_list)) + for bkt in bucket_list['Buckets']: + for gnocchi_bkt in bucket_names: + print(gnocchi_bkt) + if bkt['Name'] == gnocchi_bkt: + print('break out of 1st loop') + break + else: + AssertionError('Bucket "{}" not found'.format(gnocchi_bkt)) From a1d4a3c4ae17d7929352406c002beccd5f1753bb Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Wed, 17 Jun 2020 15:30:04 -0500 Subject: [PATCH 04/23] pep8 --- zaza/openstack/charm_tests/gnocchi/tests.py | 40 ++++++++++----------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 2f1cb83..6f7b986 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -18,12 +18,12 @@ 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.openstack as openstack_utils -from zaza.openstack.charm_tests.swift.tests import S3APITest class GnocchiTest(test_utils.OpenStackBaseTest): @@ -92,38 +92,39 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): def test_s3_connection_for_gnocchi(self): """Use S3 API to list buckets.""" - logging.info('Changing charm config to connect to swift S3 backend') model.set_application_config( 'gnocchi', {'s3-endpoint-url': self.s3_endpoint, - 's3-region-name': self.s3_region, - 's3-access-key-id': self.ec2_creds.access, - 's3-secret-access-key': self.ec2_creds.secret}, + 's3-region-name': self.s3_region, + 's3-access-key-id': self.ec2_creds.access, + 's3-secret-access-key': self.ec2_creds.secret}, model_name=self.model_name ) logging.info( - 'Waiting for units to execute config-changed hook') + 'Waiting for units to execute config-changed hook') model.wait_for_agent_status(model_name=self.model_name) logging.info( - 'Waiting for units to reach target states') + 'Waiting for units to reach target states') model.wait_for_application_states( model_name=self.model_name, - states={'gnocchi': { - 'workload-status-': 'active', - 'workload-status-message': 'Unit is ready' - }, - 'ceilometer': { - 'workload-status' : 'blocked', - 'workload-status-message': 'Run the ceilometer-upgrade action on the leader to initialize ceilometer and gnocchi' - } - } + states={ + 'gnocchi': { + 'workload-status-': 'active', + 'workload-status-message': 'Unit is ready' + }, + 'ceilometer': { + 'workload-status': 'blocked', + 'workload-status-message': 'Run the ' + + 'ceilometer-upgrade action on the leader ' + + 'to initialize ceilometer and gnocchi' + } + } ) model.block_until_all_units_idle() def test_s3_list_gnocchi_buckets(self): - """Verify that the gnocchi buckets were created in the S3 backend """ - + """Verify that the gnocchi buckets were created in the S3 backend.""" kwargs = { 'region_name': self.s3_region, 'aws_access_key_id': self.ec2_creds.access, @@ -132,7 +133,6 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): 'verify': self.cacert, } s3_client = boto3.client('s3', **kwargs) - s3 = boto3.resource('s3', **kwargs) bucket_names = ['gnocchi-measure', 'gnocchi-aggregates'] # Validate their presence @@ -140,9 +140,7 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): logging.info(pprint.pformat(bucket_list)) for bkt in bucket_list['Buckets']: for gnocchi_bkt in bucket_names: - print(gnocchi_bkt) if bkt['Name'] == gnocchi_bkt: - print('break out of 1st loop') break else: AssertionError('Bucket "{}" not found'.format(gnocchi_bkt)) From a3836e06e2f25cacd10fb2b1f788e3f48b06e635 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Thu, 18 Jun 2020 16:13:27 -0500 Subject: [PATCH 05/23] pep8 --- zaza/openstack/charm_tests/gnocchi/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 6f7b986..0a0a0cc 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -64,7 +64,7 @@ class GnocchiTest(test_utils.OpenStackBaseTest): class GnocchiS3Test(test_utils.OpenStackBaseTest): - """Test object storage S3 API.""" + """Test Gnocchi with S3 storage backend.""" @classmethod def setUpClass(cls): @@ -91,7 +91,7 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): cls.ec2_creds = ks_client.ec2.create(user_id, project_id) def test_s3_connection_for_gnocchi(self): - """Use S3 API to list buckets.""" + """Set S3 config for gnocchi-upgrade.""" logging.info('Changing charm config to connect to swift S3 backend') model.set_application_config( 'gnocchi', From a3da91e643df477cffb17156486bfa6e0fa881e8 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Thu, 18 Jun 2020 16:32:57 -0500 Subject: [PATCH 06/23] Move configure step to setup.py --- zaza/openstack/charm_tests/gnocchi/setup.py | 69 +++++++++++++++++++++ zaza/openstack/charm_tests/gnocchi/tests.py | 34 +--------- 2 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 zaza/openstack/charm_tests/gnocchi/setup.py diff --git a/zaza/openstack/charm_tests/gnocchi/setup.py b/zaza/openstack/charm_tests/gnocchi/setup.py new file mode 100644 index 0000000..086c263 --- /dev/null +++ b/zaza/openstack/charm_tests/gnocchi/setup.py @@ -0,0 +1,69 @@ +# 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. + +"""Setup for Gnocchi tests.""" + +import logging + +import zaza.model as model +import zaza.openstack.utilities.openstack as openstack_utils + + +def configure_s3_backend(): + """Inject S3 parameters from Swift for Gnocchi config.""" + session = openstack_utils.get_overcloud_keystone_session() + ks_client = openstack_utils.get_keystone_session_client(session) + + logging.info('Retrieving S3 connection data from Swift') + 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': + s3_region = endpoint['region'] + s3_endpoint = endpoint['url'] + + # Create AWS compatible application credentials in Keystone + ec2_creds = ks_client.ec2.create(user_id, project_id) + + logging.info('Changing Gnocchi charm config to connect to S3') + model.set_application_config( + 'gnocchi', + {'s3-endpoint-url': s3_endpoint, + 's3-region-name': s3_region, + 's3-access-key-id': ec2_creds.access, + 's3-secret-access-key': ec2_creds.secret} + ) + logging.info('Waiting for units to execute config-changed hook') + model.wait_for_agent_status() + logging.info('Waiting for units to reach target states') + model.wait_for_application_states( + states={ + 'gnocchi': { + 'workload-status-': 'active', + 'workload-status-message': 'Unit is ready' + }, + 'ceilometer': { + 'workload-status': 'blocked', + 'workload-status-message': 'Run the ' + + 'ceilometer-upgrade action on the leader ' + + 'to initialize ceilometer and gnocchi' + } + } + ) + model.block_until_all_units_idle() \ No newline at end of file diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 0a0a0cc..d7d5736 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -64,7 +64,7 @@ class GnocchiTest(test_utils.OpenStackBaseTest): class GnocchiS3Test(test_utils.OpenStackBaseTest): - """Test Gnocchi with S3 storage backend.""" + """Test Gnocchi for S3 storage backend.""" @classmethod def setUpClass(cls): @@ -90,38 +90,6 @@ 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_s3_connection_for_gnocchi(self): - """Set S3 config for gnocchi-upgrade.""" - logging.info('Changing charm config to connect to swift S3 backend') - model.set_application_config( - 'gnocchi', - {'s3-endpoint-url': self.s3_endpoint, - 's3-region-name': self.s3_region, - 's3-access-key-id': self.ec2_creds.access, - 's3-secret-access-key': self.ec2_creds.secret}, - model_name=self.model_name - ) - logging.info( - 'Waiting for units to execute config-changed hook') - model.wait_for_agent_status(model_name=self.model_name) - logging.info( - 'Waiting for units to reach target states') - model.wait_for_application_states( - model_name=self.model_name, - states={ - 'gnocchi': { - 'workload-status-': 'active', - 'workload-status-message': 'Unit is ready' - }, - 'ceilometer': { - 'workload-status': 'blocked', - 'workload-status-message': 'Run the ' + - 'ceilometer-upgrade action on the leader ' + - 'to initialize ceilometer and gnocchi' - } - } - ) - model.block_until_all_units_idle() def test_s3_list_gnocchi_buckets(self): """Verify that the gnocchi buckets were created in the S3 backend.""" From 692853e242bb66ba426032ecec162a840112335a Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Fri, 19 Jun 2020 14:19:25 -0500 Subject: [PATCH 07/23] pep8 --- zaza/openstack/charm_tests/gnocchi/setup.py | 2 +- zaza/openstack/charm_tests/gnocchi/tests.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/setup.py b/zaza/openstack/charm_tests/gnocchi/setup.py index 086c263..4995f22 100644 --- a/zaza/openstack/charm_tests/gnocchi/setup.py +++ b/zaza/openstack/charm_tests/gnocchi/setup.py @@ -66,4 +66,4 @@ def configure_s3_backend(): } } ) - model.block_until_all_units_idle() \ No newline at end of file + model.block_until_all_units_idle() diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index d7d5736..680bf3c 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -21,7 +21,6 @@ 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.openstack as openstack_utils @@ -90,7 +89,6 @@ 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_s3_list_gnocchi_buckets(self): """Verify that the gnocchi buckets were created in the S3 backend.""" kwargs = { From 6bbb4fd4e34102b0bd924b00461abfd0abaa745f Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Fri, 24 Jul 2020 10:13:50 -0500 Subject: [PATCH 08/23] add iscsi-connector files and setup --- .../charm_tests/iscsi-connector/__init__.py | 15 +++++ .../charm_tests/iscsi-connector/setup.py | 56 +++++++++++++++++++ .../charm_tests/iscsi-connector/tests.py | 15 +++++ 3 files changed, 86 insertions(+) create mode 100644 zaza/openstack/charm_tests/iscsi-connector/__init__.py create mode 100644 zaza/openstack/charm_tests/iscsi-connector/setup.py create mode 100644 zaza/openstack/charm_tests/iscsi-connector/tests.py diff --git a/zaza/openstack/charm_tests/iscsi-connector/__init__.py b/zaza/openstack/charm_tests/iscsi-connector/__init__.py new file mode 100644 index 0000000..c0cf179 --- /dev/null +++ b/zaza/openstack/charm_tests/iscsi-connector/__init__.py @@ -0,0 +1,15 @@ +# 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.""" \ No newline at end of file diff --git a/zaza/openstack/charm_tests/iscsi-connector/setup.py b/zaza/openstack/charm_tests/iscsi-connector/setup.py new file mode 100644 index 0000000..f18a4ad --- /dev/null +++ b/zaza/openstack/charm_tests/iscsi-connector/setup.py @@ -0,0 +1,56 @@ +# 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.""" + +# """ +# steps for testing without password: +# - deploy ubuntu for storage +# - deploy ubuntu for initiator +# configure that unit: +# - install tgt -y +# - configure iscsi target +# - need to know the initiator ip +# - restart tgt +# - configure ubuntu initiator with init dict, target, port +# """ + +import zaza.model +import zaza.openstack.utilities.openstack as openstack_utils + + +def basic_target_setup(): + """Run basic setup for iscsi guest.""" + unit = zaza.model.get_units('ubuntu-target')[0] + setup_cmds = [ + "apt install --yes tgt", + "systemctl start tgt",] + for cmd in setup_cmds: + zaza.model.run_on_unit( + unit.entity_id, + cmd) + +def configure_iscsi_target(): + lun = 'iqn.2020-07.canonical.com:lun1' + backing_store = 'dev/vdb' + initiator_address = zaza.model.get_app_ips('ubuntu')[0] + write_file = ( + """echo -e '\n\tbacking-store {}\n\tinitiator-address {}\n' | """ + """sudo tee /etc/tgt/conf.d/iscsi.conf""".format(lun, backing_store,initiator_address) + ) + 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) + diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py new file mode 100644 index 0000000..c30f38c --- /dev/null +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -0,0 +1,15 @@ +# 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.""" \ No newline at end of file From fb8de5cc81221ecc2e09a628540616da627c65ce Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Fri, 24 Jul 2020 11:09:22 -0500 Subject: [PATCH 09/23] add open-port cmd for iscsi target --- zaza/openstack/charm_tests/iscsi-connector/setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/setup.py b/zaza/openstack/charm_tests/iscsi-connector/setup.py index f18a4ad..f453ed4 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/setup.py +++ b/zaza/openstack/charm_tests/iscsi-connector/setup.py @@ -35,7 +35,8 @@ def basic_target_setup(): unit = zaza.model.get_units('ubuntu-target')[0] setup_cmds = [ "apt install --yes tgt", - "systemctl start tgt",] + "systemctl start tgt", + "open-port 3260"] for cmd in setup_cmds: zaza.model.run_on_unit( unit.entity_id, From 277272547f06b04d06ea94149f79d0b47f44a3ed Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Fri, 24 Jul 2020 14:14:19 -0500 Subject: [PATCH 10/23] add tests iscsi-connector --- .../charm_tests/iscsi-connector/setup.py | 4 +++ .../charm_tests/iscsi-connector/tests.py | 32 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/setup.py b/zaza/openstack/charm_tests/iscsi-connector/setup.py index f453ed4..d016a36 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/setup.py +++ b/zaza/openstack/charm_tests/iscsi-connector/setup.py @@ -26,12 +26,15 @@ # - configure ubuntu initiator with init dict, target, port # """ +import logging + import zaza.model import zaza.openstack.utilities.openstack as openstack_utils 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", @@ -50,6 +53,7 @@ def configure_iscsi_target(): """echo -e '\n\tbacking-store {}\n\tinitiator-address {}\n' | """ """sudo tee /etc/tgt/conf.d/iscsi.conf""".format(lun, backing_store,initiator_address) ) + 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" diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index c30f38c..5c2babf 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -12,4 +12,34 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Encapsulate iscsi-connector testing.""" \ No newline at end of file +"""Encapsulate iscsi-connector testing.""" + +import logging +import tempfile + +import zaza.model +import zaza.openstack.charm_tests.test_utils as test_utils +import zaza.openstack.utilities.generic as generic_utils + + +class ISCSIConnectorTest(test_utils.BaseCharmTest): + """Class for iscsi-connector tests.""" + + IQN = 'iqn.2020-07.canonical.com:lun1' + + def configure_iscsi_connector(self): + unit_fqdn = self.get_unit_full_hostname('ubuntu/0') + target_ip = zaza.model.get_app_ips('ubuntu-target')[0] + conf = { + 'initiator-dictionary': '{"{unit_fqdn}":"{IQN}"}', + 'target': target_ip, + 'port': '3260', + } + 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 From bad9b4c768d9669f6c14bda6a3fc6bb48992de0d Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Fri, 24 Jul 2020 14:14:19 -0500 Subject: [PATCH 11/23] add tests iscsi-connector --- .../charm_tests/iscsi-connector/setup.py | 4 +++ .../charm_tests/iscsi-connector/tests.py | 35 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/setup.py b/zaza/openstack/charm_tests/iscsi-connector/setup.py index f453ed4..d016a36 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/setup.py +++ b/zaza/openstack/charm_tests/iscsi-connector/setup.py @@ -26,12 +26,15 @@ # - configure ubuntu initiator with init dict, target, port # """ +import logging + import zaza.model import zaza.openstack.utilities.openstack as openstack_utils 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", @@ -50,6 +53,7 @@ def configure_iscsi_target(): """echo -e '\n\tbacking-store {}\n\tinitiator-address {}\n' | """ """sudo tee /etc/tgt/conf.d/iscsi.conf""".format(lun, backing_store,initiator_address) ) + 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" diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index c30f38c..d7b67fc 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -12,4 +12,37 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Encapsulate iscsi-connector testing.""" \ No newline at end of file +"""Encapsulate iscsi-connector testing.""" + +import logging +import tempfile + +import zaza.model +import zaza.openstack.charm_tests.test_utils as test_utils +import zaza.openstack.utilities.generic as generic_utils + + +class ISCSIConnectorTest(test_utils.BaseCharmTest): + """Class for iscsi-connector tests.""" + + IQN = 'iqn.2020-07.canonical.com:lun1' + + def configure_iscsi_connector(self): + unit_fqdn = self.get_unit_full_hostname('ubuntu/0') + target_ip = zaza.model.get_app_ips('ubuntu-target')[0] + conf = { + 'initiator-dictionary': '{"{unit_fqdn}":"{IQN}"}', + 'target': target_ip, + 'port': '3260', + } + 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): + self.configure_iscsi_connector() \ No newline at end of file From 5664251152e06597e78f20cd926fc0c830fd24db Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Fri, 24 Jul 2020 14:25:27 -0500 Subject: [PATCH 12/23] tests.py --- zaza/openstack/charm_tests/iscsi-connector/tests.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index f7b67ea..8f707eb 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -25,6 +25,11 @@ import zaza.openstack.utilities.generic as generic_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() + IQN = 'iqn.2020-07.canonical.com:lun1' def configure_iscsi_connector(self): From 4c57e73f73ab18d9d9fe85dd1bdf798a6b805ee8 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Fri, 24 Jul 2020 14:25:27 -0500 Subject: [PATCH 13/23] tests.py --- zaza/openstack/charm_tests/iscsi-connector/tests.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index f7b67ea..8f707eb 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -25,6 +25,11 @@ import zaza.openstack.utilities.generic as generic_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() + IQN = 'iqn.2020-07.canonical.com:lun1' def configure_iscsi_connector(self): From 411d9aeb50b2165feac7a43494521ed854ec3549 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Fri, 24 Jul 2020 15:14:12 -0500 Subject: [PATCH 14/23] fix hostname --- zaza/openstack/charm_tests/iscsi-connector/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index 8f707eb..be5cb24 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -33,7 +33,7 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest): IQN = 'iqn.2020-07.canonical.com:lun1' def configure_iscsi_connector(self): - unit_fqdn = self.get_unit_full_hostname('ubuntu/0') + unit_fqdn = self.get_unit_full_hostname('ubuntu') target_ip = zaza.model.get_app_ips('ubuntu-target')[0] conf = { 'initiator-dictionary': '{"{unit_fqdn}":"{IQN}"}', From 738664e8bab6cbacb51deedfbeb1bfbe7ffea429 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Fri, 24 Jul 2020 15:53:00 -0500 Subject: [PATCH 15/23] assert iscsi session --- .../openstack/charm_tests/iscsi-connector/tests.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index be5cb24..33a85dd 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -14,6 +14,7 @@ """Encapsulate iscsi-connector testing.""" +import json import logging import tempfile @@ -29,14 +30,14 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest): def setUpClass(cls): """Run class setup for running glance tests.""" super(ISCSIConnectorTest, cls).setUpClass() - - IQN = 'iqn.2020-07.canonical.com:lun1' def configure_iscsi_connector(self): + 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': '{"{unit_fqdn}":"{IQN}"}', + 'initiator-dictionary': initiator_dictionary, 'target': target_ip, 'port': '3260', } @@ -51,3 +52,10 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest): def test_iscsi_connector(self): self.configure_iscsi_connector() + logging.info('Wait for idle/ready status...') + zaza_model.wait_for_application_states() + + def test_validate_iscsi_session(self): + unit = zaza.model.get_units('ubuntu')[0] + run = zaza.model.run_on_unit(unit.entity_id, 'iscsiadm -m session') + assert run['Stdout'] != "iscsiadm: No active sessions." From ab91b94d779a260cf572e34114ea64448fc3cd65 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Mon, 27 Jul 2020 10:25:21 -0500 Subject: [PATCH 16/23] add logs to iscsi test --- zaza/openstack/charm_tests/iscsi-connector/tests.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index 33a85dd..bbd4e87 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -53,9 +53,11 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest): def test_iscsi_connector(self): self.configure_iscsi_connector() logging.info('Wait for idle/ready status...') - zaza_model.wait_for_application_states() + zaza.model.wait_for_application_states() def test_validate_iscsi_session(self): 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') - assert run['Stdout'] != "iscsiadm: No active sessions." + logging.info('iscsiadm -m session: Stdout: {}, Stderr: {}, Code: {}'.format(run['Stdout'], run['Stderr'], run['Code'])) + assert run['Code'] == '0' From e997647870e6f194eeaf9a29da05af862de48934 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Mon, 27 Jul 2020 15:47:21 -0500 Subject: [PATCH 17/23] Add CHAP auth to tests --- zaza/openstack/charm_tests/iscsi-connector/setup.py | 9 +++++++-- zaza/openstack/charm_tests/iscsi-connector/tests.py | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/setup.py b/zaza/openstack/charm_tests/iscsi-connector/setup.py index d016a36..dbfc6f0 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/setup.py +++ b/zaza/openstack/charm_tests/iscsi-connector/setup.py @@ -49,9 +49,14 @@ def configure_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 '\n\tbacking-store {}\n\tinitiator-address {}\n' | """ - """sudo tee /etc/tgt/conf.d/iscsi.conf""".format(lun, backing_store,initiator_address) + """echo -e '\n\tbacking-store {}\n\tinitiator-address {}\n\tincominguser {} {}\n\t""" + """outgoinguser {} {}' | 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) diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index bbd4e87..0507b81 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -40,6 +40,11 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest): '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) From 127ac7c87c9f3592292dddd88db4dd2e1d2c93bf Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Mon, 27 Jul 2020 15:59:06 -0500 Subject: [PATCH 18/23] fix typo --- zaza/openstack/charm_tests/iscsi-connector/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index 0507b81..89c1223 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -43,8 +43,8 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest): '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', + 'iscsi-node-session-auth-username-in': 'iscsi-target', + 'iscsi-node-session-auth-password-in': 'secretpass', } zaza.model.set_application_config('iscsi-connector', conf) From 7c9e2edbd1ea37b5b0f96d1e292327a1a9e35175 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Mon, 27 Jul 2020 16:23:36 -0500 Subject: [PATCH 19/23] add missing newline --- zaza/openstack/charm_tests/iscsi-connector/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/setup.py b/zaza/openstack/charm_tests/iscsi-connector/setup.py index dbfc6f0..ff58c4f 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/setup.py +++ b/zaza/openstack/charm_tests/iscsi-connector/setup.py @@ -55,7 +55,7 @@ def configure_iscsi_target(): password_in = 'secretpass' write_file = ( """echo -e '\n\tbacking-store {}\n\tinitiator-address {}\n\tincominguser {} {}\n\t""" - """outgoinguser {} {}' | sudo tee /etc/tgt/conf.d/iscsi.conf""".format(lun, backing_store, + """outgoinguser {} {}\n' | 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') From a005cf32263b3133ea72427ead080b0eda342698 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Tue, 4 Aug 2020 09:12:42 -0500 Subject: [PATCH 20/23] pep8 --- .../charm_tests/iscsi-connector/__init__.py | 2 +- .../charm_tests/iscsi-connector/setup.py | 28 ++++++++----------- .../charm_tests/iscsi-connector/tests.py | 14 ++++++---- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/zaza/openstack/charm_tests/iscsi-connector/__init__.py b/zaza/openstack/charm_tests/iscsi-connector/__init__.py index c0cf179..659b2b0 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/__init__.py +++ b/zaza/openstack/charm_tests/iscsi-connector/__init__.py @@ -12,4 +12,4 @@ # 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.""" \ No newline at end of file +"""Collection of code for setting up and testing iscsi-connector charm.""" diff --git a/zaza/openstack/charm_tests/iscsi-connector/setup.py b/zaza/openstack/charm_tests/iscsi-connector/setup.py index ff58c4f..b7a3f2d 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/setup.py +++ b/zaza/openstack/charm_tests/iscsi-connector/setup.py @@ -14,22 +14,9 @@ """Code for setting up iscsi-connector tests.""" -# """ -# steps for testing without password: -# - deploy ubuntu for storage -# - deploy ubuntu for initiator -# configure that unit: -# - install tgt -y -# - configure iscsi target -# - need to know the initiator ip -# - restart tgt -# - configure ubuntu initiator with init dict, target, port -# """ - import logging import zaza.model -import zaza.openstack.utilities.openstack as openstack_utils def basic_target_setup(): @@ -45,7 +32,9 @@ def basic_target_setup(): 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] @@ -54,13 +43,18 @@ def configure_iscsi_target(): username_in = 'iscsi-target' password_in = 'secretpass' write_file = ( - """echo -e '\n\tbacking-store {}\n\tinitiator-address {}\n\tincominguser {} {}\n\t""" - """outgoinguser {} {}\n' | sudo tee /etc/tgt/conf.d/iscsi.conf""".format(lun, backing_store, - initiator_address, username, password, username_in, password_in) + """echo -e '\n\tbacking-store {}\n\tinitiator-address """ + """{}\n\tincominguser {} {}\n\toutgoinguser {} {}\n' """ + """ | 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) - diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py index 89c1223..a703a88 100644 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ b/zaza/openstack/charm_tests/iscsi-connector/tests.py @@ -16,11 +16,9 @@ import json import logging -import tempfile import zaza.model import zaza.openstack.charm_tests.test_utils as test_utils -import zaza.openstack.utilities.generic as generic_utils class ISCSIConnectorTest(test_utils.BaseCharmTest): @@ -32,10 +30,11 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest): 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}) + initiator_dictionary = json.dumps({unit_fqdn: iqn}) conf = { 'initiator-dictionary': initiator_dictionary, 'target': target_ip, @@ -56,13 +55,18 @@ class ISCSIConnectorTest(test_utils.BaseCharmTest): 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'])) + logging.info("""iscsiadm -m session: Stdout: {}, Stderr: {}, """ + """Code: {}""".format(run['Stdout'], + run['Stderr'], + run['Code'])) assert run['Code'] == '0' From 3343582ddd80dc71c5f25d3bf140dc3b06957943 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Mon, 17 Aug 2020 17:32:22 -0500 Subject: [PATCH 21/23] add test for external cert config option for gnocchi --- zaza/openstack/charm_tests/gnocchi/tests.py | 38 ++++++++++ .../charm_tests/iscsi-connector/__init__.py | 15 ---- .../charm_tests/iscsi-connector/setup.py | 60 ---------------- .../charm_tests/iscsi-connector/tests.py | 72 ------------------- 4 files changed, 38 insertions(+), 147 deletions(-) delete mode 100644 zaza/openstack/charm_tests/iscsi-connector/__init__.py delete mode 100644 zaza/openstack/charm_tests/iscsi-connector/setup.py delete mode 100644 zaza/openstack/charm_tests/iscsi-connector/tests.py diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 680bf3c..93051d5 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 @@ -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 = { diff --git a/zaza/openstack/charm_tests/iscsi-connector/__init__.py b/zaza/openstack/charm_tests/iscsi-connector/__init__.py deleted file mode 100644 index 659b2b0..0000000 --- a/zaza/openstack/charm_tests/iscsi-connector/__init__.py +++ /dev/null @@ -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.""" diff --git a/zaza/openstack/charm_tests/iscsi-connector/setup.py b/zaza/openstack/charm_tests/iscsi-connector/setup.py deleted file mode 100644 index b7a3f2d..0000000 --- a/zaza/openstack/charm_tests/iscsi-connector/setup.py +++ /dev/null @@ -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 '\n\tbacking-store {}\n\tinitiator-address """ - """{}\n\tincominguser {} {}\n\toutgoinguser {} {}\n' """ - """ | 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) diff --git a/zaza/openstack/charm_tests/iscsi-connector/tests.py b/zaza/openstack/charm_tests/iscsi-connector/tests.py deleted file mode 100644 index a703a88..0000000 --- a/zaza/openstack/charm_tests/iscsi-connector/tests.py +++ /dev/null @@ -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' From 8a79a93e8305c31926d317f2aaea362811695a50 Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Wed, 19 Aug 2020 08:59:04 -0500 Subject: [PATCH 22/23] combine 3 functions into one --- zaza/openstack/charm_tests/gnocchi/tests.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 93051d5..3487996 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -107,8 +107,7 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): ) model.block_until_all_units_idle() - def test_validate_cert_location(self): - """Validate that the cert is correctly uploaded to the unit.""" + logging.info('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 @@ -117,13 +116,12 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): 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.""" + logging.info('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 + linked_cert_name = 'gnocchi-external.pem' + cmd = 'ls ' + linked_cert_location + '/' + linked_cert_name logging.info("Validating that the link {} is created in \ - {}".format(cert_name, linked_cert_location)) + {}".format(linked_cert_name, linked_cert_location)) result = model.run_on_unit('gnocchi/0', cmd) self.assertEqual(result['Code'], '0') From cd548b01cfd470983f1a6f49748be3297c7e9b7d Mon Sep 17 00:00:00 2001 From: "camille.rodriguez" Date: Wed, 19 Aug 2020 09:32:09 -0500 Subject: [PATCH 23/23] pep8, duplicate logs --- zaza/openstack/charm_tests/gnocchi/tests.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/zaza/openstack/charm_tests/gnocchi/tests.py b/zaza/openstack/charm_tests/gnocchi/tests.py index 3487996..e3b9ae1 100644 --- a/zaza/openstack/charm_tests/gnocchi/tests.py +++ b/zaza/openstack/charm_tests/gnocchi/tests.py @@ -107,7 +107,6 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): ) model.block_until_all_units_idle() - logging.info('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 @@ -116,7 +115,6 @@ class GnocchiS3Test(test_utils.OpenStackBaseTest): result = model.run_on_unit('gnocchi/0', cmd) self.assertEqual(result['Code'], '0') - logging.info('Validate that /usr/sbin/update-ca-certificates ran successfully') linked_cert_location = '/etc/ssl/certs' linked_cert_name = 'gnocchi-external.pem' cmd = 'ls ' + linked_cert_location + '/' + linked_cert_name