Stop provider and flavor API stubs failing calls

We have stubbed out provider and flavor in the Octavia v2 API but
these have not yet be fully implemented.
This patch returns the appropriate error when the user specifies a
provider or flavor.

Change-Id: I52350944a377791eafdb407c51301250377c8a49
Closes-Bug: #1698654
This commit is contained in:
Michael Johnson 2017-06-21 17:08:07 -07:00
parent 9b52452762
commit af71a91603
4 changed files with 63 additions and 3 deletions

View File

@ -194,6 +194,14 @@ class LoadBalancersController(base.BaseController):
listeners = lb_dict.pop('listeners', []) or []
pools = lb_dict.pop('pools', []) or []
# TODO(johnsom) Remove provider and flavor from the lb_dict
# as they have not been implemented beyond the API yet.
# Remove these lines as they are implemented.
if 'provider' in lb_dict:
del lb_dict['provider']
if 'flavor' in lb_dict:
del lb_dict['flavor']
db_lb = self.repositories.create_load_balancer_and_vip(
lock_session, lb_dict, vip_dict)

View File

@ -17,6 +17,7 @@ from wsme import types as wtypes
from octavia.api.common import types
from octavia.api.v2.types import listener
from octavia.api.v2.types import pool
from octavia.common import constants
class BaseLoadBalancerType(types.BaseType):
@ -111,8 +112,12 @@ class LoadBalancerPOST(BaseLoadBalancerType):
project_id = wtypes.wsattr(wtypes.StringType(max_length=36))
listeners = wtypes.wsattr([listener.ListenerSingleCreate], default=[])
pools = wtypes.wsattr([pool.PoolSingleCreate], default=[])
provider = wtypes.wsattr(wtypes.StringType(max_length=255))
flavor = wtypes.wsattr(wtypes.StringType(max_length=255))
# TODO(johnsom) This should be dynamic based on the loaded providers
# once providers are implemented.
provider = wtypes.wsattr(wtypes.Enum(str, *constants.SUPPORTED_PROVIDERS))
# TODO(johnsom) This should be dynamic based on the loaded flavors
# once flavors are implemented.
flavor = wtypes.wsattr(wtypes.Enum(str, *constants.SUPPORTED_FLAVORS))
class LoadBalancerRootPOST(types.BaseType):

View File

@ -440,10 +440,18 @@ RBAC_HEALTHMONITOR = '{}:healthmonitor:'.format(LOADBALANCER_API)
RBAC_L7POLICY = '{}:l7policy:'.format(LOADBALANCER_API)
RBAC_L7RULE = '{}:l7rule:'.format(LOADBALANCER_API)
RBAC_QUOTA = '{}:quota:'.format(LOADBALANCER_API)
RBAC_POST = 'post'
RBAC_PUT = 'put'
RBAC_DELETE = 'delete'
RBAC_GET_ONE = 'get_one'
RBAC_GET_ALL = 'get_all'
RBAC_GET_ALL_GLOBAL = 'get_all-global'
# PROVIDERS
# TODO(johnsom) When providers are implemented, this should be removed.
OCTAVIA = 'octavia'
SUPPORTED_PROVIDERS = OCTAVIA,
# FLAVORS
# TODO(johnsom) When flavors are implemented, this should be removed.
SUPPORTED_FLAVORS = ()

View File

@ -396,6 +396,45 @@ class TestLoadBalancer(base.BaseAPITest):
self.conf.config(auth_strategy=auth_strategy)
self.assertEqual(self.NOT_AUTHORIZED_BODY, api_lb)
def test_create_provider_octavia(self, **optionals):
lb_json = {'name': 'test1',
'vip_subnet_id': uuidutils.generate_uuid(),
'project_id': self.project_id,
'provider': constants.OCTAVIA
}
lb_json.update(optionals)
body = self._build_body(lb_json)
response = self.post(self.LBS_PATH, body)
api_lb = response.json.get(self.root_tag)
self._assert_request_matches_response(lb_json, api_lb)
return api_lb
def test_create_provider_bogus(self, **optionals):
lb_json = {'name': 'test1',
'vip_subnet_id': uuidutils.generate_uuid(),
'project_id': self.project_id,
'provider': 'BOGUS'
}
lb_json.update(optionals)
body = self._build_body(lb_json)
response = self.post(self.LBS_PATH, body, status=400)
self.assertIn("Invalid input for field/attribute provider. Value: "
"'BOGUS'. Value should be one of:",
response.json.get('faultstring'))
def test_create_flavor_bogus(self, **optionals):
lb_json = {'name': 'test1',
'vip_subnet_id': uuidutils.generate_uuid(),
'project_id': self.project_id,
'flavor': 'BOGUS'
}
lb_json.update(optionals)
body = self._build_body(lb_json)
response = self.post(self.LBS_PATH, body, status=400)
self.assertIn("Invalid input for field/attribute flavor. Value: "
"'BOGUS'. Value should be one of:",
response.json.get('faultstring'))
def test_get_all_admin(self):
project_id = uuidutils.generate_uuid()
lb1 = self.create_load_balancer(uuidutils.generate_uuid(),