Fix: set invalid None project_id on range creation

"project_id" attribute should not be set to None on shared network
segment range creation since it is not a valid string type which is
required for the API.

Change-Id: Ia2bab12e39b4bb7e05ff2acfffb851252c100651
Story: 2005205
Task: 29975
This commit is contained in:
Kailun Qin 2019-03-13 01:37:31 +08:00
parent c36e75d986
commit 28c06d0688
2 changed files with 36 additions and 8 deletions

View File

@ -207,8 +207,6 @@ class CreateNetworkSegmentRange(command.ShowOne):
# is not specified.
# Get the project id from the current auth.
attrs['project_id'] = self.app.client_manager.auth_ref.project_id
else:
attrs['project_id'] = None
if parsed_args.physical_network:
attrs['physical_network'] = parsed_args.physical_network

View File

@ -144,19 +144,19 @@ class TestCreateNetworkSegmentRange(TestNetworkSegmentRange):
self.cmd.take_action,
parsed_args)
def test_create_minimum_options(self):
def test_create_private_minimum_options(self):
arglist = [
'--private',
'--project', self._network_segment_range.project_id,
'--network-type', self._network_segment_range.network_type,
'--network-type', 'vxlan',
'--minimum', str(self._network_segment_range.minimum),
'--maximum', str(self._network_segment_range.maximum),
self._network_segment_range.name,
]
verifylist = [
('shared', self._network_segment_range.shared),
('shared', False),
('project', self._network_segment_range.project_id),
('network_type', self._network_segment_range.network_type),
('network_type', 'vxlan'),
('minimum', self._network_segment_range.minimum),
('maximum', self._network_segment_range.maximum),
('name', self._network_segment_range.name),
@ -166,9 +166,39 @@ class TestCreateNetworkSegmentRange(TestNetworkSegmentRange):
columns, data = self.cmd.take_action(parsed_args)
self.network.create_network_segment_range.assert_called_once_with(**{
'shared': self._network_segment_range.shared,
'shared': False,
'project_id': mock.ANY,
'network_type': self._network_segment_range.network_type,
'network_type': 'vxlan',
'minimum': self._network_segment_range.minimum,
'maximum': self._network_segment_range.maximum,
'name': self._network_segment_range.name,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
def test_create_shared_minimum_options(self):
arglist = [
'--shared',
'--network-type', 'vxlan',
'--minimum', str(self._network_segment_range.minimum),
'--maximum', str(self._network_segment_range.maximum),
self._network_segment_range.name,
]
verifylist = [
('shared', True),
('network_type', 'vxlan'),
('minimum', self._network_segment_range.minimum),
('maximum', self._network_segment_range.maximum),
('name', self._network_segment_range.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network.create_network_segment_range.assert_called_once_with(**{
'shared': True,
'network_type': 'vxlan',
'minimum': self._network_segment_range.minimum,
'maximum': self._network_segment_range.maximum,
'name': self._network_segment_range.name,