Add Fixtures to set server group for nova instance
A ServerStackFixture that inherits from AffinityServerGroupStackFixture or AntiAffinityServerGroupStackFixture will be scheduled in affinity or anti-affinity groups. Change-Id: I8427dcc2fff3cf326d22d337f7a0d1468eb9f296
This commit is contained in:
parent
78fcbbf119
commit
d08ba7194f
|
@ -56,6 +56,9 @@ SecurityGroupsFixture = _neutron.SecurityGroupsFixture
|
||||||
ServerStackFixture = _nova.ServerStackFixture
|
ServerStackFixture = _nova.ServerStackFixture
|
||||||
KeyPairStackFixture = _nova.KeyPairStackFixture
|
KeyPairStackFixture = _nova.KeyPairStackFixture
|
||||||
FlavorStackFixture = _nova.FlavorStackFixture
|
FlavorStackFixture = _nova.FlavorStackFixture
|
||||||
|
ServerGroupStackFixture = _nova.ServerGroupStackFixture
|
||||||
|
AffinityServerGroupStackFixture = _nova.AffinityServerGroupStackFixture
|
||||||
|
AntiAffinityServerGroupStackFixture = _nova.AntiAffinityServerGroupStackFixture
|
||||||
|
|
||||||
UbuntuFlavorStackFixture = _ubuntu.UbuntuFlavorStackFixture
|
UbuntuFlavorStackFixture = _ubuntu.UbuntuFlavorStackFixture
|
||||||
UbuntuImageFixture = _ubuntu.UbuntuImageFixture
|
UbuntuImageFixture = _ubuntu.UbuntuImageFixture
|
||||||
|
|
|
@ -161,6 +161,11 @@ class ServerStackFixture(heat.HeatStackFixture):
|
||||||
#: Schedule on same host as this Nova server instance ID
|
#: Schedule on same host as this Nova server instance ID
|
||||||
same_host = None
|
same_host = None
|
||||||
|
|
||||||
|
#: Scheduler group in which this Nova server is attached
|
||||||
|
@property
|
||||||
|
def scheduler_group(self):
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scheduler_hints(self):
|
def scheduler_hints(self):
|
||||||
scheduler_hints = {}
|
scheduler_hints = {}
|
||||||
|
@ -168,6 +173,8 @@ class ServerStackFixture(heat.HeatStackFixture):
|
||||||
scheduler_hints.update(different_host=list(self.different_host))
|
scheduler_hints.update(different_host=list(self.different_host))
|
||||||
if self.same_host:
|
if self.same_host:
|
||||||
scheduler_hints.update(same_host=list(self.same_host))
|
scheduler_hints.update(same_host=list(self.same_host))
|
||||||
|
if self.scheduler_group:
|
||||||
|
scheduler_hints.update(group=self.scheduler_group)
|
||||||
return scheduler_hints
|
return scheduler_hints
|
||||||
|
|
||||||
#: allow to retry creating server in case scheduler hits are not respected
|
#: allow to retry creating server in case scheduler hits are not respected
|
||||||
|
@ -293,3 +300,25 @@ def as_str(text):
|
||||||
return text
|
return text
|
||||||
else:
|
else:
|
||||||
return text.decode()
|
return text.decode()
|
||||||
|
|
||||||
|
|
||||||
|
class ServerGroupStackFixture(heat.HeatStackFixture):
|
||||||
|
template = _hot.heat_template_file('nova/server_group.yaml')
|
||||||
|
|
||||||
|
|
||||||
|
class AffinityServerGroupStackFixture(tobiko.SharedFixture):
|
||||||
|
server_group_stack = tobiko.required_setup_fixture(
|
||||||
|
ServerGroupStackFixture)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def scheduler_group(self):
|
||||||
|
return self.server_group_stack.affinity_server_group_id
|
||||||
|
|
||||||
|
|
||||||
|
class AntiAffinityServerGroupStackFixture(tobiko.SharedFixture):
|
||||||
|
server_group_stack = tobiko.required_setup_fixture(
|
||||||
|
ServerGroupStackFixture)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def scheduler_group(self):
|
||||||
|
return self.server_group_stack.anti_affinity_server_group_id
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
heat_template_version: 2014-10-16
|
||||||
|
|
||||||
|
description: |
|
||||||
|
Creates server groups for Nova, the first one with anti-affinity scheduling
|
||||||
|
policy, and the second with affinity scheduling policy.
|
||||||
|
|
||||||
|
resources:
|
||||||
|
anti_affinity_server_group:
|
||||||
|
type: OS::Nova::ServerGroup
|
||||||
|
properties:
|
||||||
|
name: anti_affinity_server_group
|
||||||
|
policies:
|
||||||
|
- anti-affinity
|
||||||
|
|
||||||
|
affinity_server_group:
|
||||||
|
type: OS::Nova::ServerGroup
|
||||||
|
properties:
|
||||||
|
name: affinity_server_group
|
||||||
|
policies:
|
||||||
|
- affinity
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
affinity_server_group_id:
|
||||||
|
value: {get_resource: affinity_server_group}
|
||||||
|
|
||||||
|
anti_affinity_server_group_id:
|
||||||
|
value: {get_resource: anti_affinity_server_group}
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Copyright (c) 2019 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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 __future__ import absolute_import
|
||||||
|
|
||||||
|
import testtools
|
||||||
|
|
||||||
|
import tobiko
|
||||||
|
from tobiko.openstack import stacks
|
||||||
|
|
||||||
|
|
||||||
|
class ServerGroupTestCase(testtools.TestCase):
|
||||||
|
|
||||||
|
affinity_stack = tobiko.required_setup_fixture(
|
||||||
|
stacks.AffinityServerGroupStackFixture)
|
||||||
|
|
||||||
|
def test_affinity_server_group(self):
|
||||||
|
group_id = self.affinity_stack.scheduler_group
|
||||||
|
self.assertIsNotNone(group_id)
|
||||||
|
|
||||||
|
anti_affinity_stack = tobiko.required_setup_fixture(
|
||||||
|
stacks.AntiAffinityServerGroupStackFixture)
|
||||||
|
|
||||||
|
def test_anti_affinity_server_group(self):
|
||||||
|
group_id = self.anti_affinity_stack.scheduler_group
|
||||||
|
self.assertIsNotNone(group_id)
|
Loading…
Reference in New Issue