Fix availability zone API tests

Currently, if you run the availability zone API tests when not using
the no-op drivers, the API tests will fail as they had hard-coded
availability zone names that do not exist.
Since creating availability zones requires reconfiguration of the nova
host deployments, it is not practical to create nova availability zones
for these tests.

This patch adds tempest configuration settings for the required
availability zones, and if not configured will skip the tests that
require the availability zones be present.

Change-Id: I53d5d33ae9a181b79e1d971d56452eeee5dd7759
diff --git a/octavia_tempest_plugin/config.py b/octavia_tempest_plugin/config.py
index 8573d89..fc04c33 100644
--- a/octavia_tempest_plugin/config.py
+++ b/octavia_tempest_plugin/config.py
@@ -195,6 +195,12 @@
     cfg.StrOpt('availability_zone',
                default=None,
                help='Availability zone to use for creating servers.'),
+    cfg.StrOpt('availability_zone2',
+               default=None,
+               help='A second availability zone to use for creating servers.'),
+    cfg.StrOpt('availability_zone3',
+               default=None,
+               help='A third availability zone to use for creating servers.'),
     cfg.BoolOpt('test_reuse_connection', default=True,
                 help='Reuse TCP connections while testing LB with '
                      'HTTP members (keep-alive).'),
diff --git a/octavia_tempest_plugin/tests/api/v2/test_availability_zone.py b/octavia_tempest_plugin/tests/api/v2/test_availability_zone.py
index 023d5f5..816e00e 100644
--- a/octavia_tempest_plugin/tests/api/v2/test_availability_zone.py
+++ b/octavia_tempest_plugin/tests/api/v2/test_availability_zone.py
@@ -32,6 +32,15 @@
     """Test the availability zone object API."""
 
     @classmethod
+    def skip_checks(cls):
+        super(AvailabilityZoneAPITest, cls).skip_checks()
+        if (CONF.load_balancer.availability_zone is None and
+                not CONF.load_balancer.test_with_noop):
+            raise cls.skipException(
+                'Availability Zone API tests require an availability zone '
+                'configured in the [load_balancer] availability_zone setting.')
+
+    @classmethod
     def resource_setup(cls):
         """Setup resources needed by the tests."""
         super(AvailabilityZoneAPITest, cls).resource_setup()
@@ -46,7 +55,7 @@
         availability_zone_profile_name = data_utils.rand_name(
             "lb_admin_availabilityzoneprofile-setup")
         availability_zone_data = {
-            const.COMPUTE_ZONE: 'my_compute_zone',
+            const.COMPUTE_ZONE: CONF.load_balancer.availability_zone,
             const.MANAGEMENT_NETWORK: uuidutils.generate_uuid(),
         }
         availability_zone_data_json = jsonutils.dumps(availability_zone_data)
diff --git a/octavia_tempest_plugin/tests/api/v2/test_availability_zone_profile.py b/octavia_tempest_plugin/tests/api/v2/test_availability_zone_profile.py
index 86ae066..c062dbe 100644
--- a/octavia_tempest_plugin/tests/api/v2/test_availability_zone_profile.py
+++ b/octavia_tempest_plugin/tests/api/v2/test_availability_zone_profile.py
@@ -32,6 +32,16 @@
 class AvailabilityZoneProfileAPITest(test_base.LoadBalancerBaseTest):
     """Test the availability zone profile object API."""
 
+    @classmethod
+    def skip_checks(cls):
+        super(AvailabilityZoneProfileAPITest, cls).skip_checks()
+        if (CONF.load_balancer.availability_zone is None and
+                not CONF.load_balancer.test_with_noop):
+            raise cls.skipException(
+                'Availability zone profile API tests require an availability '
+                'zone configured in the [load_balancer] availability_zone '
+                'setting in the tempest configuration file.')
+
     @decorators.idempotent_id('e512b580-ef32-44c3-bbd2-efdc27ba2ea6')
     def test_availability_zone_profile_create(self):
         """Tests availability zone profile create and basic show APIs.
@@ -53,7 +63,7 @@
         availability_zone_profile_name = data_utils.rand_name(
             "lb_admin_availabilityzoneprofile1-create")
         availability_zone_data = {
-            const.COMPUTE_ZONE: 'my_compute_zone',
+            const.COMPUTE_ZONE: CONF.load_balancer.availability_zone,
             const.MANAGEMENT_NETWORK: uuidutils.generate_uuid(),
         }
         availability_zone_data_json = jsonutils.dumps(availability_zone_data)
@@ -116,12 +126,20 @@
             raise self.skipException(
                 'Availability zone profiles are only available on '
                 'Octavia API version 2.14 or newer.')
+        if ((CONF.load_balancer.availability_zone2 is None or
+             CONF.load_balancer.availability_zone3 is None) and
+                not CONF.load_balancer.test_with_noop):
+            raise self.skipException(
+                'Availability zone profile list API test requires the '
+                '[load_balancer] availability_zone, availability_zone2, and '
+                'availability_zone3 settings be defined in the tempest '
+                'configuration file.')
 
         # Create availability zone profile 1
         availability_zone_profile1_name = data_utils.rand_name(
             "lb_admin_availabilityzoneprofile-list-1")
         availability_zone_data1 = {
-            const.COMPUTE_ZONE: 'my_compute_zone1',
+            const.COMPUTE_ZONE: CONF.load_balancer.availability_zone,
             const.MANAGEMENT_NETWORK: uuidutils.generate_uuid(),
         }
         availability_zone_data1_json = jsonutils.dumps(availability_zone_data1)
@@ -144,7 +162,7 @@
         availability_zone_profile2_name = data_utils.rand_name(
             "lb_admin_availabilityzoneprofile-list-2")
         availability_zone_data2 = {
-            const.COMPUTE_ZONE: 'my_compute_zone2',
+            const.COMPUTE_ZONE: CONF.load_balancer.availability_zone2,
             const.MANAGEMENT_NETWORK: uuidutils.generate_uuid(),
         }
         availability_zone_data2_json = jsonutils.dumps(availability_zone_data2)
@@ -167,7 +185,7 @@
         availability_zone_profile3_name = data_utils.rand_name(
             "lb_admin_availabilityzoneprofile-list-3")
         availability_zone_data3 = {
-            const.COMPUTE_ZONE: 'my_compute_zone3',
+            const.COMPUTE_ZONE: CONF.load_balancer.availability_zone3,
             const.MANAGEMENT_NETWORK: uuidutils.generate_uuid(),
         }
         availability_zone_data3_json = jsonutils.dumps(availability_zone_data3)
@@ -329,7 +347,7 @@
         availability_zone_profile_name = data_utils.rand_name(
             "lb_admin_availabilityzoneprofile1-show")
         availability_zone_data = {
-            const.COMPUTE_ZONE: 'my_compute_zone',
+            const.COMPUTE_ZONE: CONF.load_balancer.availability_zone,
             const.MANAGEMENT_NETWORK: uuidutils.generate_uuid(),
         }
         availability_zone_data_json = jsonutils.dumps(availability_zone_data)
@@ -390,11 +408,17 @@
             raise self.skipException(
                 'Availability zone profiles are only available on '
                 'Octavia API version 2.14 or newer.')
+        if (CONF.load_balancer.availability_zone2 is None and
+                not CONF.load_balancer.test_with_noop):
+            raise self.skipException(
+                'Availability zone profile update API tests requires '
+                '[load_balancer] availability_zone2 to be defined in the '
+                'tempest configuration file.')
 
         availability_zone_profile_name = data_utils.rand_name(
             "lb_admin_availabilityzoneprofile1-update")
         availability_zone_data = {
-            const.COMPUTE_ZONE: 'my_compute_zone1',
+            const.COMPUTE_ZONE: CONF.load_balancer.availability_zone,
             const.MANAGEMENT_NETWORK: uuidutils.generate_uuid(),
         }
         availability_zone_data_json = jsonutils.dumps(availability_zone_data)
@@ -427,7 +451,7 @@
         availability_zone_profile_name2 = data_utils.rand_name(
             "lb_admin_availabilityzoneprofile1-update2")
         availability_zone_data2 = {
-            const.COMPUTE_ZONE: 'my_compute_zone2',
+            const.COMPUTE_ZONE:  CONF.load_balancer.availability_zone2,
             const.MANAGEMENT_NETWORK: uuidutils.generate_uuid(),
         }
         availability_zone_data2_json = jsonutils.dumps(availability_zone_data2)
@@ -495,7 +519,7 @@
         availability_zone_profile_name = data_utils.rand_name(
             "lb_admin_availabilityzoneprofile1-delete")
         availability_zone_data = {
-            const.COMPUTE_ZONE: 'my_compute_zone',
+            const.COMPUTE_ZONE: CONF.load_balancer.availability_zone,
             const.MANAGEMENT_NETWORK: uuidutils.generate_uuid(),
         }
         availability_zone_data_json = jsonutils.dumps(availability_zone_data)
diff --git a/releasenotes/notes/skip-az-api-tests-if-azs-not-configured-c5d06cdcf29beeb5.yaml b/releasenotes/notes/skip-az-api-tests-if-azs-not-configured-c5d06cdcf29beeb5.yaml
new file mode 100644
index 0000000..84b1480
--- /dev/null
+++ b/releasenotes/notes/skip-az-api-tests-if-azs-not-configured-c5d06cdcf29beeb5.yaml
@@ -0,0 +1,6 @@
+---
+fixes:
+  - |
+    Fixed availability zone API tests to skip if the required availability
+    zones are not defined in the tempest configuration file and the test run
+    is not using no-op drivers.
diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml
index 38b2d04..392471a 100644
--- a/zuul.d/jobs.yaml
+++ b/zuul.d/jobs.yaml
@@ -365,6 +365,11 @@
           "$TEMPEST_CONFIG":
             load_balancer:
               test_with_noop: True
+              # AZ API tests with no-op need AZs configured but they do not
+              # need to actually exist in Nova due to the no-op driver.
+              availability_zone: bogus-az-1
+              availability_zone2: bogus-az-2
+              availability_zone3: bogus-az-3
         post-config:
           $OCTAVIA_CONF:
             controller_worker: