Merge "AIO-SX to DX: Check cluster-host interface config"

This commit is contained in:
Zuul 2021-04-01 19:26:08 +00:00 committed by Gerrit Code Review
commit ef6f1c560e
2 changed files with 98 additions and 15 deletions

View File

@ -275,14 +275,20 @@ class SystemController(rest.RestController):
raise wsme.exc.ClientSideError(
_("Host {} must be locked.".format(h['hostname'])))
def _check_mgmt(self, system_mode):
def _check_interfaces(self, system_mode):
iinterfaces = pecan.request.dbapi.iinterface_get_all()
mgmt_if = None
cluster_host_if = None
for iif in iinterfaces:
if (iif.networktypelist and
constants.NETWORK_TYPE_MGMT in iif.networktypelist):
mgmt_if = iif
if iif.networktypelist:
if constants.NETWORK_TYPE_MGMT in iif.networktypelist:
mgmt_if = iif
if constants.NETWORK_TYPE_CLUSTER_HOST in iif.networktypelist:
cluster_host_if = iif
if mgmt_if and cluster_host_if:
break
if mgmt_if is None:
msg = _("Cannot modify system mode to %s "
"without configuring the management "
@ -294,6 +300,17 @@ class SystemController(rest.RestController):
"configured on loopback. "
% system_mode)
raise wsme.exc.ClientSideError(msg)
if cluster_host_if is None:
msg = _("Cannot modify system mode to %s "
"without configuring the cluster-host "
"interface." % system_mode)
raise wsme.exc.ClientSideError(msg)
if cluster_host_if.ifname == constants.LOOPBACK_IFNAME:
msg = _("Cannot modify system mode to %s "
"when the cluster-host interface is "
"configured on loopback. "
% system_mode)
raise wsme.exc.ClientSideError(msg)
def _get_isystem_collection(self, marker, limit, sort_key, sort_dir,
expand=False, resource_url=None):
@ -416,7 +433,7 @@ class SystemController(rest.RestController):
"set to %s." % rpc_isystem.system_mode)
raise wsme.exc.ClientSideError(msg)
elif new_system_mode != constants.SYSTEM_MODE_SIMPLEX:
self._check_mgmt(new_system_mode)
self._check_interfaces(new_system_mode)
else:
system_mode_options.append(constants.SYSTEM_MODE_SIMPLEX)

View File

@ -90,8 +90,6 @@ class TestSystemUpdateModeFromSimplex(TestSystem):
self.dbapi = db_api.get_instance()
self.system = dbutils.create_test_isystem(system_type=constants.TIS_AIO_BUILD,
system_mode=constants.SYSTEM_MODE_SIMPLEX)
def _create_mgmt_interface_network(self, interface='mgmt'):
self.controller = dbutils.create_test_ihost(
id='1',
uuid=None,
@ -101,6 +99,8 @@ class TestSystemUpdateModeFromSimplex(TestSystem):
subfunctions=constants.CONTROLLER,
invprovision=constants.PROVISIONED,
)
def _create_mgmt_interface_network(self, interface='mgmt'):
self.address_pool_mgmt = dbutils.create_test_address_pool(
id=1,
network='192.168.204.0',
@ -114,21 +114,48 @@ class TestSystemUpdateModeFromSimplex(TestSystem):
link_capacity=1000,
vlan_id=2,
address_pool_id=self.address_pool_mgmt.id)
self.mgmt_interface = dbutils.create_test_interface(ifname=interface,
id=1,
ifclass=constants.INTERFACE_CLASS_PLATFORM,
forihostid=self.controller.id,
ihost_uuid=self.controller.uuid,
networktypelist=[constants.NETWORK_TYPE_MGMT])
self.mgmt_interface = dbutils.create_test_interface(
ifname=interface,
id=1,
ifclass=constants.INTERFACE_CLASS_PLATFORM,
forihostid=self.controller.id,
ihost_uuid=self.controller.uuid,
networktypelist=[constants.NETWORK_TYPE_MGMT])
dbutils.create_test_interface_network(
interface_id=self.mgmt_interface.id,
network_id=self.mgmt_network.id)
def _create_cluster_host_interface_network(self, interface='cluster-host'):
self.address_pool_cluster_host = dbutils.create_test_address_pool(
id=2,
network='192.168.206.0',
name='cluster-host',
ranges=[['192.168.206.2', '192.168.206.254']],
prefix=24)
self.cluster_host_network = dbutils.create_test_network(
id=2,
name='cluster-host',
type=constants.NETWORK_TYPE_CLUSTER_HOST,
link_capacity=10000,
vlan_id=3,
address_pool_id=self.address_pool_cluster_host.id)
self.cluster_host_interface = dbutils.create_test_interface(
ifname=interface,
id=2,
ifclass=constants.INTERFACE_CLASS_PLATFORM,
forihostid=self.controller.id,
ihost_uuid=self.controller.uuid,
networktypelist=[constants.NETWORK_TYPE_CLUSTER_HOST])
dbutils.create_test_interface_network(
interface_id=self.cluster_host_interface.id,
network_id=self.cluster_host_network.id)
@mock.patch('sysinv.common.utils.is_initial_config_complete', return_value=True)
def test_update_system_mode_simplex_to_duplex_with_mgmt_if(self, mock_exists):
def test_update_system_mode_simplex_to_duplex(self, mock_exists):
self._create_mgmt_interface_network()
self._create_cluster_host_interface_network()
update = {"system_mode": constants.SYSTEM_MODE_DUPLEX}
self._patch_and_check(self._get_path(self.system.uuid),
update)
@ -139,15 +166,44 @@ class TestSystemUpdateModeFromSimplex(TestSystem):
@mock.patch('sysinv.common.utils.is_initial_config_complete', return_value=True)
def test_update_system_mode_simplex_to_duplex_mgmt_on_lo(self, mock_exists):
self._create_mgmt_interface_network(interface=constants.LOOPBACK_IFNAME)
self._create_cluster_host_interface_network()
update = {"system_mode": constants.SYSTEM_MODE_DUPLEX}
self._patch_and_check(self._get_path(self.system.uuid),
update, expect_errors=True)
system = self.dbapi.isystem_get_one()
system_dict = system.as_dict()
self.assertNotIn('simplex_to_duplex_migration', system_dict['capabilities'])
@mock.patch('sysinv.common.utils.is_initial_config_complete', return_value=True)
def test_update_system_mode_simplex_to_duplex_no_mgmt_if(self, mock_exists):
self._create_cluster_host_interface_network()
update = {"system_mode": constants.SYSTEM_MODE_DUPLEX}
self._patch_and_check(self._get_path(self.system.uuid),
update, expect_errors=True)
system = self.dbapi.isystem_get_one()
system_dict = system.as_dict()
self.assertNotIn('simplex_to_duplex_migration', system_dict['capabilities'])
@mock.patch('sysinv.common.utils.is_initial_config_complete', return_value=True)
def test_update_system_mode_simplex_to_duplex_cluster_host_on_lo(self, mock_exists):
self._create_mgmt_interface_network()
self._create_cluster_host_interface_network(interface=constants.LOOPBACK_IFNAME)
update = {"system_mode": constants.SYSTEM_MODE_DUPLEX}
self._patch_and_check(self._get_path(self.system.uuid),
update, expect_errors=True)
system = self.dbapi.isystem_get_one()
system_dict = system.as_dict()
self.assertNotIn('simplex_to_duplex_migration', system_dict['capabilities'])
@mock.patch('sysinv.common.utils.is_initial_config_complete', return_value=True)
def test_update_system_mode_simplex_to_duplex_no_cluster_host_if(self, mock_exists):
self._create_mgmt_interface_network()
update = {"system_mode": constants.SYSTEM_MODE_DUPLEX}
self._patch_and_check(self._get_path(self.system.uuid),
update, expect_errors=True)
system = self.dbapi.isystem_get_one()
system_dict = system.as_dict()
self.assertNotIn('simplex_to_duplex_migration', system_dict['capabilities'])
@mock.patch('sysinv.common.utils.is_initial_config_complete', return_value=True)
def test_update_system_mode_simplex_to_simplex(self, mock_exists):
@ -167,6 +223,16 @@ class TestSystemUpdateModeFromSimplex(TestSystem):
system_dict = system.as_dict()
self.assertNotIn('simplex_to_duplex_migration', system_dict['capabilities'])
@mock.patch('sysinv.common.utils.is_initial_config_complete', return_value=False)
def test_update_system_mode_before_initial_config_complete_only_mgmt_if(self, mock_exists):
self._create_mgmt_interface_network()
update = {"system_mode": constants.SYSTEM_MODE_DUPLEX}
self._patch_and_check(self._get_path(self.system.uuid),
update)
system = self.dbapi.isystem_get_one()
system_dict = system.as_dict()
self.assertNotIn('simplex_to_duplex_migration', system_dict['capabilities'])
class TestSystemUpdateModeFromDuplex(TestSystem):