1
# Copyright 2015 Hewlett-Packard Development Company, L.P.
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
15
from oslo_log import log as logging
16
from oslo_utils import uuidutils
18
from neutron_lbaas.tests.tempest.lib.common.utils import data_utils
19
from neutron_lbaas.tests.tempest.lib import config
20
from neutron_lbaas.tests.tempest.lib import test
21
from neutron_lbaas.tests.tempest.v2.api import base
25
LOG = logging.getLogger(__name__)
28
class TestHealthMonitors(base.BaseAdminTestCase):
31
Tests the following operations in the Neutron-LBaaS API using the
32
REST client for Health Monitors with ADMIN role:
34
create health monitor with missing tenant_id
35
create health monitor with empty tenant id
36
create health monitor with another tenant_id
40
def resource_setup(cls):
41
super(TestHealthMonitors, cls).resource_setup()
42
if not test.is_extension_enabled('lbaas', 'network'):
43
msg = "lbaas extension not enabled."
44
raise cls.skipException(msg)
45
network_name = data_utils.rand_name('network-')
46
cls.network = cls.create_network(network_name)
47
cls.subnet = cls.create_subnet(cls.network)
48
cls.load_balancer = cls._create_load_balancer(
49
tenant_id=cls.subnet.get('tenant_id'),
50
vip_subnet_id=cls.subnet.get('id'))
51
cls.listener = cls._create_listener(
52
loadbalancer_id=cls.load_balancer.get('id'),
53
protocol='HTTP', protocol_port=80)
54
cls.pool = cls._create_pool(
55
protocol='HTTP', lb_algorithm='ROUND_ROBIN',
56
listener_id=cls.listener.get('id'))
59
def resource_cleanup(cls):
60
super(TestHealthMonitors, cls).resource_cleanup()
62
@test.attr(type='smoke')
63
def test_create_health_monitor_missing_tenant_id_field(self):
65
Test if admin user can create health monitor with a missing tenant id
68
hm = self._create_health_monitor(type='HTTP', delay=3, max_retries=10,
70
pool_id=self.pool.get('id'))
72
admin_hm = self.health_monitors_client.get_health_monitor(hm.get('id'))
73
admin_tenant_id = admin_hm.get('tenant_id')
74
hm_tenant_id = hm.get('tenant_id')
75
self.assertEqual(admin_tenant_id, hm_tenant_id)
78
self._delete_health_monitor(hm.get('id'))
80
@test.attr(type='smoke')
81
def test_create_health_monitor_empty_tenant_id_field(self):
83
Test with admin user create health monitor with an empty tenant id
86
hm = self._create_health_monitor(type='HTTP', delay=3, max_retries=10,
88
pool_id=self.pool.get('id'),
91
self.assertEqual(hm.get('tenant_id'), "")
94
self._delete_health_monitor(hm.get('id'))
96
@test.attr(type='smoke')
97
def test_create_health_monitor_for_another_tenant_id_field(self):
98
"""Test with admin user create health monitor for another tenant id.
101
tenantid = uuidutils.generate_uuid()
102
hm = self._create_health_monitor(type='HTTP', delay=3, max_retries=10,
104
pool_id=self.pool.get('id'),
107
self.assertEqual(hm.get('tenant_id'), tenantid)
108
self.assertNotEqual(hm.get('tenant_id'),
109
self.subnet.get('tenant_id'))
111
self._delete_health_monitor(hm.get('id'))