From 374bde62ce63aa9601c75ba8c0323211f5817c31 Mon Sep 17 00:00:00 2001 From: Shunde Zhang Date: Wed, 28 Feb 2024 17:52:44 +1100 Subject: [PATCH 1/4] add test for virtual hosted bucket --- zaza/openstack/charm_tests/ceph/tests.py | 93 ++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index aa4b7a40e..eb2d7edb6 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -900,6 +900,40 @@ def clean_rgw_multisite_config(self, app_name): '--rgw-zonegroup=default' ) + def enable_virtual_hosted_bucket(self): + """Enable virtual hosted bucket on primary rgw app.""" + + zaza_model.set_application_config( + self.primary_rgw_app, + { + 'virtual-hosted-bucket-enabled': "true" + } + ) + + def set_os_public_hostname(self): + """Set os-public-hostname on primary rgw app.""" + + zaza_model.set_application_config( + self.primary_rgw_app, + { + 'os-public-hostname': "rgw.example.com", + } + ) + + def clean_virtual_hosted_bucket(self): + """Clear virtual hosted bucket on primary app. + + :param app_name: App for which config values are to be cleared + :type app_name: str + """ + zaza_model.set_application_config( + self.primary_rgw_app, + { + 'os-public-hostname': "", + 'virtual-hosted-bucket-enabled': "false" + } + ) + def test_001_processes(self): """Verify Ceph processes. @@ -1196,6 +1230,65 @@ def test_004_migration_and_multisite_failover(self): self.purge_bucket(self.secondary_rgw_app, 'zaza-container') self.purge_bucket(self.secondary_rgw_app, 'failover-container') + def test_005_virtual_hosted_bucket(self): + """Test virtual hosted bucket.""" + logging.info('Testing virtual hosted bucket') + + # 0. Configure virtual hosted bucket + self.enable_virtual_hosted_bucket() + assert_state = { + self.primary_rgw_app: { + "workload-status": "blocked", + "workload-status-message-prefix": "os_public_hostname " + "must have a value since virtual_hosted_bucket_enabled" + " is true" + } + } + zaza_model.wait_for_application_states(self.model_name, + states=assert_state, + timeout=900) + self.set_os_public_hostname() + zaza_model.block_until_all_units_idle(self.model_name) + container_name = 'zaza-bucket' + obj_data = 'Test content from Zaza' + obj_name = 'testfile' + + # 1. Fetch Primary Endpoint Details + primary_endpoint = self.get_rgw_endpoint(self.primary_rgw_unit) + self.assertNotEqual(primary_endpoint, None) + + # 2. Create RGW Client and perform IO + access_key, secret_key = self.get_client_keys() + primary_client = boto3.resource("s3", + verify=False, + endpoint_url=primary_endpoint, + aws_access_key_id=access_key, + aws_secret_access_key=secret_key) + primary_client.Bucket(container_name).create() + primary_object_one = primary_client.Object( + container_name, + obj_name + ) + primary_object_one.put(Body=obj_data) + primary_client.Bucket(container_name).Acl().put(ACL='public-read') + primary_client.Object(container_name, obj_name).Acl().put( + ACL='public-read' + ) + + # 3. Test if we can get content via virtual hosted bucket name + public_hostname = zaza_model.get_application_config( + self.primary_rgw_app + )["os-public-hostname"]["value"] + url = f"{primary_endpoint}/{obj_name}" + headers = {'host': f"{container_name}.{public_hostname}"} + f = requests.get(url, headers=headers, verify=False) + self.assertEqual(f.text, obj_data) + + # 4. Cleanup and de-configure virtual hosted bucket + self.clean_virtual_hosted_bucket() + zaza_model.block_until_all_units_idle(self.model_name) + self.purge_bucket(self.primary_rgw_app, container_name) + class CephProxyTest(unittest.TestCase): """Test ceph via proxy.""" From 56776d0bb29ace767f3737978227e269cc028b0f Mon Sep 17 00:00:00 2001 From: Shunde Zhang Date: Tue, 2 Apr 2024 21:00:39 +1100 Subject: [PATCH 2/4] Fixed pep8 errors. --- zaza/openstack/charm_tests/ceph/tests.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index eb2d7edb6..d45a6ad9b 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -902,7 +902,6 @@ def clean_rgw_multisite_config(self, app_name): def enable_virtual_hosted_bucket(self): """Enable virtual hosted bucket on primary rgw app.""" - zaza_model.set_application_config( self.primary_rgw_app, { @@ -912,7 +911,6 @@ def enable_virtual_hosted_bucket(self): def set_os_public_hostname(self): """Set os-public-hostname on primary rgw app.""" - zaza_model.set_application_config( self.primary_rgw_app, { @@ -921,11 +919,7 @@ def set_os_public_hostname(self): ) def clean_virtual_hosted_bucket(self): - """Clear virtual hosted bucket on primary app. - - :param app_name: App for which config values are to be cleared - :type app_name: str - """ + """Clear virtual hosted bucket on primary app.""" zaza_model.set_application_config( self.primary_rgw_app, { @@ -1239,9 +1233,9 @@ def test_005_virtual_hosted_bucket(self): assert_state = { self.primary_rgw_app: { "workload-status": "blocked", - "workload-status-message-prefix": "os_public_hostname " - "must have a value since virtual_hosted_bucket_enabled" - " is true" + "workload-status-message-prefix": + "os_public_hostname must have a value since " + "virtual_hosted_bucket_enabled is true" } } zaza_model.wait_for_application_states(self.model_name, From 9bdaf703d22190de4b226e04fbb93fe6a2f6afc6 Mon Sep 17 00:00:00 2001 From: Shunde Zhang Date: Wed, 3 Apr 2024 15:38:05 +1100 Subject: [PATCH 3/4] skip virtual hosted bucket test after multi site tests --- zaza/openstack/charm_tests/ceph/tests.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index d45a6ad9b..2348e3861 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1226,6 +1226,12 @@ def test_004_migration_and_multisite_failover(self): def test_005_virtual_hosted_bucket(self): """Test virtual hosted bucket.""" + primary_rgw_unit = zaza_model.get_unit_from_name(self.primary_rgw_unit) + if primary_rgw_unit.workload_status != "active": + logging.info('Skipping virtual hosted bucket test since ' + 'primary rgw unit is not in active state') + return + logging.info('Testing virtual hosted bucket') # 0. Configure virtual hosted bucket @@ -1234,8 +1240,8 @@ def test_005_virtual_hosted_bucket(self): self.primary_rgw_app: { "workload-status": "blocked", "workload-status-message-prefix": - "os_public_hostname must have a value since " - "virtual_hosted_bucket_enabled is true" + "os-public-hostname must have a value " + "when virtual hosted bucket is enabled" } } zaza_model.wait_for_application_states(self.model_name, From ff58f1a12914908c3ae12019df71911ec11976a5 Mon Sep 17 00:00:00 2001 From: Shunde Zhang Date: Wed, 3 Apr 2024 15:40:04 +1100 Subject: [PATCH 4/4] delete whitespace in blank line --- zaza/openstack/charm_tests/ceph/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/ceph/tests.py b/zaza/openstack/charm_tests/ceph/tests.py index 2348e3861..46911c07c 100644 --- a/zaza/openstack/charm_tests/ceph/tests.py +++ b/zaza/openstack/charm_tests/ceph/tests.py @@ -1231,7 +1231,7 @@ def test_005_virtual_hosted_bucket(self): logging.info('Skipping virtual hosted bucket test since ' 'primary rgw unit is not in active state') return - + logging.info('Testing virtual hosted bucket') # 0. Configure virtual hosted bucket