Code cleanup
* Most of v2/fakes.py's content replaced by constants and a single utility function. * Corrected pool columns provisioning_status field name * Renamed TestL7Policy class name to TestL7Rule in test_l7rule.py * Removed calls for dict.keys() is tests/fakes.py * Renamed 'mem' class member to '_mem' for consistency Change-Id: Icf978dfdc3c82e16d1ca94fd9a1cce0053527db0
This commit is contained in:
@@ -99,7 +99,7 @@ POOL_COLUMNS = (
|
||||
'id',
|
||||
'name',
|
||||
'project_id',
|
||||
'provisioning status',
|
||||
'provisioning_status',
|
||||
'protocol',
|
||||
'lb_algorithm',
|
||||
'admin_state_up')
|
||||
|
@@ -208,13 +208,13 @@ class FakeResource(object):
|
||||
setattr(self, name, method)
|
||||
|
||||
def __repr__(self):
|
||||
reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and
|
||||
reprkeys = sorted(k for k in self.__dict__ if k[0] != '_' and
|
||||
k != 'manager')
|
||||
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
|
||||
return "<%s %s>" % (self.__class__.__name__, info)
|
||||
|
||||
def keys(self):
|
||||
return self._info.keys()
|
||||
return list(self._info)
|
||||
|
||||
def to_dict(self):
|
||||
return self._info
|
||||
|
146
octaviaclient/tests/unit/osc/v2/constants.py
Normal file
146
octaviaclient/tests/unit/osc/v2/constants.py
Normal file
@@ -0,0 +1,146 @@
|
||||
# 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.
|
||||
#
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
AMPHORA_ATTRS = {
|
||||
"id": uuidutils.generate_uuid(dashed=True),
|
||||
"loadbalancer_id": uuidutils.generate_uuid(dashed=True),
|
||||
"compute_id": uuidutils.generate_uuid(dashed=True),
|
||||
"lb_network_ip": "192.168.1.3",
|
||||
"vrrp_ip": "192.168.1.6",
|
||||
"ha_ip": "192.168.1.10",
|
||||
"vrrp_port_id": uuidutils.generate_uuid(dashed=True),
|
||||
"ha_port_id": uuidutils.generate_uuid(dashed=True),
|
||||
"cert_expiration": "2019-09-19 00:34:51",
|
||||
"cert_busy": 0,
|
||||
"role": "BACKUP",
|
||||
"status": "ALLOCATED",
|
||||
"vrrp_interface": "eth1",
|
||||
"vrrp_id": 1,
|
||||
"vrrp_priority": 200,
|
||||
"cached_zone": "zone2",
|
||||
}
|
||||
|
||||
HM_ATTRS = {
|
||||
"project_id": uuidutils.generate_uuid(dashed=True),
|
||||
"name": "hm-name-" + uuidutils.generate_uuid(dashed=True),
|
||||
"admin_state_up": True,
|
||||
"pools": [
|
||||
{
|
||||
"id": uuidutils.generate_uuid(dashed=True)
|
||||
}
|
||||
],
|
||||
"created_at": "2017-05-10T06:11:10",
|
||||
"provisioning_status": "PENDING_CREATE",
|
||||
"delay": 10,
|
||||
"expected_codes": "200",
|
||||
"max_retries": 2,
|
||||
"http_method": "GET",
|
||||
"timeout": 10,
|
||||
"max_retries_down": 3,
|
||||
"url_path": "/some/custom/path",
|
||||
"type": "HTTP",
|
||||
"id": uuidutils.generate_uuid(dashed=True),
|
||||
}
|
||||
|
||||
LISTENER_ATTRS = {
|
||||
"id": uuidutils.generate_uuid(),
|
||||
"name": "li-name-" + uuidutils.generate_uuid(dashed=True),
|
||||
"project_id": uuidutils.generate_uuid(dashed=True),
|
||||
"protocol": "HTTP",
|
||||
"protocol_port": 80,
|
||||
"provisioning_status": "ACTIVE",
|
||||
"default_pool_id": None,
|
||||
"connection_limit": 10,
|
||||
"admin_state_up": True,
|
||||
"default_tls_container_ref": uuidutils.generate_uuid(dashed=True),
|
||||
"sni_container_refs": [uuidutils.generate_uuid(dashed=True),
|
||||
uuidutils.generate_uuid(dashed=True)],
|
||||
}
|
||||
|
||||
LOADBALANCER_ATTRS = {
|
||||
"id": uuidutils.generate_uuid(),
|
||||
"name": "lb-name-" + uuidutils.generate_uuid(dashed=True),
|
||||
"project_id": uuidutils.generate_uuid(dashed=True),
|
||||
"vip_address": "192.0.2.124",
|
||||
"vip_network_id": uuidutils.generate_uuid(dashed=True),
|
||||
"provisioning_status": "ONLINE",
|
||||
"provider": "octavia",
|
||||
}
|
||||
|
||||
L7POLICY_ATTRS = {
|
||||
"listener_id": uuidutils.generate_uuid(),
|
||||
"description": "fake desc",
|
||||
"admin_state_up": True,
|
||||
"rules": [{"id": uuidutils.generate_uuid()}],
|
||||
"provisioning_status": "active",
|
||||
"redirect_pool_id": uuidutils.generate_uuid(),
|
||||
"action": "POOL_REDIRECT",
|
||||
"position": 1,
|
||||
"project_id": uuidutils.generate_uuid(),
|
||||
"id": uuidutils.generate_uuid(),
|
||||
"name": "l7po-name-" + uuidutils.generate_uuid(dashed=True),
|
||||
}
|
||||
|
||||
L7RULE_ATTRS = {
|
||||
"created_at": "2017-05-04T18:46:35",
|
||||
"compare_type": "ENDS_WITH",
|
||||
"provisioning_status": "ACTIVE",
|
||||
"invert": False,
|
||||
"admin_state_up": True,
|
||||
"value": ".example.com",
|
||||
"key": None,
|
||||
"project_id": uuidutils.generate_uuid(),
|
||||
"type": "HOST_NAME",
|
||||
"id": uuidutils.generate_uuid(),
|
||||
"operating_status": "ONLINE",
|
||||
}
|
||||
|
||||
MEMBER_ATTRS = {
|
||||
"project_id": uuidutils.generate_uuid(dashed=True),
|
||||
"name": "test-member",
|
||||
"weight": 1,
|
||||
"admin_state_up": True,
|
||||
"subnet_id": uuidutils.generate_uuid(dashed=True),
|
||||
"tenant_id": uuidutils.generate_uuid(dashed=True),
|
||||
"provisioning_status": "ACTIVE",
|
||||
"address": "192.0.2.122",
|
||||
"protocol_port": 80,
|
||||
"id": uuidutils.generate_uuid(dashed=True),
|
||||
"operating_status": "NO_MONITOR",
|
||||
"pool_id": uuidutils.generate_uuid(dashed=True),
|
||||
}
|
||||
|
||||
POOL_ATTRS = {
|
||||
"admin_state_up": True,
|
||||
"description": "fake desc",
|
||||
"id": uuidutils.generate_uuid(),
|
||||
"lb_algorithm": "ROUND_ROBIN",
|
||||
"listeners": [{"id": uuidutils.generate_uuid()}],
|
||||
"loadbalancers": [{"id": uuidutils.generate_uuid()}],
|
||||
"members": [{"id": uuidutils.generate_uuid()}],
|
||||
"name": "po-name-" + uuidutils.generate_uuid(dashed=True),
|
||||
"project_id": uuidutils.generate_uuid(dashed=True),
|
||||
"protocol": "HTTP",
|
||||
"provisioning_status": "ACTIVE",
|
||||
}
|
||||
|
||||
QUOTA_ATTRS = {
|
||||
"health_monitor": -1,
|
||||
"listener": None,
|
||||
"load_balancer": 5,
|
||||
"member": 50,
|
||||
"pool": None,
|
||||
"project_id": uuidutils.generate_uuid(dashed=True),
|
||||
}
|
@@ -14,18 +14,10 @@
|
||||
import copy
|
||||
import mock
|
||||
|
||||
from octaviaclient.tests import fakes
|
||||
from osc_lib.tests import utils
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
LOADBALANCER = {
|
||||
'id': 'lbid',
|
||||
'name': 'lb1',
|
||||
'project_id': 'dummyproject',
|
||||
'vip_address': '192.0.2.2',
|
||||
'provisioning_status': 'ONLINE',
|
||||
'provider': 'octavia'
|
||||
}
|
||||
from octaviaclient.tests import fakes
|
||||
from octaviaclient.tests.unit.osc.v2 import constants
|
||||
|
||||
|
||||
class FakeOctaviaClient(object):
|
||||
@@ -46,280 +38,20 @@ class TestOctaviaClient(utils.TestCommand):
|
||||
)
|
||||
|
||||
|
||||
class FakeLoadBalancer(object):
|
||||
"""Fake one or more load balancers."""
|
||||
def createFakeResource(name, attrs=None):
|
||||
"""Creates a single fake resource object.
|
||||
|
||||
@staticmethod
|
||||
def create_one_load_balancer(attrs=None):
|
||||
"""Create one load balancer.
|
||||
:param name: resource_name
|
||||
:param attrs: ``dict`` of customized resource attributes
|
||||
:returns: A FakeResource object
|
||||
"""
|
||||
attrs = attrs or {}
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all load balancer attributes
|
||||
:return:
|
||||
A FakeResource object
|
||||
"""
|
||||
attrs = attrs or {}
|
||||
# Set to default
|
||||
resource_info = getattr(constants, "{}_attrs".format(name).upper())
|
||||
assert resource_info is not None, "{} is not found".format(name)
|
||||
|
||||
# Set default attribute
|
||||
lb_info = {
|
||||
'id': uuidutils.generate_uuid(),
|
||||
'name': 'lb-name-' + uuidutils.generate_uuid(dashed=True),
|
||||
'project_id': uuidutils.generate_uuid(dashed=True),
|
||||
'vip_address': '192.0.2.124',
|
||||
'vip_network_id': uuidutils.generate_uuid(dashed=True),
|
||||
'provisioning_status': 'ONLINE',
|
||||
'provider': 'octavia'
|
||||
}
|
||||
|
||||
lb_info.update(attrs)
|
||||
|
||||
lb = fakes.FakeResource(
|
||||
info=copy.deepcopy(lb_info),
|
||||
loaded=True)
|
||||
|
||||
return lb
|
||||
|
||||
|
||||
class FakeListener(object):
|
||||
"""Fake one or more listeners."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_listener(attrs=None):
|
||||
attrs = attrs or {}
|
||||
|
||||
li_info = {
|
||||
'id': uuidutils.generate_uuid(),
|
||||
'name': 'li-name-' + uuidutils.generate_uuid(dashed=True),
|
||||
'project_id': uuidutils.generate_uuid(dashed=True),
|
||||
'protocol': 'HTTP',
|
||||
'protocol_port': 80,
|
||||
'provisioning_status': 'ACTIVE',
|
||||
'default_pool_id': None,
|
||||
'connection_limit': 10,
|
||||
'admin_state_up': True,
|
||||
'default_tls_container_ref': uuidutils.generate_uuid(dashed=True),
|
||||
'sni_container_refs': [uuidutils.generate_uuid(dashed=True),
|
||||
uuidutils.generate_uuid(dashed=True)]
|
||||
}
|
||||
|
||||
li_info.update(attrs)
|
||||
|
||||
li = fakes.FakeResource(
|
||||
info=copy.deepcopy(li_info),
|
||||
loaded=True)
|
||||
|
||||
return li
|
||||
|
||||
|
||||
class FakePool(object):
|
||||
"""Fake one or more pools."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_pool(attrs=None):
|
||||
attrs = attrs or {}
|
||||
|
||||
po_info = {
|
||||
'admin_state_up': True,
|
||||
'description': 'fake desc',
|
||||
'id': uuidutils.generate_uuid(),
|
||||
'lb_algorithm': 'ROUND_ROBIN',
|
||||
'listeners': [{'id': uuidutils.generate_uuid()}],
|
||||
'loadbalancers': [{'id': uuidutils.generate_uuid()}],
|
||||
'members': [{'id': uuidutils.generate_uuid()}],
|
||||
'name': 'po-name-' + uuidutils.generate_uuid(dashed=True),
|
||||
'project_id': uuidutils.generate_uuid(dashed=True),
|
||||
'protocol': 'HTTP',
|
||||
'provisioning_status': 'ACTIVE',
|
||||
}
|
||||
|
||||
po_info.update(attrs)
|
||||
|
||||
po = fakes.FakeResource(
|
||||
info=copy.deepcopy(po_info),
|
||||
loaded=True)
|
||||
|
||||
return po
|
||||
|
||||
|
||||
class FakeMember(object):
|
||||
"""Fake one or more members."""
|
||||
|
||||
@staticmethod
|
||||
def create_member(attrs=None):
|
||||
attrs = attrs or {}
|
||||
|
||||
member = {
|
||||
"project_id": uuidutils.generate_uuid(dashed=True),
|
||||
"name": "test-member",
|
||||
"weight": 1,
|
||||
"admin_state_up": True,
|
||||
"subnet_id": uuidutils.generate_uuid(dashed=True),
|
||||
"tenant_id": uuidutils.generate_uuid(dashed=True),
|
||||
"provisioning_status": "ACTIVE",
|
||||
"address": "192.0.2.122",
|
||||
"protocol_port": 80,
|
||||
"id": uuidutils.generate_uuid(dashed=True),
|
||||
"operating_status": "NO_MONITOR",
|
||||
"pool_id": uuidutils.generate_uuid(dashed=True)
|
||||
}
|
||||
|
||||
member.update(attrs)
|
||||
|
||||
mem = fakes.FakeResource(info=copy.deepcopy(member), loaded=True)
|
||||
|
||||
return mem
|
||||
|
||||
|
||||
class FakeL7Policy(object):
|
||||
"""Fake one or more L7policies."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_l7policy(attrs=None):
|
||||
attrs = attrs or {}
|
||||
|
||||
l7po_info = {
|
||||
"listener_id": uuidutils.generate_uuid(),
|
||||
"description": 'fake desc',
|
||||
"admin_state_up": True,
|
||||
"rules": [{'id': uuidutils.generate_uuid()}],
|
||||
"provisioning_status": 'active',
|
||||
"redirect_pool_id": uuidutils.generate_uuid(),
|
||||
"action": 'POOL_REDIRECT',
|
||||
"position": 1,
|
||||
"project_id": uuidutils.generate_uuid(),
|
||||
"id": uuidutils.generate_uuid(),
|
||||
"name": 'l7po-name-' + uuidutils.generate_uuid(dashed=True)
|
||||
}
|
||||
l7po_info.update(attrs)
|
||||
|
||||
l7po = fakes.FakeResource(
|
||||
info=copy.deepcopy(l7po_info),
|
||||
loaded=True)
|
||||
|
||||
return l7po
|
||||
|
||||
|
||||
class FakeL7Rule(object):
|
||||
"""Fake one or more L7rules."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_l7rule(attrs=None):
|
||||
attrs = attrs or {}
|
||||
|
||||
l7ru_info = {
|
||||
"created_at": "2017-05-04T18:46:35",
|
||||
"compare_type": "ENDS_WITH",
|
||||
"provisioning_status": "ACTIVE",
|
||||
"invert": False,
|
||||
"admin_state_up": True,
|
||||
"value": ".example.com",
|
||||
"key": None,
|
||||
"project_id": uuidutils.generate_uuid(),
|
||||
"type": "HOST_NAME",
|
||||
"id": uuidutils.generate_uuid(),
|
||||
"operating_status": "ONLINE"
|
||||
}
|
||||
|
||||
l7ru_info.update(attrs)
|
||||
|
||||
l7ru = fakes.FakeResource(
|
||||
info=copy.deepcopy(l7ru_info),
|
||||
loaded=True)
|
||||
|
||||
return l7ru
|
||||
|
||||
|
||||
class FakeHM(object):
|
||||
"""Fake one or more health monitors."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_health_monitor(attrs=None):
|
||||
attrs = attrs or {}
|
||||
|
||||
hm_info = {
|
||||
"project_id": uuidutils.generate_uuid(dashed=True),
|
||||
"name": 'hm-name-' + uuidutils.generate_uuid(dashed=True),
|
||||
"admin_state_up": True,
|
||||
"pools": [
|
||||
{
|
||||
"id": uuidutils.generate_uuid(dashed=True)
|
||||
}
|
||||
],
|
||||
"created_at": "2017-05-10T06:11:10",
|
||||
"provisioning_status": "PENDING_CREATE",
|
||||
"delay": 10,
|
||||
"expected_codes": "200",
|
||||
"max_retries": 2,
|
||||
"http_method": "GET",
|
||||
"timeout": 10,
|
||||
"max_retries_down": 3,
|
||||
"url_path": "/some/custom/path",
|
||||
"type": "HTTP",
|
||||
"id": uuidutils.generate_uuid(dashed=True)
|
||||
}
|
||||
|
||||
hm_info.update(attrs)
|
||||
|
||||
hm = fakes.FakeResource(
|
||||
info=copy.deepcopy(hm_info),
|
||||
loaded=True)
|
||||
|
||||
return hm
|
||||
|
||||
|
||||
class FakeQT(object):
|
||||
"""Fake one or more Quota."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_quota(attrs=None):
|
||||
attrs = attrs or {}
|
||||
|
||||
qt_info = {
|
||||
"health_monitor": -1,
|
||||
"listener": None,
|
||||
"load_balancer": 5,
|
||||
"member": 50,
|
||||
"pool": None,
|
||||
"project_id": uuidutils.generate_uuid(dashed=True)
|
||||
}
|
||||
|
||||
qt_info.update(attrs)
|
||||
|
||||
qt = fakes.FakeResource(
|
||||
info=copy.deepcopy(qt_info),
|
||||
loaded=True)
|
||||
|
||||
return qt
|
||||
|
||||
|
||||
class FakeAmphora(object):
|
||||
"""Fake one or more amphorae."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_amphora(attrs=None):
|
||||
attrs = attrs or {}
|
||||
|
||||
amphora = {
|
||||
"id": uuidutils.generate_uuid(dashed=True),
|
||||
"loadbalancer_id": uuidutils.generate_uuid(dashed=True),
|
||||
"compute_id": uuidutils.generate_uuid(dashed=True),
|
||||
"lb_network_ip": "192.168.1.3",
|
||||
"vrrp_ip": "192.168.1.6",
|
||||
"ha_ip": "192.168.1.10",
|
||||
"vrrp_port_id": uuidutils.generate_uuid(dashed=True),
|
||||
"ha_port_id": uuidutils.generate_uuid(dashed=True),
|
||||
"cert_expiration": "2019-09-19 00:34:51",
|
||||
"cert_busy": 0,
|
||||
"role": "BACKUP",
|
||||
"status": "ALLOCATED",
|
||||
"vrrp_interface": "eth1",
|
||||
"vrrp_id": 1,
|
||||
"vrrp_priority": 200,
|
||||
"cached_zone": "zone2",
|
||||
}
|
||||
|
||||
amphora.update(attrs)
|
||||
|
||||
return fakes.FakeResource(
|
||||
info=copy.deepcopy(amphora),
|
||||
loaded=True)
|
||||
resource_info.update(attrs)
|
||||
return fakes.FakeResource(
|
||||
info=copy.deepcopy(resource_info), loaded=True,
|
||||
)
|
||||
|
@@ -18,15 +18,12 @@ import osc_lib.tests.utils as osc_test_utils
|
||||
|
||||
from octaviaclient.osc.v2 import amphora
|
||||
from octaviaclient.osc.v2 import constants
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes as amp_fakes
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://192.0.2.2"
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes
|
||||
|
||||
|
||||
class TestAmphora(amp_fakes.TestOctaviaClient):
|
||||
class TestAmphora(fakes.TestOctaviaClient):
|
||||
|
||||
_amp = amp_fakes.FakeAmphora.create_one_amphora()
|
||||
_amp = fakes.createFakeResource('amphora')
|
||||
|
||||
columns = constants.AMPHORA_COLUMNS
|
||||
rows = constants.AMPHORA_ROWS
|
||||
|
@@ -17,15 +17,12 @@ import mock
|
||||
from osc_lib import exceptions
|
||||
|
||||
from octaviaclient.osc.v2 import health_monitor
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes as hm_fakes
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://192.0.2.2"
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes
|
||||
|
||||
|
||||
class TestHealthMonitor(hm_fakes.TestOctaviaClient):
|
||||
class TestHealthMonitor(fakes.TestOctaviaClient):
|
||||
|
||||
_hm = hm_fakes.FakeHM.create_one_health_monitor()
|
||||
_hm = fakes.createFakeResource('hm')
|
||||
|
||||
columns = ('id', 'name', 'project_id', 'type', 'admin_state_up')
|
||||
|
||||
|
@@ -17,15 +17,12 @@ import mock
|
||||
from osc_lib import exceptions
|
||||
|
||||
from octaviaclient.osc.v2 import l7policy
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes as po_fakes
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://192.0.2.2"
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes
|
||||
|
||||
|
||||
class TestL7Policy(po_fakes.TestOctaviaClient):
|
||||
class TestL7Policy(fakes.TestOctaviaClient):
|
||||
|
||||
_l7po = po_fakes.FakeL7Policy.create_one_l7policy()
|
||||
_l7po = fakes.createFakeResource('l7policy')
|
||||
|
||||
columns = (
|
||||
'id',
|
||||
|
@@ -15,16 +15,14 @@ import copy
|
||||
import mock
|
||||
|
||||
from octaviaclient.osc.v2 import l7rule
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes as ru_fakes
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://192.0.2.2"
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes
|
||||
from octaviaclient.tests.unit.osc.v2 import test_l7policy
|
||||
|
||||
|
||||
class TestL7Policy(ru_fakes.TestOctaviaClient):
|
||||
class TestL7Rule(fakes.TestOctaviaClient):
|
||||
|
||||
_l7ru = ru_fakes.FakeL7Rule.create_one_l7rule()
|
||||
_l7po = ru_fakes.FakeL7Policy.create_one_l7policy()
|
||||
_l7ru = fakes.createFakeResource('l7rule')
|
||||
_l7po = fakes.createFakeResource('l7policy')
|
||||
|
||||
columns = (
|
||||
'id',
|
||||
@@ -64,24 +62,14 @@ class TestL7Policy(ru_fakes.TestOctaviaClient):
|
||||
'admin_state_up': _l7ru.admin_state_up,
|
||||
'invert': _l7ru.invert
|
||||
}]}
|
||||
po_info = {'l7policies': [{
|
||||
"listener_id": _l7po.listener_id,
|
||||
"description": _l7po.description,
|
||||
"admin_state_up": _l7po.admin_state_up,
|
||||
"rules": _l7po.rules,
|
||||
"provisioning_status": _l7po.provisioning_status,
|
||||
"redirect_pool_id": _l7po.redirect_pool_id,
|
||||
"action": _l7po.action,
|
||||
"position": _l7po.position,
|
||||
"project_id": _l7po.project_id,
|
||||
"id": _l7po.id,
|
||||
"name": _l7po.name
|
||||
}]}
|
||||
|
||||
po_info = test_l7policy.TestL7Policy.info
|
||||
|
||||
l7po_info = copy.deepcopy(po_info)
|
||||
l7ru_info = copy.deepcopy(info)
|
||||
|
||||
def setUp(self):
|
||||
super(TestL7Policy, self).setUp()
|
||||
super(TestL7Rule, self).setUp()
|
||||
self.l7ru_mock = self.app.client_manager.load_balancer.load_balancers
|
||||
self.l7ru_mock.reset_mock()
|
||||
|
||||
@@ -92,7 +80,7 @@ class TestL7Policy(ru_fakes.TestOctaviaClient):
|
||||
lb_client.load_balancer = self.api_mock
|
||||
|
||||
|
||||
class TestL7RuleList(TestL7Policy):
|
||||
class TestL7RuleList(TestL7Rule):
|
||||
|
||||
def setUp(self):
|
||||
super(TestL7RuleList, self).setUp()
|
||||
@@ -112,7 +100,7 @@ class TestL7RuleList(TestL7Policy):
|
||||
self.assertEqual(self.datalist, tuple(data))
|
||||
|
||||
|
||||
class TestL7RuleDelete(TestL7Policy):
|
||||
class TestL7RuleDelete(TestL7Rule):
|
||||
|
||||
def setUp(self):
|
||||
super(TestL7RuleDelete, self).setUp()
|
||||
@@ -135,7 +123,7 @@ class TestL7RuleDelete(TestL7Policy):
|
||||
)
|
||||
|
||||
|
||||
class TestL7RuleCreate(TestL7Policy):
|
||||
class TestL7RuleCreate(TestL7Rule):
|
||||
|
||||
def setUp(self):
|
||||
super(TestL7RuleCreate, self).setUp()
|
||||
@@ -178,7 +166,7 @@ class TestL7RuleCreate(TestL7Policy):
|
||||
})
|
||||
|
||||
|
||||
class TestL7RuleShow(TestL7Policy):
|
||||
class TestL7RuleShow(TestL7Rule):
|
||||
|
||||
def setUp(self):
|
||||
super(TestL7RuleShow, self).setUp()
|
||||
@@ -206,7 +194,7 @@ class TestL7RuleShow(TestL7Policy):
|
||||
)
|
||||
|
||||
|
||||
class TestL7RuleSet(TestL7Policy):
|
||||
class TestL7RuleSet(TestL7Rule):
|
||||
|
||||
def setUp(self):
|
||||
super(TestL7RuleSet, self).setUp()
|
||||
|
@@ -16,16 +16,13 @@ import mock
|
||||
|
||||
from osc_lib import exceptions
|
||||
|
||||
from octaviaclient.osc.v2 import listener as listener
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes as li_fakes
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://192.0.2.2"
|
||||
from octaviaclient.osc.v2 import listener
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes
|
||||
|
||||
|
||||
class TestListener(li_fakes.TestOctaviaClient):
|
||||
class TestListener(fakes.TestOctaviaClient):
|
||||
|
||||
_li = li_fakes.FakeListener.create_one_listener()
|
||||
_li = fakes.createFakeResource('listener')
|
||||
|
||||
columns = (
|
||||
'id',
|
||||
|
@@ -18,16 +18,13 @@ import mock
|
||||
from osc_lib import exceptions
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
from octaviaclient.osc.v2 import load_balancer as load_balancer
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes as lb_fakes
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://192.0.2.2"
|
||||
from octaviaclient.osc.v2 import load_balancer
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes
|
||||
|
||||
|
||||
class TestLoadBalancer(lb_fakes.TestOctaviaClient):
|
||||
class TestLoadBalancer(fakes.TestOctaviaClient):
|
||||
|
||||
_lb = lb_fakes.FakeLoadBalancer.create_one_load_balancer()
|
||||
_lb = fakes.createFakeResource('loadbalancer')
|
||||
|
||||
columns = (
|
||||
'id',
|
||||
@@ -189,7 +186,7 @@ class TestLoadBalancerCreate(TestLoadBalancer):
|
||||
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
|
||||
def test_load_balancer_create_missing_args(self, mock_client):
|
||||
# Clone load balancer to avoid race conditions
|
||||
lb = lb_fakes.FakeLoadBalancer.create_one_load_balancer()
|
||||
lb = fakes.createFakeResource('loadbalancer')
|
||||
attrs_list = lb.to_dict()
|
||||
|
||||
args = ("vip_subnet_id", "vip_network_id", "vip_port_id")
|
||||
|
@@ -15,14 +15,15 @@
|
||||
import copy
|
||||
import mock
|
||||
|
||||
from octaviaclient.osc.v2 import member
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes as mem_fakes
|
||||
import osc_lib.tests.utils as osc_test_utils
|
||||
|
||||
from octaviaclient.osc.v2 import member
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes
|
||||
|
||||
class TestMember(mem_fakes.TestOctaviaClient):
|
||||
|
||||
mem = mem_fakes.FakeMember.create_member()
|
||||
class TestMember(fakes.TestOctaviaClient):
|
||||
|
||||
_mem = fakes.createFakeResource('member')
|
||||
|
||||
columns = (
|
||||
'id',
|
||||
@@ -37,27 +38,27 @@ class TestMember(mem_fakes.TestOctaviaClient):
|
||||
|
||||
datalist = (
|
||||
(
|
||||
mem.id,
|
||||
mem.name,
|
||||
mem.project_id,
|
||||
mem.provisioning_status,
|
||||
mem.address,
|
||||
mem.protocol_port,
|
||||
mem.operating_status,
|
||||
mem.weight
|
||||
_mem.id,
|
||||
_mem.name,
|
||||
_mem.project_id,
|
||||
_mem.provisioning_status,
|
||||
_mem.address,
|
||||
_mem.protocol_port,
|
||||
_mem.operating_status,
|
||||
_mem.weight
|
||||
),
|
||||
)
|
||||
|
||||
info = {'members': [{
|
||||
'id': mem.id,
|
||||
'name': mem.name,
|
||||
'project_id': mem.project_id,
|
||||
'provisioning_status': mem.provisioning_status,
|
||||
'address': mem.address,
|
||||
'protocol_port': mem.protocol_port,
|
||||
'operating_status': mem.operating_status,
|
||||
'weight': mem.weight,
|
||||
'pool_id': mem.pool_id}]
|
||||
'id': _mem.id,
|
||||
'name': _mem.name,
|
||||
'project_id': _mem.project_id,
|
||||
'provisioning_status': _mem.provisioning_status,
|
||||
'address': _mem.address,
|
||||
'protocol_port': _mem.protocol_port,
|
||||
'operating_status': _mem.operating_status,
|
||||
'weight': _mem.weight,
|
||||
'pool_id': _mem.pool_id}]
|
||||
}
|
||||
|
||||
mem_info = copy.deepcopy(info)
|
||||
@@ -90,7 +91,7 @@ class TestListMember(TestMember):
|
||||
@mock.patch('octaviaclient.osc.v2.utils.get_member_attrs')
|
||||
def test_member_list(self, mock_attrs):
|
||||
mock_attrs.return_value = {'pool_id': 'pool_id',
|
||||
'project_id': self.mem.project_id}
|
||||
'project_id': self._mem.project_id}
|
||||
arglist = ['pool_id']
|
||||
verifylist = []
|
||||
|
||||
@@ -115,10 +116,10 @@ class TestCreateMember(TestMember):
|
||||
def test_member_create(self, mock_attrs):
|
||||
mock_attrs.return_value = {
|
||||
'ip_address': '192.0.2.122',
|
||||
'protocol_port': self.mem.protocol_port,
|
||||
'weight': self.mem.weight,
|
||||
'protocol_port': self._mem.protocol_port,
|
||||
'weight': self._mem.weight,
|
||||
'admin_state_up': True,
|
||||
'pool_id': self.mem.pool_id}
|
||||
'pool_id': self._mem.pool_id}
|
||||
|
||||
arglist = ['pool_id', '--address', '192.0.2.122',
|
||||
'--protocol-port', '80',
|
||||
@@ -132,10 +133,10 @@ class TestCreateMember(TestMember):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.api_mock.member_create.assert_called_with(
|
||||
pool_id=self.mem.pool_id, json={
|
||||
pool_id=self._mem.pool_id, json={
|
||||
'member': {'ip_address': '192.0.2.122',
|
||||
'protocol_port': self.mem.protocol_port,
|
||||
'weight': self.mem.weight,
|
||||
'protocol_port': self._mem.protocol_port,
|
||||
'weight': self._mem.weight,
|
||||
'admin_state_up': True}})
|
||||
|
||||
|
||||
@@ -198,17 +199,17 @@ class TestMemberShow(TestMember):
|
||||
|
||||
@mock.patch('octaviaclient.osc.v2.utils.get_member_attrs')
|
||||
def test_member_show(self, mock_attrs):
|
||||
mock_attrs.return_value = {'member_id': self.mem.id,
|
||||
'pool_id': self.mem.pool_id}
|
||||
arglist = [self.mem.pool_id, self.mem.id]
|
||||
mock_attrs.return_value = {'member_id': self._mem.id,
|
||||
'pool_id': self._mem.pool_id}
|
||||
arglist = [self._mem.pool_id, self._mem.id]
|
||||
verifylist = [
|
||||
('pool', self.mem.pool_id),
|
||||
('member', self.mem.id)
|
||||
('pool', self._mem.pool_id),
|
||||
('member', self._mem.id)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.api_mock.member_show.assert_called_with(
|
||||
member_id=self.mem.id,
|
||||
pool_id=self.mem.pool_id
|
||||
member_id=self._mem.id,
|
||||
pool_id=self._mem.pool_id
|
||||
)
|
||||
|
@@ -17,20 +17,17 @@ import mock
|
||||
from osc_lib import exceptions
|
||||
|
||||
from octaviaclient.osc.v2 import pool as pool
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes as po_fakes
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://192.0.2.2"
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes
|
||||
|
||||
|
||||
class TestPool(po_fakes.TestOctaviaClient):
|
||||
class TestPool(fakes.TestOctaviaClient):
|
||||
|
||||
_po = po_fakes.FakePool.create_one_pool()
|
||||
_po = fakes.createFakeResource('pool')
|
||||
|
||||
columns = ('id',
|
||||
'name',
|
||||
'project_id',
|
||||
'provisioning status',
|
||||
'provisioning_status',
|
||||
'protocol',
|
||||
'lb_algorithm',
|
||||
'admin_state_up')
|
||||
|
@@ -17,15 +17,12 @@ import mock
|
||||
from osc_lib import exceptions
|
||||
|
||||
from octaviaclient.osc.v2 import quota
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes as qt_fakes
|
||||
|
||||
AUTH_TOKEN = "foobar"
|
||||
AUTH_URL = "http://192.0.2.2"
|
||||
from octaviaclient.tests.unit.osc.v2 import fakes
|
||||
|
||||
|
||||
class TestQuota(qt_fakes.TestOctaviaClient):
|
||||
class TestQuota(fakes.TestOctaviaClient):
|
||||
|
||||
_qt = qt_fakes.FakeQT.create_one_quota()
|
||||
_qt = fakes.createFakeResource('quota')
|
||||
|
||||
columns = ('project_id', 'load_balancer', 'listener', 'pool',
|
||||
'health_monitor', 'member')
|
||||
@@ -212,7 +209,7 @@ class TestQuotaReset(TestQuota):
|
||||
# due to a race condition
|
||||
project_id = 'fake_project_id'
|
||||
attrs = {'project_id': project_id}
|
||||
qt_reset = qt_fakes.FakeQT.create_one_quota(attrs)
|
||||
qt_reset = fakes.createFakeResource('quota', attrs)
|
||||
|
||||
mock_attrs.return_value = qt_reset.to_dict()
|
||||
|
||||
|
@@ -11,10 +11,11 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from octaviaclient.osc.v2 import validate
|
||||
from osc_lib import exceptions
|
||||
from osc_lib.tests import utils
|
||||
|
||||
from octaviaclient.osc.v2 import validate
|
||||
|
||||
|
||||
class TestValidations(utils.TestCommand):
|
||||
def setUp(self):
|
||||
|
Reference in New Issue
Block a user