Merge "Change config_option to config_options"
This commit is contained in:
commit
ec4ce8fff7
@ -510,10 +510,10 @@ class NUMALiveMigrationTest(BasePinningTest):
|
||||
host1_sm = clients.ServiceManager(host1, 'nova-compute')
|
||||
host2_sm = clients.ServiceManager(host2, 'nova-compute')
|
||||
with whitebox_utils.multicontext(
|
||||
host1_sm.config_option('DEFAULT', 'vcpu_pin_set',
|
||||
self._get_cpu_spec(topo_1[0])),
|
||||
host2_sm.config_option('DEFAULT', 'vcpu_pin_set',
|
||||
self._get_cpu_spec(topo_2[0]))
|
||||
host1_sm.config_options(('DEFAULT', 'vcpu_pin_set',
|
||||
self._get_cpu_spec(topo_1[0]))),
|
||||
host2_sm.config_options(('DEFAULT', 'vcpu_pin_set',
|
||||
self._get_cpu_spec(topo_2[0])))
|
||||
):
|
||||
# Boot 2 servers such that their vCPUs "fill" a NUMA node.
|
||||
specs = {'hw:cpu_policy': 'dedicated'}
|
||||
@ -556,9 +556,10 @@ class NUMALiveMigrationTest(BasePinningTest):
|
||||
host_a_sm = clients.ServiceManager(host_a_addr, 'nova-compute')
|
||||
numaclient_a = clients.NUMAClient(host_a_addr)
|
||||
topo_a = numaclient_a.get_host_topology()
|
||||
with host_a_sm.config_option(
|
||||
'DEFAULT', 'vcpu_pin_set',
|
||||
self._get_cpu_spec(topo_a[0] + topo_a[1])):
|
||||
with host_a_sm.config_options(
|
||||
('DEFAULT', 'vcpu_pin_set',
|
||||
self._get_cpu_spec(topo_a[0] + topo_a[1]))
|
||||
):
|
||||
self.live_migrate(server_b['id'], host_a, 'ACTIVE')
|
||||
|
||||
# They should have disjoint (non-null) CPU pins in their XML
|
||||
@ -584,7 +585,7 @@ class NUMALiveMigrationTest(BasePinningTest):
|
||||
'database, instead have %s and %s' % (pcpus_a, pcpus_b))
|
||||
|
||||
# NOTE(artom) At this point we have to manually delete both
|
||||
# servers before the config_option() context manager reverts
|
||||
# servers before the config_options() context manager reverts
|
||||
# any config changes it made. This is Nova bug 1836945.
|
||||
self.delete_server(server_a['id'])
|
||||
self.delete_server(server_b['id'])
|
||||
@ -605,10 +606,10 @@ class NUMALiveMigrationTest(BasePinningTest):
|
||||
host1_sm = clients.ServiceManager(host1, 'nova-compute')
|
||||
host2_sm = clients.ServiceManager(host2, 'nova-compute')
|
||||
with whitebox_utils.multicontext(
|
||||
host1_sm.config_option('DEFAULT', 'vcpu_pin_set', '0,1'),
|
||||
host1_sm.config_option('compute', 'cpu_shared_set', '2'),
|
||||
host2_sm.config_option('DEFAULT', 'vcpu_pin_set', '0,1'),
|
||||
host2_sm.config_option('compute', 'cpu_shared_set', '3')
|
||||
host1_sm.config_options(('DEFAULT', 'vcpu_pin_set', '0,1'),
|
||||
('compute', 'cpu_shared_set', '2')),
|
||||
host2_sm.config_options(('DEFAULT', 'vcpu_pin_set', '0,1'),
|
||||
('compute', 'cpu_shared_set', '3'))
|
||||
):
|
||||
# Boot two servers
|
||||
specs = {'hw:cpu_policy': 'dedicated',
|
||||
@ -648,7 +649,7 @@ class NUMALiveMigrationTest(BasePinningTest):
|
||||
'Pins overlap: %s, %s' % (pin_a, pin_b))
|
||||
|
||||
# NOTE(artom) At this point we have to manually delete both
|
||||
# servers before the config_option() context manager reverts
|
||||
# servers before the config_options() context manager reverts
|
||||
# any config changes it made. This is Nova bug 1836945.
|
||||
self.delete_server(server_a['id'])
|
||||
self.delete_server(server_b['id'])
|
||||
|
@ -89,14 +89,25 @@ class ServiceManager(SSHClient):
|
||||
self.stop_command = getattr(conf, 'stop_command', None)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def config_option(self, section, option, value):
|
||||
initial_value = self.get_conf_opt(section, option)
|
||||
self.set_conf_opt(section, option, value)
|
||||
def config_options(self, *opts):
|
||||
"""Sets config options and restarts the service. Previous values for
|
||||
the options are saved before setting the new ones, and restored when
|
||||
the context manager exists.
|
||||
|
||||
:param opts: a list of (section, option, value) tuples, each
|
||||
representing a single config option
|
||||
"""
|
||||
initial_values = []
|
||||
for section, option, value in opts:
|
||||
initial_values.append((section, option,
|
||||
self.get_conf_opt(section, option)))
|
||||
self.set_conf_opt(section, option, value)
|
||||
self.restart()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
self.set_conf_opt(section, option, initial_value)
|
||||
for section, option, value in initial_values:
|
||||
self.set_conf_opt(section, option, value)
|
||||
self.restart()
|
||||
|
||||
def get_conf_opt(self, section, option):
|
||||
|
@ -120,7 +120,9 @@ class ServiceManagerTestCase(base.WhiteboxPluginTestCase):
|
||||
service.execute = local_exec
|
||||
# Test the config_option context manager
|
||||
with mock.patch.object(service, 'restart') as mock_restart:
|
||||
with service.config_option('section', 'option', 'new-value'):
|
||||
with service.config_options(
|
||||
('section', 'option', 'new-value')
|
||||
):
|
||||
self.assertEqual('new-value',
|
||||
service.get_conf_opt('section', 'option'))
|
||||
self.assertEqual(2, mock_restart.call_count)
|
||||
|
Loading…
Reference in New Issue
Block a user