Skip to content

Commit

Permalink
review: Using shlex method
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealFalcon committed Mar 24, 2021
1 parent e1e59da commit e2c5027
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cloudinit/net/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io
import logging
import os
import re
import shlex

from cloudinit import util

Expand Down Expand Up @@ -73,8 +73,9 @@ def is_applicable(self) -> bool:
(ii) an open-iscsi interface file is present in the system
"""
if self._files:
if re.search(r'(^|\s)ip6?=', self._cmdline):
return True
for item in shlex.split(self._cmdline):
if item.startswith('ip=') or item.startswith('ip6='):
return True
if os.path.exists(_OPEN_ISCSI_INTERFACE_FILE):
# iBft can configure networking without ip=
return True
Expand Down
10 changes: 10 additions & 0 deletions tests/unittests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -4427,6 +4427,16 @@ def test_cmdline_no_lhand(self):
)
self.assertFalse(src.is_applicable())

def test_cmdline_embedded_ip(self):
content = {'net6-eno1.conf': DHCP6_CONTENT_1}
files = sorted(populate_dir(self.tmp_dir(), content))
src = cmdline.KlibcNetworkConfigSource(
_files=files,
_cmdline='opt="some things and ip=foo"',
_mac_addrs=self.macs,
)
self.assertFalse(src.is_applicable())

def test_with_both_ip_ip6(self):
content = {
'/run/net-eth0.conf': DHCP_CONTENT_1,
Expand Down

0 comments on commit e2c5027

Please sign in to comment.