Merge "Fix ServerGroup create"
This commit is contained in:
commit
4fec77f769
|
@ -35,11 +35,13 @@ class ServerGroup(resource.Resource):
|
||||||
entity = 'server_groups'
|
entity = 'server_groups'
|
||||||
|
|
||||||
PROPERTIES = (
|
PROPERTIES = (
|
||||||
NAME, POLICIES, RULE
|
NAME, POLICIES, RULES
|
||||||
) = (
|
) = (
|
||||||
'name', 'policies', 'rule'
|
'name', 'policies', 'rules'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_RULES = (MAX_SERVER_PER_HOST) = ('max_server_per_host')
|
||||||
|
|
||||||
properties_schema = {
|
properties_schema = {
|
||||||
NAME: properties.Schema(
|
NAME: properties.Schema(
|
||||||
properties.Schema.STRING,
|
properties.Schema.STRING,
|
||||||
|
@ -47,7 +49,7 @@ class ServerGroup(resource.Resource):
|
||||||
),
|
),
|
||||||
POLICIES: properties.Schema(
|
POLICIES: properties.Schema(
|
||||||
properties.Schema.LIST,
|
properties.Schema.LIST,
|
||||||
_('A list of string policies to apply. '
|
_('A list of exactly one policy to apply. '
|
||||||
'Defaults to anti-affinity.'),
|
'Defaults to anti-affinity.'),
|
||||||
default=['anti-affinity'],
|
default=['anti-affinity'],
|
||||||
constraints=[
|
constraints=[
|
||||||
|
@ -59,11 +61,17 @@ class ServerGroup(resource.Resource):
|
||||||
properties.Schema.STRING,
|
properties.Schema.STRING,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
RULE: properties.Schema(
|
RULES: properties.Schema(
|
||||||
properties.Schema.MAP,
|
properties.Schema.MAP,
|
||||||
_('A rule for the policy. Currently, only the '
|
_('Rules for a policy.'),
|
||||||
'"max_server_per_host" rule is supported for the '
|
schema={
|
||||||
'"anti-affinity" policy.'),
|
MAX_SERVER_PER_HOST: properties.Schema(
|
||||||
|
properties.Schema.NUMBER,
|
||||||
|
_('Maximum servers in a group on a given host. '
|
||||||
|
'Rule for anti-affinity policy.')
|
||||||
|
)
|
||||||
|
},
|
||||||
|
support_status=support.SupportStatus(version='17.0.0'),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,26 +85,19 @@ class ServerGroup(resource.Resource):
|
||||||
msg = _('Required microversion for soft policies not supported.')
|
msg = _('Required microversion for soft policies not supported.')
|
||||||
raise exception.StackValidationFailed(message=msg)
|
raise exception.StackValidationFailed(message=msg)
|
||||||
|
|
||||||
if self.properties[self.RULE]:
|
if self.properties[self.RULES]:
|
||||||
is_supported = self.client_plugin().is_version_supported(
|
is_supported = self.client_plugin().is_version_supported(
|
||||||
MICROVERSION_RULE)
|
MICROVERSION_RULE)
|
||||||
if not is_supported:
|
if not is_supported:
|
||||||
msg = _('Required microversion for rule not supported.')
|
msg = _('Required microversion for rules not supported.')
|
||||||
raise exception.StackValidationFailed(message=msg)
|
raise exception.StackValidationFailed(message=msg)
|
||||||
|
|
||||||
def handle_create(self):
|
def handle_create(self):
|
||||||
name = self.physical_resource_name()
|
name = self.physical_resource_name()
|
||||||
policies = self.properties[self.POLICIES]
|
policies = self.properties[self.POLICIES]
|
||||||
if self.properties[self.RULE] and 'soft-affinity' in policies:
|
rules = self.properties[self.RULES]
|
||||||
rule = self.properties[self.RULE]
|
server_group = self.client().server_groups.create(
|
||||||
client = self.client()
|
name=name, policy=policies[0], rules=rules)
|
||||||
server_group = client.server_groups.create(name=name,
|
|
||||||
policies=policies,
|
|
||||||
rule=rule)
|
|
||||||
else:
|
|
||||||
client = self.client()
|
|
||||||
server_group = client.server_groups.create(name=name,
|
|
||||||
policies=policies)
|
|
||||||
self.resource_id_set(server_group.id)
|
self.resource_id_set(server_group.id)
|
||||||
|
|
||||||
def physical_resource_name(self):
|
def physical_resource_name(self):
|
||||||
|
|
|
@ -26,7 +26,9 @@ sg_template = {
|
||||||
"type": "OS::Nova::ServerGroup",
|
"type": "OS::Nova::ServerGroup",
|
||||||
"properties": {
|
"properties": {
|
||||||
"name": "test",
|
"name": "test",
|
||||||
"policies": ["anti-affinity"]
|
"policies": ["anti-affinity"],
|
||||||
|
"rules": {
|
||||||
|
"max_server_per_host": 8}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +70,7 @@ class NovaServerGroupTest(common.HeatTestCase):
|
||||||
name = 'test'
|
name = 'test'
|
||||||
n = name
|
n = name
|
||||||
|
|
||||||
def fake_create(name, policies):
|
def fake_create(name, policy, rules):
|
||||||
self.assertGreater(len(name), 1)
|
self.assertGreater(len(name), 1)
|
||||||
return FakeGroup(n)
|
return FakeGroup(n)
|
||||||
self.sg_mgr.create = fake_create
|
self.sg_mgr.create = fake_create
|
||||||
|
@ -81,7 +83,9 @@ class NovaServerGroupTest(common.HeatTestCase):
|
||||||
self._create_sg('test')
|
self._create_sg('test')
|
||||||
expected_args = ()
|
expected_args = ()
|
||||||
expected_kwargs = {'name': 'test',
|
expected_kwargs = {'name': 'test',
|
||||||
'policies': ["anti-affinity"],
|
'policy': "anti-affinity",
|
||||||
|
'rules': {
|
||||||
|
'max_server_per_host': 8}
|
||||||
}
|
}
|
||||||
self.sg_mgr.create.assert_called_once_with(*expected_args,
|
self.sg_mgr.create.assert_called_once_with(*expected_args,
|
||||||
**expected_kwargs)
|
**expected_kwargs)
|
||||||
|
|
Loading…
Reference in New Issue