Merge "Fix resize to same host failed using anti-affinity group"
This commit is contained in:
commit
07779e52b7
@ -87,6 +87,11 @@ class _GroupAntiAffinityFilter(filters.BaseHostFilter):
|
||||
if spec_obj.instance_group else [])
|
||||
if self.policy_name not in policies:
|
||||
return True
|
||||
# NOTE(hanrong): Move operations like resize can check the same source
|
||||
# compute node where the instance is. That case, AntiAffinityFilter
|
||||
# must not return the source as a non-possible destination.
|
||||
if spec_obj.instance_uuid in host_state.instances.keys():
|
||||
return True
|
||||
|
||||
group_hosts = (spec_obj.instance_group.hosts
|
||||
if spec_obj.instance_group else [])
|
||||
|
@ -380,6 +380,21 @@ class ServerGroupTestV21(ServerGroupTestBase):
|
||||
self.assertNotEqual(servers[0]['OS-EXT-SRV-ATTR:host'],
|
||||
migrated_server['OS-EXT-SRV-ATTR:host'])
|
||||
|
||||
def test_resize_to_same_host_with_anti_affinity(self):
|
||||
self.flags(allow_resize_to_same_host=True)
|
||||
created_group = self.api.post_server_groups(self.anti_affinity)
|
||||
servers = self._boot_servers_to_group(created_group,
|
||||
flavor=self.api.get_flavors()[0])
|
||||
|
||||
post = {'resize': {'flavorRef': '2'}}
|
||||
server1_old_host = servers[1]['OS-EXT-SRV-ATTR:host']
|
||||
self.admin_api.post_server_action(servers[1]['id'], post)
|
||||
migrated_server = self._wait_for_state_change(servers[1],
|
||||
'VERIFY_RESIZE')
|
||||
|
||||
self.assertEqual(server1_old_host,
|
||||
migrated_server['OS-EXT-SRV-ATTR:host'])
|
||||
|
||||
def _get_compute_service_by_host_name(self, host_name):
|
||||
host = None
|
||||
if self.compute.host == host_name:
|
||||
|
@ -10,6 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import uuid
|
||||
|
||||
import mock
|
||||
|
||||
import nova.conf
|
||||
@ -152,7 +154,7 @@ class TestGroupAffinityFilter(test.NoDBTestCase):
|
||||
policies=['affinity']))
|
||||
self.assertTrue(filt_cls.host_passes(host, spec_obj))
|
||||
spec_obj = objects.RequestSpec(instance_group=objects.InstanceGroup(
|
||||
policies=[policy]))
|
||||
policies=[policy]), instance_uuid=str(uuid.uuid4()))
|
||||
spec_obj.instance_group.hosts = []
|
||||
self.assertTrue(filt_cls.host_passes(host, spec_obj))
|
||||
spec_obj.instance_group.hosts = ['host2']
|
||||
@ -165,9 +167,10 @@ class TestGroupAffinityFilter(test.NoDBTestCase):
|
||||
|
||||
def _test_group_anti_affinity_filter_fails(self, filt_cls, policy):
|
||||
host = fakes.FakeHostState('host1', 'node1', {})
|
||||
spec_obj = objects.RequestSpec(instance_group=objects.InstanceGroup(
|
||||
policies=[policy],
|
||||
hosts=['host1']))
|
||||
spec_obj = objects.RequestSpec(
|
||||
instance_group=objects.InstanceGroup(policies=[policy],
|
||||
hosts=['host1']),
|
||||
instance_uuid=str(uuid.uuid4()))
|
||||
self.assertFalse(filt_cls.host_passes(host, spec_obj))
|
||||
|
||||
def test_group_anti_affinity_filter_fails(self):
|
||||
@ -175,6 +178,17 @@ class TestGroupAffinityFilter(test.NoDBTestCase):
|
||||
affinity_filter.ServerGroupAntiAffinityFilter(),
|
||||
'anti-affinity')
|
||||
|
||||
def test_group_anti_affinity_filter_allows_instance_to_same_host(self):
|
||||
fake_uuid = str(uuid.uuid4())
|
||||
mock_instance = objects.Instance(uuid=fake_uuid)
|
||||
host_state = fakes.FakeHostState('host1', 'node1',
|
||||
{}, instances=[mock_instance])
|
||||
spec_obj = objects.RequestSpec(instance_group=objects.InstanceGroup(
|
||||
policies=['anti-affinity'], hosts=['host1', 'host2']),
|
||||
instance_uuid=mock_instance.uuid)
|
||||
self.assertTrue(affinity_filter.ServerGroupAntiAffinityFilter().
|
||||
host_passes(host_state, spec_obj))
|
||||
|
||||
def _test_group_affinity_filter_passes(self, filt_cls, policy):
|
||||
host = fakes.FakeHostState('host1', 'node1', {})
|
||||
spec_obj = objects.RequestSpec(instance_group=None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user