Skip to content

Commit

Permalink
Merge pull request #73 from tzumainn/node-network-list-uuids
Browse files Browse the repository at this point in the history
Add `--long` option to `openstack esi node network list`
  • Loading branch information
tzumainn authored Jan 14, 2025
2 parents a812654 + a4006d4 commit d8e9ac3
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 32 deletions.
169 changes: 152 additions & 17 deletions esiclient/tests/unit/v1/test_node_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,41 @@ def setUp(self):
super(TestList, self).setUp()

self.port1 = utils.create_mock_object({
"uuid": "port_uuid_1",
"id": "port_uuid_1",
"node_uuid": "11111111-2222-3333-4444-aaaaaaaaaaaa",
"address": "aa:aa:aa:aa:aa:aa",
"internal_info": {'tenant_vif_port_id': 'neutron_port_uuid_1'}
})
self.port2 = utils.create_mock_object({
"uuid": "port_uuid_2",
"id": "port_uuid_2",
"node_uuid": "11111111-2222-3333-4444-bbbbbbbbbbbb",
"address": "bb:bb:bb:bb:bb:bb",
"internal_info": {}
})
self.port3 = utils.create_mock_object({
"uuid": "port_uuid_3",
"id": "port_uuid_3",
"node_uuid": "11111111-2222-3333-4444-bbbbbbbbbbbb",
"address": "cc:cc:cc:cc:cc:cc",
"internal_info": {'tenant_vif_port_id': 'neutron_port_uuid_2'}
})
self.port4 = utils.create_mock_object({
"uuid": "port_uuid_4",
"id": "port_uuid_4",
"node_uuid": "11111111-2222-3333-4444-bbbbbbbbbbbb",
"address": "dd:dd:dd:dd:dd:dd",
"internal_info": {'tenant_vif_port_id': 'neutron_port_uuid_4'}
})
self.port5 = utils.create_mock_object({
'uuid': 'port_uuid_5',
'id': 'port_uuid_5',
'node_uuid': '11111111-2222-3333-4444-bbbbbbbbbbbb',
'address': 'ee:ee:ee:ee:ee:ee',
'internal_info': {'tenant_vif_port_id': 'neutron_port_uuid_3'}
})
self.node1 = utils.create_mock_object({
"uuid": "11111111-2222-3333-4444-aaaaaaaaaaaa",
"id": "11111111-2222-3333-4444-aaaaaaaaaaaa",
"name": "node1"
})
self.node2 = utils.create_mock_object({
"uuid": "11111111-2222-3333-4444-bbbbbbbbbbbb",
"id": "11111111-2222-3333-4444-bbbbbbbbbbbb",
"name": "node2"
})
self.network1 = utils.create_mock_object({
Expand Down Expand Up @@ -95,6 +95,7 @@ def setUp(self):
'name': 'neutron_port_3',
'fixed_ips': [{'ip_address': '3.3.3.3'}],
'trunk_details': {
'trunk_id': 'trunk_uuid_1',
'sub_ports': [
{'port_id': 'subport_uuid_1'},
{'port_id': 'subport_uuid_2'},
Expand All @@ -106,14 +107,14 @@ def setUp(self):
'network_id': 'network_uuid_1',
'name': 'subport_1',
'fixed_ips': [{'ip_address': '4.4.4.4'}],
'trunk_details': {}
'trunk_details': None
})
self.subport_2 = utils.create_mock_object({
'id': 'subport_uuid_2',
'network_id': 'network_uuid_2',
'name': 'subport_2',
'fixed_ips': [{'ip_address': '5.5.5.5'}],
'trunk_details': {}
'trunk_details': None
})
self.floating_network1 = utils.create_mock_object({
"id": "floating_network_id_1",
Expand All @@ -136,7 +137,7 @@ def setUp(self):
"port_id": None
})
self.floating_ip2 = utils.create_mock_object({
'id': 'floating_ip uuid_3',
'id': 'floating_ip_uuid_3',
'floating_ip_address': '10.10.10.10',
'floating_network_id': 'floating_network_id_2',
'port_id': None
Expand Down Expand Up @@ -589,6 +590,140 @@ def test_take_action(self,
mock.call(self.floating_network2),
])

@mock.patch('esiclient.utils.get_network_display_name')
@mock.patch('esi.lib.nodes.network_list')
def test_take_action_long(self,
mock_network_list,
mock_get_network_display_name):
mock_network_list.return_value = [
{
'node': self.node1,
'network_info': [
{
'baremetal_port': self.port1,
'network_ports': [self.neutron_port1],
'networks': {
'parent': self.network1,
'trunk': [],
'floating': self.floating_network1,
},
'floating_ip': self.floating_ip_pfw,
'port_forwardings': [self.pfw1, self.pfw2]
}
]
},
{
'node': self.node2,
'network_info': [
{
'baremetal_port': self.port2,
'network_ports': [],
'networks': {
'parent': None,
'trunk': [],
'floating': None
},
'floating_ip': None,
'port_forwardings': []
},
{
'baremetal_port': self.port5,
'network_ports': [
self.neutron_port3,
self.subport_1,
self.subport_2
],
'networks': {
'parent': self.network3,
'trunk': [
self.network1,
self.network2
],
'floating': self.floating_network2
},
'floating_ip': self.floating_ip2,
'port_forwardings': [self.pfw3]
}
]
}
]

mock_get_network_display_name.\
side_effect = lambda network: network.name

arglist = ['--long']
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

results = self.cmd.take_action(parsed_args)

data = [
[
'node1',
'11111111-2222-3333-4444-aaaaaaaaaaaa',
'aa:aa:aa:aa:aa:aa',
'port_uuid_1',
'neutron_port_1',
'neutron_port_uuid_1',
None,
'test_network_1',
'network_uuid_1',
'1.1.1.1',
'floating_network_1',
'floating_network_id_1',
'9.9.9.9 (22:22,23:23)',
'floating_ip_uuid_1'
],
[
'node2',
'11111111-2222-3333-4444-bbbbbbbbbbbb',
'bb:bb:bb:bb:bb:bb',
'port_uuid_2',
None,
None,
None,
None,
None,
None,
None,
None,
None,
None
],
[
'node2',
'11111111-2222-3333-4444-bbbbbbbbbbbb',
'ee:ee:ee:ee:ee:ee',
'port_uuid_5',
'neutron_port_3',
'neutron_port_uuid_3',
'trunk_uuid_1',
'test_network_3\ntest_network_1\ntest_network_2',
'network_uuid_3\nnetwork_uuid_1\nnetwork_uuid_2',
'3.3.3.3\n4.4.4.4\n5.5.5.5',
'floating_network_2',
'floating_network_id_2',
'10.10.10.10 (24:24)',
'floating_ip_uuid_3'
]
]

expected = ["Node", "Node UUID", "MAC Address", "Bare Metal Port UUID",
"Port", "Network Port UUID", "Trunk UUID", "Network",
"Network UUID", "Fixed IP", "Floating Network",
"Floating Network UUID", "Floating IP",
"Floating IP UUID"], data

self.assertEqual(expected, results)
mock_get_network_display_name.assert_has_calls([
mock.call(self.network1),
mock.call(self.floating_network1),
mock.call(self.network3),
mock.call(self.network1),
mock.call(self.network2),
mock.call(self.floating_network2),
])


class TestAttach(base.TestCommand):

Expand All @@ -597,36 +732,36 @@ def setUp(self):
self.cmd = node_network.Attach(self.app, None)

self.port1 = utils.create_mock_object({
"uuid": "port_uuid_1",
"id": "port_uuid_1",
"node_uuid": "node_uuid_1",
"address": "aa:aa:aa:aa:aa:aa",
"internal_info": {'tenant_vif_port_id': 'neutron_port_uuid_1'}
})
self.port2 = utils.create_mock_object({
"uuid": "port_uuid_2",
"id": "port_uuid_2",
"node_uuid": "node_uuid_1",
"address": "bb:bb:bb:bb:bb:bb",
"internal_info": {}
})
self.node = utils.create_mock_object({
"uuid": "node_uuid_1",
"id": "node_uuid_1",
"name": "node1",
"provision_state": "active"
})
self.node_available = utils.create_mock_object({
"uuid": "node_uuid_1",
"id": "node_uuid_1",
"name": "node1",
"provision_state": "available"
})
self.node_manageable = utils.create_mock_object({
"uuid": "node_uuid_1",
"id": "node_uuid_1",
"name": "node1",
"provision_state": "manageable",
"instance_info": {},
"driver_info": {'deploy_ramdisk': 'fake-image'},
})
self.node_manageable_instance_info = utils.create_mock_object({
"uuid": "node_uuid_1",
"id": "node_uuid_1",
"name": "node1",
"provision_state": "manageable",
"instance_info": {'image_source': 'fake-image',
Expand Down Expand Up @@ -809,7 +944,7 @@ def setUp(self):
self.cmd = node_network.Detach(self.app, None)

self.node = utils.create_mock_object({
"uuid": "node_uuid_1",
"id": "node_uuid_1",
"name": "node1",
"provision_state": "active"
})
Expand Down
Loading

0 comments on commit d8e9ac3

Please sign in to comment.