Skip to content

Commit

Permalink
Merge pull request #139 from ntsbtz/pytest_network_link
Browse files Browse the repository at this point in the history
pytest: Adding tests for network link configuration.
  • Loading branch information
ssahani authored Feb 15, 2022
2 parents 97c8487 + 9b0ebec commit 5e0199c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Configure
- NTP
- Routing Policy Rule
- Multiple default gateway with routing policy rules.
- Link's MAC, MTU.
- Link's MAC, MTU, ARP, Multicast, AllMulticast, Promiscuous, Unmanaged, Group, RequiredForOnline, RequiredFamilyForOnline, and ActivationPolicy.
- Create netdevs, vlan, vxlan, bridge, bond, veth, macvlan/macvtap, ipvlap/ipvtap, veth, tunnels(ipip, sit, gre, sit, vti), wireguard.
- Hostname.
- DHCPv4 Server.
Expand Down
2 changes: 1 addition & 1 deletion src/manager/network-config-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ _public_ int ncm_link_set_mode(int argc, char *argv[]) {
}

k = r;
r = manager_set_link_flag(p, k, "Unmanaged");
r = manager_set_link_flag(p, !k, "Unmanaged");
if (r < 0) {
printf("Failed to set link mode '%s': %s\n", p->ifname, g_strerror(-r));
return r;
Expand Down
64 changes: 64 additions & 0 deletions tests/network-config-manager-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,70 @@ def test_cli_set_mac(self):

assert(parser.get('Match', 'Name') == 'test99')
assert(parser.get('Link', 'MACAddress') == '00:0c:29:3a:bc:11')

def test_cli_set_option(self):
assert(link_exist('test99') == True)

subprocess.check_call(['nmctl', 'set-link-mode', 'test99', 'yes'])
assert(unit_exist('10-test99.network') == True)

subprocess.check_call(['sleep', '5'])
subprocess.check_call(['nmctl', 'set-link-option', 'test99', 'arp', 'yes', 'mc', 'yes', 'amc', '0', 'pcs', 'false', 'rfo', 'no'])

parser = configparser.ConfigParser()
parser.read(os.path.join(networkd_unit_file_path, '10-test99.network'))

assert(parser.get('Match', 'Name') == 'test99')
assert(parser.get('Link', 'ARP') == 'true')
assert(parser.get('Link', 'Multicast') == 'true')
assert(parser.get('Link', 'AllMulticast') == 'false')
assert(parser.get('Link', 'Promiscuous') == 'false')
assert(parser.get('Link', 'RequiredForOnline') == 'false')

def test_cli_set_group(self):
assert(link_exist('test99') == True)

subprocess.check_call(['nmctl', 'set-link-mode', 'test99', 'yes'])
assert(unit_exist('10-test99.network') == True)

subprocess.check_call(['sleep', '5'])
subprocess.check_call(['nmctl', 'set-link-group', 'test99', '2147483647'])

parser = configparser.ConfigParser()
parser.read(os.path.join(networkd_unit_file_path, '10-test99.network'))

assert(parser.get('Match', 'Name') == 'test99')
assert(parser.get('Link', 'Group') == '2147483647')

def test_cli_set_rf_online(self):
assert(link_exist('test99') == True)

subprocess.check_call(['nmctl', 'set-link-mode', 'test99', 'yes'])
assert(unit_exist('10-test99.network') == True)

subprocess.check_call(['sleep', '5'])
subprocess.check_call(['nmctl', 'set-link-rf-online', 'test99', 'ipv4'])

parser = configparser.ConfigParser()
parser.read(os.path.join(networkd_unit_file_path, '10-test99.network'))

assert(parser.get('Match', 'Name') == 'test99')
assert(parser.get('Link', 'RequiredFamilyForOnline') == 'ipv4')

def test_cli_set_act_policy(self):
assert(link_exist('test99') == True)

subprocess.check_call(['nmctl', 'set-link-mode', 'test99', 'yes'])
assert(unit_exist('10-test99.network') == True)

subprocess.check_call(['sleep', '5'])
subprocess.check_call(['nmctl', 'set-link-act-policy', 'test99', 'always-up'])

parser = configparser.ConfigParser()
parser.read(os.path.join(networkd_unit_file_path, '10-test99.network'))

assert(parser.get('Match', 'Name') == 'test99')
assert(parser.get('Link', 'ActivationPolicy') == 'always-up')

def test_cli_set_dhcp_type(self):
assert(link_exist('test99') == True)
Expand Down

0 comments on commit 5e0199c

Please sign in to comment.