diff --git a/tobiko/openstack/stacks/__init__.py b/tobiko/openstack/stacks/__init__.py index 067ed1836..d5767645e 100644 --- a/tobiko/openstack/stacks/__init__.py +++ b/tobiko/openstack/stacks/__init__.py @@ -56,6 +56,9 @@ SecurityGroupsFixture = _neutron.SecurityGroupsFixture ServerStackFixture = _nova.ServerStackFixture KeyPairStackFixture = _nova.KeyPairStackFixture FlavorStackFixture = _nova.FlavorStackFixture +ServerGroupStackFixture = _nova.ServerGroupStackFixture +AffinityServerGroupStackFixture = _nova.AffinityServerGroupStackFixture +AntiAffinityServerGroupStackFixture = _nova.AntiAffinityServerGroupStackFixture UbuntuFlavorStackFixture = _ubuntu.UbuntuFlavorStackFixture UbuntuImageFixture = _ubuntu.UbuntuImageFixture diff --git a/tobiko/openstack/stacks/_nova.py b/tobiko/openstack/stacks/_nova.py index 7b53784a1..d23ff0d0f 100644 --- a/tobiko/openstack/stacks/_nova.py +++ b/tobiko/openstack/stacks/_nova.py @@ -161,6 +161,11 @@ class ServerStackFixture(heat.HeatStackFixture): #: Schedule on same host as this Nova server instance ID same_host = None + #: Scheduler group in which this Nova server is attached + @property + def scheduler_group(self): + return None + @property def scheduler_hints(self): scheduler_hints = {} @@ -168,6 +173,8 @@ class ServerStackFixture(heat.HeatStackFixture): scheduler_hints.update(different_host=list(self.different_host)) if 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 #: allow to retry creating server in case scheduler hits are not respected @@ -293,3 +300,25 @@ def as_str(text): return text else: 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 diff --git a/tobiko/openstack/stacks/nova/server_group.yaml b/tobiko/openstack/stacks/nova/server_group.yaml new file mode 100644 index 000000000..78db5bcfe --- /dev/null +++ b/tobiko/openstack/stacks/nova/server_group.yaml @@ -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} diff --git a/tobiko/tests/functional/openstack/stacks/test_nova.py b/tobiko/tests/functional/openstack/stacks/test_nova.py new file mode 100644 index 000000000..3dc9260d3 --- /dev/null +++ b/tobiko/tests/functional/openstack/stacks/test_nova.py @@ -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)