mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
Merge pull request #21568 from yuwata/network-fix-json-format
network: fix json format
This commit is contained in:
commit
dc063e0978
@ -697,7 +697,7 @@ static int server_build_json_one_string(const char *str, NetworkConfigSource s,
|
||||
}
|
||||
|
||||
static int ntp_build_json(Link *link, JsonVariant **ret) {
|
||||
JsonVariant **elements;
|
||||
JsonVariant **elements = NULL;
|
||||
size_t n = 0;
|
||||
char **p;
|
||||
int r;
|
||||
|
@ -3985,7 +3985,7 @@ int json_buildv(JsonVariant **ret, va_list ap) {
|
||||
n = va_arg(ap, const char *);
|
||||
a = va_arg(ap, const struct in_addr *);
|
||||
|
||||
if (in4_addr_is_set(a) && current->n_suppress == 0) {
|
||||
if (a && in4_addr_is_set(a) && current->n_suppress == 0) {
|
||||
r = json_variant_new_string(&add, n);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
@ -4013,7 +4013,7 @@ int json_buildv(JsonVariant **ret, va_list ap) {
|
||||
n = va_arg(ap, const char *);
|
||||
a = va_arg(ap, const struct in6_addr *);
|
||||
|
||||
if (in6_addr_is_set(a) && current->n_suppress == 0) {
|
||||
if (a && in6_addr_is_set(a) && current->n_suppress == 0) {
|
||||
r = json_variant_new_string(&add, n);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
@ -4043,7 +4043,7 @@ int json_buildv(JsonVariant **ret, va_list ap) {
|
||||
a = va_arg(ap, const union in_addr_union *);
|
||||
f = va_arg(ap, int);
|
||||
|
||||
if (in_addr_is_set(f, a) && current->n_suppress == 0) {
|
||||
if (a && in_addr_is_set(f, a) && current->n_suppress == 0) {
|
||||
r = json_variant_new_string(&add, n);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
@ -4071,7 +4071,7 @@ int json_buildv(JsonVariant **ret, va_list ap) {
|
||||
n = va_arg(ap, const char *);
|
||||
a = va_arg(ap, const struct ether_addr *);
|
||||
|
||||
if (!ether_addr_is_null(a) && current->n_suppress == 0) {
|
||||
if (a && !ether_addr_is_null(a) && current->n_suppress == 0) {
|
||||
r = json_variant_new_string(&add, n);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
@ -4099,7 +4099,7 @@ int json_buildv(JsonVariant **ret, va_list ap) {
|
||||
n = va_arg(ap, const char *);
|
||||
a = va_arg(ap, const struct hw_addr_data *);
|
||||
|
||||
if (!hw_addr_is_null(a) && current->n_suppress == 0) {
|
||||
if (a && !hw_addr_is_null(a) && current->n_suppress == 0) {
|
||||
r = json_variant_new_string(&add, n);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
@ -3432,6 +3432,9 @@ class NetworkdStateFileTests(unittest.TestCase, Utilities):
|
||||
# make link state file updated
|
||||
check_output(*resolvectl_cmd, 'revert', 'dummy98', env=env)
|
||||
|
||||
# TODO: check json string
|
||||
check_output(*networkctl_cmd, '--json=short', 'status', env=env)
|
||||
|
||||
with open(path) as f:
|
||||
data = f.read()
|
||||
self.assertRegex(data, r'IPV4_ADDRESS_STATE=routable')
|
||||
@ -3458,6 +3461,9 @@ class NetworkdStateFileTests(unittest.TestCase, Utilities):
|
||||
check_output(*resolvectl_cmd, 'dnssec', 'dummy98', 'yes', env=env)
|
||||
check_output(*timedatectl_cmd, 'ntp-servers', 'dummy98', '2.fedora.pool.ntp.org', '3.fedora.pool.ntp.org', env=env)
|
||||
|
||||
# TODO: check json string
|
||||
check_output(*networkctl_cmd, '--json=short', 'status', env=env)
|
||||
|
||||
with open(path) as f:
|
||||
data = f.read()
|
||||
self.assertRegex(data, r'DNS=10.10.10.12#ccc.com 10.10.10.13 1111:2222::3333')
|
||||
@ -3470,6 +3476,9 @@ class NetworkdStateFileTests(unittest.TestCase, Utilities):
|
||||
|
||||
check_output(*timedatectl_cmd, 'revert', 'dummy98', env=env)
|
||||
|
||||
# TODO: check json string
|
||||
check_output(*networkctl_cmd, '--json=short', 'status', env=env)
|
||||
|
||||
with open(path) as f:
|
||||
data = f.read()
|
||||
self.assertRegex(data, r'DNS=10.10.10.12#ccc.com 10.10.10.13 1111:2222::3333')
|
||||
@ -3482,6 +3491,9 @@ class NetworkdStateFileTests(unittest.TestCase, Utilities):
|
||||
|
||||
check_output(*resolvectl_cmd, 'revert', 'dummy98', env=env)
|
||||
|
||||
# TODO: check json string
|
||||
check_output(*networkctl_cmd, '--json=short', 'status', env=env)
|
||||
|
||||
with open(path) as f:
|
||||
data = f.read()
|
||||
self.assertRegex(data, r'DNS=10.10.10.10#aaa.com 10.10.10.11:1111#bbb.com \[1111:2222::3333\]:1234#ccc.com')
|
||||
@ -4293,6 +4305,9 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
|
||||
self.assertNotRegex(output, r'8.8.8.8 via 192.168.5.[0-9]* proto dhcp src 192.168.5.[0-9]* metric 1024')
|
||||
self.assertNotRegex(output, r'9.9.9.9 via 192.168.5.[0-9]* proto dhcp src 192.168.5.[0-9]* metric 1024')
|
||||
|
||||
# TODO: check json string
|
||||
check_output(*networkctl_cmd, '--json=short', 'status', env=env)
|
||||
|
||||
def test_dhcp_client_ipv4_ipv6(self):
|
||||
copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-ipv4-only.network')
|
||||
start_networkd()
|
||||
@ -4830,6 +4845,9 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
|
||||
self.assertRegex(output, '192.168.5.1')
|
||||
self.assertRegex(output, '2600::1')
|
||||
|
||||
# TODO: check json string
|
||||
check_output(*networkctl_cmd, '--json=short', 'status', env=env)
|
||||
|
||||
def test_dhcp_client_use_dns_no(self):
|
||||
copy_unit_to_networkd_unit_path('25-veth.netdev', 'dhcp-server-veth-peer.network', 'dhcp-client-use-dns-no.network')
|
||||
|
||||
@ -5160,6 +5178,9 @@ class NetworkdIPv6PrefixTests(unittest.TestCase, Utilities):
|
||||
print(output)
|
||||
self.assertIn('example.com', output)
|
||||
|
||||
# TODO: check json string
|
||||
check_output(*networkctl_cmd, '--json=short', 'status', env=env)
|
||||
|
||||
def test_ipv6_route_prefix_deny_list(self):
|
||||
copy_unit_to_networkd_unit_path('25-veth.netdev', 'ipv6ra-prefix-client-deny-list.network', 'ipv6ra-prefix.network',
|
||||
'12-dummy.netdev', 'ipv6ra-uplink.network')
|
||||
|
Loading…
x
Reference in New Issue
Block a user