| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import testtools |
| 16 |
from uuid import UUID |
| 17 |
|
| 18 |
from dateutil import parser |
| 19 |
|
| 20 |
from oslo_log import log as logging |
| 21 |
from oslo_serialization import jsonutils |
| 22 |
from tempest import config |
| 23 |
from tempest.lib.common.utils import data_utils |
| 24 |
from tempest.lib import decorators |
| 25 |
from tempest.lib import exceptions |
| 26 |
|
| 27 |
from octavia_tempest_plugin.common import constants as const |
| 28 |
from octavia_tempest_plugin.tests import test_base |
| 29 |
from octavia_tempest_plugin.tests import waiters |
| 30 |
|
| 31 |
LOG = logging.getLogger(__name__) |
| 32 |
CONF = config.CONF |
| 33 |
|
| 34 |
|
| 35 |
class LoadBalancerScenarioTest(test_base.LoadBalancerBaseTest): |
| 36 |
|
| 37 |
@classmethod |
| 38 |
def resource_setup(cls): |
| 39 |
"""Setup resources needed by the tests.""" |
| 40 |
super(LoadBalancerScenarioTest, cls).resource_setup() |
| 41 |
|
| 42 |
cls.flavor_id = cls._flavor_create({ |
| 43 |
const.LOADBALANCER_TOPOLOGY: |
| 44 |
CONF.load_balancer.loadbalancer_topology}) |
| 45 |
|
| 46 |
@classmethod |
| 47 |
def _flavor_create(cls, flavor_dict, skip_on_not_implemented=False): |
| 48 |
if cls.lb_admin_flavor_profile_client.is_version_supported( |
| 49 |
cls.api_version, '2.6'): |
| 50 |
|
| 51 |
flavor_profile_name = data_utils.rand_name("lb_scenario-setup") |
| 52 |
flavor_data_json = jsonutils.dumps(flavor_dict) |
| 53 |
|
| 54 |
flavor_profile_kwargs = { |
| 55 |
const.NAME: flavor_profile_name, |
| 56 |
const.PROVIDER_NAME: CONF.load_balancer.provider, |
| 57 |
const.FLAVOR_DATA: flavor_data_json |
| 58 |
} |
| 59 |
|
| 60 |
try: |
| 61 |
flavor_profile = ( |
| 62 |
cls.lb_admin_flavor_profile_client.create_flavor_profile( |
| 63 |
**flavor_profile_kwargs)) |
| 64 |
cls.addClassResourceCleanup( |
| 65 |
cls.lb_admin_flavor_profile_client.cleanup_flavor_profile, |
| 66 |
flavor_profile[const.ID]) |
| 67 |
|
| 68 |
flavor_name = data_utils.rand_name("lb_scenario-setup") |
| 69 |
flavor_description = data_utils.arbitrary_string(size=255) |
| 70 |
|
| 71 |
flavor_kwargs = { |
| 72 |
const.NAME: flavor_name, |
| 73 |
const.DESCRIPTION: flavor_description, |
| 74 |
const.ENABLED: True, |
| 75 |
const.FLAVOR_PROFILE_ID: flavor_profile[const.ID]} |
| 76 |
|
| 77 |
flavor = cls.lb_admin_flavor_client.create_flavor( |
| 78 |
**flavor_kwargs) |
| 79 |
cls.addClassResourceCleanup( |
| 80 |
cls.lb_admin_flavor_client.cleanup_a_flavor, |
| 81 |
flavor[const.ID]) |
| 82 |
return flavor[const.ID] |
| 83 |
except (testtools.TestCase.skipException, |
| 84 |
exceptions.NotImplemented): |
| 85 |
msg = (f"Provider driver {CONF.load_balancer.provider} " |
| 86 |
"doesn't support flavors.") |
| 87 |
LOG.debug(msg) |
| 88 |
if skip_on_not_implemented: |
| 89 |
raise cls.skipException(msg) |
| 90 |
|
| 91 |
@decorators.idempotent_id('a5e2e120-4f7e-4c8b-8aac-cf09cb56711c') |
| 92 |
def test_load_balancer_ipv4_CRUD(self): |
| 93 |
self._test_load_balancer_CRUD(4) |
| 94 |
|
| 95 |
@decorators.idempotent_id('86ffecc4-dce8-46f9-936e-8a4c6bcf3959') |
| 96 |
@testtools.skipUnless(CONF.load_balancer.test_with_ipv6, |
| 97 |
'IPv6 testing is disabled') |
| 98 |
def test_load_balancer_ipv6_CRUD(self): |
| 99 |
self._test_load_balancer_CRUD(6) |
| 100 |
|
| 101 |
@decorators.idempotent_id('c9d8b6dd-ef29-40d8-b329-86d31857df3f') |
| 102 |
def test_load_balancer_ipv4_CRUD_with_compute_flavor(self): |
| 103 |
self._test_load_balancer_CRUD(4, |
| 104 |
use_custom_compute_flavor=True) |
| 105 |
|
| 106 |
@decorators.idempotent_id('2f1c2bdc-0df9-4c1e-be83-910fcd5af8f2') |
| 107 |
@testtools.skipUnless(CONF.load_balancer.test_with_ipv6, |
| 108 |
'IPv6 testing is disabled') |
| 109 |
def test_load_balancer_ipv6_CRUD_with_compute_flavor(self): |
| 110 |
self._test_load_balancer_CRUD(6, |
| 111 |
use_custom_compute_flavor=True) |
| 112 |
|
| 113 |
def _test_load_balancer_CRUD(self, ip_version, |
| 114 |
use_custom_compute_flavor=False): |
| 115 |
"""Tests load balancer create, read, update, delete |
| 116 |
|
| 117 |
* Create a fully populated load balancer. |
| 118 |
* Show load balancer details. |
| 119 |
* Update the load balancer. |
| 120 |
* Delete the load balancer. |
| 121 |
""" |
| 122 |
if use_custom_compute_flavor: |
| 123 |
if not self.lb_admin_flavor_profile_client.is_version_supported( |
| 124 |
self.api_version, '2.6'): |
| 125 |
raise self.skipException( |
| 126 |
'Flavors and flavor profiles are supported in ' |
| 127 |
'Octavia API version 2.6 or newer.') |
| 128 |
|
| 129 |
compute_flavor_kwargs = { |
| 130 |
const.NAME: data_utils.rand_name("lb_scenario_alt_amp_flavor"), |
| 131 |
const.RAM: 2048, |
| 132 |
const.VCPUS: 1, |
| 133 |
const.DISK: 4, |
| 134 |
} |
| 135 |
|
| 136 |
compute_flavor = ( |
| 137 |
self.os_admin_compute_flavors_client.create_flavor( |
| 138 |
**compute_flavor_kwargs)['flavor']) |
| 139 |
self.addCleanup( |
| 140 |
self.os_admin_compute_flavors_client.delete_flavor, |
| 141 |
compute_flavor[const.ID]) |
| 142 |
|
| 143 |
flavor_id = self._flavor_create({ |
| 144 |
const.COMPUTE_FLAVOR: compute_flavor[const.ID] |
| 145 |
}, skip_on_not_implemented=True) |
| 146 |
else: |
| 147 |
flavor_id = self.flavor_id |
| 148 |
|
| 149 |
lb_name = data_utils.rand_name("lb_member_lb1-CRUD") |
| 150 |
lb_description = data_utils.arbitrary_string(size=255) |
| 151 |
|
| 152 |
lb_kwargs = {const.ADMIN_STATE_UP: False, |
| 153 |
const.DESCRIPTION: lb_description, |
| 154 |
const.PROVIDER: CONF.load_balancer.provider, |
| 155 |
const.NAME: lb_name} |
| 156 |
|
| 157 |
if self.lb_admin_flavor_profile_client.is_version_supported( |
| 158 |
self.api_version, '2.6') and flavor_id: |
| 159 |
lb_kwargs[const.FLAVOR_ID] = flavor_id |
| 160 |
|
| 161 |
self._setup_lb_network_kwargs(lb_kwargs, ip_version) |
| 162 |
|
| 163 |
lb = self.mem_lb_client.create_loadbalancer(**lb_kwargs) |
| 164 |
self.addCleanup( |
| 165 |
self.mem_lb_client.cleanup_loadbalancer, |
| 166 |
lb[const.ID]) |
| 167 |
|
| 168 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 169 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 170 |
const.ACTIVE, |
| 171 |
CONF.load_balancer.lb_build_interval, |
| 172 |
CONF.load_balancer.lb_build_timeout) |
| 173 |
|
| 174 |
self.assertFalse(lb[const.ADMIN_STATE_UP]) |
| 175 |
parser.parse(lb[const.CREATED_AT]) |
| 176 |
parser.parse(lb[const.UPDATED_AT]) |
| 177 |
self.assertEqual(lb_description, lb[const.DESCRIPTION]) |
| 178 |
UUID(lb[const.ID]) |
| 179 |
self.assertEqual(lb_name, lb[const.NAME]) |
| 180 |
self.assertEqual(const.OFFLINE, lb[const.OPERATING_STATUS]) |
| 181 |
self.assertEqual(self.os_roles_lb_member.credentials.project_id, |
| 182 |
lb[const.PROJECT_ID]) |
| 183 |
self.assertEqual(CONF.load_balancer.provider, lb[const.PROVIDER]) |
| 184 |
if ip_version == 4: |
| 185 |
self.assertEqual(self.lb_member_vip_net[const.ID], |
| 186 |
lb[const.VIP_NETWORK_ID]) |
| 187 |
else: |
| 188 |
self.assertEqual(self.lb_member_vip_ipv6_net[const.ID], |
| 189 |
lb[const.VIP_NETWORK_ID]) |
| 190 |
self.assertIsNotNone(lb[const.VIP_PORT_ID]) |
| 191 |
if lb_kwargs[const.VIP_SUBNET_ID]: |
| 192 |
self.assertEqual(lb_kwargs[const.VIP_SUBNET_ID], |
| 193 |
lb[const.VIP_SUBNET_ID]) |
| 194 |
|
| 195 |
if use_custom_compute_flavor: |
| 196 |
amphorae = self.lb_admin_amphora_client.list_amphorae( |
| 197 |
query_params=f'{const.LOADBALANCER_ID}={lb[const.ID]}') |
| 198 |
amphora = amphorae[0] |
| 199 |
self.assertEqual(compute_flavor[const.ID], |
| 200 |
amphora[const.COMPUTE_FLAVOR]) |
| 201 |
|
| 202 |
|
| 203 |
new_name = data_utils.rand_name("lb_member_lb1-update") |
| 204 |
new_description = data_utils.arbitrary_string(size=255, |
| 205 |
base_text='new') |
| 206 |
lb = self.mem_lb_client.update_loadbalancer( |
| 207 |
lb[const.ID], |
| 208 |
admin_state_up=True, |
| 209 |
description=new_description, |
| 210 |
name=new_name) |
| 211 |
|
| 212 |
lb = waiters.wait_for_status(self.mem_lb_client.show_loadbalancer, |
| 213 |
lb[const.ID], const.PROVISIONING_STATUS, |
| 214 |
const.ACTIVE, |
| 215 |
CONF.load_balancer.lb_build_interval, |
| 216 |
CONF.load_balancer.lb_build_timeout) |
| 217 |
|
| 218 |
self.assertTrue(lb[const.ADMIN_STATE_UP]) |
| 219 |
self.assertEqual(new_description, lb[const.DESCRIPTION]) |
| 220 |
self.assertEqual(new_name, lb[const.NAME]) |
| 221 |
|
| 222 |
|
| 223 |
self.mem_lb_client.delete_loadbalancer(lb[const.ID], cascade=True) |
| 224 |
|
| 225 |
waiters.wait_for_deleted_status_or_not_found( |
| 226 |
self.mem_lb_client.show_loadbalancer, lb[const.ID], |
| 227 |
const.PROVISIONING_STATUS, |
| 228 |
CONF.load_balancer.check_interval, |
| 229 |
CONF.load_balancer.check_timeout) |