Merge "Dropping the use of 'addFixedIp' server action"
This commit is contained in:
commit
90fe18e51b
@ -345,10 +345,6 @@ class AddFixedIP(command.ShowOne):
|
|||||||
else:
|
else:
|
||||||
net_id = parsed_args.network
|
net_id = parsed_args.network
|
||||||
|
|
||||||
if not sdk_utils.supports_microversion(compute_client, '2.44'):
|
|
||||||
compute_client.add_fixed_ip_to_server(server.id, net_id)
|
|
||||||
return ((), ())
|
|
||||||
|
|
||||||
kwargs = {'net_id': net_id}
|
kwargs = {'net_id': net_id}
|
||||||
if parsed_args.fixed_ip_address:
|
if parsed_args.fixed_ip_address:
|
||||||
kwargs['fixed_ips'] = [
|
kwargs['fixed_ips'] = [
|
||||||
@ -375,9 +371,11 @@ class AddFixedIP(command.ShowOne):
|
|||||||
'Port State',
|
'Port State',
|
||||||
'Fixed IPs',
|
'Fixed IPs',
|
||||||
)
|
)
|
||||||
if sdk_utils.supports_microversion(compute_client, '2.49'):
|
|
||||||
columns += ('tag',)
|
if parsed_args.tag:
|
||||||
column_headers += ('Tag',)
|
if sdk_utils.supports_microversion(compute_client, '2.49'):
|
||||||
|
columns += ('tag',)
|
||||||
|
column_headers += ('Tag',)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
column_headers,
|
column_headers,
|
||||||
|
@ -205,105 +205,6 @@ class TestServerAddFixedIP(TestServer):
|
|||||||
self.find_network = mock.Mock()
|
self.find_network = mock.Mock()
|
||||||
self.app.client_manager.network.find_network = self.find_network
|
self.app.client_manager.network.find_network = self.find_network
|
||||||
|
|
||||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
||||||
def test_server_add_fixed_ip_pre_v244(self, sm_mock):
|
|
||||||
sm_mock.return_value = False
|
|
||||||
|
|
||||||
servers = self.setup_sdk_servers_mock(count=1)
|
|
||||||
network = compute_fakes.create_one_network()
|
|
||||||
|
|
||||||
with mock.patch.object(
|
|
||||||
self.app.client_manager,
|
|
||||||
'is_network_endpoint_enabled',
|
|
||||||
return_value=False,
|
|
||||||
):
|
|
||||||
arglist = [
|
|
||||||
servers[0].id,
|
|
||||||
network['id'],
|
|
||||||
]
|
|
||||||
verifylist = [
|
|
||||||
('server', servers[0].id),
|
|
||||||
('network', network['id']),
|
|
||||||
('fixed_ip_address', None),
|
|
||||||
]
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
|
||||||
|
|
||||||
self.sdk_client.add_fixed_ip_to_server.assert_called_once_with(
|
|
||||||
servers[0].id, network['id']
|
|
||||||
)
|
|
||||||
# the legacy API operates asynchronously
|
|
||||||
self.assertEqual(((), ()), result)
|
|
||||||
|
|
||||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
||||||
def test_server_add_fixed_ip_pre_v244_with_fixed_ip(self, sm_mock):
|
|
||||||
sm_mock.return_value = False
|
|
||||||
|
|
||||||
servers = self.setup_sdk_servers_mock(count=1)
|
|
||||||
network = compute_fakes.create_one_network()
|
|
||||||
|
|
||||||
with mock.patch.object(
|
|
||||||
self.app.client_manager,
|
|
||||||
'is_network_endpoint_enabled',
|
|
||||||
return_value=False,
|
|
||||||
):
|
|
||||||
arglist = [
|
|
||||||
servers[0].id,
|
|
||||||
network['id'],
|
|
||||||
'--fixed-ip-address',
|
|
||||||
'5.6.7.8',
|
|
||||||
]
|
|
||||||
verifylist = [
|
|
||||||
('server', servers[0].id),
|
|
||||||
('network', network['id']),
|
|
||||||
('fixed_ip_address', '5.6.7.8'),
|
|
||||||
]
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
|
||||||
|
|
||||||
self.sdk_client.add_fixed_ip_to_server.assert_called_once_with(
|
|
||||||
servers[0].id, network['id']
|
|
||||||
)
|
|
||||||
# the legacy API operates asynchronously
|
|
||||||
self.assertEqual(((), ()), result)
|
|
||||||
|
|
||||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
|
||||||
def test_server_add_fixed_ip_pre_v244_with_tag(self, sm_mock):
|
|
||||||
sm_mock.return_value = False
|
|
||||||
|
|
||||||
servers = self.setup_sdk_servers_mock(count=1)
|
|
||||||
network = compute_fakes.create_one_network()
|
|
||||||
|
|
||||||
with mock.patch.object(
|
|
||||||
self.app.client_manager,
|
|
||||||
'is_network_endpoint_enabled',
|
|
||||||
return_value=False,
|
|
||||||
):
|
|
||||||
arglist = [
|
|
||||||
servers[0].id,
|
|
||||||
network['id'],
|
|
||||||
'--fixed-ip-address',
|
|
||||||
'5.6.7.8',
|
|
||||||
'--tag',
|
|
||||||
'tag1',
|
|
||||||
]
|
|
||||||
verifylist = [
|
|
||||||
('server', servers[0].id),
|
|
||||||
('network', network['id']),
|
|
||||||
('fixed_ip_address', '5.6.7.8'),
|
|
||||||
('tag', 'tag1'),
|
|
||||||
]
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
||||||
|
|
||||||
ex = self.assertRaises(
|
|
||||||
exceptions.CommandError, self.cmd.take_action, parsed_args
|
|
||||||
)
|
|
||||||
self.assertIn(
|
|
||||||
'--os-compute-api-version 2.49 or greater is required', str(ex)
|
|
||||||
)
|
|
||||||
|
|
||||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||||
def test_server_add_fixed_ip_pre_v249_with_tag(self, sm_mock):
|
def test_server_add_fixed_ip_pre_v249_with_tag(self, sm_mock):
|
||||||
sm_mock.side_effect = [False, True]
|
sm_mock.side_effect = [False, True]
|
||||||
@ -412,6 +313,63 @@ class TestServerAddFixedIP(TestServer):
|
|||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
expected_columns = (
|
||||||
|
'Port ID',
|
||||||
|
'Server ID',
|
||||||
|
'Network ID',
|
||||||
|
'MAC Address',
|
||||||
|
'Port State',
|
||||||
|
'Fixed IPs',
|
||||||
|
)
|
||||||
|
expected_data = (
|
||||||
|
interface.port_id,
|
||||||
|
interface.server_id,
|
||||||
|
interface.net_id,
|
||||||
|
interface.mac_addr,
|
||||||
|
interface.port_state,
|
||||||
|
format_columns.ListDictColumn(interface.fixed_ips),
|
||||||
|
)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertEqual(expected_columns, columns)
|
||||||
|
self.assertEqual(expected_data, tuple(data))
|
||||||
|
self.sdk_client.create_server_interface.assert_called_once_with(
|
||||||
|
servers[0].id,
|
||||||
|
net_id=network['id'],
|
||||||
|
fixed_ips=[{'ip_address': '5.6.7.8'}],
|
||||||
|
)
|
||||||
|
|
||||||
|
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||||
|
def test_server_add_fixed_ip_with_tag(self, sm_mock):
|
||||||
|
sm_mock.side_effect = [True, True, True]
|
||||||
|
|
||||||
|
servers = self.setup_sdk_servers_mock(count=1)
|
||||||
|
network = compute_fakes.create_one_network()
|
||||||
|
interface = compute_fakes.create_one_server_interface()
|
||||||
|
self.sdk_client.create_server_interface.return_value = interface
|
||||||
|
|
||||||
|
with mock.patch.object(
|
||||||
|
self.app.client_manager,
|
||||||
|
'is_network_endpoint_enabled',
|
||||||
|
return_value=False,
|
||||||
|
):
|
||||||
|
arglist = [
|
||||||
|
servers[0].id,
|
||||||
|
network['id'],
|
||||||
|
'--fixed-ip-address',
|
||||||
|
'5.6.7.8',
|
||||||
|
'--tag',
|
||||||
|
'tag1',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('server', servers[0].id),
|
||||||
|
('network', network['id']),
|
||||||
|
('fixed_ip_address', '5.6.7.8'),
|
||||||
|
('tag', 'tag1'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
expected_columns = (
|
expected_columns = (
|
||||||
'Port ID',
|
'Port ID',
|
||||||
'Server ID',
|
'Server ID',
|
||||||
@ -439,11 +397,12 @@ class TestServerAddFixedIP(TestServer):
|
|||||||
servers[0].id,
|
servers[0].id,
|
||||||
net_id=network['id'],
|
net_id=network['id'],
|
||||||
fixed_ips=[{'ip_address': '5.6.7.8'}],
|
fixed_ips=[{'ip_address': '5.6.7.8'}],
|
||||||
|
tag='tag1',
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||||
def test_server_add_fixed_ip_with_tag(self, sm_mock):
|
def test_server_add_fixed_ip_with_fixed_ip_with_tag(self, sm_mock):
|
||||||
sm_mock.side_effect = [True, True, True]
|
sm_mock.side_effect = [True, True]
|
||||||
|
|
||||||
servers = self.setup_sdk_servers_mock(count=1)
|
servers = self.setup_sdk_servers_mock(count=1)
|
||||||
network = compute_fakes.create_one_network()
|
network = compute_fakes.create_one_network()
|
||||||
|
Loading…
Reference in New Issue
Block a user