Skip to content

Commit d22f264

Browse files
committed
compute: Prevent use of conflicting v*-fixed-ip for 'server create --nic'
Currently this check is handled by novaclient. In the future, we won't have that so we need to do it ourselves. Do so now, fixing a typo along the way and adding tests to prevent regressions. Change-Id: Iaa9c087d846390b6a4f95ed3fa121dd8dc640903 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent e6dc0f3 commit d22f264

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,10 +931,17 @@ def __call__(self, parser, namespace, values, option_string=None):
931931

932932
if info['net-id'] and info['port-id']:
933933
msg = _(
934-
'Invalid argument %s; either network or port should be '
935-
'specified but not both'
934+
"Invalid argument %s; either 'network' or 'port' should be "
935+
"specified but not both"
936936
)
937-
raise argparse.ArgumenteError(self, msg % values)
937+
raise argparse.ArgumentError(self, msg % values)
938+
939+
if info['v4-fixed-ip'] and info['v6-fixed-ip']:
940+
msg = _(
941+
"Invalid argument %s; either 'v4-fixed-ip' or 'v6-fixed-ip' "
942+
"should be specified but not both"
943+
)
944+
raise argparse.ArgumentError(self, msg % values)
938945

939946
getattr(namespace, self.dest).append(info)
940947

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,46 @@ def test_server_create_with_only_network_key(self):
23082308
arglist,
23092309
[],
23102310
)
2311+
self.assertNotCalled(self.servers_mock.create)
23112312

2313+
def test_server_create_with_conflicting_net_port_filters(self):
2314+
arglist = [
2315+
'--image',
2316+
'image1',
2317+
'--flavor',
2318+
'flavor1',
2319+
'--nic',
2320+
'net-id=abc,port-id=xyz',
2321+
self.new_server.name,
2322+
]
2323+
exc = self.assertRaises(
2324+
test_utils.ParserException,
2325+
self.check_parser,
2326+
self.cmd,
2327+
arglist,
2328+
[],
2329+
)
2330+
self.assertIn("either 'network' or 'port'", str(exc))
2331+
self.assertNotCalled(self.servers_mock.create)
2332+
2333+
def test_server_create_with_conflicting_fixed_ip_filters(self):
2334+
arglist = [
2335+
'--image',
2336+
'image1',
2337+
'--flavor',
2338+
'flavor1',
2339+
'--nic',
2340+
'net-id=abc,v4-fixed-ip=1.2.3.4,v6-fixed-ip=2001:db8:abcd',
2341+
self.new_server.name,
2342+
]
2343+
exc = self.assertRaises(
2344+
test_utils.ParserException,
2345+
self.check_parser,
2346+
self.cmd,
2347+
arglist,
2348+
[],
2349+
)
2350+
self.assertIn("either 'v4-fixed-ip' or 'v6-fixed-ip'", str(exc))
23122351
self.assertNotCalled(self.servers_mock.create)
23132352

23142353
@mock.patch.object(common_utils, 'wait_for_status', return_value=True)

0 commit comments

Comments
 (0)