Skip to content

Commit 955f070

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Reproducer test for live migration with power management" into stable/2023.1
2 parents d0a6cd0 + 6d48c12 commit 955f070

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

nova/tests/functional/libvirt/test_power_manage.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,86 @@ def _assert_cpu_set_state(self, cpu_set, expected='online'):
8888
self.assertEqual('performance', core.governor)
8989

9090

91+
class FakeCore(object):
92+
93+
def __init__(self, i):
94+
self.ident = i
95+
self.power_state = 'online'
96+
97+
@property
98+
def online(self):
99+
return self.power_state == 'online'
100+
101+
@online.setter
102+
def online(self, state):
103+
if state:
104+
self.power_state = 'online'
105+
else:
106+
self.power_state = 'offline'
107+
108+
109+
class CoresStub(object):
110+
111+
def __init__(self):
112+
self.cores = {}
113+
114+
def __call__(self, i):
115+
if i not in self.cores:
116+
self.cores[i] = FakeCore(i)
117+
return self.cores[i]
118+
119+
120+
class PowerManagementLiveMigrationTests(base.LibvirtMigrationMixin,
121+
PowerManagementTestsBase):
122+
123+
def setUp(self):
124+
super().setUp()
125+
126+
self.useFixture(nova_fixtures.SysFileSystemFixture())
127+
self.flags(cpu_dedicated_set='1-9', cpu_shared_set=None,
128+
group='compute')
129+
self.flags(vcpu_pin_set=None)
130+
self.flags(cpu_power_management=True, group='libvirt')
131+
132+
# NOTE(artom) Fill up all dedicated CPUs. This makes the assertions
133+
# further down easier.
134+
self.pcpu_flavor_id = self._create_flavor(
135+
vcpu=9, extra_spec=self.extra_spec)
136+
137+
self.start_compute(
138+
host_info=fakelibvirt.HostInfo(cpu_nodes=1, cpu_sockets=1,
139+
cpu_cores=5, cpu_threads=2),
140+
hostname='src')
141+
self.src = self.computes['src']
142+
self.src.driver.cpu_api.core = CoresStub()
143+
# NOTE(artom) In init_host() the libvirt driver calls
144+
# power_down_all_dedicated_cpus(). Call it again now after swapping to
145+
# our stub to fake reality.
146+
self.src.driver.cpu_api.power_down_all_dedicated_cpus()
147+
148+
self.start_compute(
149+
host_info=fakelibvirt.HostInfo(cpu_nodes=1, cpu_sockets=1,
150+
cpu_cores=5, cpu_threads=2),
151+
hostname='dest')
152+
self.dest = self.computes['dest']
153+
self.dest.driver.cpu_api.power_down_all_dedicated_cpus()
154+
155+
def assert_cores(self, host, cores, online=True):
156+
for i in cores:
157+
self.assertEqual(online, host.driver.cpu_api.core(i).online)
158+
159+
def test_live_migrate_server(self):
160+
self.server = self._create_server(
161+
flavor_id=self.pcpu_flavor_id,
162+
expected_state='ACTIVE', host='src')
163+
server = self._live_migrate(self.server)
164+
self.assertEqual('dest', server['OS-EXT-SRV-ATTR:host'])
165+
# FIXME(artom) We've not powered up the dest cores, and left the src
166+
# cores powered on.
167+
self.assert_cores(self.src, range(1, 10), online=True)
168+
self.assert_cores(self.dest, range(1, 10), online=False)
169+
170+
91171
class PowerManagementTests(PowerManagementTestsBase):
92172
"""Test suite for a single host with 9 dedicated cores and 1 used for OS"""
93173

0 commit comments

Comments
 (0)