Skip to content

Commit 15d0bfc

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add NUMA affinity policy parameter to "port""
2 parents 0566ad6 + 454b219 commit 15d0bfc

4 files changed

Lines changed: 134 additions & 0 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ def _get_attrs(client_manager, parsed_args):
158158
parsed_args.disable_uplink_status_propagation):
159159
attrs['propagate_uplink_status'] = False
160160

161+
if ('numa_policy_required' in parsed_args and
162+
parsed_args.numa_policy_required):
163+
attrs['numa_affinity_policy'] = 'required'
164+
elif ('numa_policy_preferred' in parsed_args and
165+
parsed_args.numa_policy_preferred):
166+
attrs['numa_affinity_policy'] = 'preferred'
167+
elif ('numa_policy_legacy' in parsed_args and
168+
parsed_args.numa_policy_legacy):
169+
attrs['numa_affinity_policy'] = 'legacy'
170+
161171
return attrs
162172

163173

@@ -265,6 +275,22 @@ def _add_updatable_args(parser):
265275
help=_("Set DNS name for this port "
266276
"(requires DNS integration extension)")
267277
)
278+
numa_affinity_policy_group = parser.add_mutually_exclusive_group()
279+
numa_affinity_policy_group.add_argument(
280+
'--numa-policy-required',
281+
action='store_true',
282+
help=_("NUMA affinity policy required to schedule this port")
283+
)
284+
numa_affinity_policy_group.add_argument(
285+
'--numa-policy-preferred',
286+
action='store_true',
287+
help=_("NUMA affinity policy preferred to schedule this port")
288+
)
289+
numa_affinity_policy_group.add_argument(
290+
'--numa-policy-legacy',
291+
action='store_true',
292+
help=_("NUMA affinity policy using legacy mode to schedule this port")
293+
)
268294

269295

270296
# TODO(abhiraut): Use the SDK resource mapped attribute names once the
@@ -904,6 +930,11 @@ def get_parser(self, prog_name):
904930
action='store_true',
905931
help=_("Clear existing information of data plane status")
906932
)
933+
parser.add_argument(
934+
'--numa-policy',
935+
action='store_true',
936+
help=_("Clear existing NUMA affinity policy")
937+
)
907938

908939
_tag.add_tag_option_to_parser_for_unset(parser, _('port'))
909940

@@ -959,6 +990,8 @@ def take_action(self, parsed_args):
959990
attrs['qos_policy_id'] = None
960991
if parsed_args.data_plane_status:
961992
attrs['data_plane_status'] = None
993+
if parsed_args.numa_policy:
994+
attrs['numa_affinity_policy'] = None
962995

963996
if attrs:
964997
client.update_port(obj, **attrs)

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ def create_one_port(attrs=None):
634634
'mac_address': 'fa:16:3e:a9:4e:72',
635635
'name': 'port-name-' + uuid.uuid4().hex,
636636
'network_id': 'network-id-' + uuid.uuid4().hex,
637+
'numa_affinity_policy': 'required',
637638
'port_security_enabled': True,
638639
'security_group_ids': [],
639640
'status': 'ACTIVE',

openstackclient/tests/unit/network/v2/test_port.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def _get_common_cols_data(fake_port):
5959
'mac_address',
6060
'name',
6161
'network_id',
62+
'numa_affinity_policy',
6263
'port_security_enabled',
6364
'project_id',
6465
'qos_network_policy_id',
@@ -90,6 +91,7 @@ def _get_common_cols_data(fake_port):
9091
fake_port.mac_address,
9192
fake_port.name,
9293
fake_port.network_id,
94+
fake_port.numa_affinity_policy,
9395
fake_port.port_security_enabled,
9496
fake_port.project_id,
9597
fake_port.qos_network_policy_id,
@@ -655,6 +657,50 @@ def test_create_port_with_extra_dhcp_option(self):
655657
'name': 'test-port',
656658
})
657659

660+
def _test_create_with_numa_affinity_policy(self, policy=None):
661+
arglist = [
662+
'--network', self._port.network_id,
663+
'test-port',
664+
]
665+
if policy:
666+
arglist += ['--numa-policy-%s' % policy]
667+
668+
numa_affinity_policy = None if not policy else policy
669+
verifylist = [
670+
('network', self._port.network_id,),
671+
('name', 'test-port'),
672+
]
673+
if policy:
674+
verifylist.append(('numa_policy_%s' % policy, True))
675+
676+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
677+
678+
columns, data = (self.cmd.take_action(parsed_args))
679+
680+
create_args = {
681+
'admin_state_up': True,
682+
'network_id': self._port.network_id,
683+
'name': 'test-port',
684+
}
685+
if numa_affinity_policy:
686+
create_args['numa_affinity_policy'] = numa_affinity_policy
687+
self.network.create_port.assert_called_once_with(**create_args)
688+
689+
self.assertEqual(self.columns, columns)
690+
self.assertItemEqual(self.data, data)
691+
692+
def test_create_with_numa_affinity_policy_required(self):
693+
self._test_create_with_numa_affinity_policy(policy='required')
694+
695+
def test_create_with_numa_affinity_policy_preferred(self):
696+
self._test_create_with_numa_affinity_policy(policy='preferred')
697+
698+
def test_create_with_numa_affinity_policy_legacy(self):
699+
self._test_create_with_numa_affinity_policy(policy='legacy')
700+
701+
def test_create_with_numa_affinity_policy_null(self):
702+
self._test_create_with_numa_affinity_policy()
703+
658704

659705
class TestDeletePort(TestPort):
660706

@@ -1668,6 +1714,32 @@ def test_set_with_tags(self):
16681714
def test_set_with_no_tag(self):
16691715
self._test_set_tags(with_tags=False)
16701716

1717+
def _test_create_with_numa_affinity_policy(self, policy):
1718+
arglist = [
1719+
'--numa-policy-%s' % policy,
1720+
self._port.id,
1721+
]
1722+
verifylist = [
1723+
('numa_policy_%s' % policy, True),
1724+
('port', self._port.id,)
1725+
]
1726+
1727+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1728+
1729+
self.cmd.take_action(parsed_args)
1730+
1731+
self.network.update_port.assert_called_once_with(
1732+
self._port, **{'numa_affinity_policy': policy})
1733+
1734+
def test_create_with_numa_affinity_policy_required(self):
1735+
self._test_create_with_numa_affinity_policy('required')
1736+
1737+
def test_create_with_numa_affinity_policy_preferred(self):
1738+
self._test_create_with_numa_affinity_policy('preferred')
1739+
1740+
def test_create_with_numa_affinity_policy_legacy(self):
1741+
self._test_create_with_numa_affinity_policy('legacy')
1742+
16711743

16721744
class TestShowPort(TestPort):
16731745

@@ -1923,3 +1995,26 @@ def test_unset_with_tags(self):
19231995

19241996
def test_unset_with_all_tag(self):
19251997
self._test_unset_tags(with_tags=False)
1998+
1999+
def test_unset_numa_affinity_policy(self):
2000+
_fake_port = network_fakes.FakePort.create_one_port(
2001+
{'numa_affinity_policy': 'required'})
2002+
self.network.find_port = mock.Mock(return_value=_fake_port)
2003+
arglist = [
2004+
'--numa-policy',
2005+
_fake_port.name,
2006+
]
2007+
verifylist = [
2008+
('numa_policy', True),
2009+
('port', _fake_port.name),
2010+
]
2011+
2012+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
2013+
result = self.cmd.take_action(parsed_args)
2014+
2015+
attrs = {
2016+
'numa_affinity_policy': None,
2017+
}
2018+
2019+
self.network.update_port.assert_called_once_with(_fake_port, **attrs)
2020+
self.assertIsNone(result)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add NUMA affinity policy to ``port create``, ``port set`` and
5+
``port unset`` commands.

0 commit comments

Comments
 (0)